r/GraphicsProgramming • • 1d 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?

21 Upvotes

17 comments sorted by

•

u/AutoModerator 1d 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.

16

u/Jebikoh 1d 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 21h 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

1

u/Jebikoh 4h ago edited 4h ago

I would refer to Lord_Zones comment; you will almost certainly need shadow rays + NEE to get the shadows you want.

My reason for the distinction above was to clarify that shadow rays in themselves, will not result in sharp shadows. Adding shadow rays to the scene you posted will still result in soft shadows.

You get sharp shadows with delta lights or lights that are very small and/or away, which as you say, end up making your scene quite dim as the odds you sample a path into an emitter is so low.

Given enough time, your naive tracer and another tracer with shadow rays + MIS will converge to the same result. The difference being how effectively they sample important paths.

25

u/Lord_Zane 1d 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 21h 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 15h 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 17h 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 1d ago

Well your source light looks really big, if you tried making a point light and not an area light?

7

u/sirpalee 1d 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 1d 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 1d ago

Wouldn't work? Smaller lights give harder shadows.

3

u/sirpalee 1d ago

Read the first two sentences as a whole.

-2

u/VictoryMotel 1d ago

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

1

u/sirpalee 1d ago

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

1

u/VictoryMotel 22h ago

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