开发者

Knowing which pixel or UV you are on with GLSL?

开发者 https://www.devze.com 2023-03-08 21:30 出处:网络
Right now I can obtain the color of the 开发者_Go百科neighbouring pixelby doing color = texture2D(backBuffer, vec2(gl_TexCoord[0].x + i,gl_TexCoord[0].y + j);

Right now I can obtain the color of the 开发者_Go百科neighbouring pixel by doing

color = texture2D(backBuffer, vec2(gl_TexCoord[0].x + i,gl_TexCoord[0].y + j);

But how can I know what pixel that is or at least the current uv of that pixel on the texture?

Which pixel of the fragment. The UV / ST is a number from 0 to 1 representing the whole texture.

I want to calculate a pixels brightness based on its distance from a point.


gl_TexCoord[0].x gives you the s texture coordinate, while gl_TexCoord[0].y gives you the s texture coordinate.

If you are writing fragment shader, the pixel position shouldn't matter. I haven't tried, but maybe you can get it using gl_in, which is defined as :

in gl_PerVertex {
vec4 gl_Position;
float gl_PointSize;
float gl_ClipDistance[];
} gl_in[];

but I am not sure it if it available for pixel shader.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号