# Deferred lighting and problem with resolution

This topic is 3029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, i have some problem with resolution of G-Buffer, for example if i have viewport resolution: 800X600 i have ~80 FPS, if i have 4 times less i have 200FPS, if i have 1280X1024 i have only 30 FPS. Do u have any idea why ive got so less frame rate? If you need parts of my code to recognize problem just write, ill paste it.

##### Share on other sites
The speed of writing to and reading from a texture is dependent on its size. This speed is called the fill rate, and the more pixels in the texture, the longer it takes to fill.

200 x 150: 30000 pixels
800 x 600: 480000 pixels - 16x bigger than 200 x 150.
1280 x 1024: 1310720 pixels - 44x bigger than 200 x 150.

So you can see from this that the speed of operations will be much slower on the largest texture, because it has 44 times more pixels for the graphics card to fill.

If you don't need the precision, keep the buffer a smaller size than the viewport, maybe half the size in each dimension? Experiment with different values to find out what you need in your application.

You could also try simplifying your shader code so that it takes less time for each fragment. If you want some help doing this, post it up and I'll take a look. And you may have unnecessary steps in your rendering code, so post that up too :P

Sput

##### Share on other sites
First of all - i need good precision because if game is in 1280 X 1024 resolution - it should be at this resolution yes? So i cannot change viewport size to smaller(i think).

"Defferred steps":
1. set Blending off, set depth test to LEQUAL
2. starting render to depth G-buffer:
[source=cpp]    GLenum bufs[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT};	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, deferredShadingFBO);	glDrawBuffers( 3, bufs);	glClearColor(0,0,0,0);	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

3.render objects(with shader which name in ZIP is "basic") with VBO/VAO
4.stop render into depth G-buffer
5.start render into G-buffer lightSpace:
[source=cpp]GLenum bufs[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT};	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, lightAccumFBO);        glDrawBuffers( 1, bufs);	glClearColor(0,0,0,0);	glClear(GL_COLOR_BUFFER_BIT);    glBlendFunc( GL_ONE, GL_ONE);    glEnable( GL_BLEND);    glEnable( GL_DEPTH_TEST);    glDepthMask( GL_FALSE);/*here are FBO textures in which i render into*/    glActiveTexture( GL_TEXTURE0);    glBindTexture( GL_TEXTURE_2D, normal);    glActiveTexture( GL_TEXTURE1);    glBindTexture( GL_TEXTURE_2D, material);    glActiveTexture( GL_TEXTURE2);    glBindTexture( GL_TEXTURE_2D, pos);

6. render lights(dir light shader u got at ZIP file)- rendering here is maximum efficient(im sure)
7.stop render into g-buffer light space:
[source=cpp]glDepthMask( GL_TRUE);		glBindTexture( GL_TEXTURE_2D, 0);		glActiveTexture( GL_TEXTURE2);		glBindTexture( GL_TEXTURE_2D, 0);		glActiveTexture( GL_TEXTURE1);		glBindTexture( GL_TEXTURE_2D, 0);		glActiveTexture( GL_TEXTURE0);		glBindTexture( GL_TEXTURE_2D, 0);					glEnable( GL_DEPTH_TEST);			//here is place objects without lighting effect		glDisable( GL_BLEND);	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

##### Share on other sites
Quote:
 hi, i have some problem with resolution of G-Buffer, for example if i have viewport resolution: 800X600 i have ~80 FPS, if i have 4 times less i have 200FPS, if i have 1280X1024 i have only 30 FPS. Do u have any idea why ive got so less frame rate? If you need parts of my code to recognize problem just write, i`ll paste it.Thanks for any advices

Deferred shaders are often pixel bound, meaning that when increasing the resolution it will get much slower.

To solve your problem you have to optimize your render pipeline. One option is to reduce the resolution of a framebuffer for "some" operations. You don't need the full resolution for blurring or ssao, still lighting should be done in full resolution.

The next option is to optimize the format of your framebuffers. Try to use half-float instead of float. Get rid of unused channels. Bundle channels in one framebuffer so that in your pipeline you don't need to use always all framebuffers as input. Pack normals into just two channels instead of three.

The next option is to optimize the shaders. Try to avoid many texture fetches. Instead of rendering a fullscreen quad for each light, try to calculate the lighting of X lights in a single pass. Try to avoid dynamic branching.

##### Share on other sites
Quote:
 To solve your problem you have to optimize your render pipeline. One option is to reduce the resolution of a framebuffer for "some" operations. You don't need the full resolution for blurring or ssao, still lighting should be done in full resolution.

Em, i get this FPS without HDR/MSAA/SSAO

Quote:
 The next option is to optimize the format of your framebuffers. Try to use half-float instead of float. Get rid of unused channels. Bundle channels in one framebuffer so that in your pipeline you don't need to use always all framebuffers as input. Pack normals into just two channels instead of three.

I ll try this but really i dont have any idea how to pack it.

I have heard thats its possible to do something with stencil test. Can someone tall me more about this?

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013223
×