- Home /
How to get the global position of a vertex in a Cg vertex shader?
I'm trying to write a Shader with Cg that calculates a vertex's uv-texcoord out of its position in 3d space. I got some results but the shader obviously uses the positions of the vertices relative to the local coordinate system of the mesh, because every GameObject I applied this shader to gets texture coordinates accordingly to its rotation. And that's the way it should behave normally, of course. However, I wan't to compute the global - the world vertex coordinates. Is there any way to retrieve them in Cg? Maybe through some glstate.matrix multiplications? I don't quite get these yet.
Answer by Aras · Jun 08, 2010 at 08:43 AM
Something like this should work (see more in the sparse docs).
// v.vertex is the input vertex in the vertex shader
float3 worldPos = mul (_Object2World, v.vertex).xyz;
Your answer
Follow this Question
Related Questions
Shifting Texture Coordinates via CG Shader 1 Answer
Prevent ColorMask obscuring parts of an object's mesh 0 Answers
Shader vertex position depends on camera ? 1 Answer
uv not being passed through from vertex to surface shader 1 Answer
Unexpected behavior in Vertex/Fragment shader when using saturate method (CG) 0 Answers