I am attemting an unlit shader that color tints an object depending on its relation to the world axis. As an example, any normals of a rotating object facing the world-x axis would get tinted with agreen color. 1. Is there any optimized way to get the world rotation from within the shader? 2. Would it be better/(more optimized) to supply it as a parameter through code to the shader?
Sounds like you don't need a shader, you just need a script that modifies the objects material based on its rotation.
example in shader Code (CSharp): Properties { _RotationSpeed ("Rotation Speed", Float) = 2.0 } float sinX = sin ( _RotationSpeed * _Time ); float cosX = cos ( _RotationSpeed * _Time ); float sinY = sin ( _RotationSpeed * _Time ); float2x2 rotationMatrix = float2x2( cosX, -sinX, sinY, cosX); } example : JS script : Code (JavaScript): var scrollSpeed = 0.90; var scrollSpeed2 = 0.90; function FixedUpdate() { var offset = Time.time * scrollSpeed; var offset2 = Time.time * scrollSpeed2; renderer.material.mainTextureOffset = Vector2 (offset2,-offset); }
@GGeff: If I was not dependent on the objects normals, a script would work. I think I would avoid iterating through all those meshes normals in script if I can put that work on the gpu instead. @Niko-belik: Thanks, but not quite what I am looking for. I need some way to get the rotation relation between the vertex normal and the world axis.
Aha! Found what I was looking for, and ironically it brought me back to where I first started, with _Object2World. The reason it did not work before was the order: Code (CSharp): //correct: normalize(mul((float3x3)_Object2World, i.normal).xyz); //incorrect: normalize(mul(i.normal, ((float3x3)_Object2World).xyz); The effect was that I no longer got the proper rotation of the normal if I had the wrong order. I hope anyone following in my footsteps can benifit from this.