From 9431337efe160bcdb725323b69418544d756f216 Mon Sep 17 00:00:00 2001 From: Lubos Lenco Date: Thu, 12 May 2016 21:03:23 +0200 Subject: [PATCH] God-rays pass base. --- Sources/cycles/trait/RigidBody.hx | 4 +- Sources/cycles/trait/VehicleBody.hx | 2 +- blender/start.py | 31 ------- raw/bloom_pass/bloom_pass.frag.glsl | 2 +- raw/compile.py | 4 + raw/deferred_light/deferred_light.frag.glsl | 52 +++++------ raw/deferred_light/deferred_light.shader.json | 6 +- raw/forward/forward.frag.glsl | 50 +++++------ raw/forward/forward.shader.json | 6 +- raw/godrays_pass/godrays_pass.frag.glsl | 87 +++++++++++++++++++ raw/godrays_pass/godrays_pass.shader.json | 25 ++++++ raw/godrays_pass/godrays_pass.vert.glsl | 18 ++++ 12 files changed, 197 insertions(+), 90 deletions(-) delete mode 100755 blender/start.py create mode 100644 raw/godrays_pass/godrays_pass.frag.glsl create mode 100755 raw/godrays_pass/godrays_pass.shader.json create mode 100644 raw/godrays_pass/godrays_pass.vert.glsl diff --git a/Sources/cycles/trait/RigidBody.hx b/Sources/cycles/trait/RigidBody.hx index 88423ecb..59350491 100644 --- a/Sources/cycles/trait/RigidBody.hx +++ b/Sources/cycles/trait/RigidBody.hx @@ -139,7 +139,7 @@ class RigidBody extends Trait { body.ptr.setRollingFriction(friction); } else { - _shapeConvex.value.calculateLocalInertia(mass, _inertia.value); + _shapeConvex.ptr.calculateLocalInertia(mass, _inertia.value); var _bodyCI = BtRigidBodyConstructionInfo.create(mass, _motionState, _shapeConvex, _inertia.value); body = BtRigidBody.create(_bodyCI.value); } @@ -239,7 +239,7 @@ class RigidBody extends Trait { #if js shape.addPoint(BtVector3.create(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]).value, true); #elseif cpp - shape.value.addPoint(BtVector3.create(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]).value, true); + shape.ptr.addPoint(BtVector3.create(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]).value, true); #end } } diff --git a/Sources/cycles/trait/VehicleBody.hx b/Sources/cycles/trait/VehicleBody.hx index 6d084516..4ee5e6d1 100644 --- a/Sources/cycles/trait/VehicleBody.hx +++ b/Sources/cycles/trait/VehicleBody.hx @@ -216,7 +216,7 @@ class VehicleBody extends Trait { function createRigidBody(mass:Float, shape:BtCompoundShapePointer):BtRigidBodyPointer { var localInertia = BtVector3.create(0, 0, 0); - shape.value.calculateLocalInertia(mass, localInertia.value); + shape.ptr.calculateLocalInertia(mass, localInertia.value); var centerOfMassOffset = BtTransform.create(); centerOfMassOffset.value.setIdentity(); diff --git a/blender/start.py b/blender/start.py deleted file mode 100755 index b25b6414..00000000 --- a/blender/start.py +++ /dev/null @@ -1,31 +0,0 @@ -import project -import nodes_logic -import nodes_pipeline -import nodes_world -import armory -import traits_animation -import traits_params -import traits -import props - -def register(): - project.register() - nodes_logic.register() - nodes_pipeline.register() - nodes_world.register() - armory.register() - traits_animation.register() - traits_params.register() - traits.register() - props.register() - -def unregister(): - project.unregister() - nodes_logic.unregister() - nodes_pipeline.unregister() - nodes_world.unregister() - armory.unregister() - traits_animation.unregister() - traits_params.unregister() - traits.unregister() - props.unregister() diff --git a/raw/bloom_pass/bloom_pass.frag.glsl b/raw/bloom_pass/bloom_pass.frag.glsl index 1bf5c31e..da8f475b 100644 --- a/raw/bloom_pass/bloom_pass.frag.glsl +++ b/raw/bloom_pass/bloom_pass.frag.glsl @@ -11,7 +11,7 @@ in vec2 texCoord; void main() { vec4 col = texture(tex, texCoord); float brightness = dot(col.rgb, vec3(0.2126, 0.7152, 0.0722)); - if (brightness > 2.7) { + if (brightness > 2.0) { gl_FragColor.rgb = vec3(col.rgb); return; } diff --git a/raw/compile.py b/raw/compile.py index 95b7fe7a..29bd4884 100644 --- a/raw/compile.py +++ b/raw/compile.py @@ -67,6 +67,10 @@ os.chdir('../water_pass') make_resources.make('water_pass.shader.json') make_variants.make('water_pass.shader.json') +os.chdir('../godrays_pass') +make_resources.make('godrays_pass.shader.json') +make_variants.make('godrays_pass.shader.json') + # os.chdir('../pt_trace_pass') # make_resources.make('pt_trace_pass.shader.json') # make_variants.make('pt_trace_pass.shader.json') diff --git a/raw/deferred_light/deferred_light.frag.glsl b/raw/deferred_light/deferred_light.frag.glsl index d7ec2773..f8cab4e7 100644 --- a/raw/deferred_light/deferred_light.frag.glsl +++ b/raw/deferred_light/deferred_light.frag.glsl @@ -17,8 +17,8 @@ uniform sampler2D shadowMap; uniform sampler2D senvmapRadiance; uniform sampler2D senvmapIrradiance; uniform sampler2D senvmapBrdf; -uniform sampler2D sltcMat; -uniform sampler2D sltcMag; +// uniform sampler2D sltcMat; +// uniform sampler2D sltcMag; // uniform mat4 invVP; uniform mat4 LMVP; @@ -454,32 +454,32 @@ void main() { // LTC - const float rectSizeX = 2.5; - const float rectSizeY = 1.2; - vec3 ex = vec3(1, 0, 0)*rectSizeX; - vec3 ey = vec3(0, 0, 1)*rectSizeY; - vec3 p1 = light - ex + ey; - vec3 p2 = light + ex + ey; - vec3 p3 = light + ex - ey; - vec3 p4 = light - ex - ey; - float theta = acos(dotNV); - vec2 tuv = vec2(roughness, theta/(0.5*PI)); - tuv = tuv*LUT_SCALE + LUT_BIAS; + // const float rectSizeX = 2.5; + // const float rectSizeY = 1.2; + // vec3 ex = vec3(1, 0, 0)*rectSizeX; + // vec3 ey = vec3(0, 0, 1)*rectSizeY; + // vec3 p1 = light - ex + ey; + // vec3 p2 = light + ex + ey; + // vec3 p3 = light + ex - ey; + // vec3 p4 = light - ex - ey; + // float theta = acos(dotNV); + // vec2 tuv = vec2(roughness, theta/(0.5*PI)); + // tuv = tuv*LUT_SCALE + LUT_BIAS; - vec4 t = texture(sltcMat, tuv); - mat3 Minv = mat3( - vec3( 1, t.y, 0), - vec3( 0, 0, t.z), - vec3(t.w, 0, t.x) - ); + // vec4 t = texture(sltcMat, tuv); + // mat3 Minv = mat3( + // vec3( 1, t.y, 0), + // vec3( 0, 0, t.z), + // vec3(t.w, 0, t.x) + // ); - vec3 ltcspec = LTC_Evaluate(n, v, p, Minv, p1, p2, p3, p4, true); - ltcspec *= texture(sltcMag, tuv).a; - vec3 ltcdiff = LTC_Evaluate(n, v, p, mat3(1), p1, p2, p3, p4, true); - vec3 ltccol = ltcspec + ltcdiff * albedo; - ltccol /= 2.0*PI; - // outColor.rgb = ltccol * 12.0 * visibility + (indirect / 14.0 * ao); - outColor.rgb = ltccol * visibility + (indirect / 2.0 * ao); + // vec3 ltcspec = LTC_Evaluate(n, v, p, Minv, p1, p2, p3, p4, true); + // ltcspec *= texture(sltcMag, tuv).a; + // vec3 ltcdiff = LTC_Evaluate(n, v, p, mat3(1), p1, p2, p3, p4, true); + // vec3 ltccol = ltcspec + ltcdiff * albedo; + // ltccol /= 2.0*PI; + // // outColor.rgb = ltccol * 12.0 * visibility + (indirect / 14.0 * ao); + // outColor.rgb = ltccol * visibility + (indirect / 2.0 * ao); diff --git a/raw/deferred_light/deferred_light.shader.json b/raw/deferred_light/deferred_light.shader.json index 72390be9..f13126aa 100755 --- a/raw/deferred_light/deferred_light.shader.json +++ b/raw/deferred_light/deferred_light.shader.json @@ -51,11 +51,13 @@ }, { "id": "sltcMat", - "link": "_ltcMat" + "link": "_ltcMat", + "ifdef": ["_PolyLight"] }, { "id": "sltcMag", - "link": "_ltcMag" + "link": "_ltcMag", + "ifdef": ["_PolyLight"] } ], "vertex_shader": "deferred_light.vert.glsl", diff --git a/raw/forward/forward.frag.glsl b/raw/forward/forward.frag.glsl index 31bd0675..7c0e38a7 100644 --- a/raw/forward/forward.frag.glsl +++ b/raw/forward/forward.frag.glsl @@ -18,8 +18,8 @@ uniform sampler2D shadowMap; uniform sampler2D senvmapRadiance; uniform sampler2D senvmapIrradiance; uniform sampler2D senvmapBrdf; -uniform sampler2D sltcMat; -uniform sampler2D sltcMag; +// uniform sampler2D sltcMat; +// uniform sampler2D sltcMag; #ifdef _NMTex uniform sampler2D snormal; #endif @@ -516,30 +516,30 @@ void main() { #endif // LTC - const float rectSizeX = 2.5; - const float rectSizeY = 1.2; - vec3 ex = vec3(1, 0, 0)*rectSizeX; - vec3 ey = vec3(0, 0, 1)*rectSizeY; - vec3 p1 = light - ex + ey; - vec3 p2 = light + ex + ey; - vec3 p3 = light + ex - ey; - vec3 p4 = light - ex - ey; - float theta = acos(dotNV); - vec2 tuv = vec2(roughness, theta/(0.5*PI)); - tuv = tuv*LUT_SCALE + LUT_BIAS; + // const float rectSizeX = 2.5; + // const float rectSizeY = 1.2; + // vec3 ex = vec3(1, 0, 0)*rectSizeX; + // vec3 ey = vec3(0, 0, 1)*rectSizeY; + // vec3 p1 = light - ex + ey; + // vec3 p2 = light + ex + ey; + // vec3 p3 = light + ex - ey; + // vec3 p4 = light - ex - ey; + // float theta = acos(dotNV); + // vec2 tuv = vec2(roughness, theta/(0.5*PI)); + // tuv = tuv*LUT_SCALE + LUT_BIAS; - vec4 t = texture(sltcMat, tuv); - mat3 Minv = mat3( - vec3( 1, t.y, 0), - vec3( 0, 0, t.z), - vec3(t.w, 0, t.x) - ); + // vec4 t = texture(sltcMat, tuv); + // mat3 Minv = mat3( + // vec3( 1, t.y, 0), + // vec3( 0, 0, t.z), + // vec3(t.w, 0, t.x) + // ); - vec3 ltcspec = LTC_Evaluate(n, v, position, Minv, p1, p2, p3, p4, true); - ltcspec *= texture(sltcMag, tuv).a; - vec3 ltcdiff = LTC_Evaluate(n, v, position, mat3(1), p1, p2, p3, p4, true); - vec3 ltccol = ltcspec + ltcdiff * albedo; - ltccol /= 2.0*PI; + // vec3 ltcspec = LTC_Evaluate(n, v, position, Minv, p1, p2, p3, p4, true); + // ltcspec *= texture(sltcMag, tuv).a; + // vec3 ltcdiff = LTC_Evaluate(n, v, position, mat3(1), p1, p2, p3, p4, true); + // vec3 ltccol = ltcspec + ltcdiff * albedo; + // ltccol /= 2.0*PI; @@ -567,7 +567,7 @@ void main() { outColor.rgb *= occlusion; #endif // LTC - outColor.rgb = ltccol * 10.0 * visibility + indirect / 14.0; + // outColor.rgb = ltccol * 10.0 * visibility + indirect / 14.0; } else { outColor = vec4(baseColor * visibility, 1.0); diff --git a/raw/forward/forward.shader.json b/raw/forward/forward.shader.json index 80e37221..5684243e 100755 --- a/raw/forward/forward.shader.json +++ b/raw/forward/forward.shader.json @@ -64,11 +64,13 @@ }, { "id": "sltcMat", - "link": "_ltcMat" + "link": "_ltcMat", + "ifdef": ["_PolyLight"] }, { "id": "sltcMag", - "link": "_ltcMag" + "link": "_ltcMag", + "ifdef": ["_PolyLight"] } ], "vertex_shader": "forward.vert.glsl", diff --git a/raw/godrays_pass/godrays_pass.frag.glsl b/raw/godrays_pass/godrays_pass.frag.glsl new file mode 100644 index 00000000..8ed337ed --- /dev/null +++ b/raw/godrays_pass/godrays_pass.frag.glsl @@ -0,0 +1,87 @@ +// http://http.developer.nvidia.com/GPUGems3/gpugems3_ch13.html +#version 450 + +#ifdef GL_ES +precision mediump float; +#endif + +uniform sampler2D tex; + +in vec2 texCoord; + +void main() { + const float decay = 0.96815; + const float exposure = 0.2; + const float density = 0.926; + const float weight = 0.58767; + const int NUM_SAMPLES = 10; // 100 + vec2 tc = texCoord;// * vec2(800, 600); + vec2 lightPositionOnScreen = vec2(0.3, 0.3); + vec2 deltaTexCoord = (tc - lightPositionOnScreen.xy); + deltaTexCoord *= 1.0 / float(NUM_SAMPLES) * density; + float illuminationDecay = 1.0; + vec4 color = texture(tex, tc) * 0.4; + // for (int i=0; i < NUM_SAMPLES; i++) { + tc -= deltaTexCoord; + vec4 sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // + tc -= deltaTexCoord; + sampleCol = texture(tex, tc) * 0.4; + sampleCol *= illuminationDecay * weight; + color += sampleCol; + illuminationDecay *= decay; + // } + + gl_FragColor = color; +} diff --git a/raw/godrays_pass/godrays_pass.shader.json b/raw/godrays_pass/godrays_pass.shader.json new file mode 100755 index 00000000..b8bee79d --- /dev/null +++ b/raw/godrays_pass/godrays_pass.shader.json @@ -0,0 +1,25 @@ +{ + "contexts": [ + { + "id": "godrays_pass", + "params": [ + { + "id": "depth_write", + "value": "true" + }, + { + "id": "compare_mode", + "value": "always" + }, + { + "id": "cull_mode", + "value": "none" + } + ], + "links": [], + "texture_params": [], + "vertex_shader": "godrays_pass.vert.glsl", + "fragment_shader": "godrays_pass.frag.glsl" + } + ] +} diff --git a/raw/godrays_pass/godrays_pass.vert.glsl b/raw/godrays_pass/godrays_pass.vert.glsl new file mode 100644 index 00000000..e1cc9c08 --- /dev/null +++ b/raw/godrays_pass/godrays_pass.vert.glsl @@ -0,0 +1,18 @@ +#version 450 + +#ifdef GL_ES +precision highp float; +#endif + +in vec2 pos; + +out vec2 texCoord; + +const vec2 madd = vec2(0.5, 0.5); + +void main() { + // Scale vertex attribute to [0-1] range + texCoord = pos.xy * madd + madd; + + gl_Position = vec4(pos.xy, 0.0, 1.0); +}