http://www.jmonkeyengine.com/jmeforum/index.php?topic=4955.0
Can anyone here tell me if this is a jME or a lwjgl related error?
I cannot get this shadow shader to work in either one
Thanks
Vertex
attribute float Accessibility;
varying vec4 ShadowCoord;
const float As = 1.0/1.5;
const float Ds = 1.0/3.0;
void main(){
vec4 ecPosition = gl_ModelViewMatrix*gl_Vertex;
vec3 ecPosition3 = (vec3(ecPosition))/ecPosition.w;
vec3 VP = vec3(gl_LightSource[0].position)-ecPosition3;
VP = normalize(VP);
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
float diffuse = max(0.0,dot(normal,VP));
float scale = min(1.0,Accessibility * As + diffuse * Ds);
vec4 texCoord = gl_TextureMatrix[1] * gl_Vertex;
ShadowCoord = texCoord / texCoord.w;
gl_FrontColor = vec4(scale * gl_Color.rgb,gl_Color.a);
gl_Position = ftransform();
}
Fragment
uniform sampler2DShadow ShadowMap;
uniform float Epsilon;
uniform bool SelfShadowed;
uniform float SelfShadowedVal;
uniform float NonSelfShadowedVal;
varying vec4 ShadowCoord;
float Illumination;
float lookup(float x, float y)
{
float depth = shadow2D(ShadowMap,
ShadowCoord.wxy + vec3(x,y,0) * Epsilon).x;
return depth != 1.0 ? Illumination : 1.0;
}
void main(void)
{
Illumination = SelfShadowed ? SelfShadowedVal: NonSelfShadowedVal;
// vec2 o = mod(floor(gl_FragCoord.xy),2.0);
float sum = 0.0;
//sum += lookup(vec2(-1.5,1.5) + o);
// sum += lookup(vec2(0.5,1.5) + o);
// sum += lookup(vec2(-1.5,-0.5) + o);
// sum += lookup(vec2(0.5,-0.5) + o);
sum += lookup(-0.5,-0.5);
sum += lookup(0.5,-0.5);
sum += lookup(-0.5,0.5);
sum += lookup(0.5,0.5);
gl_FragColor = vec4(sum*0.25*gl_Color.rgb,gl_Color.a);
}