Coding Adventure: Ray Tracing

Sebastian Lague
942697
52662
I tried creating a custom ray/path tracing renderer. Featuring: maths, shaders, and cats!
This project was written in C# and HLSL, and uses the Unity game engine.

Source Code:
Support the channel:
Coding Adventures Playlist:

Learning Resources:

Music Credits:

Chapters:
0:00 Intro
1:08 Cameras and Rays
3:30 The Pixel Shader
5:02 Drawing a Sphere
6:59 Multiple Spheres, and Colour!
8:21 Two Types of Reflections
9:04 Experimenting with Randomness
11:14 Random Hemisphere Directions
14:11 The Trace Function
16:35 Testing Lights
17:55 Chair Thief
18:23 Progressive Rendering
19:54 A Simple Sky
20:49 Lambert’s Cosine Law
22:47 Cosine Weighted Rays
22:36 Triangles
24:52 Some Tests
27:14 Specular Reflections
29:59 Tomatoes and Glossiness
31:57 Blur and Anti-Aliasing
34:42 Depth of Field
37:14 The End

131 Comments

  1. Always a good day when a Coding Adventure releases. his video feels both calm and inspiring, and never boring.

  2. Hey man just wanted to post a comment to express my love for your videos.

    Im currently in school studying software development but my love for programming and technology goes beyond that. I'm not the smartest guy and I'm not going to pretend to understand everything you do or say. But man I've learned ALOT.

    So far the most fascinating thing you taught me is the HOW math is actually used in creating all sorts of things. I've always heard that math is important but I never got an explanation for why or how.

    I appreciate and love everything you do and I hope you continue making videos like this for a long time. Much love ❤

  3. What Editor does Sebastian use? Visual Studio?

  4. Michael Johnson[][][][][][][][][][][][][][][][][] says:

    Top and back white

  5. I am frustrated, how did Sebastian make a Point and how did he make a Arrow?

  6. This is great but then it becomes useless once you realise blender has most of this stuff already. But the big difference is you can make games in unity and you cant in blender

  7. I've got a question. Triangle struct has normalA, normalB and normalC but there are no values assigned to these vectors. How are they calculated?

  8. there should be SoME but for programming
    SoPE
    Summer or Programming Exposition

  9. Your channel is just so chill!!! I love it!!! Keep it up bro!

  10. 28:40 you just melted my mind with the infinity spheres–
    as a traditional artist stuff like this is so– esoteric in a way
    because all artists in history attempted to understand things such as this-
    and now its just what it is now to the standard consumer-
    we are not even a decade away from the fact that we didnt even have HD resolution

    and now i can generate HD AI artwork on my home PC since it evolved in 12 months what took us human an entire 4 decades to invent and create at a home staple- graphic progression has created an odd norm that people dont question what the point of the Las Vegas Dome is– its a digital 3d sphere that would have melted the minds of people from not even 60 years ago–

  11. The math reason for normal distribution to be working is the following:

    When generating a value from a normal distribution, you can get ANY number, not just ones between 0 and 1.

    If we graph the probability (density) of each number appearing, with a uniform distribution we would get a square, which is not circularly symmetrical, but with a normal distribution we get the plane itself, just a bit bunched up at 0. And the plane is circularly symmetrical.

  12. I think this is my favorite video on youtube

  13. Hello, I am new to all this graphics thing. Could you please give me some advice on where to start? I feel a little lost:D

  14. 33:05 Am I the only one who thinks that this gaussian distribution makes more sense than a plain disc?

  15. "I reckon we've spent enough time looking at these balls" Sebastian, and my girlfriend……

    Also, top marks for the use of the word "reckon"

  16. 2:45 it's quite fascinating that IIRC the first theory of optics (Ancient Greeks) also assumed that the eye sent out rays that "illuminated" the visible world. PS. I should stop writing comments the moment they pop into my head and wait for the video to finish xD

  17. I don't code, so I can't vouch for Sebastian's skills objectively, but to me, he is a magician. And his videos are comfort food for my soul.

  18. the sponsorblock highlight is the cat portion of the video

  19. If you run into a graphics glitch like @ 12:00 you may be able to avoid needing to reboot by resetting your graphics driver in windows using the hotkey: win+shift+ctrl+B

  20. Wow, another amazing video, thank you very much for sharing!

  21. You are on a whole new level of awesome brother! I envy your work!

  22. I know someone who found out how to use ai algerithems to simulate ray tracing on any computer, and made a game to demo it, even my 5 year old laptop can run it at around 50 fps with out an rtx card

  23. I'm a bit late here, but when generating random directions, wouldn't it make sense to generate polar coordinates instead of continuing to pick values until one is inside a sphere? Why not generate three angles and build a vector from there?

  24. Forget the code, where can I download those cats?

  25. I've been thinking. Why not use this to do even better portals? It will even allow light and shadows to pass through

  26. Currently studying a 3D graphics module for a computer science degree and this is explained so much better than my lecturer. Thank you 🙂

  27. Hey
    Love your videos)
    I was thinking
    You seem to be using the generator of random points on the sphere quite a bit. I think using polar coordinates (just generating two random angles with uniform distribution) can make it a little faster? And if you need the cosine distribution just generate one angle and one linear coordinate. Square the coordinate and you’ve got a distribution, where probability density at each value is proportional to the value itself.
    So, imagine your normal vector aligns with the x axis. You generate the x coordinate of your point on a sphere, such that it’s probably is proportional to x coordinate. X coordinate is precisely the cosine of the angle between your random vector and x axis if you take a unit sphere
    (I’m not extremely sure in the cosine one, but the uniform definitely works)
    And one more question. I don’t really understand why would you generate a random value at each pixel and then namely average it out over time or number of rays. Wouldn’t it be faster and less noise, if you straight up give the expected value of your distribution?

  28. Great work! It's amazing to see this raytracing in close to real time. When I played with POVray in the late 80s any of these scenes would make my 286 cry for days. Moore's Law is indeed a wonderful thing.

  29. 31:50 что, котов двое?! Крутые.
    А вообще видео интересное

  30. You make great videos. Really impressive stuff.
    But cpuld ypu kindly consider dropping the ASMR voice, please? Or at least tone it out a bit…

  31. just another unity noob, who understands nothing about coding. now try to do it without "press a button" software aids

  32. Best YouTube channel in the world!!!!!!!

  33. a great video, many thanks. the inclusion of the code snippets is a real help!

Leave a Reply

Your email address will not be published. Required fields are marked *