World vs View space and normal offsets

Started by
0 comments, last by WFP 8 years, 11 months ago

I'm working on removing shadowmap acne using normal offsets as per http://www.dissidentlogic.com/old/#Normal%20Offset%20Shadows

The math to do basic normal offsets is this:


const float texSize = 2.0 / SHADOWMAP_SIZE;
const loat normalOffset = 5.0;
    
// used to sample shadowmap
position += (normal * normalOffset * texSize);

The above example assumes world space.

In my pipeline I am working in view space rather than world space - my position and normal is both in view space. Does this have any impact on the code above? Is the math the same regardless is position/normals are world or view space?

And as a sidenote, does anyone have any typical constant values for normalOffset?

Advertisement
I recently implemented a very similar solution to what you have above, and I also store my data in view space rather than world space. In short, the answer is no, there is no real impact on the code. Just be sure that ALL your relevant calculations are taking place in the same space. For example, I further scale my normal offset value by the angle between the negated light direction and the surface normal (an idea that can be found in the dissidentlogic link you provided). If the surface normal were in view space and the light was in world space, there would obviously be a problem (and you'd notice it immediately). I don't have a great answer for typical values, unfortunately. I've found that it still depends on a combination of the light range, shadow projection matrix, and of course shadow map resolution to some extent. I use a combination of depth bias and normal offsets like what's described here http://www.digitalrune.com/Support/Blog/tabid/719/EntryId/218/Shadow-Acne.aspx and in general I've found that I'm always setting the normal offset value higher than the depth bias, which is typically very small. You may have to adjust it per-light, but if you get it all set up, you can get pretty decent looking shadows this way with some fine tuning.

This topic is closed to new replies.

Advertisement