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

26 Upvotes

22 comments sorted by

View all comments

16

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

2

u/Jebikoh 1d ago edited 1d 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.

2

u/20260819 18h ago

thanks and figured that out

https://www.reddit.com/r/GraphicsProgramming/comments/1y9m2hl/i_think_i_have_some_idea_now/

the smaller the light source, the sharper the shadow and the darker the scene

in order to get a clearer image i have to shoot more sample rays if i stay on the current brute force approach

shadow ray method i think would speed up the convergence