Recently I come across the term forward rendering. I'm kind of curious how this could be done in OpenGL. I have done a lot of search on this, majority of the result I get are on theory but not code implementation. May I know is there any code implementation on OpenGL for this rendering technique?


2 Answers 2


There are two major types of rendering:

  1. forward rendering
  2. deferred rendering

In both types you have you objects and lights present in the scene, but the difference is when to calculate lighting.

Forward rendering

Render object, and while running its (usually) fragment shader, for each fragment you calculate lighting from all the light sources.

So, you for every object, and all of its fragments, calculate ligthing.

Why is this good and why is it bad?

  • It's bad because it might happen (and in most cases it does) that fragment is overwritten by the next, and all your lighting calculations are wasted. Also, running lighting calculations on each and every fragment is quite expensive. The cost is const and is equal to num_fragments * num_lights, and that's a lot.

  • It's good because it uses hardware enabled AA

Deferred rendering

Render into buffers the data that is required for calculating lighting later, such as diffuse color, specular power, normals... and after you've done that, run ligthing calculations for every light, but only on the parts of the image that cold possibly be affected by that light.

Cons and pros?

  • It's good because, once you have the information what is visible in the scene, you run calculations only on those parts. Further more, only on the parts of the image that could be affected by that light. The cost is in worst case scenario num_lights * num_pixels_of_screen.

  • It's bad because there's no AA and no support for transparent objects

In short, that's the difference between forward and deferred rendering. So if you put your lighting calculations directly into shading of the object, then it's called forward rendering. That means, almost any tutorial that you might find on the internet is probably implementing forward rendering type.

Hope this helps.

  • \$\begingroup\$ Except there is AA in deferred rendering http.developer.nvidia.com/GPUGems2/gpugems2_chapter09.html (look at part 9.5). And you can achieve transparency/translucency using the stencil buffer, look john-chapman.net/content.php?id=13 \$\endgroup\$
    – Soapy
    Dec 4, 2013 at 12:05
  • \$\begingroup\$ @Soapy, I meant by default. There is no hw AA, you need to do it as post-processing effect. Deferred rendering could use forward rendering for transparent objects. \$\endgroup\$ Dec 4, 2013 at 15:49
  • \$\begingroup\$ Well you should mention that in your question instead of saying "there is no AA and no support for transparent objects", it's misleading. \$\endgroup\$
    – Soapy
    Dec 4, 2013 at 22:06
  • \$\begingroup\$ @Soapy that link no longer works. It's for GPU Gems 2, available at the NVIDIA website. The article name is "Chapter 9. Deferred Shading in S.T.A.L.K.E.R." by Oles Shishkovtsov. As of 2024 this appears to be a direct link: developer.nvidia.com/gpugems/gpugems2/… \$\endgroup\$
    – markspace
    Mar 24 at 15:29

Forward rendering is the classic approach to rendering where the data for a scene is generally used directly to calculate a final pixel color in a single pass (additional post-processing passes can be used as well, but these are usually still considered part of forward rendering). The alternative, deferred rendering, generally encodes much more data (not necessarily actual colors) to an intermediate target, then defers the final render pass that uses the intermediate target as its source.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .