Add a sunlight technique to disable shadows, and avoid shader syntax problems with old NV cards
This commit is contained in:
parent
ceb1cb102b
commit
5678c1cd76
2 changed files with 111 additions and 1 deletions
|
@ -1,7 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PropertyList>
|
<PropertyList>
|
||||||
<name>Effects/sunlight</name>
|
<name>Effects/sunlight</name>
|
||||||
<technique n="11">
|
<technique n="10">
|
||||||
|
<predicate>
|
||||||
|
<property>/sim/rendering/shadows/enabled</property>
|
||||||
|
</predicate>
|
||||||
<pass>
|
<pass>
|
||||||
<lighting>false</lighting>
|
<lighting>false</lighting>
|
||||||
<depth>
|
<depth>
|
||||||
|
@ -76,5 +79,71 @@
|
||||||
-->
|
-->
|
||||||
</pass>
|
</pass>
|
||||||
</technique>
|
</technique>
|
||||||
|
<technique n="11">
|
||||||
|
<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>
|
||||||
|
<program>
|
||||||
|
<vertex-shader>Shaders/sunlight.vert</vertex-shader>
|
||||||
|
<fragment-shader>Shaders/sunlight-noshadow.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>
|
||||||
|
<!-- The following uniforms are automatically defined and initialized :
|
||||||
|
- fg_SunAmbientColor
|
||||||
|
- fg_SunDiffuseColor
|
||||||
|
- fg_SunSpecularColor
|
||||||
|
- fg_SunDirection
|
||||||
|
- fg_ProjectionMatrixInverse
|
||||||
|
- fg_ViewMatrixInverse
|
||||||
|
- fg_ViewMatrix
|
||||||
|
- fg_Planes
|
||||||
|
-->
|
||||||
|
</pass>
|
||||||
|
</technique>
|
||||||
</PropertyList>
|
</PropertyList>
|
||||||
|
|
||||||
|
|
41
Shaders/sunlight-noshadow.frag
Normal file
41
Shaders/sunlight-noshadow.frag
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
uniform mat4 fg_ViewMatrix;
|
||||||
|
uniform sampler2D depth_tex;
|
||||||
|
uniform sampler2D normal_tex;
|
||||||
|
uniform sampler2D color_tex;
|
||||||
|
uniform sampler2D spec_emis_tex;
|
||||||
|
uniform vec4 fg_SunDiffuseColor;
|
||||||
|
uniform vec4 fg_SunSpecularColor;
|
||||||
|
uniform vec3 fg_SunDirection;
|
||||||
|
uniform vec3 fg_Planes;
|
||||||
|
varying vec3 ray;
|
||||||
|
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.xy = texture2D( normal_tex, coords ).rg * 2.0 - vec2(1.0,1.0);
|
||||||
|
normal.z = sqrt( 1.0 - dot( normal.xy, normal.xy ) );
|
||||||
|
float len = length(normal);
|
||||||
|
normal /= len;
|
||||||
|
vec3 viewDir = normalize(ray);
|
||||||
|
float depth = texture2D( depth_tex, coords ).r;
|
||||||
|
vec3 pos;
|
||||||
|
pos.z = - fg_Planes.y / (fg_Planes.x + depth * fg_Planes.z);
|
||||||
|
pos.xy = viewDir.xy / viewDir.z * pos.z;
|
||||||
|
|
||||||
|
vec4 tint;
|
||||||
|
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 * 255.0 ) * spec_emis.x * fg_SunSpecularColor.rgb;
|
||||||
|
}
|
||||||
|
gl_FragColor = vec4(Idiff + Ispec + Iemis, 1.0);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue