Revision: 8913
http://playerstage.svn.sourceforge.net/playerstage/?rev=8913&view=rev
Author: natepak
Date: 2010-09-20 21:55:19 +0000 (Mon, 20 Sep 2010)
Log Message:
-----------
Updates shadow shaders
Modified Paths:
--------------
code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt
code/gazebo/branches/wx/Media/materials/programs/blur.glsl
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_fp.glsl
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_vp.glsl
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_fp.glsl
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_vp.glsl
Modified: code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt
2010-09-18 14:14:26 UTC (rev 8912)
+++ code/gazebo/branches/wx/Media/materials/programs/CMakeLists.txt
2010-09-20 21:55:19 UTC (rev 8913)
@@ -3,6 +3,7 @@
pssm_vsm_receiver_fp.glsl
pssm_vsm_receiver_vp.glsl
AmbientOneTexture.glsl
+ blur.glsl
)
INSTALL(FILES ${files} DESTINATION
${CMAKE_INSTALL_PREFIX}/share/gazebo/Media/materials/programs/)
Modified: code/gazebo/branches/wx/Media/materials/programs/blur.glsl
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/blur.glsl 2010-09-18
14:14:26 UTC (rev 8912)
+++ code/gazebo/branches/wx/Media/materials/programs/blur.glsl 2010-09-20
21:55:19 UTC (rev 8913)
@@ -5,15 +5,16 @@
{
vec3 sample = vec3(0.0, 0.0, 0.0);
- float radius = 3.0;
+ float radius = 9.0;
for (float x = -radius; x <= radius; x += 1.0)
{
- for (float y = -radius; y <= radius; y += 1)
+ for (float y = -radius; y <= radius; y += 1.0)
{
sample += texture2D(map, vec2(gl_TexCoord[0].x + x * invSMSize.x,
gl_TexCoord[0].y + y * invSMSize.y)).rgb;
}
}
- gl_FragColor = vec4(sample / ((radius * 2.0 + 1.0) * (radius * 2.0 + 1.0)),
1.0);
+ //gl_FragColor = vec4(sample / ((radius * 2.0 + 1.0) * (radius * 2.0 +
1.0)), 1.0);
+ gl_FragColor = vec4(1.0,0.0,0.0,1.0);
}
Modified:
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_fp.glsl
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_fp.glsl
2010-09-18 14:14:26 UTC (rev 8912)
+++ code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_fp.glsl
2010-09-20 21:55:19 UTC (rev 8913)
@@ -1,15 +1,11 @@
-uniform vec4 depthRange;
+uniform float far;
varying vec4 vertexDepth;
void main()
{
- // derive a per-pixel depth and depth squared
- // (length of the view space position == distance from camera)
- // (this is linear space, not post-projection quadratic space)
-
- float d = (length(vertexDepth.xyz)- depthRange.x) * depthRange.w;
-
-
- gl_FragColor = vec4(d, d*d, 1, 1);
+ //float depth = length(vertexDepth.z) / far;
+ //gl_FragColor = vec4(depth, depth*depth, 0.0, 1.0);
+
+ gl_FragColor = vec4(vertexDepth.x, vertexDepth.x, vertexDepth.x, 1.0);
}
Modified:
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_vp.glsl
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_vp.glsl
2010-09-18 14:14:26 UTC (rev 8912)
+++ code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_caster_vp.glsl
2010-09-20 21:55:19 UTC (rev 8913)
@@ -1,10 +1,15 @@
-uniform mat4 wvMat;
+uniform mat4 wvpMat;
+uniform vec4 texel_offsets;
+uniform vec4 depth_range;
+attribute vec4 vertex;
+
varying vec4 vertexDepth;
void main()
{
- vertexDepth = wvMat * gl_Vertex;
+ gl_Position = wvpMat * vertex;
+ gl_Position.xy += texel_offsets.zw * gl_Position.w;
- gl_Position = ftransform();
+ vertexDepth.x = (gl_Position.z - depth_range.x) * depth_range.w;
}
Modified:
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_fp.glsl
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_fp.glsl
2010-09-18 14:14:26 UTC (rev 8912)
+++ code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_fp.glsl
2010-09-20 21:55:19 UTC (rev 8913)
@@ -1,89 +1,158 @@
-uniform vec3 lightDif0;
-uniform vec4 lightPos0;
-uniform vec4 lightAtt0;
-uniform vec4 invSMSize;
-uniform vec4 depthRange;
-uniform vec4 spotlightParams;
-uniform sampler2D dMap;
+uniform vec4 invShadowMapSize;
+uniform vec3 derived_light_diffuse_color;
+uniform vec4 derived_light_specular_color;
+uniform float surface_shininess;
+
+uniform vec4 light_position_view_space;
+uniform vec4 light_direction_view_space;
+uniform vec4 light_attenuation;
+uniform vec4 spotlight_params;
+
uniform sampler2D shadowMap;
+uniform sampler2D diffuseMap;
-varying vec4 vertexWorldPosition;
-varying vec4 lightPosition0;
-varying vec3 vertexNormal;
-varying vec3 sdir;
+varying vec3 vertexWorldViewPos;
+varying vec3 vertexWorldPos;
+varying vec3 vertexWorldNorm;
+varying vec4 vertexLightPos;
-vec2 btex2D_rg(sampler2D map, vec2 uv, float radius, vec2 offset)
+float ShadowPCF()
{
- // simple 3x3 filter
- vec2 o = offset;
- vec2 c = texture2D(map, uv.xy).rg; // center
- c += texture2D(map, uv.xy - o.xy).rg; // top left
- c += texture2D(map, uv.xy + o.xy).rg; // bottom right
- c += texture2D(map, vec2(uv.x - o.x, uv.y)).rg; // left
- c += texture2D(map, vec2(uv.x + o.x, uv.y)).rg; // right
- c += texture2D(map, vec2(uv.x, uv.y + o.y)).rg; // bottom
- c += texture2D(map, vec2(uv.x, uv.y - o.y)).rg; // top
- c += texture2D(map, vec2(uv.x - o.x, uv.y + o.y)).rg; // bottom left
- c += texture2D(map, vec2(uv.x + o.x, uv.y - o.y)).rg; // top right
- return c / 9.0;
-}
+ // Get the shadow map position
+ vec4 shadowMapPos = vertexLightPos / vertexLightPos.w;
+ vec2 uv = shadowMapPos.xy;
-float shadow(in sampler2D shadowMap, in vec4 shadowMapPos, float ourDepth,
float radius, vec2 offset)
-{
- vec2 suv = shadowMapPos.xy / shadowMapPos.w;
+ //float dist = length(vertexLightPos.z) / light_attenuation.x ;
+ float dist = vertexLightPos.z;
- vec2 moments = btex2D_rg(shadowMap, suv, radius, offset);
+ vec2 o = invShadowMapSize.xy;
- float litFactor = (ourDepth <= moments.x ? 1.0 : 0.0);
+ float centerDepth = texture2D(shadowMap, uv.xy).x;
- // standard variance shadow mapping code
- float E_x2 = moments.y;
- float Ex_2 = moments.x * moments.x;
- float vsmEpsilon = 0.0001;
- float variance = min(max(E_x2 - Ex_2, 0.0) + vsmEpsilon, 1.0);
- float m_d = moments.x - ourDepth;
- float denom = (variance + m_d * m_d);
- float p = variance / denom;
+ //vec4 depths = vec4( texture2D(shadowMap, vec2(uv.x - offset.x, uv.y)).x,
+ // texture2D(shadowMap, vec2(uv.x + offset.x, uv.y)).x,
+ // texture2D(shadowMap, vec2(uv.x, uv.y - offset.y)).x,
+ // texture2D(shadowMap, vec2(uv.x, uv.y + offset.y)).x );
+
- return smoothstep(0.4, 1.0, max(litFactor, p));
+ float final = (centerDepth > dist) ? 1.0 : 0.0;
+ final += (texture2D(shadowMap, uv.xy - o.xy).x > dist) ? 1.0 : 0.0;
+ final += (texture2D(shadowMap, uv.xy + o.xy).x > dist) ? 1.0 : 0.0;
+ final += (texture2D(shadowMap, vec2(uv.x - o.x, uv.y)).x > dist) ? 1.0 : 0.0;
+ final += (texture2D(shadowMap, vec2(uv.x + o.x, uv.y)).x > dist) ? 1.0 : 0.0;
+ final += (texture2D(shadowMap, vec2(uv.x, uv.y + o.y)).x > dist) ? 1.0 : 0.0;
+ final += (texture2D(shadowMap, vec2(uv.x, uv.y - o.y)).x > dist) ? 1.0 : 0.0;
+ final += (texture2D(shadowMap, vec2(uv.x - o.x, uv.y + o.y)).x > dist) ? 1.0
: 0.0;
+ final += (texture2D(shadowMap, vec2(uv.x + o.x, uv.y - o.y)).x > dist) ? 1.0
: 0.0;
+
+ final /= 9.0;
+ return final;
+
+ //vec2 c = texture2D(shadowMap, uv.xy).rg; // center
+ //c += texture2D(shadowMap, uv.xy - offset.xy).rg; // top left
+ //c += texture2D(shadowMap, uv.xy + offset.xy).rg; // bottom right
+ //c += texture2D(shadowMap, vec2(uv.x - offset.x, uv.y)).rg; // left
+ //c += texture2D(shadowMap, vec2(uv.x + offset.x, uv.y)).rg; // right
+ //c += texture2D(shadowMap, vec2(uv.x, uv.y + offset.y)).rg; // bottom
+ //c += texture2D(shadowMap, vec2(uv.x, uv.y - offset.y)).rg; // top
+ //c += texture2D(shadowMap, vec2(uv.x - offset.x, uv.y + offset.y)).rg; //
bottom left
+ //c += texture2D(shadowMap, vec2(uv.x + offset.x, uv.y - offset.y)).rg; //
top right
+ //c /= 9.0;
+
+ //vec2 moments = c;
+ //float litFactor = (dist <= moments.x ? 1.0 : 0.0);
+ //return litFactor;
+
+ //// standard variance shadow mapping code
+ //float variance = min(max( moments.y - (moments.x * moments.x), 0.0), 1.0);
+ //float m_d = moments.x - dist;
+ //float p = variance / (variance + m_d * m_d);
+
+ //return smoothstep(0.4, 1.0, max(litFactor, p));
}
+//-----------------------------------------------------------------------------
+float Light_Spot_Diffuse(
+ in vec3 vNegLightDirView,
+ in vec3 vLightView,
+ in vec4 vAttParams,
+ in vec3 vSpotParams,
+ in float fLightD,
+ in float nDotL)
+{
+ float spot = 1.0;
+
+ if (nDotL > 0.0 && fLightD <= vAttParams.x)
+ {
+ float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD +
vAttParams.w*fLightD*fLightD);
+ float rho = dot(vNegLightDirView, vLightView);
+ float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x -
vSpotParams.y), 0.0, 1.0);
+ float fSpotT = pow(fSpotE, vSpotParams.z);
+
+ spot = nDotL * fAtten * fSpotT;
+ }
+
+ return spot;
+}
+
void main()
{
- // direction
- vec3 ld0 = normalize(lightPos0.xyz - (lightPos0.w *
vertexWorldPosition.xyz));
+ float spot = 1.0;
+ float specular = 0.0;
- // attenuation
- float ila = length(lightPos0.xyz - vertexWorldPosition.xyz) / lightAtt0.r;
- ila *= ila; // quadratic falloff
- float la = 1.0 - ila;
+ // Normalized fragment normal
+ vec3 N = normalize(vertexWorldNorm);
- vec3 normal = normalize(vertexNormal);
+ // Direction from the fragment to the light
+ vec3 lightDirView = light_position_view_space.xyz - vertexWorldViewPos.xyz *
light_position_view_space.w;
- float LdotN0 = max(dot(ld0, normal), 0.0);
- vec4 difTex = texture2D(dMap, gl_TexCoord[0].xy);
+ // light_position_view_space.w == 0 for directional lights
+ float lightDist = length(lightDirView) * light_position_view_space.w;
+ lightDirView = normalize(lightDirView);
- // calculate the spotlight effect
- float spot = dot(ld0, normalize(-sdir)); // angle between spotlight dir and
actual dir
- spot = clamp((spot - spotlightParams.y) / (spotlightParams.x -
spotlightParams.y),0.0,1.0);
+ float lambertTerm = max( dot(N, lightDirView), 0.0 );
- vec3 light0C =
- // N . L LIGHT DIF TEX DIF ATT
- //(LdotN0 * lightDif0 * difTex.xyz) * la * spot
- (LdotN0 * lightDif0 * difTex.xyz) * la * spot *
- shadow(
- // pass in the shadow map
- shadowMap,
- // the calculated shadow position in the shadow map
- lightPosition0,
- // distance to light, done just as in the caster shader
- (length(lightPos0.xyz - vertexWorldPosition.xyz) - depthRange.x) *
depthRange.w,
- // radius to blur (we discussed)
- 3.0,
- // inverse shadow map size so we know how much to move when blurring
- invSMSize.xy);
+
//////////////////////////////////////////////////////////////////////////////
+ // COMPUTE DIFFUSE CONTRIBUTION
+ vec4 diffuseTex = texture2D(diffuseMap, gl_TexCoord[0].st);
+ vec4 diffuseContrib = vec4(derived_light_diffuse_color * diffuseTex.rgb *
lambertTerm,1.0);
- gl_FragColor = vec4(light0C, 1.0);
-
+
+
//////////////////////////////////////////////////////////////////////////////
+ // COMPUTE SPOT AND SPECULAR COMPONENTS
+ if (lambertTerm > 0.0 && lightDist <= light_attenuation.x)
+ {
+ vec3 view = -normalize(vertexWorldViewPos.xyz);
+ vec3 halfway = normalize( view + lightDirView );
+ float nDotH = dot(N, halfway);
+
+ float fAtten = 1.0 / (light_attenuation.y +
+ light_attenuation.z*lightDist +
+ light_attenuation.w*lightDist*lightDist);
+
+ float rho = dot(-light_direction_view_space.xyz, lightDirView);
+
+ float fSpotE = clamp((rho - spotlight_params.y) /
+ (spotlight_params.x - spotlight_params.y),0.0,1.0);
+
+ float fSpotT = pow(fSpotE, spotlight_params.z);
+
+ // Make sure we have a spot light
+ if ( !(spotlight_params.x == 1.0 && spotlight_params.y == 0.0 &&
+ spotlight_params.z == 0.0 && spotlight_params.w == 1.0) )
+ {
+ spot = lambertTerm * fAtten * fSpotT;
+ }
+
+ // Works for all light types
+ specular = pow(clamp(nDotH, 0.0, 1.0), surface_shininess) * fAtten, fSpotT;
+ }
+
+
//////////////////////////////////////////////////////////////////////////////
+ // COMPUTE SHADOW CONTRIBUTION
+ float shadowAmount = ShadowPCF();
+
+ vec4 specularContrib = specular * derived_light_specular_color;
+
+ gl_FragColor = (diffuseContrib + specularContrib) * shadowAmount * spot;
}
-
Modified:
code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_vp.glsl
===================================================================
--- code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_vp.glsl
2010-09-18 14:14:26 UTC (rev 8912)
+++ code/gazebo/branches/wx/Media/materials/programs/pssm_vsm_receiver_vp.glsl
2010-09-20 21:55:19 UTC (rev 8913)
@@ -1,26 +1,37 @@
uniform mat4 wMat;
+uniform mat4 wvMat;
uniform mat4 wvpMat;
-uniform mat4 tvpMat;
-uniform vec4 spotlightDir;
+uniform mat4 inv_trans_wvMat;
+uniform vec4 lightWorldPos;
-varying vec4 vertexWorldPosition;
-varying vec4 lightPosition0;
-varying vec3 vertexNormal;
-varying vec3 sdir;
+uniform mat4 twvpMat;
+uniform vec4 spotDir;
+uniform vec4 shadow_depth_range;
+attribute vec3 normal;
+attribute vec4 vertex;
+
+varying vec3 vertexWorldNorm;
+varying vec3 vertexWorldViewPos;
+varying vec3 vertexWorldPos;
+
+varying vec4 vertexLightPos;
+
void main()
{
- gl_Position = ftransform();
+ gl_Position = wvpMat * vertex;
- vertexWorldPosition = mul(wMat, gl_Vertex);
- //gl_Position = mul(wvpMat, gl_Vertex);
+ // Vertex in world space
+ vertexWorldViewPos = (wvMat * vertex).xyz;
+ vertexWorldPos = (wMat * vertex).xyz;
- gl_TexCoord[0] = gl_MultiTexCoord0;
- gl_TexCoord[1] = gl_MultiTexCoord1;
+ // Vertex normal in world space
+ vertexWorldNorm = (inv_trans_wvMat * vec4(normal, 1.0)).xyz;
- vertexNormal = vec3(wMat * vec4(gl_Normal.xyz, 0.0));
+ // Position of the vertex in light space (shadow map texture coords)
+ vertexLightPos = twvpMat * vertex;
+ vertexLightPos.z = (vertexLightPos.z - shadow_depth_range.x) *
shadow_depth_range.w;
- sdir = vec3(wMat * spotlightDir);
-
- lightPosition0 = tvpMat * vertexWorldPosition;
+ // Pass through the diffuse component
+ gl_TexCoord[0] = gl_MultiTexCoord0;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit