Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
Can't see the video now, but isn't it multipass shading? –  Gustavo Maciel Jul 9 '13 at 13:37
3  
I believe you're talking about deferred rendering/shadubg. A simple search will show you many many good articles about it.wiki –  akaltar Jul 9 '13 at 14:24
    
"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. –  Sean Middleditch Jul 9 '13 at 18:03
add comment

1 Answer

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

share|improve this answer
    
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. –  Kutluhan Metin Jul 9 '13 at 19:44
    
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. –  Boreal Jul 10 '13 at 8:00
    
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? –  Kutluhan Metin Jul 10 '13 at 8:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.