I am trying to make a shader that simulates the sun position and the light that it reflects in a object.
To simulate the sun trajectory I have a timer, and the light position is defined by:
fvLightPosition.x=-cos(Time)*speed;
fvLightPosition.y=sin(Time)*speed;
fvLightPosition.z=100.0;
The timer is a variable float Time0_X
I almost get the right trajectory, except that is upside down, and somehow look a bit weird. Can anyone give me a tip how to simulate the sun trajectory in the right way?
I am using RenderMonkey to make the shader.
Make sure that you scale your
Timevalue so that it lies between0and2*PIradians (which corresponds to 0 and 180 degrees respectively). If your originalTimevalue ranges from0to some numberMAX, you can do the scaling like this:(Time / MAX) * 2PI.I’m not sure what
speedrefers to, but you should most likely not be multiplying by that. Thecosandsinvalues represent the X and Y components of the vector between the sun and the origin, so you should multiply by the distance of the sun from the centre of your scene, which is usually constant.