[QUOTE=Atomic;1243324]Blender supports … a shadow map. I have controls for map size and map bias. …
How do I gain access to that information inside my fragment code? If I were in RSL I would just make a call to shadow() with a map name and return an alternate color based upon the result from shadow. Is there an equivalent to shadow in the GLSL language?[/QUOTE]
Sure, the concept is exactly the same. It’s just a texture map containing depth values.
(I notice that you’re not specifying a GLSL version directive (#version 330) so I’ll pitch what I’m saying based on that to the default GLSL version – 1.20.)
First, up-top you need to declare a uniform for the shadow map that blender provides. Consult your Blender gurus/docs for what name they provide it as, and whether or not Blender enables hardware depth comparisons for that texture (i.e. uses a texture with a base type of GL_DEPTH_COMPONENT, enables GL_TEXTURE_COMPARE_MODE, and optionally enables GL_LINEAR filtering which gives you PCF). Pending the name, and assuming a 2D texture, you’ll need one of the following:
uniform sampler2DShadow ShadowTexture; // If Blender enables HW depth comparisons/filtering
uniform sampler2D ShadowTexture; // If Blender does not and expects the shader to do it
You also need to dig up what they’re calling the matrix that gets passed into the shader to get you from the camera’s eye-space over into the light’s clip-space, and pass it in using a “uniform mat4 …;”. This lets you compute the shadow map texture coordinate based on the position of the current fragment.
Then you just feed it to one of the following to do the shadow texture lookup:
shadow2D() or shadow2DProj() // If HW depth comparisons/filtering
texture2D() or texture2DProj() // If not
to sample the shadow map. Note that in the HW depth comparisons/filtering case, you get back a 0…1 visibility value (where 0 is 0% lit – i.e. 100% shadow – and 1 is 100% lit). In the other case, you get back a depth value and have to do the depth comparison yourself in the shader.
Also note that in the case where you’re just doing a lookup for a directional light source, you don’t need the Proj versions (projective texturing), which internally do the divided-by-w for you. Of course, for point light sources you’ll need the divide-by-w, and can either use the Proj versions or do the divide-by-w yourself in the shader and just use the non-Proj versions.
(Depending on how they implemented it, point light sources might even feed in a cube shadow map texture rather than a 2D shadow map texture…)
Also note that post GLSL 1.3, the texture lookups were simplified, and you’d just call texture() or textureProj() – no more sampler types in the texture access function names.
That’ll give you basic shadow mapping. Then stack on filtering and/or acne prevention schemes (like biasing) to-taste.