2

I implemented a fairly simple shadow map. I have a simple obj imported plane as ground and a bunch of trees.

I have a weird shadow on the plane which I think is the plane's self shadow. I am not sure what code to post. If it would help please tell me and I'll do so then.

First image, camera view of the scene. The weird textured lowpoly sphere is just for reference of the light position.

camera view of the scene

Second image, the depth texture stored in the framebuffer. I calculated shadow coords from light perspective with it. Since I can't post more than 2 links, I'll leave this one.

Third image, depth texture with a better view of the plane projecting the shadow from a different light position above the whole scene.

depth buffer from another perspective

LE: the second picture http://i41.tinypic.com/23h3wqf.jpg (Depth Texture of first picture) Tried some fixes, adding glCullFace(GL_BACK) before drawing the ground in the first pass removes it from the depth texture but still appears in the final render(like in the first picture, the back part of the ground) - i tried adding CullFace in the second pass also, still showing the shadow on the ground , tried all combinations of Front and Back facing. Can it be because of the values in the ortographic projection ?

Shadow fragment shader:

#version 330 core

layout(location = 0) out vec3 color;

in vec2 texcoord;
in vec4 ShadowCoord;

uniform sampler2D textura1;
uniform sampler2D textura2;
uniform sampler2D textura_depth;

uniform int has_alpha;

void main(){

vec3 tex1 = texture(textura1, texcoord).xyz;
vec3 tex2 = texture(textura2, texcoord).xyz;

if(has_alpha>0.5) if((tex2.r<0.1) && (tex2.g<0.1) && (tex2.b<0.1)) discard;

//Z value of depth texture from pass 1
float hartaDepth=texture( textura_depth,(ShadowCoord.xy/ShadowCoord.w)).z;

float shadowValue=1.0;

if(hartaDepth < ShadowCoord.z-0.005)
    shadowValue=0.5;

color = shadowValue * tex1 ;
}
D.Razvan
  • 325
  • 1
  • 5
  • 18
  • 1
    I embedded the images into your post so that you, hopefully, can link to the second screenshot as well. – danijar Dec 13 '13 at 16:55
  • Fragment shader where you compute the shadows could help. – Jaa-c Dec 13 '13 at 23:40
  • Coming right up, i'll edit my initial question. – D.Razvan Dec 13 '13 at 23:50
  • Is the projection matrix for the light suppose to change if the light changes position ? And the values inside the projection matrix(xmin,xmax,etc) are related to the position of the light ? Or it is simply mapped to the scene coord. For example my entire scene is between -70,70,-25,35,-70,70 (ground + tree heights) and for my projection i use this values with a +/- 10. – D.Razvan Dec 14 '13 at 10:52
  • The problem got solved by increasing the BoundingBox of the projection(the x,y,z values) , but now i have a different problem, the size is too much and the shadows look very jagged and lose shape(see photo for ref). How can i approach this issue ? Also when i try to use texture2DProj instead of texture in shader i get "unable to find compatible overloaded function" and it all renders black. I want to use it for PCF so i need a sampler2DShadow instead of sampler2D. PHOTO: http://i41.tinypic.com/sccro0.jpg – D.Razvan Dec 14 '13 at 13:40
  • Correct, you need to use `sampler2DShadow` for hardware-based PCF. But you do not have to use `texture2DProj (...)` with `sampler2DShadow`. All `sampler2DShadow` does is perform a depth test at the same time it samples your depth texture. A normal `sampler2D` will just return the depth value and when you use linear filtering on such a `sampler` you get an averaged depth value instead of the average result of the nearest 4 depth tests. Although, if memory serves `sampler2DShadow` is not ***required*** to do PCF when you use a linear filter, it is a driver feature. – Andon M. Coleman Dec 14 '13 at 23:16
  • Yes thank you, i managed to implement my own PCF :). I can post the code if someone asks for it. – D.Razvan Dec 15 '13 at 20:27

0 Answers0