Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎯 Unreal

texture tileing problem (solved)

Started by fazekaim Jan 12, 2005 at 5:32 PM 1 replies 700+ views
Original Post
fazekaim
fazekaim
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:
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);
}

fragment shader:
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;
            }


and the result is: http://delfin.unideb.hu/~fazekaim/problem.jpg Thanks! [Edited by - fazekaim on January 13, 2005 4:28:39 PM]
MButchers
MButchers
What I tend to do is animate textures via the texture matrix rather than altering the actual texture coordinates, this allows you to apply all the usual transforms like translation, rotation and scaling simply and very quickly!

Mark
fazekaim
fazekaim
Ohhh! Many thanks! I try it write now:)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.