Crossposted https://forum.openframeworks.cc/t/shader-cannot-move-texture-x-y-location/29395 Hello I am trying to move the x y location of the texture using this code but it doest not work.
//Fragment shader
#version 120
#extension GL_ARB_texture_rectangle : enable
#extension GL_EXT_gpu_shader4 : enable
uniform sampler2DRect texture0;
void main(){
//Getting coordinates of the current pixel in texture
vec2 pos = gl_TexCoord[0].xy;
// pos.x = (pos.x/0.5); //working
pos.x += 0.2 //<-- not working how to fixed this?
//Getting the pixel color from the texture texture0 in pos
vec4 color = texture2DRect(texture0, pos);
//Changing the color - invert red, green, blue components
//color.r = 1.0 - color.r;
color.g = 1.0 - color.g; //working..
//color.b = 1.0 - color.b;
//Output the color of shader
gl_FragColor = color;
}
//Vertex shader
#version 120
#extension GL_ARB_texture_rectangle : enable
#extension GL_EXT_gpu_shader4 : enable
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}
whats wrong with this code? pos.x += 0.2 //not working how to fixed this?
////////////////////////////////////////////////////////////////////////
I found the solution pos.x += 0.2 already working but it is not visible. if I tried bigger number like pos.x += 100 it is clear that the textures moves.
move x, y location of the texture
as in move the object that the texture is applied on? offsetting the texture on the object? $\endgroup$I found the solution pos.x += 0.2 already working but it is not visible. if I tried bigger number like pos.x += 100 it is clear that the textures moves.
You should read up on how texture coordinates work. They are within the range of [0, 1]. They can repeat outside that - but in that case, the coordinates (0.2, 0.2) and (100.2, 50.2) are still the same. $\endgroup$