有没有一种简单的方法可以在OpenGL中获得阴影?

发布于 2024-09-26 01:26:47 字数 130 浏览 3 评论 0原文

我最近创建了一些景观代码,并向场景添加了一些漫射照明,但是,令我失望的是,没有阴影。我在网上浏览了几个小时,寻找在 OpenGL 中获得阴影的方法,但它们看起来都非常复杂;他们自己的演示程序非常独特。

有没有简单的方法来制作阴影?

I recently created some landscape code and added some diffuse lighting to the scene, however, to my disappointment, there are no shadows. I looked around the web for hours looking for ways to get shadows in OpenGL, however they all seemed terribly complicated; and very unique to their own demo programs.

Are there any simple ways to make shadows?

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

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

发布评论

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

评论(2

明月松间行 2024-10-03 01:26:47

不。光栅化在这方面非常糟糕(即使是最近的 AAA 游戏也有明显的阴影伪影),但每个人都忍受着它。

解决方案包括(大约从最简单/最差到最好/最难):

  • 无阴影。只需考虑较深颜色的遮挡即可。 xNormal搅拌机
  • 如果你想要一个角色的近似阴影,地面上一个带有透明和模糊纹理的简单平面多边形就可以了。例如,请参阅《塞尔达》屏幕截图。甚至最近的一些游戏仍然使用这个。
  • 光照贴图。仅静态几何体,但完美的照明(预先计算)。实施起来相当简单。存在很多工具。
  • 影子卷,由卡马克推广。像素完美,实现起来相当简单,但速度很慢。适合一些物体。没有柔和的阴影。
  • 阴影贴图。如果你从未制作过任何 openGL,那么实现起来有点困难。很难做对。像素化阴影。处理大量多边形。不涉及大世界。
  • 无数的阴影贴图变体。近年来研究较多。目前最好的是级联阴影贴图:很难,仍然很难使其看起来不错,但速度很快,可以处理大量的多边形和巨大的世界。
  • 光线追踪阴影:这可能是下一代。除了一些研究论文之外,没有人真正使用它。非常复杂,不太适合动态世界(还),巨大的静态场景还可以。像素完美或柔和阴影,具体取决于您拥有多少备用 GPU。 几种变体;截至 2014 年,这仍然没有在任何游戏中出现 出于性能原因

因此,通常的技巧是将漂亮但仅静态的方法与动态但不太好的方法混合在一起。例如,请参阅我的关于 光照贴图阴影贴图

No. Rasterization is very bad at this (even recent AAA games have noticeable shadow artefacts), but everybody lives with it.

Solutions include (approx. from easiest/poorest to best/hardest) :

  • No shadows. Simply account for occlusion with darker colors. xNormal, Blender.
  • If you want an approximate shadow for a character, a simple flat polygon on the ground with a transparent and blurry texture will do. See Zelda screenshots, for instance. Even some recent games still use this.
  • Lightmaps. Static geometry only, but perfect lighting (precomputed). Reasonnably simple to implement. Lots of tools exist.
  • Shadow volumes, popularised by Carmack. Pixel perfect, reasonnably simple to implement, quite slow. Good for a few objects. No soft shadows.
  • Shadow maps. A little hard to implement if you never made any openGL. Hard to get right. Pixellated shadows. Deals with lots of polygons. Doesn't deal with big worlds.
  • Myriads of Shadow maps variants. Lots of research these recent years. Current best is Cascaded Shadow Maps : Difficult, still hard to make it look good, but fast, deals with loads of polygons and huge worlds.
  • Raytraced shadows : This may be the next-gen. Nobody really uses that except for some research papers. Very complicated, doesn't do well with dynamic worlds (yet), huge static scenes ok. Pixel perfect or soft shadows, depending on how much spare GPU you have. Several variants; as of 2014 this still didn't make in any game for performance reasons.

So the usual trick is to mix beautiful-but-static-only approaches with dynamic-but-not-that-good approaches. For instance, see my tutorials on lightmapping and shadowmapping.

娜些时光,永不杰束 2024-10-03 01:26:47

不。

我所知道的最简单的方法是使用预先生成的阴影纹理,该纹理通过多重纹理叠加到地形上。复杂的部分是生成这种纹理,但如果不使用定向照明,一个简单的“大模糊点”通常比没有好。

No.

The easiest way I know of involves using a pregenerated shadow texture that is overlaid onto the terrain using multitexturing. The complicated part is generating this texture, but if you don't use directional lighting, a simple "big blurry dot" is usually better than nothing.

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