Shadow Map gradients in Forward+ lighting loop

Started by
1 comment, last by ingramb 8 years, 2 months ago

I'm experimenting with a forward+ rendering setup, where I loop over a list of lights to apply in the pixel shader. If a given light has shadows enabled, I sample the shadow map for that light directly in the loop. I'd like to use EVSM shadow maps with anisotropic filtering, so I need the ddx/ddy of the texture sample position.

I'm thinking I can compute ddx/ddy of the world position outside the lighting loop, and then transform these derivatives into shadow map space using shadow matrix for each light. This seems like it would work, but might be expensive. Are there any other/better tricks for getting approximate derivatives to use?

Advertisement
In our engine I implemented it the way that you've described. It definitely works, but it consumes extra registers which isn't great. I don't know of any cheaper alternatives that would work with anisotropic filtering.

Awesome, thanks.

Follow up question, what about applying shadow in a deferred pass? In this case, I would be reconstructing world position from depth buffer, and then use that position to look up shadow map. This will mostly work, except the derivatives will be discontinuous on object edges in the depth buffer.

Googling around, the only real solutions I could find were to clamp the maximum mip level to minimize the problem, or remove mips all together. Is there any better technique to handle this case?

This topic is closed to new replies.

Advertisement