How to get vertex coordinates in world space

Hi community,

Could you please let me know how to get the vertex coordinates in world space in shaders. I would like to send this coordinate to my fragment shader using the varying vposition.

I know that “position” provides vertex coordinate in local space.

I tried the following but I no luck

varying vec3 vposition

vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);
gl_Position = projectionMatrix * modelViewPosition;
vposition = vec3 (gl_Position.x, gl_Position .y, gl_Position .z);

Thanks,

You can do vposition = (modelMatrix * vec4(position, 1.0)).xyz;

1 Like

It worked for me !

Thanks a lot !

1 Like