OpenGL 光照和定位

发布于 2025-01-07 17:14:22 字数 1485 浏览 2 评论 0原文

我很抱歉,因为这似乎是一个非常简单的问题,应该是显而易见的,但看来我一无所知。

我正在编写一个引擎并使用 Light 0 作为场景的“太阳”。我认为,理想情况下,太阳将是一个固定光源,而不是矢量,因此位置矢量中的 w/第四个索引应该是 1.0f。

我设置了场景的正交视点,然后将灯光设置在角色的位置(x/y 是平面地形的坐标,正 z 面向相机并指示地形上的“高度”——场景是还旋转了 x 轴上的等距视图)。

角色始终位于屏幕中央 - 但我注意到,由于某种原因,光线似乎照射在角色和世界坐标 0,0,0 之间的位置。角色距离世界坐标 0,0,0 越远,光线就越大/越宽。如果角色位于 0,0,0,则光线非常小。如果角色移动到 0,200,0 之类的位置,则光线会很大。

我只是想把脚弄湿,让“光”跟随角色(然后调整位置等,稍后创建太阳)。

        Graphics.BeginRenderingLayer();
        {
            Video.MapRenderingMode();

            Graphics.BeginLightingLayer( Graphics.AmbientR, Graphics.AmbientG, Graphics.AmbientB, Graphics.DiffuseR, Graphics.DiffuseG, Graphics.DiffuseB, pCenter.X, pCenter.Y, pCenter.Z );
            {
                Graphics.BeginRenderingLayer();
                {
                    Graphics.CenterCamera( pCenter.X, pCenter.Y, pCenter.Z );
                    RenderMap( pWorld, pCenter, pCoordinate );
                }
                Graphics.EndRenderingLayer();

                Graphics.BeginRenderingLayer();
                {
                    Graphics.DrawMan( pCenter );
                }
                Graphics.EndRenderingLayer();
            }
            Graphics.EndLightingLayer();
        }
        Graphics.EndRenderingLayer();

Graphics.BeginRenderingLayer = PushMatrix,EndRenderingLayer = PopMatrix Video.MapRenderingMode = 正射投影和场景旋转/缩放 CenterCamera 进行与 X/Y/Z 相反的转换,这样角色现在就位于屏幕中间的 X/Y/Z 中心。

有什么想法吗?也许我在这里的一些代码有点混乱?

I apologize, because this seems like a pretty straightforward problem that should be obvious, but it appears that I'm clueless.

I'm writing an engine and using Light 0 as the "sun" for the scene. I figure, ideally, the sun will be a fixed light source, not a vector, so the w/fourth index in the position vector should be 1.0f.

I setup the scene's Ortho viewpoint, then setup the light to be at the position of the character (x/y are coordinates of the plane terrain, with a positive z facing the camera and indicating "height" on the terrain -- the scene is also rotated for an isometric view on the x axis).

The character is always centered in the screen -- but I've noticed that for some reason, the light seems to shine at a position between the character and world coordinates 0,0,0. The further the character gets from world coordinates 0,0,0, the larger/wider the light is. If the character is at 0,0,0, the light is very small. If the character moves to something like 0,200,0, the light is HUGE.

I'm just trying to get my feet wet and have a "light" that follows the character (and then adjust for position, etc, later, to create a sun).

        Graphics.BeginRenderingLayer();
        {
            Video.MapRenderingMode();

            Graphics.BeginLightingLayer( Graphics.AmbientR, Graphics.AmbientG, Graphics.AmbientB, Graphics.DiffuseR, Graphics.DiffuseG, Graphics.DiffuseB, pCenter.X, pCenter.Y, pCenter.Z );
            {
                Graphics.BeginRenderingLayer();
                {
                    Graphics.CenterCamera( pCenter.X, pCenter.Y, pCenter.Z );
                    RenderMap( pWorld, pCenter, pCoordinate );
                }
                Graphics.EndRenderingLayer();

                Graphics.BeginRenderingLayer();
                {
                    Graphics.DrawMan( pCenter );
                }
                Graphics.EndRenderingLayer();
            }
            Graphics.EndLightingLayer();
        }
        Graphics.EndRenderingLayer();

Graphics.BeginRenderingLayer = PushMatrix, EndRenderingLayer = PopMatrix
Video.MapRenderingMode = Ortho Projection and Scene Rotation/Zoom
CenterCamera does a translate to the opposite of the X/Y/Z, such that the character is now centered at X/Y/Z in the middle of the screen.

Any thoughts? Maybe I've confused some of my code here a little?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2025-01-14 17:14:22

我认为,理想情况下,太阳将是一个固定光源,而不是矢量,因此位置矢量中的 w/第四个索引应该是 1.0f。

就人类基本尺度上发生的任何事情而言,太阳都是无限远的。这几乎是明确的“定向光”。因此,除非您要跨越数百或数千英里进行渲染,否则阳光方向的差异将完全无关紧要。

简而言之:您应该像其他人一样使用定向灯。

I figure, ideally, the sun will be a fixed light source, not a vector, so the w/fourth index in the position vector should be 1.0f.

As far as anything happening over basic human scales is concerned, the Sun is infinitely far away. It's pretty much the definitive "directional light". So unless you are rendering across hundreds or thousands of miles, the differences in the direction of sunlight will be entirely irrelevant.

In short: you should use a directional light, just like everyone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文