How are hard and soft shadows cast?

I have been studying computer graphics, from the book Fundamentals of Computer Graphic (but the third edition), and I lastly read about texture mapping and shadow maps. Though, I didn't exactly understand how they function. I know there is also another type of texture map called projective texture map which allows to cast hard shadows, but how they function? On the other hand, how are soft shadows cast? And what's exactly the difference between hard and soft shadows?

Hard shadows are simple that only needs a point light.

How it's done is by rendering the scene from the point of view of the light and only keep only the depth information. This is the shadow map.

Then when doing the actual rendering you calculate the point on the triangle in world space and find where it would be on the shadow map. Then you sample the depth from the shadowmap at that point and compare it to the distance to the light.

Soft shadows are harder. They require figuring out how close you are to the edge of what would be a hard shadow and adjusting the light value based on that. There are several techniques for that. One of which is simply sampling multiple times.

• A image might do wonders. Commented May 3, 2016 at 4:43

@ratchetfreak's answer describes shadow mapping, however, there's another not so difficult to implement way of drawing hard shadows. The shadow volume technique uses extruded geometry plus some stencil buffer tricks to simulate the area occluded by an object. The idea behind it is to generate a volume from the light source's perspective and then render it as you would render other geometry. The resulting shadow geometry will be as accurate as your graphics hardware is capable of rendering it, so the shadows will be very clear cut. There's no simple way of producing soft shadow edges with this technique though.

• I'd upvote if there was also an example of a (possibly unrelated) soft shadow technique for contrast, as part of the question was what is the difference between them. Commented May 3, 2016 at 14:56
• Soft shadows with shadow volumes makes me think of Instant Radiosity - essentially approximate area light sources as multiple point light sources and accumulate the results. Many shadow (100+) passes are doable in real time on a modern GPU with stacked memory if the shadow casting geometry can be limited.
– user2500
Commented May 3, 2016 at 19:09