r/GraphicsProgramming • u/20260819 • 13h 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?
11
u/Jebikoh 12h 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
1
u/20260819 2h ago
thanks and that makes sense but i have to add some ambient lights (i.e. another light sources) otherwise let's imagine if the entire scene has only one point light source it would be terribly dim. after gamma correction it would become extremely noisy
16
u/Lord_Zane 11h 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.
1
u/Tetrakis-dev 2h 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.
-1
u/HaMMeReD 13h ago
Well your source light looks really big, if you tried making a point light and not an area light?
5
u/sirpalee 13h ago
That wouldn't work if OP is just firing random rays in a path tracer. They would end up with very noisy results.
Next Event Estimation is the answer and yes, that includes tracing "shadow rays".
2
u/HaMMeReD 12h ago
It certainly isn't going to help to have a giant soft box light source. You sample enough rays, a soft or hard shadow is going to emerge based on your scene geometry.
The scene is the problem here. If there was a point light and a opaque cylinder, I bet the shadow penumbra would be pretty tight. OP should fix the scene layout and prove they actually have a problem first. (Before they focus on acceleration and NR).
-2
u/VictoryMotel 11h ago
Wouldn't work? Smaller lights give harder shadows.
2
u/sirpalee 10h ago
Read the first two sentences as a whole.
-2
u/VictoryMotel 9h ago
Noisy shadows are still soft shadows. These are two separate and distinct concepts.
1
u/sirpalee 9h ago
OP was asking for clear and sharp shadows. Not just for sharp.
1
u/VictoryMotel 3h ago
You have to have the solution right either way. There is no point in conflating two things that can be easily separated.
•
u/AutoModerator 13h ago
Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:
No showcases.
Disclose AI usage in post or project.
Present a topic to talk about, e.g. how something works.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.