# Vertex Shader world_position of a vertex, how?

4.2.1

### Question

I’m trying to get alot of vertecies to move around using the same sort of “flowing” offset. Like grass really.
But I have a hard time figuring out how to get the world position of a vertex.

I’m trying things like this:

``````vertex_uv = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xz;
``````

But ofcourse that isn’t working.

I think what isn´t working is that yes i get the world position, but i can’t deform the vertecies in world space. They just move back and forth sort of relative to “itself”.

the vertex code I’m trying right now is this:

``````void vertex() {
vertex_uv = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xz;
vec2 uv = (vertex_uv / wind_noise_scale) + (TIME * wind_time_scale/100.0);
VERTEX.x += sin(uv.x + UV.y + 0.0 + (TIME * 1.0000)) * wind_noise_scale * (1.0 - UV.y);
VERTEX.z += sin(uv.y + UV.y + 0.2 + (TIME * 1.5111)) * wind_noise_scale * 0.5 * (1.0 - UV.y);
}
``````

(I’ve looked at tuts, and videos - but i have a feeling that maybe things has changed in GODOT - becuause i can’t get other solutions to work)

trying out this one proves to me that the vertecies are indeed just rocking back and forth on their “own” plane.

``````VERTEX.x += sin(TIME) + vertex_uv.x*0.1 * (1.0 - UV.y);
``````

wonder if anyone knows how to move a vertex by x amount on the world X axis???

so I guess VERTEX is inherently “local” wonder how I can get the diff between it and global…?
Does a vertex have a direction? A direction separate from the normal?

you can use the `vert_world_coordinates` flag to do everything in world space in vertex shaders

1 Like

Ok I will try this. I also found this, a page I previously ignored because I thought it was fragment only.

i dont understand where and how to implement this? does it go at the top? and will it automatically make the vertex calculations world space or do i have to do anything other than that?

I’ve searched for “vert_world_coordinates” but it seems to yield no good results.

It might be this:

world_vertex_coords: VERTEX/NORMAL/etc. are modified in world coordinates instead of local.

Which is a render mode:

``````shader_type spatial;
render_mode world_vertex_coords;

void vertex() {
}
``````

Edit: Changed `vert_world_coordinate` to `world_vertex_coords`.

1 Like

Yes this works. The other one must be deprecated.

Sorry, I wasn’t at my pc so i got the spelling wrong.

1 Like