Results 1 to 3 of 3

Thread: Output type of frag shader - can it be set dynamic

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    16

    Output type of frag shader - can it be set dynamic

    Hi,
    Is it possible for a fragment shader to write out either a uint OR a vec4 all depending on the state of a uniform bool?
    Assuming the appropriate FBO is attached once the drawing is started of course?

    I have tried but cannot make it work so I am just looking to double checking if I have missed something. I cannot see this explicitly stated in the standard, which says something about unused outputs being ignored.

    I understand that I can write out two datatypes simultaneously, but that is not what I am looking for.

    My frag shader is below and depending on the state of indxmode I would like to write out either "mcode" or "color".

    Thanks!


    #version 420
    in vec3 texcoord;
    out uint mcode;
    out vec4 color;

    uniform usampler3D texindx;
    uniform usampler3D tex;
    uniform vec2 winlevel;
    uniform bool indxmode;
    float colval;
    float alpha=1.0;
    uvec4 val;


    void main()
    {


    if (!indxmode)
    {
    val=texture(tex,texcoord);

    float imgmin=winlevel[1]-0.5*winlevel[0];

    colval=(float(val.r)-imgmin)/(winlevel[0]);

    color = vec4(colval,colval,colval,alpha);
    } else
    {
    val=texture(texindx,texcoord);
    //mcode=val.r;
    mcode=1999;

    }

    }

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,674

    Re: Output type of frag shader - can it be set dynamic

    And what exactly would be written to the other image?

    If you want to do this kind of thing, you shouldn't use outputs. Use shader_image_load_store instead.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2010
    Posts
    16

    Re: Output type of frag shader - can it be set dynamic

    Thanks for reply.
    Nothing would be written to the screen buffer when indxmode is false. The intention is to set indxmode to true only when there has been a spatial change in the scene and then only as a second render to the FBO (following/before the scene redraw).
    Thanks for the pointer to the new functionality that I may make use of. It will either be that or simply have a second shader program for the integer buffer.
    Thanks again,
    Soren

Similar Threads

  1. Point Frag Shader: If statement causes inconsistent color output.
    By CaptainSnugglebottom in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-21-2018, 11:12 PM
  2. Frag Shader vs BlendFunc
    By imported_CRasterImage in forum OpenGL: GLSL
    Replies: 2
    Last Post: 09-12-2012, 12:15 PM
  3. Getting list of frag data output names
    By nesister in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 02-06-2012, 09:46 AM
  4. Frag shader without vertex shader?
    By tajscener in forum OpenGL: GLSL
    Replies: 14
    Last Post: 03-01-2008, 03:36 PM
  5. Why need to have one vertex and one frag shader?
    By Bruce Sinner in forum OpenGL: GLSL
    Replies: 4
    Last Post: 09-02-2004, 06:18 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