4
\$\begingroup\$

I'm building a deferred renderer and since I want to support a large amount of lights in the scene I've had a look at tiled deferred shading.

The problem is that I have to target OpenGL 3.3 hardware and it doesn't support GLSL compute shaders.

Is there a possibility to implement tiled deferred shading with normal shaders?

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

You can sort of fake it with a pixel shader, but it requires an extra pass. I don't claim this is a great approach, BUT it will work:

Create two low-res render targets - say, 1/8th of your framebuffer size - and render each of your lights. Render to the first target, with the second bound to a sampler. In your PS, sample the second target, set a bit in the result corresponding to the light's ID, and write it to the first (gl_Color, output var or whatever). CPU side, swap the two targets and repeat for each light.

When you're done, you'll have a texture where every texel has a bit set for the lights that touch it.

This isn't nearly as flexible as using compute, especially async compute, but it'll take some pressure off of the lighting pass.

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Yes, you can. The issue is performance. The main benefit of tiling is that it enables the use of compute shaders so that you can short circuit your rendering logic and avoid unnecessary calculations.

There's no reason you can't do the same thing without compute shaders but the problem is that you will have much less pleasing performance. Which makes it kind of pointless.

So if you want to use tiled deferred shading then it's probably better to use separate deferred shading implementations for versions of ogl that support compute shaders and the ones that don't.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ This assumption is possibly flawed (A) because hardware tends to take advantage of short-circuits just fine, as long as the entire block takes the same path, and (B) because a good implementation can simply write out the first layer of lights for all pixels, and load screen-tile polygons in the meantime, so that the further layers don't hit extra pixels. \$\endgroup\$ – MickLH Feb 9 '17 at 1:42

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.