知道 GLSL 处于哪个像素或 UV 上?
现在我可以通过以下方式获取相邻像素的颜色
color = texture2D(backBuffer, vec2(gl_TexCoord[0].x + i,gl_TexCoord[0].y + j);
但是我如何知道该像素是哪个像素或至少是纹理上该像素的当前 uv ?
片段的哪个像素。 UV / ST 是代表整个纹理的从 0 到 1 的数字。
我想根据距点的距离计算像素亮度。
Right now I can obtain the color of the 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gl_TexCoord[0].x
为您提供 s 纹理坐标,而gl_TexCoord[0].y
为您提供 s 纹理坐标。如果您正在编写片段着色器,则像素位置应该不重要。我没有尝试过,但也许你可以使用
gl_in
来获取它,它的定义为:但我不确定它是否可用于像素着色器。
gl_TexCoord[0].x
gives you the s texture coordinate, whilegl_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 :but I am not sure it if it available for pixel shader.