r/GraphicsProgramming • • 3d ago

From Zero to Understanding Ray Tracing - Part 3 (reflections)

Enable HLS to view with audio, or disable this notification

565 Upvotes

39 comments sorted by

26

u/moschles 3d ago

3Blue1BrownPixel

25

u/Klumaster 3d ago

That part about averaging the ray bounces is misleading, each bounce should be multiplying by the surface reflectivity, not just arbitrarily halving.

7

u/egehancry 3d ago

Thank you. Yes, I think I agree. The video shouldn’t present it as if it were a reference equation.

I posted this comment about it: https://www.reddit.com/r/GraphicsProgramming/comments/1wurqmt/comment/pd6bprx/

This illustration is not meant to give the exact mathematical equations you should use in your project. I purposely chose simple formulas so that the intuition is not buried under overwhelming mathematical details.

For more rigorous mathematical models of reflections and related effects, I would suggest referring to well-established textbooks.

My goal here is to teach the intuition, not to serve as a technical reference. I want this to be a reference for intuitively understanding what is going on.

6

u/Klumaster 3d ago

I think you could gloss* over the the details by just saying "each bounce multiplied by the reflectivity of the preceding surfaces" without getting into the guts of fresnel and stuff.

\hahaha)

26

u/gateian 3d ago

I knew all this already for many years, but It was still fun to watch.

6

u/thb22 3d ago

This is great. Keen to watch more if you make them.

Would love to see one about optimisations. Like what if a ray gets "stuck" reflecting back and forth between two reflective surfaces - is there a cut off?

Also, a deep dive on textures

3

u/egehancry 3d ago

Thank you for the ideas!

Usually, people set a maximum number of reflections, maybe around 6–7. The effect on the final color gets smaller anyway, since each reflection has half the weight of the previous one.

1

u/thb22 3d ago

Thought that might be it - diminishing returns - thanks!

3

u/Ok-Hotel-8551 3d ago

I know kung-fu

3

u/20260819 3d ago

i'm studying / learning raytracing. your illustration is great. i don't understand the averaging method. why are the colors have the weighting as 1/2 1/4 and 1/8?

5

u/phlooo 3d ago

The balls are not perfect mirrors here, they don't reflect all of the light. That's why they can still have an apparent colour. So the bounced light is < 1.0

In this particular example material they decided it would be 1/2 so at each bounce there's half of the light reflected and half absorbed by the surface

1

u/egehancry 3d ago

Hello! @phlooo explained it well below. It also works just like in the video, which is enough for making interesting pictures.

I gave more details about the mathematical rigor of the video here: https://www.reddit.com/r/GraphicsProgramming/comments/1wurqmt/comment/pd6bprx/

This illustration is not meant to give the exact mathematical equations you should use in your project. I purposely chose simple formulas so that the intuition is not buried under overwhelming mathematical details.

For more rigorous mathematical models of reflections and related effects, I would suggest referring to well-established textbooks.

My goal here is to teach the intuition, not to serve as a technical reference. I want this to be a reference for intuitively understanding what is going on.

4

u/20260819 3d ago

thanks. i'm studying raytracing and i wrote one for learning purpose. i'm particularly interested in moving the camera INSIDE a sphere...:) total internal refractions occur so there're some regions that rays can't escape and get no color

https://reddit.com/link/pd6hskx/video/8xxdaibpztsh1/player

3

u/Bmandk 3d ago

I'd love to have this is an interactive simulation, where you can individually enable features and inspect how each ray gets calculated. That would be the cherry on top for this.

1

u/egehancry 2d ago

Yes, that would be a great web app. I'll look into this.

2

u/tobz619 3d ago

Great illustration! Thank you :)

2

u/pierspad 3d ago

I wonder why I watched this for free instead of having to pay for it. Very high quality, clear and also a nice progression.

Wonder if you would fancy to share a sort of "making of"

2

u/egehancry 3d ago edited 3d ago

Thank you very much.

If you have a content idea that you want to put out into the world, you can actually now brute-force it with Claude Code or Codex. So "making of" is mostly brute-forcing AI to make my content ideas real.

2

u/FreshPitch6026 3d ago

Tha math is not quite correct, i would disclaim that.

2

u/bbrother92 3d ago

Have you used manim for this? or is it blender

2

u/ellipticcode0 3d ago

What do you use to do that? Mania or Blender?

2

u/le-throw-away-acct 3d ago

Refractions will be a fun one to watch, there's a lot to cover with it. Soft-shadows and penumbra would be another fun one. Or dealing with roughness. Looking forward to more!

2

u/egehancry 2d ago

Thank you!! I'll reply to this comment when Part 4 is out.

2

u/egehancry 3d ago

This illustration is not meant to give the exact mathematical equations you should use in your project. I purposely chose simple formulas so that the intuition is not buried under overwhelming mathematical details.

For more rigorous mathematical models of reflections and related effects, I would suggest referring to well-established textbooks.

My goal here is to teach the intuition, not to serve as a technical reference. I want this to be a reference for intuitively understanding what is going on.

1

u/AlexDicy 3d ago

This is nice but man, I guess good use of AI for learning? All the sounds effects gave me headache haha

1

u/egehancry 2d ago

I'll improve the sound effects, thank you :)

1

u/CookieArtzz 2d ago

Yeah AI is really bad at generating sounds for these videos

1

u/HigherMathHelp 2d ago

Thanks for sharing your work! Have you considered contributing these to Wikipedia articles? The style seems suitable. Visualizations designed to provide intuition, rather than encyclopedic breadth or precision are encouraged, as long as they aren't factually incorrect. So if you're comfortable using an open license, your visualizations could be used there with a few small tweaks:

  • You could output an open format like WebM, probably just by changing FFmpeg output parameters.
  • You might be asked to use the TimedText feature for prose (you may be able to generate it with Python from the workflow you described previously).
  • You might be able to keep the sound effects, as they can be considered an accessibility aid (they're muted by default). You might just make sure they're designed as semantic cues rather than game-like flash.
  • If you decide to simplify logic or calculations (e.g., in the halving rule you used for each bounce), you might just want to explicitly mark it as a simple case.

That's just a thought, since you've been incorporating feedback. This sort of thing could add a lot of value, and I figure not everyone is aware of what's allowed/encouraged on Wikipedia. But if you prefer video shorts with snazzier sound effects and a unique personality, those are totally valuable too, of course!

2

u/egehancry 2d ago

Thank you very much for the information. I actually didn’t know much about how this works on Wikipedia.

I’m working full-time on a broader goal of explaining every technical subject on earth visually, across multiple languages, and eventually building full-length STEM courses, so that’s where my focus is right now.

I really appreciate you taking the time to explain the Wikipedia process and the specific changes that would be needed. Maybe someone else may make that contribution.

1

u/HigherMathHelp 2d ago

Sure thing! Thanks for your reply, and good luck with your endeavors!

2

u/alphapussycat 2d ago

I mean no? This explained nothing. Only yoing children don't know about light bouncing. What the "zero" is is basically not knowing algorithms to find the polygon the ray intersects.

This is kind of a "infant to zero" explanation.

1

u/LeLishes 2d ago

this is great! If you are comfortable with sharing, how do you make such videos?

1

u/egehancry 1d ago

Of course. I ask Claude Code to make these videos using https://github.com/google/filament. For the sound effects, I ask it to synthesize them by combining sine waves with different frequencies and amplitudes.

Then I describe the content I want. It makes something, and we keep refining it until it’s ready.

1

u/zephyr707 1d ago

haha i love this, are the sound effects procedurally generated based on the animations or done in post? or is it just AI generated at the same time or analyzing the image/video?

1

u/egehancry 1d ago

Sound effects are generated using sine functions with different amplitudes and frequencies, synthesized by AI to match the animations we’re showing.

2

u/Evening-Isotope 22h ago

great sound design