Hi,
I am writting a shader were I need to format the X rotation value of my directional light (_WorldSpaceLightPos0.x) in a certain way.
The table bellow shows how I need the value to behave at certain points (ie.: above 90degree i need negative value until 180 degree):
Input X Rotation Required float value
0 degrees 1
45 degrees 0.2929
90 degrees 0
135 degrees -0.2929
180 degrees -1
Here is my current code:
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float LightDirAdjust = 1;
float v; // the float value I need
if (_WorldSpaceLightPos0.x > 90 && _WorldSpaceLightPos0.x < 180)
LightDirAdjust = -1;
v = ((lightDirection.y * -1) + 1) * LightDirAdjust;
In the last line I multiply by -1 to reverse the value then add 1 so when X Rotation=0 my float = 1.
It also works fine for X45 = float 0.2929 and X90=float 0.
Whe I go above 90 degrees for some reason the values stays positive, I tried a lot of things to make the value work as I expect and i just cant get it.
I think I am lost somewere in bettwen quaternions, euler angles and simply not understanding what comes out of _WorldSpaceLightPos0.xyz in relation to the actual rotation values in the inspecter. I also smell a potential issue with worldspace vs localspace values… im a bit lost.
Would someone please turn on a search light for me?
Thank you!