Get rid of TexGen magic and do the projective texturing for shadow mapping ourself
This commit is contained in:
parent
746954cbf2
commit
59e0f41283
5 changed files with 34 additions and 215 deletions
|
@ -4,26 +4,14 @@
|
||||||
<parameters>
|
<parameters>
|
||||||
<filtering><use>/sim/rendering/shadows/filtering</use></filtering>
|
<filtering><use>/sim/rendering/shadows/filtering</use></filtering>
|
||||||
</parameters>
|
</parameters>
|
||||||
<technique n="8">
|
<technique n="9">
|
||||||
<predicate>
|
<predicate>
|
||||||
<and>
|
<and>
|
||||||
<property>/sim/rendering/shadows/enabled</property>
|
<property>/sim/rendering/shadows/enabled</property>
|
||||||
<or> <!-- filtering >= 3 || ( filtering >= 2 && num-cascades >= 2 ) -->
|
<less> <!-- filtering >= 2 -->
|
||||||
<less>
|
<value type="float">1.0</value>
|
||||||
<value type="float">2.0</value>
|
<float-property>/sim/rendering/shadows/filtering</float-property>
|
||||||
<float-property>/sim/rendering/shadows/filtering</float-property>
|
</less>
|
||||||
</less>
|
|
||||||
<and>
|
|
||||||
<less>
|
|
||||||
<value type="float">1.0</value>
|
|
||||||
<float-property>/sim/rendering/shadows/filtering</float-property>
|
|
||||||
</less>
|
|
||||||
<less>
|
|
||||||
<value type="float">1.0</value>
|
|
||||||
<float-property>/sim/rendering/shadows/num-cascades</float-property>
|
|
||||||
</less>
|
|
||||||
</and>
|
|
||||||
</or>
|
|
||||||
</and>
|
</and>
|
||||||
</predicate>
|
</predicate>
|
||||||
<pass>
|
<pass>
|
||||||
|
@ -110,18 +98,17 @@
|
||||||
- fg_Planes
|
- fg_Planes
|
||||||
- fg_ShadowNumber
|
- fg_ShadowNumber
|
||||||
- fg_ShadowDistances
|
- fg_ShadowDistances
|
||||||
|
- fg_ShadowMatrix_0
|
||||||
|
- fg_ShadowMatrix_1
|
||||||
|
- fg_ShadowMatrix_2
|
||||||
|
- fg_ShadowMatrix_3
|
||||||
-->
|
-->
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
<technique n="9">
|
<technique n="10">
|
||||||
<predicate>
|
<predicate>
|
||||||
<and>
|
<and>
|
||||||
<property>/sim/rendering/shadows/enabled</property>
|
<property>/sim/rendering/shadows/enabled</property>
|
||||||
<!-- num-cascades >= 2 -->
|
|
||||||
<less>
|
|
||||||
<value type="float">1.0</value>
|
|
||||||
<float-property>/sim/rendering/shadows/num-cascades</float-property>
|
|
||||||
</less>
|
|
||||||
</and>
|
</and>
|
||||||
</predicate>
|
</predicate>
|
||||||
<pass>
|
<pass>
|
||||||
|
@ -203,92 +190,10 @@
|
||||||
- fg_Planes
|
- fg_Planes
|
||||||
- fg_ShadowNumber
|
- fg_ShadowNumber
|
||||||
- fg_ShadowDistances
|
- fg_ShadowDistances
|
||||||
-->
|
- fg_ShadowMatrix_0
|
||||||
</pass>
|
- fg_ShadowMatrix_1
|
||||||
</technique>
|
- fg_ShadowMatrix_2
|
||||||
<technique n="10">
|
- fg_ShadowMatrix_3
|
||||||
<predicate>
|
|
||||||
<property>/sim/rendering/shadows/enabled</property>
|
|
||||||
</predicate>
|
|
||||||
<pass>
|
|
||||||
<lighting>false</lighting>
|
|
||||||
<depth>
|
|
||||||
<enabled>false</enabled>
|
|
||||||
</depth>
|
|
||||||
<blend>
|
|
||||||
<source>one</source>
|
|
||||||
<destination>one</destination>
|
|
||||||
</blend>
|
|
||||||
<render-bin>
|
|
||||||
<bin-number>1</bin-number>
|
|
||||||
<bin-name>RenderBin</bin-name>
|
|
||||||
</render-bin>
|
|
||||||
<texture-unit>
|
|
||||||
<unit>0</unit>
|
|
||||||
<type>depth-buffer</type>
|
|
||||||
</texture-unit>
|
|
||||||
<texture-unit>
|
|
||||||
<unit>1</unit>
|
|
||||||
<type>normal-buffer</type>
|
|
||||||
</texture-unit>
|
|
||||||
<texture-unit>
|
|
||||||
<unit>2</unit>
|
|
||||||
<type>diffuse-buffer</type>
|
|
||||||
</texture-unit>
|
|
||||||
<texture-unit>
|
|
||||||
<unit>3</unit>
|
|
||||||
<type>spec-emis-buffer</type>
|
|
||||||
</texture-unit>
|
|
||||||
<texture-unit>
|
|
||||||
<unit>4</unit>
|
|
||||||
<type>shadow-buffer</type>
|
|
||||||
</texture-unit>
|
|
||||||
<program>
|
|
||||||
<vertex-shader>Shaders/sunlight-simple.vert</vertex-shader>
|
|
||||||
<fragment-shader>Shaders/sunlight-simple.frag</fragment-shader>
|
|
||||||
<fragment-shader>Shaders/gbuffer-functions.frag</fragment-shader>
|
|
||||||
</program>
|
|
||||||
<uniform>
|
|
||||||
<name>depth_tex</name>
|
|
||||||
<type>sampler-2d</type>
|
|
||||||
<value type="int">0</value>
|
|
||||||
</uniform>
|
|
||||||
<uniform>
|
|
||||||
<name>normal_tex</name>
|
|
||||||
<type>sampler-2d</type>
|
|
||||||
<value type="int">1</value>
|
|
||||||
</uniform>
|
|
||||||
<uniform>
|
|
||||||
<name>color_tex</name>
|
|
||||||
<type>sampler-2d</type>
|
|
||||||
<value type="int">2</value>
|
|
||||||
</uniform>
|
|
||||||
<uniform>
|
|
||||||
<name>spec_emis_tex</name>
|
|
||||||
<type>sampler-2d</type>
|
|
||||||
<value type="int">3</value>
|
|
||||||
</uniform>
|
|
||||||
<uniform>
|
|
||||||
<name>shadow_tex</name>
|
|
||||||
<type>sampler-2d</type>
|
|
||||||
<value type="int">4</value>
|
|
||||||
</uniform>
|
|
||||||
<uniform>
|
|
||||||
<name>filtering</name>
|
|
||||||
<type>int</type>
|
|
||||||
<value type="int"><use>filtering</use></value>
|
|
||||||
</uniform>
|
|
||||||
<!-- The following uniforms are automatically defined and initialized :
|
|
||||||
- fg_SunAmbientColor
|
|
||||||
- fg_SunDiffuseColor
|
|
||||||
- fg_SunSpecularColor
|
|
||||||
- fg_SunDirection
|
|
||||||
- fg_ProjectionMatrixInverse
|
|
||||||
- fg_ViewMatrixInverse
|
|
||||||
- fg_ViewMatrix
|
|
||||||
- fg_Planes
|
|
||||||
- fg_ShadowNumber
|
|
||||||
- fg_ShadowDistances
|
|
||||||
-->
|
-->
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
|
|
|
@ -10,6 +10,12 @@ uniform vec3 fg_SunDirection;
|
||||||
uniform vec3 fg_Planes;
|
uniform vec3 fg_Planes;
|
||||||
uniform int fg_ShadowNumber;
|
uniform int fg_ShadowNumber;
|
||||||
uniform vec4 fg_ShadowDistances;
|
uniform vec4 fg_ShadowDistances;
|
||||||
|
|
||||||
|
uniform mat4 fg_ShadowMatrix_0;
|
||||||
|
uniform mat4 fg_ShadowMatrix_1;
|
||||||
|
uniform mat4 fg_ShadowMatrix_2;
|
||||||
|
uniform mat4 fg_ShadowMatrix_3;
|
||||||
|
|
||||||
varying vec3 ray;
|
varying vec3 ray;
|
||||||
|
|
||||||
vec3 position( vec3 viewDir, vec2 coords, sampler2D depth_tex );
|
vec3 position( vec3 viewDir, vec2 coords, sampler2D depth_tex );
|
||||||
|
@ -26,24 +32,24 @@ vec4 DynamicShadow( in vec4 ecPosition, out vec4 tint )
|
||||||
if (fg_ShadowNumber == 1)
|
if (fg_ShadowNumber == 1)
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
tint = vec4(0.0,1.0,0.0,1.0);
|
tint = vec4(0.0,1.0,0.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_0 * ecPosition;
|
||||||
} else if (ecPosition.z > -fg_ShadowDistances.y && fg_ShadowNumber > 1) {
|
} else if (ecPosition.z > -fg_ShadowDistances.y && fg_ShadowNumber > 1) {
|
||||||
index = 2;
|
index = 2;
|
||||||
shift = vec2( 0.0, 0.5 );
|
shift = vec2( 0.0, 0.5 );
|
||||||
tint = vec4(0.0,0.0,1.0,1.0);
|
tint = vec4(0.0,0.0,1.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_1 * ecPosition;
|
||||||
} else if (ecPosition.z > -fg_ShadowDistances.z && fg_ShadowNumber > 2) {
|
} else if (ecPosition.z > -fg_ShadowDistances.z && fg_ShadowNumber > 2) {
|
||||||
index = 3;
|
index = 3;
|
||||||
shift = vec2( 0.5, 0.0 );
|
shift = vec2( 0.5, 0.0 );
|
||||||
tint = vec4(1.0,1.0,0.0,1.0);
|
tint = vec4(1.0,1.0,0.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_2 * ecPosition;
|
||||||
} else if (ecPosition.z > -fg_ShadowDistances.w && fg_ShadowNumber > 3) {
|
} else if (ecPosition.z > -fg_ShadowDistances.w && fg_ShadowNumber > 3) {
|
||||||
shift = vec2( 0.5, 0.5 );
|
shift = vec2( 0.5, 0.5 );
|
||||||
tint = vec4(1.0,0.0,0.0,1.0);
|
tint = vec4(1.0,0.0,0.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_3 * ecPosition;
|
||||||
} else {
|
} else {
|
||||||
return vec4(1.1,1.1,0.0,1.0); // outside, clamp to border
|
return vec4(1.1,1.1,0.0,1.0); // outside, clamp to border
|
||||||
}
|
}
|
||||||
coords.s = dot( ecPosition, gl_EyePlaneS[index] );
|
|
||||||
coords.t = dot( ecPosition, gl_EyePlaneT[index] );
|
|
||||||
coords.p = dot( ecPosition, gl_EyePlaneR[index] );
|
|
||||||
coords.q = dot( ecPosition, gl_EyePlaneQ[index] );
|
|
||||||
coords.st *= factor;
|
coords.st *= factor;
|
||||||
coords.st += shift;
|
coords.st += shift;
|
||||||
return coords;
|
return coords;
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
uniform mat4 fg_ViewMatrix;
|
|
||||||
uniform sampler2D depth_tex;
|
|
||||||
uniform sampler2D normal_tex;
|
|
||||||
uniform sampler2D color_tex;
|
|
||||||
uniform sampler2D spec_emis_tex;
|
|
||||||
uniform sampler2DShadow shadow_tex;
|
|
||||||
uniform vec4 fg_SunDiffuseColor;
|
|
||||||
uniform vec4 fg_SunSpecularColor;
|
|
||||||
uniform vec3 fg_SunDirection;
|
|
||||||
uniform vec3 fg_Planes;
|
|
||||||
uniform vec4 fg_ShadowDistances;
|
|
||||||
uniform int filtering;
|
|
||||||
|
|
||||||
varying vec3 ray;
|
|
||||||
varying vec4 eyePlaneS;
|
|
||||||
varying vec4 eyePlaneT;
|
|
||||||
varying vec4 eyePlaneR;
|
|
||||||
varying vec4 eyePlaneQ;
|
|
||||||
|
|
||||||
vec3 position( vec3 viewDir, vec2 coords, sampler2D depth_tex );
|
|
||||||
vec3 normal_decode(vec2 enc);
|
|
||||||
|
|
||||||
vec4 DynamicShadow( in vec4 ecPosition, out vec4 tint )
|
|
||||||
{
|
|
||||||
vec4 coords;
|
|
||||||
if (ecPosition.z > -fg_ShadowDistances.x) {
|
|
||||||
tint = vec4(0.0,1.0,0.0,1.0);
|
|
||||||
coords.s = dot( ecPosition, eyePlaneS );
|
|
||||||
coords.t = dot( ecPosition, eyePlaneT );
|
|
||||||
coords.p = dot( ecPosition, eyePlaneR );
|
|
||||||
coords.q = dot( ecPosition, eyePlaneQ );
|
|
||||||
} else {
|
|
||||||
return vec4(1.1,1.1,0.0,1.0); // outside, clamp to border
|
|
||||||
}
|
|
||||||
return coords;
|
|
||||||
}
|
|
||||||
void main() {
|
|
||||||
vec2 coords = gl_TexCoord[0].xy;
|
|
||||||
vec4 spec_emis = texture2D( spec_emis_tex, coords );
|
|
||||||
if ( spec_emis.a < 0.1 )
|
|
||||||
discard;
|
|
||||||
vec3 normal = normal_decode(texture2D( normal_tex, coords ).rg);
|
|
||||||
float len = length(normal);
|
|
||||||
normal /= len;
|
|
||||||
vec3 viewDir = normalize(ray);
|
|
||||||
vec3 pos = position( viewDir, coords, depth_tex );
|
|
||||||
|
|
||||||
vec4 tint;
|
|
||||||
float shadow;
|
|
||||||
if (filtering == 2) {
|
|
||||||
shadow += 0.333 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos, 1.0), tint ) ).r;
|
|
||||||
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3(-0.003 * pos.z, -0.002 * pos.z, 0), 1.0), tint ) ).r;
|
|
||||||
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3( 0.003 * pos.z, 0.002 * pos.z, 0), 1.0), tint ) ).r;
|
|
||||||
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3(-0.003 * pos.z, 0.002 * pos.z, 0), 1.0), tint ) ).r;
|
|
||||||
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3( 0.003 * pos.z, -0.002 * pos.z, 0), 1.0), tint ) ).r;
|
|
||||||
} else {
|
|
||||||
shadow = shadow2DProj( shadow_tex, DynamicShadow( vec4( pos, 1.0 ), tint ) ).r;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 lightDir = (fg_ViewMatrix * vec4( fg_SunDirection, 0.0 )).xyz;
|
|
||||||
lightDir = normalize( lightDir );
|
|
||||||
vec3 color = texture2D( color_tex, coords ).rgb;
|
|
||||||
vec3 Idiff = clamp( dot( lightDir, normal ), 0.0, 1.0 ) * color * fg_SunDiffuseColor.rgb;
|
|
||||||
vec3 halfDir = lightDir - viewDir;
|
|
||||||
len = length( halfDir );
|
|
||||||
vec3 Ispec = vec3(0.0);
|
|
||||||
vec3 Iemis = spec_emis.z * color;
|
|
||||||
if (len > 0.0001) {
|
|
||||||
halfDir /= len;
|
|
||||||
Ispec = pow( clamp( dot( halfDir, normal ), 0.0, 1.0 ), spec_emis.y * 128.0 ) * spec_emis.x * fg_SunSpecularColor.rgb;
|
|
||||||
}
|
|
||||||
|
|
||||||
float matID = texture2D( color_tex, coords ).a * 255.0;
|
|
||||||
if (matID == 255.0)
|
|
||||||
Idiff += Ispec * spec_emis.x;
|
|
||||||
|
|
||||||
gl_FragColor = vec4(mix(vec3(0.0), Idiff + Ispec, shadow) + Iemis, 1.0);
|
|
||||||
// gl_FragColor = mix(tint, vec4(mix(vec3(0.0), Idiff + Ispec, shadow) + Iemis, 1.0), 0.92);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
//uniform mat4 fg_ViewMatrixInverse;
|
|
||||||
uniform mat4 fg_ProjectionMatrixInverse;
|
|
||||||
varying vec3 ray;
|
|
||||||
varying vec4 eyePlaneS;
|
|
||||||
varying vec4 eyePlaneT;
|
|
||||||
varying vec4 eyePlaneR;
|
|
||||||
varying vec4 eyePlaneQ;
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
gl_Position = gl_Vertex;
|
|
||||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
|
||||||
// ray = (fg_ViewMatrixInverse * vec4((fg_ProjectionMatrixInverse * gl_Vertex).xyz, 0.0)).xyz;
|
|
||||||
ray = (fg_ProjectionMatrixInverse * gl_Vertex).xyz;
|
|
||||||
|
|
||||||
eyePlaneS = gl_EyePlaneS[1];
|
|
||||||
eyePlaneT = gl_EyePlaneT[1];
|
|
||||||
eyePlaneR = gl_EyePlaneR[1];
|
|
||||||
eyePlaneQ = gl_EyePlaneQ[1];
|
|
||||||
}
|
|
|
@ -11,6 +11,12 @@ uniform vec3 fg_SunDirection;
|
||||||
uniform vec3 fg_Planes;
|
uniform vec3 fg_Planes;
|
||||||
uniform int fg_ShadowNumber;
|
uniform int fg_ShadowNumber;
|
||||||
uniform vec4 fg_ShadowDistances;
|
uniform vec4 fg_ShadowDistances;
|
||||||
|
|
||||||
|
uniform mat4 fg_ShadowMatrix_0;
|
||||||
|
uniform mat4 fg_ShadowMatrix_1;
|
||||||
|
uniform mat4 fg_ShadowMatrix_2;
|
||||||
|
uniform mat4 fg_ShadowMatrix_3;
|
||||||
|
|
||||||
uniform int filtering;
|
uniform int filtering;
|
||||||
varying vec3 ray;
|
varying vec3 ray;
|
||||||
|
|
||||||
|
@ -28,24 +34,24 @@ vec4 DynamicShadow( in vec4 ecPosition, out vec4 tint )
|
||||||
if (fg_ShadowNumber == 1)
|
if (fg_ShadowNumber == 1)
|
||||||
factor = 1.0;
|
factor = 1.0;
|
||||||
tint = vec4(0.0,1.0,0.0,1.0);
|
tint = vec4(0.0,1.0,0.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_0 * ecPosition;
|
||||||
} else if (ecPosition.z > -fg_ShadowDistances.y && fg_ShadowNumber > 1) {
|
} else if (ecPosition.z > -fg_ShadowDistances.y && fg_ShadowNumber > 1) {
|
||||||
index = 2;
|
index = 2;
|
||||||
shift = vec2( 0.0, 0.5 );
|
shift = vec2( 0.0, 0.5 );
|
||||||
tint = vec4(0.0,0.0,1.0,1.0);
|
tint = vec4(0.0,0.0,1.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_1 * ecPosition;
|
||||||
} else if (ecPosition.z > -fg_ShadowDistances.z && fg_ShadowNumber > 2) {
|
} else if (ecPosition.z > -fg_ShadowDistances.z && fg_ShadowNumber > 2) {
|
||||||
index = 3;
|
index = 3;
|
||||||
shift = vec2( 0.5, 0.0 );
|
shift = vec2( 0.5, 0.0 );
|
||||||
tint = vec4(1.0,1.0,0.0,1.0);
|
tint = vec4(1.0,1.0,0.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_2 * ecPosition;
|
||||||
} else if (ecPosition.z > -fg_ShadowDistances.w && fg_ShadowNumber > 3) {
|
} else if (ecPosition.z > -fg_ShadowDistances.w && fg_ShadowNumber > 3) {
|
||||||
shift = vec2( 0.5, 0.5 );
|
shift = vec2( 0.5, 0.5 );
|
||||||
tint = vec4(1.0,0.0,0.0,1.0);
|
tint = vec4(1.0,0.0,0.0,1.0);
|
||||||
|
coords = fg_ShadowMatrix_3 * ecPosition;
|
||||||
} else {
|
} else {
|
||||||
return vec4(1.1,1.1,0.0,1.0); // outside, clamp to border
|
return vec4(1.1,1.1,0.0,1.0); // outside, clamp to border
|
||||||
}
|
}
|
||||||
coords.s = dot( ecPosition, gl_EyePlaneS[index] );
|
|
||||||
coords.t = dot( ecPosition, gl_EyePlaneT[index] );
|
|
||||||
coords.p = dot( ecPosition, gl_EyePlaneR[index] );
|
|
||||||
coords.q = dot( ecPosition, gl_EyePlaneQ[index] );
|
|
||||||
coords.st *= factor;
|
coords.st *= factor;
|
||||||
coords.st += shift;
|
coords.st += shift;
|
||||||
return coords;
|
return coords;
|
||||||
|
|
Loading…
Reference in a new issue