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 10 of 10

Thread: Color Input For Multiple Attached Fragment Shaders - OpenGL 1.2

Hybrid View

  1. #1
    Intern Contributor
    Join Date
    Sep 2007
    Location
    Southern California
    Posts
    60

    Color Input For Multiple Attached Fragment Shaders - OpenGL 1.2

    I want to attached a second fragment shader to an OpenGL 1.2 shader program that gets its input from a fragment shader that writes to glFragColor. This is all implemented on FBO's with render-to-texture.

    What is the correct syntax to access the RGBA pixel colors from the output of the first shader? The only variables I see in the orange book are glFrontColor and glBackColor, which I assume are for screen rendering, and not FBO rendering.prog

    FYI- My first fragment shader accesses a 16 bit float texture from a film scan, so I don't want to lose the color precision.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Don't think of it as "attaching a second fragment shader to an OpenGL 1.2 shader program that gets its input from a fragment shader that writes to glFragColor." That's only confusing yourself. Think of it as exactly what it is:

    1: render color values to a texture.
    2: make a second rendering using that texture as source input.

    Step 2 is no different from any other shader that accesses a texture. Therefore, the precision of Step 2 is based entirely on the precision of the texture.

    If you need 16-bit floating-point precision for inputs to step 2, the step 1 needs to write to a 16-bit floating-point texture (which step 2 will read).

  3. #3
    Intern Contributor
    Join Date
    Sep 2007
    Location
    Southern California
    Posts
    60
    Alfonse:

    Thanks for your advice. I thought I replied to your message last night, but I don't see the post. I guess I must have dreamed it.

    I'd rather not create an extra drawing procedure unless necessary. I'm already taking too long to process film scans at 24fps. I've been Googling multiple shader attachments and it seems that it's done with attaching multiple code fragments that are assembled as one shader with a single main() and output. Is that correct?

    Is it possible to declare uniform variables inside the main() body of a fragment shader? I've always declared them in the global variable space before main() executes. But if I can declare the uniforms that are accessed in each code fragment, I can split up some very long and complicated fragment shaders into fragment shader code sections. I could create a vec4 variable that holds the current color ouput, and just keep operating on it on each fragment.

    What do you think?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    that it's done with attaching multiple code fragments that are assembled as one shader with a single main() and output.
    Now we're talking about something else. Now you're talking about one fragment program with a single path of execution that comes from two shader objects. There's no FBO, no render-to-texture. It's all within a single program object.

    It doesn't work the way you think. If you link two shader objects together, you get a single program. But only one of them can have `main`. The system doesn't merge their `main` functions.

    The only reason to link multiple shader objects in the same stage together like this is for doing library stuff. That is, one of them defines one or more functions that are used by the other one. You can't use it to daisy-chain shaders. Well, not automatically; you can have one shader object's main function call a shader object's function, passing it whatever value it would have written. But that's up to you.

  5. #5
    Intern Contributor
    Join Date
    Sep 2007
    Location
    Southern California
    Posts
    60
    Dang this is confusing.

    If you can only have one shader with a main function, how does the other shader compile successfully?

    What would happen if I put the first half of a complete fragment shader text into one shader object, and the second half into another shader object. Would they conpile and assemble correctly into a program?

    Does the shader compiler look for a complete main function, or does it just compile any code with legal syntax, like a c++ compiler would. Please don't ask me why I want to do this, becasue I don't have a good answer.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    If you can only have one shader with a main function, how does the other shader compile successfully?
    The same way source files in C and C++ compile without having `main` in them. Shader objects are like object files in C/C++; you can't use them until you link them into a program.

    You should read up on this on the wiki.

Posting Permissions

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