Godot Version
4.2.2
Question
Hello to all.
I am building a shader that always rotates a mesh to camera view, but I need help on how to inversely move the UV, so it seems like the object is indeed rotating.
Example: if the camera moves horizontally and the mesh rotates 45º, I need the UV to translate 0.5 on X.
Here’s is my current code to make the vertex rotate:
float x = radians(rotateX);
float y = radians(rotateY);
float z = radians(rotateZ);
// Identity Matrix - simple bilboard
// #################################
mat4 identity = mat4(
vec4(1.0, 0.0, 0.0, MODELVIEW_MATRIX[0][3]),
vec4(0.0, 1.0, 0.0, MODELVIEW_MATRIX[1][3]),
vec4(0.0, 0.0, 1.0, MODELVIEW_MATRIX[2][3]),
vec4( MODELVIEW_MATRIX[3][0], MODELVIEW_MATRIX[3][1],
MODELVIEW_MATRIX[3][2], MODELVIEW_MATRIX[3][3]));
// Rotate around X-axix Matrix
// ###########################
mat4 rotate_x = mat4(
vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, cos(x), sin(x), 0.0),
vec4(0.0, -sin(x), cos(x), 0.0),
vec4(0.0, 0.0, 0.0, 1.0));
// Rotate around Y-axix Matrix
// ###########################
mat4 rotate_y = mat4(
vec4(cos(y), 0.0, -sin(y), 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(sin(y), 0.0, cos(y), 0.0),
vec4(0.0, 0.0, 0.0, 1.0));
// Rotate around Z-axix Matrix
// ###########################
mat4 rotate_z = mat4(
vec4(cos(z), sin(z), 0.0, 0.0),
vec4(-sin(z), cos(z), 0.0, 0.0),
vec4(0.0, 0.0, 1.0, 0.0),
vec4(0.0, 0.0, 0.0, 1.0));
transfUV = UV????;
vec3 transfVertex = (identity * rotate_z * rotate_x * rotate_y * vec4(VERTEX, 1.0)).xyz;
VERTEX = transfVertex;
Sorry, but it doesn’t seem my math can cope with this… I’ve blown a fuse…How can I achieve this?