In Ray Tracing in One Weekend, we took a very brute force and we hope intuitive approach that didn't use "shadow rays", or as some on the whipper-snappers say "next event estimation". Instead we scattered rays and they got "direct light" (light that is emitted by a radiant object, hits one surface, and is scattered to the camera) implicitly by having a ray randomly scatter and happen to hit to hit the light source.
Direct light with shadow rays can make some scenes much more efficient, and 99%+ of production ray tracers use shadow rays. Let's look at a simple scene where the only thing in the world is two spheres, one diffusely reflective with reflectivity R, and one that absorbs all light but emits light uniformly in all directions, so it looks white. So if we render just the light source, let's assume it is color RGB = (2,2,2). (for now, assume RGB=(1,1,1) is white on the screen, and anything above (1,1,1) "burns out" to also be white-- this is a tone mapping issue which is its own field of study! But we will just truncate above 1 for now which is the best tone mapping technique when measured by quality over effort :) ).
To color a pixel in the "brute force path tracer" paradigm, the color of an object is:
color = reflectivity * weighted_average(color coming into surface)
The weighted average says not all directions are created equal-- some influence the surface color more than others. We can approximate that weighted average above by taking some random rays, weighting them, and averaging them:
for the six rays above, the weighted average is
color = reflectivity*(w1*(0,0,0) + w2*(0,0,0) w3*(2,2,2) + w4*(2,2,2) w5*(0,0,0) + w6*(0,0,0))) / (w1+w2+w3+w4+w5+w6)
So reflectivity*(2/3, 2/3, 2.3) so a very light color. If we had happened to have an extra ray randomly hit it would be reflectivity*(1,1,1) and if one more missed reflectivity*(1/3, 1/3, 1/3)
So we see why there is noise in ray tracings but also why the bottom of the sphere is black-- no scattered rays can hit the light.
A key thing is this sort of Monte Carlo is any distribution of rays can be used, and any weighting functions can be used, and the picture will usually be "reasonable". Surfaces attenuate light (with reflectivity-- their "color") and they preferentially average some directions over others.
Commonly, we will just make all the weights one, and make the ray directions "appropriate" for the surface type (like for a mirror, only one direction is chosen.
The above is a perfectly reasonable way to compute shading from a light. However, it gets very noisy for a small light (or more precisely, a light that subtends a small angle, light our biggest light, the Sun).
A completely different way to compute direct lighting is to view all those "missed" rays wasted, and only send rays that don't yield a zero contribution. But to do that, we need to somehow figure out the weighting so that we get the same answer.
What we do there is just send rays toward the light source, and count the ones that hit (if they hit some other object, like a bird between the shaded sphere and the light, it's a zero).
So the rays are all random, but also only in directions toward the light. Now the magic formula is
color = MAGICCONSTANT*reflectivity*(w1*(0,0,0) + w2*(0,0,0) w3*(2,2,2) + w4*(2,2,2) w5*(0,0,0) + w6*(0,0,0))) / (w1+w2+w3+w4+w5+w6)
What is different is:
1. what directions are chosen?
2. what are the weights?
3. What is the MAGICCONSTANT? // will depend on the geometry for that specific point-- like it will have some distance squared attenuation in it
The place where we have freedom is 1. Choose some way to sample directions toward the sphere. For example, pick random points on the sphere and send rays to them. Then 2 and 3 will be math. The bad news is that the math is "advanced calculus" and looks intimidating because of the formulas and because 3D actually is confusing. The good news is that that advanced calc can be done methodically. More on that in a future post.
But great cheat! Just use some common sense for guesses on 2 and 3 (checking the quality of your guesses with the more brute force technique) and your pictures will look pretty reasonable! That is the beauty of weighted averages.
8 comments:
Informative post!
Looking forward for more.
The reflectivity is the albedo/color of the surface, I take it?
"...or as some on the whipper-snappers say "next event estimation""
IIRC, the original "next event estimation" name comes from the nuclear engineering literature of the 60s - neuron transport and all that - that also delved into Monte Carlo radiative transport.
Not sure who introduced this into graphics, but I have a vague recollection it was somewhere during the early 90s, so rather early in the whole MC rendering story.
Nice work. Digitizing Services LLovely.
Step into your divine power with Apna Showroom’s spiritual-goddess combo. This set features a pure Brass Gangajal Kalash, Feng Shui tortoise to stabilize energy, a healing crystal for clarity, the rare APNA SHOWROOM Bra for Women Combo Pack of 6 - Cup Size 36(B) Non-Wired Multicolor Everyday Cotton Bra 36B
APNA SHOWROOM Bra for Women Combo Pack of 6 - Cup Size 32(B) Non-Wired Multicolor Everyday Cotton Bra 32B
APNA SHOWROOM Bra for Women Combo Pack of 6 - Cup Size 34(B) Non-Wired Multicolor Everyday Cotton Bra 34B
Apna Showroom Ganga Jal - Holy pure Ganga Jal Har ki pauri Brahmakund Prasad Tasveer Chunni Haridwar Ganga Jal Natural Ganga jal
APNA SHOWROOM Rudraksha Mala 5 Panchmukhi Authentic Genuine Rudraksha Beads Ornament Rosary Japa Mala Beads Necklace Puja | Prayer (108+1) Beads | 10mm Mala
Black Shaligram Shivling for protection, and fashion-forward fishnet stockings for women. For women who live by mantra and make a mark, this combo amplifies both presence and peace. Give your rituals a bold twist—shop now for the ultimate sacred style statement.
Really helpful information here! For anyone based around Delhi NCR, partnering with a web development company in Noida can be a smart move — they combine tech expertise with local market understanding.
The Outdoor LED Smart Lighting Solution Market is expanding rapidly with the global push toward energy-efficient, sustainable urban infrastructure. These systems integrate LED technology with IoT-based controls, allowing for automated brightness adjustment, fault detection, and energy monitoring. Municipalities and smart city projects are major adopters, seeking to reduce energy consumption and improve public safety. Enhanced features like motion detection, environmental sensors, and wireless connectivity are adding value, attracting investments from both public and private sectors. North America and Europe are leading in implementation, with Asia-Pacific quickly catching up.
It is a wonderful experience to study in Belfast, but assignment work can prove to be very stressful. You don't have to do it all on your own. By availing The Tutors Help, you receive specialized guidance and high-quality help for all your scholastic needs.
We can relieve you of the pressure of studying. Chat with The Tutors Help today for the highest quality assignment assistance in Belfast and begin attaining those grades that you so rightly deserve!
https://uk.thetutorshelp.com/assignment-help-in-belfast
Assignment Help in Edinburgh
If you are a student in Edinburgh and struggling to maintain your assignments, don't worry. The Tutors Help is ready to assist you. Our professional writers, welcoming service, and high-quality work make us the most suitable option for assignment assistance in Edinburgh.
Chat with UKThe Tutors Help today and move one step towards academic achievement!
https://uk.thetutorshelp.com/assignment-help-in-edinburgh
Assignment Help in Edinburg
Post a Comment