着色器太阳位置 - glsl
我正在尝试制作一个着色器来模拟太阳位置及其在物体中反射的光。
为了模拟太阳轨迹,我有一个计时器,并且灯光位置定义为:
fvLightPosition.x=-cos(Time)*speed;
fvLightPosition.y=sin(Time)*speed;
fvLightPosition.z=100.0;
计时器是一个变量 float Time0_X
我几乎得到了正确的轨迹,除了它是颠倒的,并且不知何故看起来有点诡异的。谁能告诉我如何以正确的方式模拟太阳轨迹?
我正在使用 RenderMonkey 来制作着色器。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保缩放
Time
值,使其位于0
和2*PI
弧度(分别对应于 0 度和 180 度)之间。如果您的原始Time
值范围从0
到某个数字MAX
,您可以按如下方式进行缩放:(Time / MAX) * 2PI。
我不确定速度指的是什么,但您很可能不应该乘以它。
cos
和sin
值代表太阳与原点之间向量的 X 和 Y 分量,因此您应该乘以太阳距地球中心的距离。场景,通常是恒定的。Make sure that you scale your
Time
value so that it lies between0
and2*PI
radians (which corresponds to 0 and 180 degrees respectively). If your originalTime
value ranges from0
to some numberMAX
, you can do the scaling like this:(Time / MAX) * 2PI
.I'm not sure what
speed
refers to, but you should most likely not be multiplying by that. Thecos
andsin
values 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.