为什么我无法编辑 gl_FragCoord?
Why I cannot edit gl_FragCoord?
作为标题,
我在 WebGL 程序的片段着色器中有这一行,
gl_FragCoord.xy = vec2(gl_FragCoord.x + 1.0,gl_FragCoord.y);
并且 Google Chrome 控制台显示:
错误:0:45:'assign':需要l-value "gl_FragCoord"(无法修改gl_FragCoord)
为什么?
gl_FragCoord
是您的着色器当前运行的片段的坐标。您不能动态选择正在处理的片段 "for parallelization reasons",因为 "GPUs are not designed that way",如果您想了解更多有关 GPU 架构的信息,A trip through the Graphics Pipeline by Fabian Giesen aka ryg 是一个很好的资源。
Available only in the fragment language, gl_FragCoord is an input variable that contains the window relative coordinate (x, y, z, 1/w) values for the fragment. If multi-sampling, this value can be for any location within the pixel, or one of the fragment samples. This value is the result of fixed functionality that interpolates primitives after vertex processing to generate fragments.
OpenGL SDK Doc
作为标题, 我在 WebGL 程序的片段着色器中有这一行,
gl_FragCoord.xy = vec2(gl_FragCoord.x + 1.0,gl_FragCoord.y);
并且 Google Chrome 控制台显示:
错误:0:45:'assign':需要l-value "gl_FragCoord"(无法修改gl_FragCoord)
为什么?
gl_FragCoord
是您的着色器当前运行的片段的坐标。您不能动态选择正在处理的片段 "for parallelization reasons",因为 "GPUs are not designed that way",如果您想了解更多有关 GPU 架构的信息,A trip through the Graphics Pipeline by Fabian Giesen aka ryg 是一个很好的资源。
Available only in the fragment language, gl_FragCoord is an input variable that contains the window relative coordinate (x, y, z, 1/w) values for the fragment. If multi-sampling, this value can be for any location within the pixel, or one of the fragment samples. This value is the result of fixed functionality that interpolates primitives after vertex processing to generate fragments. OpenGL SDK Doc