|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
Scorch |
I have a 2D bush sprite and I can make its Y-axis face the player by setting the billboard to “Y-billboard” which is neat. I want it to sway in the wind so I changed its StandardMaterial3D into a ShaderMaterial and the shader works, however, now I want it to face the player again and I don’t know how.
Here is the shader code:
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
float offset = TIME * wind_speed;
float noise = texture(noise_tex, NODE_POSITION_WORLD.xz - offset).r;
noise -= .5;
noise *= wind_strength;
VERTEX.x += noise * length(VERTEX.y - NODE_POSITION_WORLD.y);}
|
|
|
|
Reply From: |
mrdunk |
Hi, i was just playing with exactly this.
Here’s what i came up with:
void vertex() {
mat4 modified_model_view = VIEW_MATRIX * mat4(
INV_VIEW_MATRIX[0],
INV_VIEW_MATRIX[1],
INV_VIEW_MATRIX[2],
MODEL_MATRIX[3]
);
MODELVIEW_MATRIX = modified_model_view;
}
[EDIT]
I mean the billboard part.
Add it to your existing shader and you should be good.
So playing with shaders some more,
i’ve found out in Godot 4.0, if you create a “New StandardMaterial3D” with the parameters you are interested in, you can then “Convert to ShaderMaterial” and see the raw shader code.
I presume there are similar options available for V3.X as well.
I’ve just used this to work out how to retrieve part of a texture. I think you’ll be able to see the raw billboard implementation this way too.
mrdunk | 2023-05-02 01:05
Converting it did the trick! Thank you brother
Scorch | 2023-05-02 08:22