Hi Aras. sorry for the dig up of this old thread. But i get interrested in it.
Could you please detail more the process please ?
As far as i understand, a shadowmap must be drawn in the light view. If the light is directionnal,
a parallel camera should be setup on the light, and the scene rendered from this point of view,
storing only Z data in a texture. Am i right or wrong ?
Anyway, what shoud be stored in this shadow texture?
Z ? W ? both ? what would be in the sader ? some helpers like UNITY_OUTPUT_DEPTH(i.depth)
in fragment ? or should the depth encoded in RGBA with
distance = EncodeFloatRGBA(i.depth.x); // Z
return(distance);
or should i encode both Z and W in RG and BA ?
Things must be detailed precisely ( as it’s not cooking
) and are not clear to me.
Here is for the rendering of the shadowmap from the light point of view…
but now. from the observer view… i understand, we must transfer the previously rendered shadowmap in
the observer view cam shader. then for each rendered pixel in the observer view, calculate the UV
coordinates in the shadowmap.
what would CLEARLY be the needed matrix for achieving this ? I undersdtand the matrix is set up in
a script and transfered to the shader. and it seems the code above:
o.sh = mul( _Object2World, v.vertex );
o.sh = mul( ShadowMatrix, o.sh );
do the right job.
o.sh = mul( _Object2World, v.vertex ); takes the v.vertex in object coords and transform then in world coords, then…
o.sh = mul( ShadowMatrix, o.sh ); take those calculated world coords and ‘simulate’ the light view camera to retrieve
UV texture coordinates.
Am i right or wrong ?
Then, from those UV coordinates we retrieve the Z ? W ? Z/W? W/Z? finally , what do/should we retrieve from this shadowmap
with the:
float4 shadow = tex2Dproj( _ShadowMap, i.sh );
???
Finally, this depth info we retrieved from the shadowmap., we compare it with the
depth of the observer view… but what are the coordinates those depths are compared in ?
as comparing a Z in objects space and a Z in light space is a nonsense.
I confess the best whole explanation of this principle would be 2 scripts and 2 shaders. or better…
a package what would load and run showing all the mechanics used in this shadowing process.
Maybe it’s whal i’ll offer here when i understand the whole thing and make a clear and simple
explanation. But first of all, i have to get this working in unity.
Thanks Aras and all for your incoming answers !
regards.