这个着色器代码有什么问题吗?

The*_*per 1 opengl glsl sfml

rippleShader.frag文件代码:

// attibutes from vertShader.vert
varying vec4 vColor;
varying vec2 vTexCoord;

// uniforms
uniform sampler2D uTexture;
uniform float uTime;

void main() {
    float coef = sin(gl_FragCoord.y * 0.1 + 1 * uTime);
    vTexCoord.y += coef * 0.03;
    gl_FragColor = vColor * texture2D(uTexture, vTexCoord);
}
Run Code Online (Sandbox Code Playgroud)

vertShader.vert文件的代码:

#version 110

//varying "out" variables to be used in the fragment shader
varying vec4 vColor;
varying vec2 vTexCoord;

void main() {
    vColor = gl_Color;
    vTexCoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Run Code Online (Sandbox Code Playgroud)

请接受我的道歉,我现在无法发布图片.但是,当我运行该程序时,错误提示如下:

图片

Rab*_*d76 6

错误消息意味着您不允许为变量分配任何值vTexCoord,因为它是片段着色器的输入.

像这样改变你的代码:

void main() {
    float coef   = sin(gl_FragCoord.y * 0.1 + 1.0 * uTime);
    vec2 texC    = vec2(vTexCoord.x, vTexCoord.y + coef * 0.03);
    gl_FragColor = vColor * texture2D(uTexture, texC);
}
Run Code Online (Sandbox Code Playgroud)

注意,您会收到警告消息,因为您使用了一个整数常量值(1),而不是浮点值(1.0).