how can i get world space coordinates in a fragment shader
- User
how can i get world space coordinates in a fragment shader
- Assistant
To obtain world space coordinates in a fragment shader, you can use the model-view-projection (MVP) matrix and apply it to the vertex's position. By transforming the vertex position from object space to clip space, and then dividing by the homogeneous coordinate, you can obtain normalized device coordinates (NDC). After that, you can multiply the NDC by the inverse of the projection matrix to get clip space coordinates. Finally, multiply the clip space coordinates by the inverse of the model-view matrix to get the world space coordinates.