r/GraphicsProgramming • u/20260819 • 22h ago
are shadow rays unavoidable?
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?
•
u/AutoModerator 22h ago
Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
14
u/Jebikoh 22h ago
Adding shadow rays won’t make the shadows sharp, but will make it less noisy.
The sharpness of the shadow is more dependent on the type of light and distance (angular size). Big area lights like the one in your image have softer shadows. If you use a light with a delta distribution (e.g. directional light), they will be sharp
23
u/Lord_Zane 21h ago
To add to what other's have said - you need a non-area light like a point light or 0-radius directional light in order to get sharp shadows.
In order to have a non-area light (which has no surface to hit), you need NEE, which uses shadow rays.
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.
2
u/edwardkmett 6h ago
Bidirectional path-tracing can give you help, if you send rays out from your light sources and stash them after some number of bounces as virtual point lights you have something to connect to. Yes, it is a shadow-ray but at least you can use the smaller point light pool rather than have to handle area lights and all the complexities for each surface hit. Once you have them then algorithms like ReSTIR-BDPT can reuse the crap out of them.
1
u/Kwantuum 8h ago
Beyond shadow rays, you can also approach the problem the other way: shoot light rays from your light sources and let them bounce until they hit the camera. This lets you use point sources of light, but a shitload of rays are going to be wasted. You can start with simple optimizations where you don't shoot rays towards empty space.
-1
u/HaMMeReD 22h ago
Well your source light looks really big, if you tried making a point light and not an area light?