GLSL woes

I’ve got my FBO ping pong up and running. But I’m having an issue on the GLSL side. I have a setup where I’m doing two passes with different shaders in my render loop. The first pass with my “process” shader writes to my FBO and creates a texture. The second, rendering, pass uses the texture created from the first pass to generate colors (it does not actually render the texture).

I know this set up works, because in my “process” shader, I can set gl_FragData[0] to a color, and in my “render” shader, I can render that color.

My problem is more with coordinates. In my “process” shader, I need to look at neighboring pixels in the texture and update gl_FragData[] based on their values. In my “render” shader, I need to do the same thing to create a color based on shading/refraction.

I’m passing in the screen width and height to both, and am successfully retrieving those values, so I have that to work with. However, I just can’t get my texture coordinates lined up to save my life.

Is there any way I can use the screen width and height variables I have in my shaders to get everything into screen space? How do I get the color of neighboring pixels in my texture?

Thanks in advance.

Texture addressing is 0,0 lower left and 1,1 upper right.

0,0 is one half a pixel below and left of the center of the lower left texel, and 1,1 ir one half a pixel above and right of the upper right texel.

Sampling one texel left or right is just a matter of adding or subtracting 1.0/texture_width.

Sampling one texel above or below is a matter of adding or subtracting 1.0/texture_height.

However in order to sample a texel center your fetch point for the 0,0 pixel center should be (0.51.0/texture_width, 0.51.0/texture_height).

Getting that value on that pixel center is a matter of rasterizing with appropriate texture coordinates. teh simplest way is to draw a vertex at the pixel midpoint with a coordinate 0,0 and let the hardware do the interpolation during rasterization.

So there are thre components; correct pixel rasterization coordinates (after transform), correct texture coordinate alignment after rasterization and correct shader texel offset.

Useful note about hapfpixel business Dorbie.
(On the side note: nice performance at the Torrey Pines Gliderport :slight_smile:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.