0
\$\begingroup\$

Currently I have two ideas how to implement my lighting system:

1) Use one framebuffer per light source

  • no need to switch texture attachments of framebuffer
  • may be faster
  • bigger memory usage

2) Use one framebuffer for every light source

  • some time may be wasted on attaching new textures to framebuffer
  • less memory usage

So could you please tell me which way is better and why? Or I'm totally wrong on my thoughts and there is no difference at all?

\$\endgroup\$
  • \$\begingroup\$ Please describe your lighting method in a little more detail. How will colors be written into these buffers? Are you calculating lighting in world- or screen-space? \$\endgroup\$ – Jon Mar 7 '16 at 21:33
  • \$\begingroup\$ @Jon this isn't matter, is it? I'm just going to render the depth values for shadow projection. The real question is should I allocate a new framebuffer for each light or use only one by switching attached textures. \$\endgroup\$ – Ocelot Mar 7 '16 at 21:36
1
\$\begingroup\$

I know it's not the answer you're looking for, but you just need to pick one and implement it, because "it depends". Better answers will suggest that you optimize after the (working) code begins to create performance problems, by profiling both methods. Profiling is the only way to non-subjectively answer which is "better" and precisely how/why. Your game may already run at 1200 FPS using either method. You might also find that by moving a single Map(...) call down a few lines, the bottleneck is diminished or eliminated.

As an example, the memory footprint, alone, of 1000 lights using method 1 may be astronomical, impractical and, not to mention, impossible. So, if you plan to implement 1000's of lights, the design requirements may have already chosen "NOT method 1" for you. Since we don't currently know the limits of what you might implement in the finished product, we can't say which will definitely be better.

Don't Repeat Yourself (DRY) tells me not to create a ton of identical buffers so I, personally, would almost always opt for method 2.

\$\endgroup\$
  • \$\begingroup\$ About impossibility of first way - there is no real limit of framebuffers in OpenGL \$\endgroup\$ – Ocelot Mar 8 '16 at 0:42
  • \$\begingroup\$ There are limits defined by the OpenGL equivalent to a DirectX "feature level", but I agree that you're unlikely to push the limits at all, binding only one at a time; still, it's a bunch of unnecessary CPU overhead since they're all identically described. There's also no real good reason to "save" them beyond their immediate consumption by the lighting/shadow shader, is there? \$\endgroup\$ – Jon Mar 8 '16 at 1:36

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.