# Ray tracing - soft shadow

I'm implementing my own ray tracer as an iPad app for a school project. At the moment this is the result:

I need to add the last requirement, soft shadows, but I can't find a complete reference anywhere. If I understood well, to implement this feature I have to shoot many rays from an intersection point to mt light source. This one must be an area light. Suppose i use a sphere, my questions are:

• which point on the sphere i must use to calculate the shadow ray?
• how do I average the result?

Thanks for helping me.

First of all, you can implement soft shadows with a simple trick that doesn't even use area lights. This won't be as accurate, but is easy to implement and might be a good first step for you to get a feel for how soft shadows work. The idea is to shoot many test rays from your intersection point towards the point light source (as you mentioned) but to add a bit of an offset to each one, so that it goes close to your point light, but just misses. This offset can be a regular grid (good uniformity, but causes banding), completely random (non-uniform, but less banding), or a combination of the two, which I think gives the best of both worlds. You can then test these rays for intersection against other objects in your scene, as you would for sharp shadows. Then you can simply add up the number that hit something and divide it by the number of test rays. That fraction will range from 0 (no shadow) to 1 (fully occluded), and you can light your point based on that value.

Area lights add a bit of accuracy by giving you a specific area to target. By shooting your test rays at a collection of points on the area light, you get the same effect as the offset in the point light case above, but based on the actual shape of the light, rather than just a trick. Averaging the result will work just like the point light case. Selecting the collection of points in the shape can be done in a few different ways. I don't know which is best, but you can experiment and see which looks best to you. A few ideas to get you started could include random points inside the sphere, a uniform grid within the sphere, points on the surface of the sphere (uniformly or randomly distributed), or points on a disc within the sphere facing your intersection point.

• GPU Gems has a good article on rendering soft shadows here. It's focused on conventional rendering but the jitter-based sampling pattern should be applicable to positioning the test rays for ray tracing as well. Jul 30, 2015 at 0:36
• Thank you guys. I have another question: how dow i select random points on a sphere? Do you have any reference example? Jul 31, 2015 at 6:19
• This should help: mathworld.wolfram.com/SpherePointPicking.html
– Jeff
Jul 31, 2015 at 19:13
• Thanks you guys. Now I facing another problem. See the new question gamedev.stackexchange.com/questions/105187/…. Can you help me? Aug 5, 2015 at 19:32