在球体内部照明?

发布于 2024-09-14 01:22:50 字数 157 浏览 5 评论 0原文

我心中有一个问题:我需要制作一个看起来像真实天空的场景。我的第一个想法是制作一个立方体并对其进行纹理化。本来就不好看。我想出了使用球体的想法。但我无法从里面点燃它。我已将相机放在原点上观看(0,0,-100)。环境光源和镜面光源也在原点。看不到任何亮着的东西!制作天空的方法有哪些?如何照亮球体内部?

I have this question in mind: I need to make a scene that looks like a real sky. My first idea was to make a cube and texturize it. It wasn't that good looking. I came up with the idea of using a sphere. But I couldn't light it from inside. I've put the camera on the origin watching (0,0,-100). Ambient and specular light source also at the origin. Couldn't see any thing lit! What are the ways of making a sky and how can I light the inside of a sphere?

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

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

发布评论

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

评论(5

美人骨 2024-09-21 01:22:50

由于您位于球体内部,因此请尝试更改剔除模式。

我是 XNA 人员,但看来这将是 OpenGL等价。我相信,如果您按照您所说打开了环境照明,那么无论法线如何,您都应该能够看到一些东西。

Try changing the cull mode since you're on the inside of the sphere.

I'm an XNA guy, but it appears that this would be the OpenGL equivalent. If you have ambient lighting on as you said, you should be able to see something regardless of normals, I believe.

来世叙缘 2024-09-21 01:22:50

尝试翻转球体的法线(更多搜索结果 此处)。一般来说,渲染引擎使用算法来确定哪些内容是不可能看到的,因此不应该被渲染;其中一种技术是背面剔除。我猜测球体是在法线远离中心投射到球体之外的典型方式;你需要你的法线面向相反的方向。

Try flipping the normals of the sphere (more search results here). In general rendering engines use algorithms to determine what could not be possibly seen and thus should not be rendered; one such technique is backface culling. I'm guessing that the sphere is created in the typical way where the normals project out of the sphere, away from the center; you need your normals facing the opposite way.

不交电费瞎发啥光 2024-09-21 01:22:50

如果它从外部照亮,但从内部黑暗,那么球体的法线可能指向错误的方向。

假设您正在进行 phong/gouraud 照明,法线方向和视图方向之间的余弦将在某处计算。余弦将为负,您的显卡将钳位为零,从而产生黑色。

因此,如果明确指定了法线,您应该尝试反转它们的方向 ->乘以-1。如果只有顶点和面,您可能需要更改面中的顶点顺序。只需切换两个索引即可。 (1-2-3)→ (1-3-2)。这会将顺序从顺时针更改为逆时针(或相反)。要测试结果,您可以打开和关闭背面剔除,看看会发生什么。

If it's lit from outside, but dark from the inside, then it's probably that the normals of the sphere are pointing in the wrong direction.

Assuming that you're doing phong/gouraud lighting, the cosine between the normal and the view direction will be computed somewhere. The cosine will be negative and your graphics card will clamp to zero which results in black color.

So, if your normals are specified explicitly, you should try inverting their direction -> multiply with -1. If you have just vertices and faces, you might want to change the vertex order in the faces. Just switch two indices. (1-2-3) -> (1-3-2). This changes the order from clockwise to counterclockwise (or reverse). To test your results, you can switch backface culling on and off and see what happens.

遗心遗梦遗幸福 2024-09-21 01:22:50

问题解决了。谢谢,但正常情况不是答案。我使用 glutSolidSphere 所以法线不会错。尝试使用 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);这应该可以帮到你。

Problem solved. Thanks but normals are not the answer. I use glutSolidSphere so normals are not wrong. try using glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); that should do the job for ya.

迷荒 2024-09-21 01:22:50

当我制作天空穹顶、天空盒或天空平面时,我实际上并没有照亮它。我只是在其上放置纹理并渲染它。

glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
Render sky dome
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);

然而,这样做的问题是改变状态的成本可能很高。因此,消除 GL_CULL_FACE 状态更改的一种方法是确保法线指向正确的方向。如果 CULL_FACE 设置为 CCW(逆时针),则法线应指向您。但是,如果 CULL_FACE 设置为 CW(顺时针),则法线应指向远离您的方向。我认为消除 GL_LIGHTING 状态更改的唯一方法是使用着色器并定义您自己的照明方案。不过不知道是贵了还是贵了。

天空盒问题是一个类似的问题,但它还有其他问题。如果您的视点不在中心,您可能会遇到失真问题。我通常做的是首先渲染以相机为中心的天空盒,然后清除深度缓冲区并渲染其他所有内容。这样你的天空盒就不必大得离谱。

When I make a sky dome, sky box, or sky plane, I don't actually light it. I just put a texture on it and render it.

glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
Render sky dome
glEnable(GL_LIGHTING);
glEnable(GL_CULL_FACE);

However, the problem with this is that changing state can be expensive. So one way to eliminate the GL_CULL_FACE state change is to make sure your normals are pointing the right way. If CULL_FACE is set to CCW (Counter ClockWise) then the normals should be pointing toward you. However, if CULL_FACE is set to CW (ClockWise) then the normals should be pointing away from you. The only way I can see to eliminate the GL_LIGHTING state change is to use shaders and define your own lighting scheme. However, I don't know if that is more or less expensive.

The sky box issue is a similar story but it has other problems. You can run into distortion issues if your viewpoint is not at the center. What I generally do is render the sky box first, centered on the camera, then clear the depth buffer and render everything else. That way your sky box doesn't have to be ridiculously big.

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