PDA

View Full Version : GLSL shaders - keeping a value per fragment iteration



high_flyer
21st June 2007, 15:21
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!

minimoog
22nd June 2007, 12:36
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.

high_flyer
22nd June 2007, 12:45
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 :-)

minimoog
22nd June 2007, 15:22
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...