3
\$\begingroup\$

I need to render two shapes with opengl (let's say a cube and a triangular prism) and one of them has texture and the other one has lightning fx. The thing I want to do is first draw texture and lightning and then render the shapes. I made a research, the only thing I could find is this is called gpu batching. Do you have any ideas or any tutorials etc. about this subject? How can I do this?

Edit: This video explains what I want to do: Crysis 2 - Rendering Pipeline

Edit: I heard that it is not possible for gpu to render different fxs for different geometries back to back. So I need to group geometries by fxs.(Cube has texture put it in the texture array, prism has lightning put it in the lightning array...then loop these arrays and render the scene) My aim is to first render fxs and then render geometries to render the whole scene.

\$\endgroup\$
3
  • \$\begingroup\$ Can't see the video now, but isn't it multipass shading? \$\endgroup\$ Jul 9, 2013 at 13:37
  • 3
    \$\begingroup\$ I believe you're talking about deferred rendering/shadubg. A simple search will show you many many good articles about it.wiki \$\endgroup\$
    – akaltar
    Jul 9, 2013 at 14:24
  • \$\begingroup\$ "Batching" is the process of organizing the objects you draw to use as few graphics API calls as possible, specifically as few draw calls as possible. \$\endgroup\$ Jul 9, 2013 at 18:03

1 Answer 1

3
\$\begingroup\$

You are looking for a technique called deferred shading. The basic premise is to reduce the number of lighting calculations done on a render while avoiding the expensive sorting used in the reverse painter's algorithm. The complexity of the whole procedure is O(number of objects + number of light sources). It takes (n+1) steps, where n is the number of light sources.

The first step renders each object to an intermediate buffer called the g-buffer. This wide buffer stores the depth, world-space normals, albedo (color), and other material parameters; all per-pixel. It is a quite cheap shader because it really just does vertex transformation and texture reads.

The second step runs once per light source and adds to a buffer called the la-buffer (light accumulation). The shader reads in the data for each pixel from the g-buffer and performs lighting calculations for the corresponding pixel in the la-buffer. The la-buffer is then either used directly as the output or run through a post-processing step. This step can be rendered with light geometry (sphere for point light, cone for spotlight, full-screen for ambient light) to avoid doing unnecessary light calculations.

The advantages of deferred rendering are that it scales much better to scenes with many dynamic light sources and that it only needs to do at worst one light calculation per pixel per light. However, it uses up a lot of memory for the g-buffer and is dependent on the fill rate of the GPU. The good news is that this problem will disappear as hardware gets faster and has more memory. It is also more difficult to implement transparency, but there is a method published to work around that problem. It also constrains you to essentially one lighting equation per light source, but this is generally a non-issue.

Here is an image describing the basic pipeline. enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ Thank you for your answer. This answer is a part of my aim. But I heard that it is not possible for gpu to render different fxs for different geometries back to back. My aim is to first render fxs and then render geometries to render the whole scene. \$\endgroup\$
    – kmetin
    Jul 9, 2013 at 19:44
  • \$\begingroup\$ I'm confused about what you are trying to achieve. From what it sounds like, you want to first render lighting effects and then geometry? This is not really possible. \$\endgroup\$
    – jmegaffin
    Jul 10, 2013 at 8:00
  • \$\begingroup\$ ok. I wonder what is your opinion about my last edit? "I heard that it is not possible for gpu to render different fxs for different geometries back to back. So I need to group geometries by fxs.(Cube has texture put it in the texture array, prism has lightning put it in the lightning array...then loop these arrays and render the scene)" isn't it possible? \$\endgroup\$
    – kmetin
    Jul 10, 2013 at 8:04

You must log in to answer this question.

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