This is what I am currently doing, but it seems to not really work, I have also tried quite a few other methods… figure it just getting the correct combo of matrices.
its on line 565 where I am sampling the shadowmap, I have a sneaking suspicion I am just sampling the wrong global point or the incorrect perspective amount.
You want to shadow the clouds that are hidden (blocked by geometries) from the point of view of the sun?
If yes, what I don’t understand is that you take the value from the shadow map (return texture2D(sunShadowMap, uv).x;) as the light attenuation in your lighting equation.
However, the value in the shadow map is a depth from the light point of view (the depth of the geometry nearest to the light). So, in your code, it means the farther the point is from the light, the darker it is, being in shadow or not (meaning no geometry blocking the path of light).
What you need to do is to transform your point into the light (sun) coordinate system and get the depth of this point in this system (the z value). If the depth is less than the one in the shadow map for this location, then the point is not in shadow (so the factor in your lighting equation is 1.), else it is (use whatever factor you want to darken the point).
Going to give a try to do this, but don’t hold your breath…
if we can figure this out then I will optimize the whole system to run at 60 fps, and then introduce simulation shaders to make it so we can have some real volumetric smoke and other things.
I think I know what you are saying, I was mistaken about what the shadowmaps data had on it! I did not realise it was a depth value, now that I know that though we might be able to make this happen.
And that is still off… I have tried using the lights matrix, the shadowGenerators Matrix hmmm there is gonna be an answer and once its figured out this is gonna look cool…
I think it might be I am sampling the wrong position still, which I am troubleshooting now as I drink me coffeeeee…
I think DepthMetric should not be 1.0 in the sampleSunShadow function.
It should be the depth of your point (pos) in the light coordinate system (LCS), meaning the z value after pos is transformed into the LCS. For this you need the light matrix.
Also I don’t really understand the calculation with the sun and point positions, being normalized (?)
I don’t either, I’m just guessing at this point… I’ve tried like every combination I can think of.
I’m thinking my sample position was off so I am going back and checking that I am feeling the correct global position in then I am going to try to multiply it by the shadowGenerators TransformMatrix agian and see if I am just being dumb.