Skip to content

Instantly share code, notes, and snippets.

@h3r2tic
Last active May 22, 2022 00:22
Show Gist options
  • Save h3r2tic/5671b999b8b6e5dde29665bdece4fd1a to your computer and use it in GitHub Desktop.
Save h3r2tic/5671b999b8b6e5dde29665bdece4fd1a to your computer and use it in GitHub Desktop.
kajiya ray count breakdown

There are two types of rays being traced: shadow and "gbuffer". The latter return gbuffer-style information from hit points, and don't recursively launch more rays. Lighting is done in a deferred way. There is just one light: the sun.

  • irradiance cache: usually fewer than 16k cache entries:

    • main trace: 4/entry * (1 gbuffer ray + 1 shadow ray for the sun)
    • restir validation trace: 4/entry * (1 gbuffer ray + 1 shadow ray for the sun)
    • accessibility check: 16/entry short shadow rays
  • sun shadow pass: 1/pixel shadow ray

  • final gather done at half-res; every third frame is a ReSTIR validation frame, and instead of tracing new candidates, it checks the old ones, and updates their radiance. in addition to that, the validation frame also traces very short contact rays; on paper it seems like it would be doing more work, but it's actually slightly cheaper, so I'm counting conservatively here:

    • 2/3 frames: regular trace: 0.25/pixel * (1 gbuffer ray + 1 shadow ray)
    • 1/3 frames:
      • validation trace: 0.25/pixel * (1 gbuffer ray + 1 shadow ray)
      • contact trace: 0.25/pixel * (1 gbuffer ray + 1 shadow ray)
  • reflections done at half-res, validation every frame at quarter-res

    • main trace: 0.25/pixel * (1 gbuffer ray + 1 shadow ray)
    • validation trace: 0.0625/pixel * (1 gbuffer ray + 1 shadow ray)

summing it up, we have:

  • irradiance cache: 128k gbuffer rays and 384k shadow rays
  • sun shadows: 1 shadow ray per pixel
  • final gather: 0.25..0.5 gbuffer rays and 0.25..0.5 shadow rays per pixel
  • reflections gather: 0.3125 gbuffer rays 0.3125 shadow rays per pixel

therefore, averaging:

(0.65/pixel + 128k) gbuffer rays and (1.65/pixel + 384k) shadow rays per frame

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment