Original Post
Hello! I want to render water with an animated plane. I'm using a texture, and I move the coordinates by the time using cos and sin functions. I divided the plan into tiles. My problem is, when I add the sin and cos value to the texture coordinate, the texture will have got a "border" when the tiles meet. The water texture is seamless, so I compute something wrong... Here is my code: vertex shader: fragment shader: and the result is: http://delfin.unideb.hu/~fazekaim/problem.jpg Thanks! [Edited by - fazekaim on January 13, 2005 4:28:39 PM]
uniform float time;
void main(void)
{
float t = time * 0.25;
gl_Position = ftransform();
float sin1 = sin(t) * 0.2;
float cos1 = cos(t) * 0.2;
float temp1 = gl_MultiTexCoord0.x + sin1;
float temp2 = gl_MultiTexCoord0.y - cos1;
float temp3 = gl_MultiTexCoord0.x - sin1;
float temp4 = gl_MultiTexCoord0.y + cos1;
gl_TexCoord[0].x = temp1 < 0.0 ? 1.0 + temp1 : ( temp1 > 1.0 ? temp1 - 1.0 : temp1);
gl_TexCoord[0].y = temp2 < 0.0 ? 1.0 + temp2 : ( temp2 > 1.0 ? temp2 - 1.0 : temp2);
gl_TexCoord[0].z = temp3 < 0.0 ? 1.0 + temp3 : ( temp3 > 1.0 ? temp3 - 1.0 : temp3);
gl_TexCoord[0].w = temp4 < 0.0 ? 1.0 + temp4 : ( temp4 > 1.0 ? temp4 - 1.0 : temp4);
}
uniform sampler2D water;
varying float waterdistance;
void main (void)
{
vec3 normal = texture2D(water,gl_TexCoord[0].xy).xyz - texture2D(water,gl_TexCoord[0].zw).xyz;
float temp = dot(normal, vec3(0.5,0.707,0.5) );
gl_FragColor = clamp( (vec4( temp * temp * 2.0 + 0.5) * vec4(0.05,0.4,1.0,0.8) ), 0.0, 1.0 );
gl_FragColor.a = 0.9;
}