0
\$\begingroup\$

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?

\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\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 '13 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\$ – Abstract Algorithm Dec 4 '13 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 '13 at 22:06
1
\$\begingroup\$

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.

\$\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.