Object-Space or World-Space coordinate system for Input vertex in Unity shader?

Hi all,

I am new to Unity shader, and I acquire some basic knowledge of OpenGL and NVIDIA CG program .

My question is regarding the coordinate system of input position parameter in Unity vertex-fragment program.

As a typical vertex processor:

#pragma vertex vert

float4 vert(appdata_base v) : POSITION {
return mul (UNITY_MATRIX_MVP, v.vertex);
}

That input parameter “v.vertex” is passed in by CPU program, I just want to know if the vertex is extraced from model directly (So in Object-Space/Model space) or already been transformed to World-Space using scene coordinate system?

Simply based on the fact that it transform by matrix UNITY_MATRIX_MVP, I trend to assume the vertex is in object-space. Would like to know if my assumption’s correct.

Thanks for viewing.

crying for an answer
:rage:

okay … i manage to find the answer in

http://en.wikibooks.org/wiki/Cg_Programming/Unity/Debugging_of_Shaders

Where Does the Vertex Data Come from?

— Within Unity, the answer is that the Mesh Renderer component of a game object sends all the data of the mesh of the game object to OpenGL in each frame

So my initial assumption is correct. The input vertex’s position value is in object-space.

1 Like

yes. to make into world space:
float3 pos = mul (_Object2World, i.uv).xyz;

1 Like

That’d be pretty insane, don’t we have GPU-side vertex buffer objects (VBO) these days?

Anyway for your purpose, it doesn’t matter whether the vertices into your vertex shader came straight from the CPU or from a GPU-VBO. By the time your shader executes, the vertices are all in VRAM one way or the other…

Thanks.

Your assumption is correct. Do note that when objects are batched together, the vertices will actually be in object and world space. (For a batched model the model matrix is set to the identity matrix.)