Add optional shadow filtering
This commit is contained in:
parent
9807be4f0d
commit
adf766aeff
3 changed files with 31 additions and 24 deletions
|
@ -1,6 +1,9 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PropertyList>
|
<PropertyList>
|
||||||
<name>Effects/sunlight</name>
|
<name>Effects/sunlight</name>
|
||||||
|
<parameters>
|
||||||
|
<filtering><use>/sim/rendering/shadows/filtering</use></filtering>
|
||||||
|
</parameters>
|
||||||
<technique n="10">
|
<technique n="10">
|
||||||
<predicate>
|
<predicate>
|
||||||
<property>/sim/rendering/shadows/enabled</property>
|
<property>/sim/rendering/shadows/enabled</property>
|
||||||
|
@ -68,6 +71,11 @@
|
||||||
<type>sampler-2d</type>
|
<type>sampler-2d</type>
|
||||||
<value type="int">4</value>
|
<value type="int">4</value>
|
||||||
</uniform>
|
</uniform>
|
||||||
|
<uniform>
|
||||||
|
<name>filtering</name>
|
||||||
|
<type>int</type>
|
||||||
|
<value type="int"><use>filtering</use></value>
|
||||||
|
</uniform>
|
||||||
<!-- The following uniforms are automatically defined and initialized :
|
<!-- The following uniforms are automatically defined and initialized :
|
||||||
- fg_SunAmbientColor
|
- fg_SunAmbientColor
|
||||||
- fg_SunDiffuseColor
|
- fg_SunDiffuseColor
|
||||||
|
|
|
@ -10,6 +10,7 @@ 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 int filtering;
|
||||||
varying vec3 ray;
|
varying vec3 ray;
|
||||||
|
|
||||||
vec3 position( vec3 viewdir, float depth );
|
vec3 position( vec3 viewdir, float depth );
|
||||||
|
@ -60,26 +61,23 @@ void main() {
|
||||||
vec3 pos = position( viewDir, texture2D( depth_tex, coords ).r );
|
vec3 pos = position( viewDir, texture2D( depth_tex, coords ).r );
|
||||||
|
|
||||||
vec4 tint;
|
vec4 tint;
|
||||||
#if 0
|
|
||||||
float shadow = 1.0;
|
|
||||||
#elif 1
|
|
||||||
float shadow = shadow2DProj( shadow_tex, DynamicShadow( vec4( pos, 1.0 ), tint ) ).r;
|
|
||||||
#elif 0
|
|
||||||
float shadow = 0.0;
|
float shadow = 0.0;
|
||||||
shadow += 0.333 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos, 1.0), tint ) ).r;
|
if (filtering == 1) {
|
||||||
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3(-0.003 * pos.z, -0.003 * pos.z, 0), 1.0), tint ) ).r;
|
shadow = 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.003 * pos.z, 0), 1.0), tint ) ).r;
|
} else if (filtering == 2) {
|
||||||
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3(-0.003 * pos.z, 0.003 * pos.z, 0), 1.0), tint ) ).r;
|
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.003 * 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 += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3( 0.003 * pos.z, 0.002 * pos.z, 0), 1.0), tint ) ).r;
|
||||||
float kernel[9] = float[]( 36/256.0, 24/256.0, 6/256.0,
|
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3(-0.003 * pos.z, 0.002 * pos.z, 0), 1.0), tint ) ).r;
|
||||||
24/256.0, 16/256.0, 4/256.0,
|
shadow += 0.166 * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3( 0.003 * pos.z, -0.002 * pos.z, 0), 1.0), tint ) ).r;
|
||||||
6/256.0, 4/256.0, 1/256.0 );
|
} else {
|
||||||
float shadow = 0;
|
float kernel[9] = float[]( 36/256.0, 24/256.0, 6/256.0,
|
||||||
for( int x = -2; x <= 2; ++x )
|
24/256.0, 16/256.0, 4/256.0,
|
||||||
for( int y = -2; y <= 2; ++y )
|
6/256.0, 4/256.0, 1/256.0 );
|
||||||
shadow += kernel[abs(x)*3 + abs(y)] * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3(-0.005 * x * pos.z, -0.005 * y * pos.z, 0), 1.0), tint ) ).r;
|
for( int x = -2; x <= 2; ++x )
|
||||||
#endif
|
for( int y = -2; y <= 2; ++y )
|
||||||
|
shadow += kernel[abs(x)*3 + abs(y)] * shadow2DProj( shadow_tex, DynamicShadow( vec4(pos + vec3(-0.0025 * x * pos.z, -0.0025 * y * pos.z, 0), 1.0), tint ) ).r;
|
||||||
|
}
|
||||||
vec3 lightDir = (fg_ViewMatrix * vec4( fg_SunDirection, 0.0 )).xyz;
|
vec3 lightDir = (fg_ViewMatrix * vec4( fg_SunDirection, 0.0 )).xyz;
|
||||||
lightDir = normalize( lightDir );
|
lightDir = normalize( lightDir );
|
||||||
vec3 color = texture2D( color_tex, coords ).rgb;
|
vec3 color = texture2D( color_tex, coords ).rgb;
|
||||||
|
|
|
@ -182,11 +182,12 @@ Started September 2000 by David Megginson, david@megginson.com
|
||||||
<debug type="bool"
|
<debug type="bool"
|
||||||
userarchive="y">false</debug>
|
userarchive="y">false</debug>
|
||||||
<map-size type="int">4096</map-size>
|
<map-size type="int">4096</map-size>
|
||||||
<num-cascades type="int">4</num-cascades>
|
<num-cascades type="int" userarchive="y">4</num-cascades>
|
||||||
<cascade-far-m index="0" type="float">5.0</cascade-far-m>
|
<cascade-far-m index="0" type="float" userarchive="y">5.0</cascade-far-m>
|
||||||
<cascade-far-m index="1" type="float">50.0</cascade-far-m>
|
<cascade-far-m index="1" type="float" userarchive="y">50.0</cascade-far-m>
|
||||||
<cascade-far-m index="2" type="float">500.0</cascade-far-m>
|
<cascade-far-m index="2" type="float" userarchive="y">500.0</cascade-far-m>
|
||||||
<cascade-far-m index="3" type="float">5000.0</cascade-far-m>
|
<cascade-far-m index="3" type="float" userarchive="y">5000.0</cascade-far-m>
|
||||||
|
<filtering type="int" userarchive="y">2</filtering>
|
||||||
</shadows>
|
</shadows>
|
||||||
<shader-experimental type="bool"
|
<shader-experimental type="bool"
|
||||||
userarchive="y">false</shader-experimental>
|
userarchive="y">false</shader-experimental>
|
||||||
|
|
Loading…
Add table
Reference in a new issue