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

•

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:

  • 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.

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

1

u/20260819 12h 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

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?

7

u/sirpalee 22h 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 22h 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 20h ago

Wouldn't work? Smaller lights give harder shadows.

3

u/sirpalee 19h ago

Read the first two sentences as a whole.

-2

u/VictoryMotel 19h ago

Noisy shadows are still soft shadows. These are two separate and distinct concepts.

1

u/sirpalee 18h ago

OP was asking for clear and sharp shadows. Not just for sharp.

1

u/VictoryMotel 13h ago

You have to have the solution right either way. There is no point in conflating two things that can be easily separated.