I would like to try and implement some shadows in my application but I can’t seem to find any tutorials on using OpenGL Core specification. As I understand it this is how to do shadow mapping in a nutshell and would like some clarification on whether this approach seems correct. If anyone knows some tutorials for OpenGL Core and not using glut shortcuts I could really use those as well, or book recommendations.
- Create a FBO and set as target to render to
- Create texture matrix:
texMatrix = (projectionMatrix * modelViewMatrix) * inverse(modelViewMatrix);
- Apply with shaders, Vertex:
uniform mat4 texMatrix; //calculated texture matrix
uniform mat4 mvMatrix; //model view matrix
varying vec4 shadowTexCoord;
void main () {
shadowTexCoord = texMatrix * mvMatrix * glVertex;
}
Fragment:
uniform sampler2Dshadow shadowMap;
varying vec4 shadowTexCoord;
void main() {
gl_FragColor = shadow2Dproj(shadowMap , shadowTexCoord).r * glColor;
}
These shaders are just “in a nutshell” and don’t include all the in/out/uniforms for everything. I got this information from http://wiki.vrmedia.it/index.php?title=Shadow_Mapping