I'm taking an intro to computer graphics course, so this is something we haven't touched on.
I am reading this tutorial http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/ but I cant figure out what to do after creating the depth texture. The depth texture is from the lights point of view (directional light). I sent the depth texture to my post process shader where I want to apply the shadows. The depth texture:
From what I understand from the article, I also need the position texture from the light's point of view.
The position texture:
And then the article determines if the current pixel is visible from the lights point of view like this:
float visibility = 1.0;
//ShadowCoord is the position of the vertex as seen from the light
if ( texture2D( shadowMap, ShadowCoord.xy ).z < ShadowCoord.z){
visibility = 0.5;
}
Here is what I end up with:
Im not sure, but I believe my position texture is wrong?
Edit: Here is how I create the position relative to the light texture in my shader:
positionSunPOV = (biasMatrix * sunMVP * vPosition).xyz;
// biasMatrix is the matrix that changes the coords from [-1,1] to [0,1]
// sunMVP is the model view projection matrix for the sun than I passed in
// vPosition is the position of the vertex
Here is how I create sunMVP:
SunDir = vec3(0,30,-30);
sunProjectionMatrix = ortho(left, right, bottom, ytop, nearO, farO);
sunViewMatrix = lookAt(SunDir, vec3(0,0,0), up);
sunModelMatrix = mat4(1.0);
//sunMV = mult(sunViewMatrix,sunModelMatrix);
sunMVP = mult( sunProjectionMatrix, mult(sunViewMatrix,sunModelMatrix) );