0
votes

I'm trying to write a deferred renderer in OpenGL that supports multiple materials (different lighting models etc.) and layered materials (different materials blended together).

I'm writing the material ID to a g-buffer as well as the standard vertex attribute g-buffers. How would I use a different shader for each pixel in the second stage (when the lighting is calculated and rendered to the screen)?

I thought about using a compute shader to make a list of pixels for each material ID then generating a mixture of quads, points, and maybe lines out of it and then reading these meshes back to the CPU and rendering them with their respective materials. I think this would be a bit slow the mesh has to be read and written back each frame.

1

1 Answers

2
votes

A. Write an uber-shader that chooses exact shader path based on pixel MaterialID attribute. That could work well for multiple materials. That uber-shader could consist of several sections stitched together programatically, to simplify development.

B. Reduce materials count. Speaks for itself.

C. Add more channels to your g-buffer to store varying material parameters (e.g. Specular)

D. Do multiple passes with different shaders and use MaterialID as a sort of "stencil" to either render if it's matching material and shader or discard; to skip the pixel ASAP.

You can combine these solutions as well.