Is there an easy way to get shadows in OpenGL?

后端 未结 2 2003
遇见更好的自我
遇见更好的自我 2021-02-04 06:04

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 looki

2条回答
  •  我在风中等你
    2021-02-04 06:44

    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.

提交回复
热议问题