2
\$\begingroup\$

I am currently thinking about how to organize shadowing and lighting.

We use forward rendering and currently, our algorithm looks like this:

  • collect all items that are visible in the view
  • for each item, collect a list of lights where the item is in the attenuation radius (each item keeps a list of lights)
  • determine the shadow light by the distance of the main character (only one light can currently cast shadow)
  • render the scene by using a constant buffer of the currently processed item to shade it (each item is rendered with a constant buffer which contains light properties. the number of lights per item is predefined so we have a Light[16] and numLights in the constant buffer)

How would I do multiple shadow-casting lights in an organisatory way?
We do not want to go the deferred way, since we dont want to limit us to GBuffers.

\$\endgroup\$
1
\$\begingroup\$

The answer is primarily depends on target hardware. For modern GPU I would like to suggest tiled or clustered forward rendering.

The core idea behind the clustered forward rendering is to split frustum on clusters (froxels).

You need the following GPU resources:

  • Texture3D to be aligned within frustum.
  • Buffer to keep indices of lights (list).
  • Several constant or structured buffers to keep lights' data for each light type (omni, spot, etc).

Shading algorithm is following:

  1. On CPU: For each cluster collect all lights that affect given cluster. Add indices of these lights to list of indices. Write starting offset and count of indices to 3D texture. This part could be done on GPU side, but CPU is pretty fast.

  2. On GPU: In pixel shader determine cluster, get index offset and number of indices and iterate over all lights.

For shadows I would recommend to render all shadow maps to atlas. Light may contain atlas region and shadow map projection matrix.

See this paper for more details:

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.