Jump to content

how can I get a object's world position in a vertex shader?


photo

Recommended Posts

Posted

I'm trying to create some new shaders, but I don't know how to get a world position of an object, I've also noticed there is a shader variable s_transform, but the shader code about it seems a little confusing.

 

so the simple question, how to get a object's world position in a vertex shader?

 

and these kind of objects might be instanced.

Posted

Use vertex_leaf.shader as template.

The world position is: "float3 world_vertex = mul4(s_imodelview,vertex.xyz);"

You will have rendering artefacts on big distances because of floating point errors.

Posted

:) I mean world position of object not vertex.

Posted

The answer in the vertex_leaf.shader file:

float3 center = mul4(s_imodelview,float3(row_0.w,row_1.w,row_2.w));

×
×
  • Create New...