Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Directional Light Cookie Sync Issue

Discussion in 'High Definition Render Pipeline' started by three-ms-creative, Apr 18, 2022.

  1. three-ms-creative


    May 5, 2021
    Hi everyone,

    I've been banging my head against the wall with a particular issue involving the directional light cookie.

    I have a custom volumetric clouds shader that renders out a shadowmap from the sun's perspective every frame. It then sets this shadowmap as the sun's light cookie texture, so that the clouds cast shadows on scene geometry.

    This is all well and good, except for when the directional light's y rotation is updated. In this case, the cookie appears to jitter momentarily as the rotation is adjusted, before falling into place as the rotation stops changing.

    See the following video:

    Things that I've tried so far:
    • Grabbing the light's forward/up/right axes from HDRP's builtin shader variables (i.e. the
      array), as opposed to the lights array I populate myself.
    • Rendering the shadow map at a few different points in the pipeline.
    • Projecting the light's transform one frame forward with an eulerian step based on the delta with the last frame (this was a shot in the dark and definitely did not work).
    The problem seems to be something like,
    • The expected view transform for the light cookie lags behind the light's proper transform by a frame or so.
    • OR the light cookie atlas doesn't update every frame in the way you'd expect, meaning the shadow map displayed for a given frame isn't the one that was actually rendered that frame.
    IIRC, HDRP's clouds implementation uses the light cookie for shadows as well. I imagine there's a fix here, but even after inspecting the source for hours I can't seem to sort out what I'm doing wrong.

    Thanks in advance!
    ftejada and AxonGenesis like this.