God-rays pass base.

This commit is contained in:
Lubos Lenco 2016-05-12 21:03:23 +02:00
parent 96fa1d6d32
commit 9431337efe
12 changed files with 197 additions and 90 deletions

View file

@ -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
}
}

View file

@ -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();

View file

@ -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()

View file

@ -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;
}

View file

@ -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')

View file

@ -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);

View file

@ -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",

View file

@ -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);

View file

@ -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",

View file

@ -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;
}

View file

@ -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"
}
]
}

View file

@ -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);
}