i had been using stencil shadows so far, but i’d like to give shadow mapping a try. ok, so i render the scene depth from the light’s point of view into a fbo. i’m now at the next step, projecting the texture onto my geometry. i’ve applied this shader to the floor:
It’s because you are using the camera projection/modelview matrix, what you really need is the light projection and modelview matrix.
I wrote a small tutorial about this, i am sure you can extract the relevant bit’s. http://www.flashbang.se/index.php?id=35
Also, for performance reasons you should consider adding parantheses to your matrix multiplications above. Keep in mind that evaluation is left to right and matrix by matrix multiplication is a lot more expensive than matrix by vector multiplication.
I would multiply all that matrices into one in the mainprogram (CPU side). That will be much faster than doing 5 Matrix * Vector multiplication for each Vertex.
this is what it looks like with a 4096² shadow map. the shadows themselves are fine, but there are still a lot of self shadowing artifacts.
i’ll get rid of them somehow, but first there are two more important iusses:
what’s the right way to setup the light’s projection matrix? should i use an orthographic or and perspective one? and should i use the screen’s aspect ratio (which is 4:3) or the shadow map’s (which is 1:1 of course)? atm i’m using the shadow map’s ratio, which displays the shadows correctly, but the spotlight texture is stretched horizontally. if i use the shadow map’s ratio, the spotlight texture is perfectly round, but the shadows are misplaced sigh
i would like to blur the shadow to improve visual quality. i know how to blur a vec2, but how should i setup an appropiate kernel for a vec4?
orthographic or perspective projection, it all depends on what the lightsource is, for the sun orthographic might be the best and projection is best for spotlights, use whatever looks the best.
a 1:1 ratio is the best ratio, you should also change your viewport to fit this ratio when rendering the depth map.
the same way as a vec 2(when reading from the texture, only the two first ones really matter for blurring), but you do need to test the depth values individually for each sample.
You could also use light jittering, but that takes a lot of time and memory.
And finally, a lot of self shadowing artifacts can be hidden by multiplying the shadow value with the diffuse value
thanks overlord! i got rid of most artifacts and i managed to soften the shadows i have not solved the problem with my projection matrix, although i am setting up the viewport correctly, though. i’ll figure it out somehow.
next question - can i perform the deopth values comparison myself, i.e. using sampler2D instead of sampler2DShadow? i would like to soften the shadows according to the distance from their casters, so i need to be able to access the original depth values.