Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Opengl Deffered Rendering Questions

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    23

    Question Opengl Deffered Rendering Questions

    I just started getting into deferred rendering and in order to completely add this feature in my application I need to know certain things that I din't find an answer to yet.

    1. If I have multiple textures attached to my FBO for example: GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3. How do I chose in the fragment shader to which texture I want to render ?

    Do I create the output like this if I want to write to GL_COLOR_ATTACHMENTn: layout(location = n) out vec3 color; ?

    2. In order to render the contents of the FBO to screen do I need to draw a full screen quad ?

    Thanks in advance !

    Btw Its the first time I use this forum

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675
    Do I create the output like this if I want to write to GL_COLOR_ATTACHMENTn: layout(location = n) out vec3 color; ?
    That's close to how it works, but not exact. The output color index indexes into the array of draw buffers that is part of the framebuffer state. So you need to set both the output indices and the draw buffer array.

    In order to render the contents of the FBO to screen do I need to draw a full screen quad ?
    That is the traditional method. Though there's evidence to suggest that it's faster to render multiple, smaller quads, for cache-coherency reasons.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    23
    Thanks, That cleared out what I needed

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    23
    I have one last question. How can I get the texture from GL_COLOR_ATTACHMENTn and send it to the fragment shader of the full screen quad for drawing ?

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    23
    If I bind frameBuffer to 0 and use glBlitFramebuffer() whould it draw to the screen without having to draw quad and setting the GL_COLOR_ATTACHMENTn to the corresponding attribute in the fragment shader ?

  6. #6
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675
    How can I get the texture from GL_COLOR_ATTACHMENTn and send it to the fragment shader of the full screen quad for drawing ?
    Well, since you put that texture there, I assume you know what texture it is. So just use that texture with a sampler in your shader. Just like normal. The only special thing you need to make sure of is that it's not currently part of the draw framebuffer object when you try to read from it in the shader.

    If you have somehow forgotten which texture you put somewhere, you can query this from OpenGL with glGetFramebufferAttachmentParameter. But this would represent a pretty pathological element of your code, with your left hand not knowing what your right hand is doing.

    If I bind frameBuffer to 0 and use glBlitFramebuffer() whould it draw to the screen without having to draw quad and setting the GL_COLOR_ATTACHMENTn to the corresponding attribute in the fragment shader ?
    I'm not sure what you mean by "the corresponding attribute in the fragment shader". If you're asking "does blitting call the current fragment shader", then the answer is "no." A blit is a copy operation. If you want to invoke the fragment shader, you need to actually draw something.

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    23
    Can you give me some code example of sending GL_COLOR_ATTACHMENTn to a shader ?

  8. #8
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675
    Can you give me some code example of sending GL_COLOR_ATTACHMENTn to a shader ?
    You don't "send" a color attachment to a shader.

    It's not clear what part you're having trouble with. Do you know how to use a texture with a shader at all? Do you know how to use a texture with an FBO as a render target?

    If you know both of these, then you know everything you need. Nothing special happens to the texture just because you use an FBO to render to it. Simply unbind the FBO and use that texture as you always have.

  9. #9
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    23
    Oh.. yes I got confused, now I remember it ) , thanks !

  10. #10
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    23
    I have one problem now, I get black textures...

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 02-01-2016, 02:27 PM
  2. Lighting don't work properly with deffered rendering
    By RobertBerg in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-15-2015, 01:40 PM
  3. Deffered shading on Iphone. Is it possible?
    By ei05tbe in forum OpenGL: GLSL
    Replies: 1
    Last Post: 06-27-2010, 06:54 PM
  4. Deffered Shading
    By isato in forum OpenGL: GLSL
    Replies: 12
    Last Post: 05-14-2010, 06:42 PM
  5. Deffered shadows!
    By yooyo in forum OpenGL: GLSL
    Replies: 1
    Last Post: 07-07-2004, 03:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean