Hi,
As I was figuring out why shadow rendering takes a long time when object counts increase I found a very peculiar thing. I discovered that the shadow light frustum is projected once per object for each light.
in pseudo code:
For each shadow casting light
Clear the 2k x 2k shadow buffer
for each object
Render object to the shadow buffer at assigned tiles im the shadow buffer
for each object
Render the shadow light frustum to the view depth stencil to discover pixels affected by the light
Apply light calculation bsed on the stencil values
Clear the stencil
This is a totally non-optimal way of doing this and absolutely not scalable. I would rather first clear the stencil, then render all objects to the shadow buffer and then project the shadow caster frustums on the view and mark the affected
pixels with stencil. Then I would apply the lighting based on the stencil values.
in pseudo code:
For each shadow casting light
Clear the 2k x 2k shadow buffer
Clear stencil
for each object
Render object to the shadow buffer at assigned tiles im the shadow buffer
Render the shadow light frustum to the view depth stencil to discover pixels affected by the light
Apply light calculation bsed on the stencil values
Clear the stencil
Note how in the second implementation there is just one stencil clear and we do not apply lights for each object.
My qusetion is that is there an implementation for the second approach? If not I will write it. Why does the first implementation even exist?
Does it have something to do with the fact that this way we can select objects that do not receive shadow? Is there a check box for that?