- Home /
Getting the forward position of an object in a vertex shader
I have a vertex shader that tries to get the forward position of the pivot point of the object and do something based on that position. I've tried
float4 objectOrigin = mul(_Object2World, float4(0.0, 0.0, 0.0, 1.0));
originForward= objectOrigin.z;
but obviosly objectOrigin.z is not always the forward position.
I've also tried
float4 objectOrigin = mul(_World2Object, float4(0.0, 0.0, 0.0, 1.0));
originForward= objectOrigin.z;
which kinda works better but it still isn't its forward position, depending on the rotation sometimes its reversed and also for some reason this value gets changed as I rotate the object.
I'm not very good with matrix math and haven't found anything useful on google either. is it possible to get the forward matrix of a point in a vertex shader?
what I really want is equivalent of transform.forward in a shader.
Your answer
Follow this Question
Related Questions
Any idea how to get object rotation or transformMatrix in the vertex shader? 0 Answers
Shader doesn't work when object is inverted by axis 1 Answer
Efficient way to keep a fixed rotation for sprite? 0 Answers
Shadergraph: How do I get an object's rotation value inside of shadergraph? (HDRP) 1 Answer
accessing inverse view matrix 1 Answer