views:

132

answers:

2

Hi,

I recently created a landscape code which I full understand, and added some diffuse lighting to the scene. However to my disappointment there was 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.

Is their any simple way to make shadows?

Please Help,

Thanks In Advance,

Joe

+2  A: 

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.

Zooba
Oh, the even easier way is to use an engine with it already built in, but I assume that you're not interested in just building models for someone else's engine (fair enough, neither am I).
Zooba
No, I don't want to build models for someone elses engine. As for the answer above, where could I find out how to do this?
Joesavage1
Any basic introduction to multitexturing will cover it. The trick is to set the texture to wrap (with transparent edges) and position it using the UV parameters on the terrain. Alternatively you can make an extra surface for the shadow, which is easy on a flat surface, but a bit more involved on a terrain...
Zooba
Alternatively, if you want terrain shadows, the easiest way is to turn your heightmap (assuming black is lowest) into a texture and apply it over the whole terrain. I was coming at the answer from a "providing a shadow for a character" POV, rather than adding terrain shadows.
Zooba
+9  A: 

Agreed with Zooba : 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.
  • 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 wel with dynamic worlds (yet), huge scenes ok. Pixel perfect or soft shadows, depending on how much spare GPU you have.

So the usual trick is to mix beautiful-but-static-only approaches with dynamic-but-not-that-good approaches.

Good luck !

Calvin1602
Thanks for this long list of shadow techniques! For now I've just got it wired up with my heightmap so that lower areas are darker; and that looks OK for my current project (which is basically my first game :P). However for future projects I'll definitely look into different shadow solutions!
Joesavage1
If you're trying to get shadows of the mountains with a static sun, lightmaps are the way to go. Export your map into any 3D format, open in Blender, follow any tutorial : you've got your lightmap. Mix with the texture with a shader (or directly in Photoshop if you're lazy), you're done.
Calvin1602
Sorry, the pedant in me makes me comment: shadow volumes were first proposed in 1977 by Frank Crow. They're a technique, like BSP trees or that fast square root that you see around, that Carmack has popularised for games but definitely didn't invent.
Tommy
Thanks for the comment, I didn't know. Message updated accordingly.
Calvin1602