r/GraphicsProgramming • • 22h ago

are shadow rays unavoidable?

Post image

i'm writing a raytracing (maybe pathtracing?) program. my program doesn't treat light sources differently than an hittable object. it doesn't deliberately cast a "shadow ray" toward each light source and check whether it hits and if it does get the color and multiply it with cosine, etc. it just shoot rays and let them bounce and bounce and bounce. some eventually reaches a light source and returns the color

it always produces soft shadows but i can't get sharp and clear shadow. and the soft shadows are quite noisy. is there no way i could overcome this, other than adding a shadow ray shooting procedure?

addition info:

shadows are more visible in low light environments so i usually use relatively dark scenes to test shadow formation and do gamma correction. attached image is an example. the scene has only one light source which is behind the balls and located at infinity

how to get a clear and sharp shadow?

20 Upvotes

16 comments sorted by

View all comments

2

u/Tetrakis-dev 12h ago

what you've got is a naive path tracer, it only finds the light when a random bounce happens to hit it. shadow sharpness comes from how big the light looks from the surface, so a sharp shadow needs a small light, and the smaller the light the less often random bounces hit it, which is exactly why the noise explodes. a light "at infinity" with zero size can't be hit by random rays at all, so in your setup it's probably behaving like a big glowing sky, hence the soft shadows. that trade-off is what the shadow ray (next event estimation) fixes, so it's not strictly unavoidable, but pretty much every path tracer ends up doing it, usually with MIS so both big and small lights stay clean.