Which matirx can be used to make position fromworld space to local space ?

I want to achieve the Fake Interior effect.But I don’t konw how to make position fromworld space to local space.

vec4 objCam = ObjectMatrix *vec4( cameraPosition, 1.0 );
vec3 viewDir =normalize(position - objCam.xyz);

Ask for help.

Please do not forget to add a link to a Playground to get a faster answer:

Welcome aboard!

To convert from world space to loca space, you must use the invert world matrix:

vec4 objCam = invert(world) *vec4( cameraPosition, 1.0 );
vec3 viewDir =normalize(position - objCam.xyz);

You can also compute the invert of the world matrix on the CPU and pass it to the shader to avoid a matrix inversion each time the vertex shader is run.

2 Likes

Thank you for your help. I use invert(),but an error is prompted when compiling-“‘invert’ : no matching overloaded function found”。
Link:https://playground.babylonjs.com/#YSIA4K#2

Sorry, it is inverse and not invert!

1 Like

Hello @heyefeng229 just checking in if you need any further help?