Skip to main content
gamedev.net
🔒 Locked

Problem with Perspective Shadowmapping

Started by devildeath 0 replies 600+ views
Original Post
devildeath
devildeath
Hi.

I have a very big problem which I could not fix up to now.
I try to implement the ShadowMapping algorithm described here: http://wiki.delphigl.com/index.php/GLSL_Licht_und_Schatten#Perspektivische_Maps
The one using Perspective Shadowmaps.
My map-generator code is:
Vertex-Program:void main(void) {	vec3 mvertex =  vec3 (gl_ModelViewMatrix * gl_Vertex); //Vertex in den Modelspace projezieren    vec3 lightdir = normalize(gl_LightSource[0].position.xyz - mvertex); //Lichtvektor in den Modelsprace rotieren	vec2 pos = mvertex.xz + lightdir.xz * lightdir.y; //Schnittpunkt mit der XZ Referenzebene	pos = pos / (abs(pos)+1.0); //Projektion der Ebene auf ein Quadrat	pos = pos * vec2(1.0,1.8) + vec2(0.0,0.8); //Abschneiden des Bereiches hinter der Kammera		gl_Position.xy = pos;	gl_Position.z = -mvertex.y; // * 0.5 + 0.5 - 0.005; // far and near clamping and Anti-Z-fighting-offset }Fragment Program:void main(void){	gl_FragColor = gl_Color;}

and the shader for usage of the map is this one:
Vertex:varying vec3 spos;varying vec4 depth; void main(void){		vec3 mvertex =  vec3 (gl_ModelViewMatrix * gl_Vertex);    	vec3 lightdir = normalize(gl_LightSource[0].position.xyz - mvertex); //Lichtvektor in den Modelsprace rotieren        vec2 pos = mvertex.xz + lightdir.xz * lightdir.y; //Schnittpunkt mit der XZ Referenzebene        pos = pos / (abs(pos)+1.0); //Projektion der Ebene auf ein Quadrat        pos = pos * vec2(1.0,1.8) + vec2(0.0,0.8); //Abschneiden des Bereiches hinter der Kammera        pos = pos * 0.5 + 0.5; //auf Texturkoordinaten umrechnen         spos.xy = pos; //Daten in einer Varying verpacken        spos.z = -mvertex.y * 0.5 + 0.5 - 0.005; // far and near clamping and Anti-Z-fighting-offset          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; //Die echte Transformation        }Fragment:uniform sampler2D Shadowmap;varying vec3 spos;void main(void){		vec4 color = gl_Color * 0.8;        if ( texture2D(Shadowmap, spos.xy).b > spos.z ){              //Licht			  color.g = 0.9;              }        else{              //Schatten			  color.r = 0.2;              }	gl_FragColor = color;}


The problem is, that the final image looks like there are green fragments in the upper part of the image and red pixels in the lower part of the image and the split is exactly in the middle.
I also found some post where some people said, that this wiki isn't finished.
But how does this algorithm work and produce some shadows?

Here is an image
ShadowMap


Thanks
devildeath

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.