Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Problem to write fragment buffer

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    28

    Problem to write fragment buffer

    Hi,

    I would like to write the output/buffer of fragment shader as I wish (e.g. all white), however this result is depending of the model's shapes presented in the scene. How can I proceed with this correctly?

    Follow below my minimal source code and the results.

    Thanks in advance!

    - Vertex:

    Code :
    #version 130
     
    void main() {
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }

    - Fragment:
    Code :
    #version 130
     
    void main() {
        gl_FragData[0] = vec4(1,0,0,1);
    }

    - Expected result:
    Click image for larger version. 

Name:	shader image_005.jpg 
Views:	52 
Size:	1.9 KB 
ID:	2814

    - Current result:
    Click image for larger version. 

Name:	shader image_006.jpg 
Views:	46 
Size:	4.2 KB 
ID:	2815

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,546
    Quote Originally Posted by romulogcerqueira View Post
    I would like to write the output/buffer of fragment shader as I wish (e.g. all white),
    however this result is depending of the model's shapes presented in the scene.
    In order to write a value for pixel, the shape(s) you send down have to cover the pixel. If you want to fill the whole screen, send down a full-screen quad.

    You also need to turn off any pipeline state (or internal app processing such as post-FX) which could modify the output of your fragment shader before it hits the framebuffer. For example, disable state such as BLENDing, ALPHA_TESTing, and multisample antialiasing.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    28
    Hi @DarkPhoton,

    thanks for your comment. I am using FBO-RTT in my C++/OSG code, so the gl_FragData is writing the buffer in the correct texture. In this case, is it necessary to send down a full-screen quad?

    Could you kindly give an example how can I do this?

    Best regards,

    Rômulo

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,546
    In OSG? No. You're more likely to find what you want looking through the OSG examples, searching the OSG mailing lists or forums, or reading the OSG docs. Basically you want to create an osg::Geometry containing a quad, a StateSet that turns off things like blending, alpha test, etc., and an Camera with a viewing and ortho projection that have the quad filling the width/height of the view frustum and screen.

    A random web search for "openscenegraph full-screen quad" turns up this as the first hit:

    http://forum.openscenegraph.org/viewtopic.php?t=13319

    Search down to createTexturedQuadGeometry. I have no idea if this is the best way to do it in the latest OSG.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •