Per-light Shadow Type Pt 1 : Move Spot / Directional Light Shadow Functions
This PR moves the shadow type check up to the lighting loop in lights_fragment_begin.glsl.js in a step towards enabling per-light shadow types, as discussed in #18934. This will allow both VSM and PCF shadows to be used in the same scene, for example.
The shadow logic for directional and spot lights has been separated into different functions so they can be individually called based on the shadow type define. In an upcoming PR the shadow code will be changed to something like so:
#if DIR_LIGHT_SHADOW_TYPE_{{ UNROLLED_LOOP_INDEX }} == SHADOWMAP_TYPE_PCF
// ...
#endif
A couple things I'd like some ideas on as well as a general review:
- In separating out the shadow logic there is some redundancy in in the shadow functions -- any thoughts on how to best reuse it?
- I see that
shadowVSMwas separated out into another function previously. Was there a reason?Is it okay to move the logic into the new VSM function?
Next PRs
- Update point light shadows similarly
- Fix CSM example
- Implement per-light shadow type defines
/ping @Oletus
I think this is a reasonable step, and the plan on next PRs looks good as well. Maybe the code that's the same across the different shadow functions could be put in a separate helper function with a few out parameters? I'm not sure about what's the history of the VSM code.
Nit: There are a few tabs vs. spaces formatting issues in the shader code.
Nit: There are a few tabs vs. spaces formatting issues in the shader code.
Thanks for the catch -- fixed those. The templated code blocks always get me...
Other updates:
-
I've pulled the frustum test out out into a separate function for reuse. I looked into whether or not we'd be able to do anything fancy with macros but given where the code is going I think it could get very complicated. I'll look into that a bit more in a future PR.
-
I've updated the CSM example so it doesn't block a release.
-
I've updated the
shadowMaskshader chunk which I forgot to do previously.
I'm going to consider this ready for review and have tested it by running all of the the "shadowmap" and "lights" examples. An aside but I did notice that some of the examples logged a shader error before I fixed the "shadowMask" chunk. Maybe it's worth updated the E2E tests so they fail if an error is logged?