Godot Version
4.3 beta
Question
Hello, i made a wind shader using vertex colors from model to simulate wind on a tree, my shader works as intended until i rotate my model and see that the wind effect is tied to the model rotation, i search the Docs and i found that i need to put “world_vertex_coords” in render mode but after adding this to my shader if i move my model from world origin (0,0,0) its get distorted and the models location is out of place. Can someone can give me any idea on what i can do. My shader without the world_vertex_coords works but its rotating with the model, if using world_vertex_coords is not possible there is a way to get the model rotation in radians and subtract from the wind_direction (is in radians too)?
Here is the code that is causing the problem:
void vertex() {
float wind_factor = COLOR.b / 255.0;
float wind_variation = COLOR.g;
float height_factor = pow(VERTEX.y / 30000.0, 1.2);
float wind_direction_radian_sway = float(wind_direction_angle + 135) * 3.14159 / 180.0;// convert to radians
float sine_sign = (wind_direction_angle >= 180 && wind_direction_angle < 360) ? -1.0 : 1.0;
float trunk_sway_angle = height_factor *
sin(TIME * (trunk_frequency + model_scale) / 20.0 + wind_direction_radian_sway) *
trunk_motion * 50.0 * 3.14159 / 180.0 * sine_sign;
mat3 rotationWind = mat3(
vec3(cos(wind_direction_radian_sway), 0.0, sin(wind_direction_radian_sway)),
vec3(0.0, 1.0, 0.0),
vec3(-sin(wind_direction_radian_sway), 0.0, cos(wind_direction_radian_sway))
);
mat3 rotationX = mat3(
vec3(1.0, 0.0, 0.0),
vec3(0.0, cos(trunk_sway_angle), -sin(trunk_sway_angle)),
vec3(0.0, sin(trunk_sway_angle), cos(trunk_sway_angle))
);
mat3 rotationZ = mat3(
vec3(cos(trunk_sway_angle), -sin(trunk_sway_angle), 0.0),
vec3(sin(trunk_sway_angle), cos(trunk_sway_angle), 0.0),
vec3(0.0, 0.0, 1.0)
);
mat3 rotation_matrix = rotationWind * rotationX * rotationZ;
vec3 trunk_vertex = rotation_matrix * VERTEX;
VERTEX = trunk_vertex;
vec3 rotated_normal = rotation_matrix * NORMAL;
NORMAL = normalize(rotated_normal);
}