Shaders ready.

This commit is contained in:
Lubos Lenco 2016-10-23 15:32:26 +02:00
parent 016dc01e5f
commit e50f60454e
14 changed files with 90 additions and 65 deletions

View file

@ -19,14 +19,17 @@ uniform sampler2D gbufferD;
uniform sampler2D gbuffer0;
uniform sampler2D gbuffer1;
#ifdef _CompoPos
uniform vec3 eye;
uniform vec3 eyeLook;
#endif
// #ifdef _CompoPos
// uniform vec3 eye;
// uniform vec3 eyeLook;
// #endif
#ifdef _CompoGlare
uniform vec3 light;
uniform mat4 VP;
uniform vec3 eye;
uniform vec3 eyeLook;
uniform float aspectRatio;
#endif
// #ifdef _CompoFXAA
@ -41,12 +44,10 @@ uniform float time;
uniform float dynamicScale;
#endif
uniform float aspectRatio;
in vec2 texCoord;
#ifdef _CompoPos
in vec3 viewRay;
#endif
// #ifdef _CompoPos
// in vec3 viewRay;
// #endif
out vec4 fragColor;
#ifdef _CompoFog
@ -73,6 +74,7 @@ float vignette() {
return 0.3 + 0.7 * pow(16.0 * texCoord.x * texCoord.y * (1.0 - texCoord.x) * (1.0 - texCoord.y), 0.2);
}
#ifdef _CompoGlare
// Based on lense flare implementation by musk
// https://www.shadertoy.com/view/4sX3Rs
vec3 lensflare(vec2 uv, vec2 pos) {
@ -102,6 +104,7 @@ vec3 lensflare(vec2 uv, vec2 pos) {
c.b += f23 + f43 + f53 + f63;
return c;
}
#endif
void main() {
vec2 texCo = texCoord;
@ -202,22 +205,24 @@ void main() {
#endif
#ifdef _CompoGlare
vec4 lndc = VP * vec4(light, 1.0);
lndc.xy /= lndc.w;
float lightDistance = distance(eye, light);
vec2 lss = lndc.xy * 0.5 + 0.5;
float lssdepth = linearize(texture(gbufferD, lss).r * 2.0 - 1.0);
if (lssdepth >= lightDistance) {
vec2 lensuv = (texCoord - 0.5) * 2.0;
lensuv.x *= aspectRatio;
vec3 lensflarecol = vec3(1.4, 1.2, 1.0) * lensflare(lensuv, lndc.xy);
col.rgb += lensflarecol;
if (dot(light, eyeLook) > 0.0) { // Facing light
vec4 lndc = VP * vec4(light, 1.0);
lndc.xy /= lndc.w;
vec2 lss = lndc.xy * 0.5 + 0.5;
float lssdepth = linearize(texture(gbufferD, lss).r * 2.0 - 1.0);
float lightDistance = distance(eye, light);
if (lightDistance <= lssdepth) {
vec2 lensuv = texCo * 2.0 - 1.0;
lensuv.x *= aspectRatio;
vec3 lensflarecol = vec3(1.4, 1.2, 1.0) * lensflare(lensuv, lndc.xy);
col.rgb += lensflarecol;
}
}
#endif
#ifdef _CompoGrain
// const float compoGrainStrength = 4.0;
float x = (texCoord.x + 4.0) * (texCoord.y + 4.0) * (time * 10.0);
float x = (texCo.x + 4.0) * (texCo.y + 4.0) * (time * 10.0);
col.rgb += vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01) - 0.005) * compoGrainStrength;
#endif
@ -244,8 +249,8 @@ void main() {
// #ifdef _CompoContrast
// -0.5 - 0.5
const float compoContrast = 0.2;
col.rgb = ((col.rgb - 0.5) * max(compoContrast + 1.0, 0.0)) + 0.5;
// const float compoContrast = 0.2;
// col.rgb = ((col.rgb - 0.5) * max(compoContrast + 1.0, 0.0)) + 0.5;
// #endif
// #ifdef _CompoBrighness
@ -254,7 +259,7 @@ void main() {
#ifdef _CompoLetterbox
// const float compoLetterboxSize = 0.1;
col.rgb *= 1.0 - step(0.5 - compoLetterboxSize, abs(0.5 - texCoord.y));
col.rgb *= 1.0 - step(0.5 - compoLetterboxSize, abs(0.5 - texCo.y));
#endif
fragColor = vec4(col, 1.0);

View file

@ -9,17 +9,27 @@
{
"name": "eye",
"link": "_cameraPosition",
"ifdef": ["_CompoPos"]
"ifdef": ["_CompoGlare"]
},
{
"name": "eye",
"link": "_cameraPosition",
"ifdef": ["_Disabled_CompoPos"]
},
{
"name": "eyeLook",
"link": "_cameraLook",
"ifdef": ["_CompoPos"]
"ifdef": ["_CompoGlare"]
},
{
"name": "eyeLook",
"link": "_cameraLook",
"ifdef": ["_Disabled_CompoPos"]
},
{
"name": "invVP",
"link": "_inverseViewProjectionMatrix",
"ifdef": ["_CompoPos"]
"ifdef": ["_Disabled_CompoPos"]
},
{
"name": "light",
@ -56,7 +66,8 @@
},
{
"name": "aspectRatio",
"link": "_aspectRatio"
"link": "_aspectRatioF",
"ifdef": ["_CompoGlare"]
}
],
"texture_params": [],

View file

@ -4,17 +4,17 @@
precision highp float;
#endif
#ifdef _CompoPos
uniform mat4 invVP;
uniform vec3 eye;
#endif
// #ifdef _CompoPos
// uniform mat4 invVP;
// uniform vec3 eye;
// #endif
in vec2 pos;
out vec2 texCoord;
#ifdef _CompoPos
out vec3 viewRay;
#endif
// #ifdef _CompoPos
// out vec3 viewRay;
// #endif
void main() {
// Scale vertex attribute to [0-1] range
@ -23,11 +23,11 @@ void main() {
gl_Position = vec4(pos.xy, 0.0, 1.0);
#ifdef _CompoPos
// #ifdef _CompoPos
// NDC (at the back of cube)
vec4 v = vec4(pos.xy, 1.0, 1.0);
v = vec4(invVP * v);
v.xyz /= v.w;
viewRay = v.xyz - eye;
#endif
// vec4 v = vec4(pos.xy, 1.0, 1.0);
// v = vec4(invVP * v);
// v.xyz /= v.w;
// viewRay = v.xyz - eye;
// #endif
}

View file

@ -132,7 +132,11 @@ void main() {
#endif
// Direct
vec3 direct = diffuseBRDF(albedo, roughness, dotNV, dotNL, dotVH, dotLV) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH, dotLH);
#ifdef _OrenNayar
vec3 direct = orenNayarDiffuseBRDF(albedo, roughness, dotNV, dotNL, dotVH) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
#else
vec3 direct = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
#endif
if (lightType == 2) { // Spot
float spotEffect = dot(lightDir, l);

View file

@ -146,7 +146,11 @@ void main() {
#endif
// Direct
vec3 direct = diffuseBRDF(albedo, roughness, dotNV, dotNL, dotVH, dotLV) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH, dotLH);
#ifdef _OrenNayar
vec3 direct = orenNayarDiffuseBRDF(albedo, roughness, dotNV, dotNL, dotVH) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
#else
vec3 direct = lambertDiffuseBRDF(albedo, dotNL) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH);
#endif
direct = direct * lightColor * lightStrength;
// Indirect
@ -168,7 +172,7 @@ void main() {
vec3 indirectSpecular = prefilteredColor * (f0 * envBRDF.x + envBRDF.y);
indirect += indirectSpecular;
#endif
indirect = indirect * envmapStrength // * lightColor * lightStrength;
indirect = indirect * envmapStrength; // * lightColor * lightStrength;
fragColor = vec4(vec3(direct * visibility + indirect), 1.0);
#ifdef _OccTex

View file

@ -26,7 +26,7 @@ out vec4 fragColor;
vec2 getVelocity(vec2 coord, float depth) {
vec4 currentPos = vec4(coord.xy * 2.0 - 1.0, depth, 1.0);
vec4 worldPos = vec4(getPos(eye, eyelook, viewRay, depth), 1.0);
vec4 worldPos = vec4(getPos(eye, eyeLook, viewRay, depth), 1.0);
vec4 previousPos = prevVP * worldPos;
previousPos /= previousPos.w;
vec2 velocity = (currentPos - previousPos).xy / 40.0;

View file

@ -34,7 +34,7 @@ vec3 color(vec2 coords, const float blur, const sampler2D tex, const vec2 texSte
}
vec3 dof(const vec2 texCoord, const float gdepth, const sampler2D tex, const sampler2D gbufferD, const vec2 texStep) {
float depth = linearize(gdepth * 0.5 + 0.5);
float depth = linearize(gdepth);
const float fDepth = compoDOFDistance;
// float fDepth = linearize(texture(gbufferD, focus).r * 2.0 - 1.0); // Autofocus
@ -218,7 +218,7 @@ vec3 dof(const vec2 texCoord, const float gdepth, const sampler2D tex, const sam
col /= s;
}
return col;
}

View file

@ -6,6 +6,7 @@ precision mediump float;
#endif
#include "../compiled.glsl"
#include "../std/gbuffer.glsl"
uniform sampler2D gbufferD;
#ifndef _NoShadows

View file

@ -17,7 +17,7 @@ class RigidBody extends Trait {
#else
var shape:Shape;
var _motionState:BtMotionState;
var _motionState:BtMotionStatePointer;
public var physics:PhysicsWorld;
public var transform:Transform = null;
@ -128,7 +128,7 @@ class RigidBody extends Trait {
if (!shapeConvexCreated) {
if (shape != Shape.StaticMesh && shape != Shape.Terrain) {
_shape.ptr.calculateLocalInertia(mass, _inertia.value);
_shape.ptr.calculateLocalInertia(mass, _inertia);
}
var _bodyCI = BtRigidBodyConstructionInfo.create(mass, _motionState, _shape, _inertia.value);
body = BtRigidBody.create(_bodyCI.value);
@ -136,7 +136,7 @@ class RigidBody extends Trait {
body.ptr.setRollingFriction(friction);
}
else {
_shapeConvex.ptr.calculateLocalInertia(mass, _inertia.value);
_shapeConvex.ptr.calculateLocalInertia(mass, _inertia);
var _bodyCI = BtRigidBodyConstructionInfo.create(mass, _motionState, _shapeConvex, _inertia.value);
body = BtRigidBody.create(_bodyCI.value);
}

View file

@ -1666,8 +1666,6 @@ class ArmoryExporter:
return
print('Exporting mesh ' + bobject.data.name)
if bobject.type != 'FONT' and len(bobject.data.vertices) > 40000:
print('Armory Warning: "' + bobject.name + '" contains over 40000 vertices, split mesh to smaller parts to fit into 16-bit indices')
o = {}
o['name'] = oid
@ -1970,10 +1968,12 @@ class ArmoryExporter:
# Viewport Camera - override fov for every camera for now
if bpy.data.worlds['Arm'].arm_play_viewport_camera:
# Extract fov from projection
# yscale = self.get_viewport_projection_matrix()[1][1]
# fov = math.atan(1.0 / yscale) * 0.9
# o['fov'] = fov
o['fov'] = math.pi / 3.0
yscale = self.get_viewport_projection_matrix()[1][1]
if yscale < 0:
yscale *= -1 # Reverse
fov = math.atan(1.0 / yscale) * 0.9
o['fov'] = fov
# o['fov'] = math.pi / 3.0
if objref.type == 'PERSP':
o['type'] = 'perspective'

View file

@ -403,7 +403,7 @@ def clean_project():
wrd = bpy.data.worlds['Arm']
# Preserve envmaps
if not wrd.arm_clean_envmaps:
if wrd.arm_cache_envmaps:
envmaps_path = 'build/compiled/Assets/envmaps'
if os.path.isdir(envmaps_path):
shutil.move(envmaps_path, '.')
@ -413,7 +413,7 @@ def clean_project():
shutil.rmtree('build')
# Move envmaps back
if not wrd.arm_clean_envmaps and os.path.isdir('envmaps'):
if wrd.arm_cache_envmaps and os.path.isdir('envmaps'):
os.makedirs('build/compiled/Assets')
shutil.move('envmaps', 'build/compiled/Assets')

View file

@ -224,7 +224,7 @@ def make_draw_compositor(stage, node_group, node, with_fxaa=False):
compositor_defs = make_compositor.parse_defs(bpy.data.scenes[0].node_tree) # Thrown in scene 0 for now
# Additional compositor flags
compo_depth = False # Read depth
compo_pos = False # Construct position from depth
# compo_pos = False # Construct position from depth
if with_fxaa: # FXAA directly in compositor, useful for forward path
compositor_defs += '_CompoFXAA'
if wrd.generate_letterbox:
@ -235,13 +235,13 @@ def make_draw_compositor(stage, node_group, node, with_fxaa=False):
compositor_defs += '_CompoExposure'
if wrd.generate_fog:
compositor_defs += '_CompoFog'
compo_pos = True
# compo_pos = True
if build_node_tree.cam.dof_distance > 0.0:
compositor_defs += '_CompoDOF'
compo_depth = True
if compo_pos:
compositor_defs += '_CompoPos'
compo_depth = True
# if compo_pos:
# compositor_defs += '_CompoPos'
# compo_depth = True
if compo_depth:
compositor_defs += '_CompoDepth'

View file

@ -52,7 +52,7 @@ def init_properties():
bpy.types.World.arm_object_advanced = BoolProperty(name="Advanced", default=False)
bpy.types.World.arm_material_advanced = BoolProperty(name="Advanced", default=False)
bpy.types.World.arm_cache_shaders = BoolProperty(name="Cache Shaders", description="Do not rebuild existing shaders", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.arm_clean_envmaps = BoolProperty(name="Clean Envmaps", description="Remove prefiltered maps when cleaning project", default=True)
bpy.types.World.arm_cache_envmaps = BoolProperty(name="Cache Envmaps", description="Do not remove prefiltered maps when cleaning project", default=True)
bpy.types.World.arm_play_live_patch = BoolProperty(name="Live Patching", description="Sync running player data to Blender", default=True)
bpy.types.World.arm_play_auto_build = BoolProperty(name="Auto Build", description="Rebuild scene on operator changes", default=True)
bpy.types.World.arm_play_viewport_camera = BoolProperty(name="Viewport Camera", description="Start player at viewport camera position", default=False)
@ -178,7 +178,7 @@ def init_properties():
bpy.types.World.generate_ssao_texture_scale = bpy.props.FloatProperty(name="Texture Scale", default=1.0, min=0.0, max=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_shadows = bpy.props.BoolProperty(name="Shadows", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom = bpy.props.BoolProperty(name="Bloom", default=True, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_treshold = bpy.props.FloatProperty(name="Treshold", default=4.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_treshold = bpy.props.FloatProperty(name="Treshold", default=6.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_strength = bpy.props.FloatProperty(name="Strength", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_bloom_radius = bpy.props.FloatProperty(name="Radius", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.generate_motion_blur = bpy.props.BoolProperty(name="Motion Blur", default=True, update=assets.invalidate_shader_cache)

View file

@ -433,7 +433,7 @@ class ArmoryBuildPanel(bpy.types.Panel):
layout.prop(wrd, 'arm_build_advanced')
if wrd.arm_build_advanced:
layout.prop(wrd, 'arm_cache_shaders')
layout.prop(wrd, 'arm_clean_envmaps')
layout.prop(wrd, 'arm_cache_envmaps')
layout.prop(wrd, 'arm_minimize')
layout.prop(wrd, 'arm_optimize_mesh')
layout.prop(wrd, 'arm_sampled_animation')