Results 1 to 4 of 4

Thread: GLSL shaders - keeping a value per fragment iteration

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default GLSL shaders - keeping a value per fragment iteration

    Hi,

    I need to implement a demosaic/debayer algorithm in a fragment shader.
    The bayer masked image is given as a texture to the shader.
    I have the need to know if my current fragment position is on an odd or
    even position.
    However, the texture position (s,t) is given in float values 0.0-1.0.
    Converting the values to ints by using a float unit of my dimension is
    ambiguous due to the float resolution:
    float yUnit = 1/texHight;
    float currentY = gl_TexCoord[0].t * yUnit;
    There is no guarantee currentY will have a zero exponent. (i.e X.00),
    and even if the exponent is 0, its not nesseseraly correct.

    So my questions are:
    1. As far as I know there is no concept of "static" in GLSL. - is this
    true?
    If it is, is there a way to have a value stored from one fragment
    iteration to the next?
    This could solve my problem, since I could just keep a counter to
    know on which Y line I am on.
    2. Any other suggestions on how to deal with this problem is more then
    welcome.

    Thanks!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  2. #2
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GLSL shaders - keeping a value per fragment iteration

    Quote Originally Posted by high_flyer View Post
    I need to implement a demosaic/debayer algorithm in a fragment shader.
    The bayer masked image is given as a texture to the shader.
    I have the need to know if my current fragment position is on an odd or
    even position.
    You can use predefined even/odd texture same dimensions like masked image, where values for the texels would be, example, 0 for even, 1 for odd.

    If it is, is there a way to have a value stored from one fragment
    iteration to the next?
    Render to texture(s), aka FBO.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: GLSL shaders - keeping a value per fragment iteration

    You can use predefined even/odd texture same dimensions like masked image, where values for the texels would be, example, 0 for even, 1 for odd.
    Thanks for answering.
    Yes, I thought of that, but I really would like to stay with one texture.
    I tryied using calculation with floats, and it looks like it does work.
    I thought that there is going to be an accumulated floating resolution error, but it looks that there is none.
    Render to texture(s), aka FBO.
    True, I could just use one pixel texture. thanks, I don't need it any more, but thanks never the less for the idea, might come handy some day :-)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GLSL shaders - keeping a value per fragment iteration

    Thanks for answering.
    Yes, I thought of that, but I really would like to stay with one texture.
    I tryied using calculation with floats, and it looks like it does work.
    I thought that there is going to be an accumulated floating resolution error, but it looks that there is none.
    Another variant of my idea. The even/odd texture could be small, 2x2 size. GL_REPEAT will do the rest...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.