有一个简单的方法来获得阴影在OpenGL吗? [英] Is there an easy way to get shadows in OpenGL?
问题描述
我最近创建了一些景观代码,并添加了一些漫射照明的场景,但是,对我的失望,没有阴影。我在网上找了很多时间寻找在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?
推荐答案
否。光栅化是非常糟糕的(即使最近的AAA游戏有明显的影子文物),但每个人都与它一起生活。
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) :
- 没有阴影。只需考虑更暗的颜色的遮挡。 xNormal ,
- 如果你想要一个字符的近似阴影,一个简单的平面多边形在地面上与透明和模糊的纹理将做。例如,见塞尔达的截图。即使最近的一些游戏仍在使用此功能。
- Lightmaps。仅静态几何,但完美的照明(预先计算)。实际上很简单。
- Carmack推广的影子卷。像素完美,原理实现简单,相当缓慢。适合几个对象。没有柔和的阴影。
- 阴影贴图。如果你从来没有做过任何openGL有点难以实现。很难得到正确。像素化阴影。交易有很多多边形。不处理大世界。
- 无数阴影地图变体。近年来的大量研究。当前最好的是Cascaded Shadow Maps:困难,仍然很难让它看起来不错,但很快,处理多边形和巨大的世界的负载。
- 光线跟踪阴影:这可能是下一代。没有人真正使用,除了一些研究论文。非常复杂,不能很好地与动态世界(还),巨大的静态场景确定。像素完美或柔和的阴影,这取决于你有多少备用的GPU。 几种变体;截至2014年,这仍然没有在任何游戏由于性能原因。
- 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.
这篇关于有一个简单的方法来获得阴影在OpenGL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!