Search code examples
openglglslshadersfml

Is there anything wrong in this shader code?


Code of rippleShader.frag file:

// 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);
}

Code of vertShader.vert file:

#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;
}

Please accept my apologies, i can't post the image now. But when i run the program the a error promt as follow:

image


Solution

  • The error messages means, that you are not allowed to assign any value to the variable vTexCoord, because it is an input to the fragment shader.

    Change your code somehow like this:

    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);
    }
    

    Note, you get the warning message, because you used an integral constant value (1), instead of an floating point value (1.0).