Coding Adventure: Optimizing a Ray Tracer (by building a BVH)

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.พ. 2025

ความคิดเห็น • 1.2K

  • @griffinschreiber6867
    @griffinschreiber6867 8 หลายเดือนก่อน +3880

    "Just recursively split the children in half" is my new favorite Sebastian Lague quote.

    • @RandomGuyJCI
      @RandomGuyJCI 8 หลายเดือนก่อน +228

      The venn diagram of data structure terms and serial killer terms is a bit closer than you think 😅

    • @blog.daLuna
      @blog.daLuna 8 หลายเดือนก่อน +15

      This is the type of thing I laugh of

    • @jonasgajdosikas1125
      @jonasgajdosikas1125 8 หลายเดือนก่อน +19

      reminds me of the "are you being intentionally dense?" scene

    • @Jakwab
      @Jakwab 8 หลายเดือนก่อน +13

      I was zoning-out a little, but hearing that got me immediately focused again.

    • @dawidjlb2589
      @dawidjlb2589 8 หลายเดือนก่อน +27

      Salomon Lague

  • @theothetorch8016
    @theothetorch8016 8 หลายเดือนก่อน +2109

    "But sometimes, I suppose, one has to prioritise the computer's happiness over one's own."

    • @GeorgeTsiros
      @GeorgeTsiros 8 หลายเดือนก่อน +38

      No. The computer must suffer lest _we_ suffer instead.

    • @ValeBridges
      @ValeBridges 8 หลายเดือนก่อน +38

      ​@@GeorgeTsirosBut if the computer is happier now, then its work will be done faster, so we can be happy with that work sooner. It's a win-win!

    • @GeorgeTsiros
      @GeorgeTsiros 8 หลายเดือนก่อน +5

      @@ValeBridges It was mostly in jest

    • @musica00-7z
      @musica00-7z 8 หลายเดือนก่อน +9

      The true Bob Ross of programming.

    • @chameleonedm
      @chameleonedm 8 หลายเดือนก่อน +4

      @@GeorgeTsiros In my now decade of programming, I couldn't agree more

  • @TilghmanReiss
    @TilghmanReiss 8 หลายเดือนก่อน +2064

    I’ve never been so excited to watch an hour long coding adventure before

    • @rubendriezen7177
      @rubendriezen7177 8 หลายเดือนก่อน +5

      Mee toooooo!!!!!

    • @HistoryOnPaper
      @HistoryOnPaper 8 หลายเดือนก่อน +6

      I more excited that I have an hour long video to watch while I wait for a game to install

    • @agsystems8220
      @agsystems8220 8 หลายเดือนก่อน +13

      Wait, that was almost an hour? I suppose it was!

    • @Josh-op6dl
      @Josh-op6dl 8 หลายเดือนก่อน

      Same!

    • @muenstercheese
      @muenstercheese 8 หลายเดือนก่อน

      the font vid was hype af too tho

  • @20x20
    @20x20 8 หลายเดือนก่อน +1058

    > I want to measure our inefficiency so that we can track improvements to it
    what a philosophy

    • @Bassalicious
      @Bassalicious 8 หลายเดือนก่อน +31

      maximum inefficiency is pretty much my life motto

    • @christophnaber163
      @christophnaber163 7 หลายเดือนก่อน +22

      Which is the correct starting point of any performance optimisation with code. NEVER just assume you know what is slowing the program down. Measure the performance „in action“. Then you start your changes.

    • @carlosmspk
      @carlosmspk 7 หลายเดือนก่อน +2

      Humm, how would you do it if not by finding the innefficiencies?

  • @truc_e
    @truc_e 8 หลายเดือนก่อน +948

    For your next coding adventure you should try some multiplayer sync stuff if you haven't already. I recently have gone down a rabbit hole of different types of network sync models and there is still a lot of nuance that is left ambiguous in even the most detailed blog posts. Something that I would personally love to see.

    • @SebastianLague
      @SebastianLague  8 หลายเดือนก่อน +729

      Perhaps, if I’m feeling brave!

    • @nocluebruh3792
      @nocluebruh3792 8 หลายเดือนก่อน +108

      @@SebastianLague yeah I always wondered how all of the battlefield games were able to host 64 players, events, vehicles, explosions with pretty good efficiency (benchmarked with my old crappy wifi connection) and all of that good stuff:)

    • @whaloob
      @whaloob 8 หลายเดือนก่อน +50

      @@SebastianLagueseconding this suggestion, although I understand the hesitation 😅

    • @just_smilez
      @just_smilez 8 หลายเดือนก่อน +59

      Network code is the path to madness

    • @VexVex24
      @VexVex24 8 หลายเดือนก่อน +9

      @SebastianLague The world of networking has always been a mystery to me, so I would love to see you cover it.

  • @greenguy5294
    @greenguy5294 8 หลายเดือนก่อน +345

    "Where we left off a year or so ago" dealt me 1d6 of psychic danage

    • @musica00-7z
      @musica00-7z 8 หลายเดือนก่อน +17

      2d20 of old age

    • @bactrosaurus
      @bactrosaurus 7 หลายเดือนก่อน +7

      It shows in your spelling😮

    • @shadowofcat
      @shadowofcat 6 หลายเดือนก่อน +1

      So real, it felt like only a few months have passed

    • @thatcatthatalwayseatsyourchees
      @thatcatthatalwayseatsyourchees 5 หลายเดือนก่อน

      ​@@bactrosaurushuh

  • @thehuggz-i9k
    @thehuggz-i9k 8 หลายเดือนก่อน +844

    18:10 the arm waves in the reflection was so real 😂

    • @epiklizard6629
      @epiklizard6629 8 หลายเดือนก่อน +45

      A hallmark of graphics programming

    • @DigitalJedi
      @DigitalJedi 8 หลายเดือนก่อน

      @@epiklizard6629 I've been getting back into Vulkan and yeah...

    • @bocket
      @bocket 8 หลายเดือนก่อน +4

      I wondered if I was the only one who saw that

    • @BudgiePanic
      @BudgiePanic 8 หลายเดือนก่อน +5

      Side channel leaking his appearance

    • @calcu_
      @calcu_ 8 หลายเดือนก่อน +1

      I was searching for this comment

  • @sietzethebest
    @sietzethebest 8 หลายเดือนก่อน +589

    OMG you've found the blog of my thesis supervisor (JBikker)! My thesis is related to BVHs so this video is a treat to watch :)

    • @milanpolle
      @milanpolle 8 หลายเดือนก่อน +73

      Haha, I didn't even notice that, Jacco is a former colleague of mine, back from when I worked at Davilex Games, small world indeed.
      Really interesting video, I've been creating some real-time ray-tracing shaders, but nothing using triangles yet.

    • @sleepi5550
      @sleepi5550 8 หลายเดือนก่อน +41

      Fellow Jacco student!
      It's surprising how often he comes up in my own research 😄

    • @GeorgeTsiros
      @GeorgeTsiros 8 หลายเดือนก่อน +23

      Your supervisor has a very rich and informative github.

    • @jaccobikker
      @jaccobikker 8 หลายเดือนก่อน +69

      Hey Sietze. :)

    • @Watashiwapitadesu
      @Watashiwapitadesu 8 หลายเดือนก่อน +29

      @@jaccobikker Amazing to read that you are still teaching. The graphics course was the most engaging and fun course I've had the pleasure of taking.

  • @seanloughran6714
    @seanloughran6714 8 หลายเดือนก่อน +387

    That was awesome. One of the structures I've used in the past when I have all the data ahead of time is a Sort-Tile-Recursive (STR) R*Tree. You sort the data in space first, then build the tree from the bottom up. The result is a very well balanced tree that is extremely quick to query. You then set the maximum number of children in a leaf, so you get even performance. I don't know if the query times would speed up that much after your final iteration, but my guess is, the build time would be infinitely quicker. As always, just an extremely informative and entertaining video!

    • @SebastianLague
      @SebastianLague  8 หลายเดือนก่อน +216

      I've never heard of that, but it sounds interesting -- will check it out. And thanks, I'm happy you enjoyed the video!

    • @knitnatsnokprogramming
      @knitnatsnokprogramming 8 หลายเดือนก่อน +8

      How did you get to see the video that fast

    • @dogeron8132
      @dogeron8132 8 หลายเดือนก่อน +6

      How tf did u watch 1hr video and replied when it only came out 1 min ago

    • @Jake28
      @Jake28 8 หลายเดือนก่อน

      @@dogeron8132 60x speed

    • @Felix-mk3sd
      @Felix-mk3sd 8 หลายเดือนก่อน +5

      How tf did you comment 23h ago when video was uploaded 18mins ago??

  • @Gwilo
    @Gwilo 8 หลายเดือนก่อน +272

    these coding adventures get more and more complex. I reckon Sebastian's working on something big, but first has to learn every technique to its fullest before starting and then finishing it

    • @ClaffAMV
      @ClaffAMV 8 หลายเดือนก่อน +13

      The perfect Game Engine, offering the best performance on every possible aspect hahahahah

    • @bullshitman155
      @bullshitman155 8 หลายเดือนก่อน

      Sebastian in 50 years: Hello everyone and welcome to another episode of Coding Adventures. Today, I wanted to try simulating our universe.

    • @kidmosey
      @kidmosey 8 หลายเดือนก่อน +34

      He's actually working in reverse. Started out creating a universe, now he's on figuring out light.

    • @bigfin20
      @bigfin20 8 หลายเดือนก่อน +13

      at this point he's just doing his own thing for its own sake none of this is necessary for a game project or really anything past tech demos

    • @thatcatthatalwayseatsyourchees
      @thatcatthatalwayseatsyourchees 7 หลายเดือนก่อน

      @@ClaffAMV with incrdeible preview rendering

  • @oskarristolang
    @oskarristolang 8 หลายเดือนก่อน +703

    babe wake up sebastian uploaded

    • @warriorsfg
      @warriorsfg 8 หลายเดือนก่อน +34

    • @tirushone6446
      @tirushone6446 8 หลายเดือนก่อน +5

      I hope he keeps these monthley uploads up that would be awesome

    • @йцукен5959
      @йцукен5959 8 หลายเดือนก่อน +6

      ​@@warriorsfg no 🅱️itches😔

    • @ThibaultM.
      @ThibaultM. 8 หลายเดือนก่อน

      exactly

  • @Xa31er
    @Xa31er 8 หลายเดือนก่อน +194

    I hear the "hello everyone" and I drop anything just to watch it. 10/10 dropped my phone on a lake.

    • @willmungas8964
      @willmungas8964 8 หลายเดือนก่อน +6

      On??

    • @Xa31er
      @Xa31er 8 หลายเดือนก่อน +23

      @@willmungas8964 yes, on.
      Water physics are a WIP...

    • @SpringySpring04
      @SpringySpring04 7 หลายเดือนก่อน

      ​@@Xa31er lmfaoooo

    • @danisob3633
      @danisob3633 7 หลายเดือนก่อน +5

      @@Xa31er mine bounced off of it. Its still bouncing, it never stops. I dont know what im doing wrong

    • @meijuta
      @meijuta 7 หลายเดือนก่อน +1

      frozen lake

  • @GeorgeTsiros
    @GeorgeTsiros 8 หลายเดือนก่อน +62

    My absolute favorite part of your videos is that the tone of your voice is like you are _smiling_ while speaking.
    I do not know why, normally I would consider it condescending, but from you it sounds _honest_
    People who code well are rare. Equally rare are people who can explain well. People who can do _both_ are exceedingly rare. You deserve every bit of praise you get.

  • @hestojam
    @hestojam 8 หลายเดือนก่อน +220

    Very impressive results, bravo.
    I keep being in awe by how you manage to make things work first, then optimize it in a structured way and without getting weighted down by premature optimizations and such.

    • @chadbramwell977
      @chadbramwell977 8 หลายเดือนก่อน +94

      If I were to make a guess, some of the content order is following papers / intuition and the rest is messing up a bunch, taking notes along the way, and then reforming into a delightful journey for viewers. Sebastian is a wonderful storyteller that I bet embellishes certain points and spends extra time on debugging tools for us. :)

    • @SebastianLague
      @SebastianLague  8 หลายเดือนก่อน +83

      Thank you!

    • @bogoid
      @bogoid 7 หลายเดือนก่อน +3

      the old motto of software design
      make it work
      make it right
      make it fast
      it's simple, but helps a lot

  • @smestre
    @smestre 8 หลายเดือนก่อน +97

    Hey Sebastian, cool video!
    There's a slightly different approach that would let you try every possible cut in the SAH without too much additional cost.
    Right now you're evaluating each cut by looping over all the triangles (O(N*K) cost for N triangles and K cuts), but this does not take advantage of previous evaluations.
    Imagine you sorted the triangles along one of the axis, then computed and stored the bounding box of each prefix and each suffix of the triangle list. Now you can evaluate each cut in constant time (child A corresponds to a prefix of the list and child B to a suffix).
    Sorting has cost O(N log N), but then you can try all the cuts along that axis in O(N) time. Overall, the cost is O(N log N), which should be much better than O(NK) for large values of K.
    Here is an outline of the general approach:
    sort tris along the x axis
    prefixes = array of length n
    prefixes[0] = bounding box of tri[0]
    for i = 1 to n-1, assign prefixes[i] = bounding box union of prefixes[i-1] and tri[i]
    suffixes = arraay of length n
    suffixes[n-1] = bounding box of tri[n-1]
    for i = n-2 to 0, assign suffixes[i] = bounding box union of suffixes[i+1] and tri[i]
    for i = 1 to n-1, the cost is i*surfaceArea(prefixes[i-1]) + (n-i)*surfaceArea(suffixes[i])
    As described, the idea involves performing three sorting operations at each node of the tree, but this is not strictly necessary. If you sort all the triangles along the three axis just once at the top level, it's possible to preserve the order as you go down the tree construction algorithm. This might be too complicated to implement while keeping the code readable, though.

  • @jaccobikker
    @jaccobikker 8 หลายเดือนก่อน +93

    Very nice video. Nice illustration of the BVH concepts! Greets, Jacco.

    • @JamEngulfer
      @JamEngulfer 8 หลายเดือนก่อน +2

      Your student and an old colleague commented on this video as well. Just letting you know in case you wanted to say anything to them.

    • @KoshakiDev
      @KoshakiDev 8 หลายเดือนก่อน +4

      Hi Jacco!

    • @bakje24
      @bakje24 8 หลายเดือนก่อน +4

      this guy a real one fr fr big shout out

  • @toara
    @toara 8 หลายเดือนก่อน +92

    Can't wait for more fluid simulation next!

    • @musica00-7z
      @musica00-7z 8 หลายเดือนก่อน +6

      What about the volumetric effects?

    • @ms-fk6eb
      @ms-fk6eb 8 หลายเดือนก่อน +5

      yeah it's been like 5 years since he made that comment about voxel erosion, I've been binging cave exploration videos and thinking about how to approach doing it myself hahaha

    • @ThePC007
      @ThePC007 8 หลายเดือนก่อน +4

      Or rendering voxels. I’ve gone down that rabbit hole and I have yet to return. D:

    • @vibaj16
      @vibaj16 8 หลายเดือนก่อน +4

      ray traced fluid simulation with refraction and caustics

    • @Redingold
      @Redingold หลายเดือนก่อน

      ​@@ms-fk6ebI'm sure I heard him mention the idea of tectonic plate simulations for the planet generation way way back and I think that'd be really cool to see.

  • @calebgilbertyt
    @calebgilbertyt 8 หลายเดือนก่อน +36

    I fell asleep watching this video and I'm not even joking, you have the calmest voice and I wouldn't trade it for anything!

    • @pvic6959
      @pvic6959 8 หลายเดือนก่อน +12

      hes going to be like "do i take this as a compliment (calm voice) or an insult (not engaging)" LOL

    • @calebgilbertyt
      @calebgilbertyt 8 หลายเดือนก่อน

      No it was engaging, I was just pretty sleepy I guess 😅 great video 👌​@@pvic6959

    • @JamEngulfer
      @JamEngulfer 8 หลายเดือนก่อน +5

      Same! I was watching it last night and nodded off before I could finish, it’s too calming. I’m back to see the rest this morning though.

  • @bejoscha
    @bejoscha 8 หลายเดือนก่อน +35

    Your detailed explanation style is very much appreciated. It's often a tiny "practical" thing between "the theory" and "the final program" which is the biggest coding hurdle to overcome. Your videos are great to overcome these hurdles and learn how to approach such problems in general. Important skills well taught.

  • @seejay_through_life
    @seejay_through_life 4 หลายเดือนก่อน +3

    it's been over a year since a fellow game programming student introduced me to the "cult of sebastian lague" (his words), and i'm so glad because your content is unbelievably lovely to watch (over and over). many times, i've rewatched various episodes of coding adventures to rekindle my joy for programming, and it always works.
    thank you, Bob Ross of Software Engineering

  • @suri4Musiq
    @suri4Musiq 8 หลายเดือนก่อน +16

    Your visualizations are immensely beautiful and helps understand complex concepts like BVH. I am not lying when I said, I read this and implemented this myself, but I don't believe this is what my understanding was! Much love to your work

    • @suri4Musiq
      @suri4Musiq 8 หลายเดือนก่อน +1

      Also minor suggestion, add option to TIP on youtube videos. That way it would be easier for me or others to support your work without having to through Patreon.

  • @Awesomekid2283
    @Awesomekid2283 หลายเดือนก่อน +3

    Really great job with switching to an array of index values for your stack and leaving the nodes alone in their own array! The reason this is much better is because primitive types like floats and ints are always copied since they're considered trivially copyable (i.e., they don't take much time to copy at all and the computer could do it in its sleep), but when you have a lot of them, that time adds up. Now instead of copying all of the node data each time new nodes are pushed and popped from the stack, only single integer values are copied, which reduces the overal number of copies by a lot. Additionally, arrays are constant-time lookup, meaning no matter how big an array gets, it will always take the same amount of time to access a value. This is because the index values are actually just memory offsets, meaning only a single addition and multiplication are needed to go from the start of an array to a particular element. This means that you ended up trading in the cost of a bunch of unnecessary copies for the constant-time lookup of the nodes. I definitely believed that result when I saw it! Also I'm glad to see you getting more detailed about how computers work! You actually optimized your code to prevent cache misses!
    Your videos are so relaxing to watch, and your coding adventures cover all of the things I want to do, but simply don't have time for. I cannot appreciate enough the effort you put into these videos! Please keep them coming!

  • @thebluetoo_
    @thebluetoo_ 8 หลายเดือนก่อน +39

    always excited to watch these videos, even though i dont understand much of it, the things you accomplish are so cool to see and its nice to learn something i have no idea about!

  • @FisheySauce
    @FisheySauce 7 หลายเดือนก่อน +6

    The exploratory nature of your videos is why I will spend an hour of my life the next available moment I have watching your channel. I love learning, and as a non programmer and you just make it so fun and easy to understand. Thank you for the knowledge and enthusiasm you give me to keep knowing more. :)

  • @finnwassmart
    @finnwassmart 8 หลายเดือนก่อน +22

    Tbh I really love your videos. Your voice always feels like you're enjoying every moment of the explanation. Not only it gives both coding knowledge but also inspiring for me to continue my coding journey. I think it does the same things for other people too. Thank you for posting those videos!

  • @wendelin1515
    @wendelin1515 3 หลายเดือนก่อน +1

    I really really love the humour, the in depth explanations, the animations, pretty much everything. It feels so relaxing and like you really care abt everything which makes it so enjoyable to watch

  • @jmlopezponce
    @jmlopezponce 8 หลายเดือนก่อน +7

    The result is excellent, and the explanations are great. I think the key to sebastian's success is his attention to the small details. When he explains he may put a slight animation that you only see for 3 seconds in the video, but he has taken the time to prepare it carefully. That enhances the quality of an already 100/100 content. Thanks for taking the time to do the remaining 20% of things that enhance the content so much. Greetings from a big fan. Keep it up💪💪💪

  • @webtweakers634
    @webtweakers634 8 หลายเดือนก่อน +3

    This visualisation of the rays hitting the model and the BVH test at 8:50 is really quite awesome. Great videos, please continue Sebastian.

  • @cachecoder
    @cachecoder 8 หลายเดือนก่อน +5

    Two things I love about this channel, your ability to break down really complex programming concepts in to something easy to get my head around and the fact that your test and explainer side projects are damn near finished projects in their own right. Love it all!

  • @Rohit-kl4gl
    @Rohit-kl4gl หลายเดือนก่อน +2

    "Hi Sebastian!
    I’ve been following your content for a while, and your videos on procedural generation and game development are incredibly insightful. I’m working on a voxel-based game inspired by Minecraft, and I was wondering if you’d consider making a video that goes in-depth on voxel world generation, similar to how Minecraft does it. It would be amazing to see your take on chunk loading, terrain generation using noise functions, and optimization techniques for creating large worlds.
    Your expertise and clear explanations would be incredibly helpful for many aspiring developers like me! Thanks for all the great content you’ve shared so far!"

  • @manassarpatwar
    @manassarpatwar 7 หลายเดือนก่อน +3

    It's always great to watch a coding adventures video. I didn't know where the 50 minutes went by, your videos are always so interesting Sebastian!

  • @MrBobby2169
    @MrBobby2169 7 หลายเดือนก่อน +1

    I love seeing how each change increases the performance, and how certain changes benefit (or require) other changes in order to actually bring a benefit.
    I similarly loved watching the different operations of the chess bot play against each other.

  • @JacobGordiak
    @JacobGordiak 8 หลายเดือนก่อน +5

    It's perfect timing. I’ve been diving into ray tracing concepts for about a year now, and it's impressive how you've managed to pull this off so quickly. Your video is inspiring and gives me some new ideas to explore. Keep up the great work! 👍

  • @NickCombs
    @NickCombs 8 หลายเดือนก่อน +2

    Wonderful video as always! I recently saw a presentation by EA on how blue noise using the golden ratio is a huge improvement to perceived quality when rendering, since each pixel is randomized with respect to its neighbors rather than the full spectrum. This could speed up rendering by lowering the number of rays needed, and helps a lot with depth of field blurring which can look patchy at lower quality with white noise.
    What's also neat is that blue noise applies to any pseudorandom function by making the frequency higher. Essentially, it makes the next roll related to the previous roll and allows the gambler's fallacy to no longer be false.

  • @niceguysayshi5765
    @niceguysayshi5765 8 หลายเดือนก่อน +8

    very nice video as always! I am implementing a simple raytracer in plain C right now as well, but i am using a simple grid instead of a BVH

  • @maxpetschack3342
    @maxpetschack3342 7 หลายเดือนก่อน +1

    Some of those renders are absolutely gorgeous

  • @stick-Iink
    @stick-Iink 8 หลายเดือนก่อน +3

    Please keep making more coding adventure videos like this!

  • @SvenHeidemann-uo2yl
    @SvenHeidemann-uo2yl 7 หลายเดือนก่อน +1

    You coding adventures are among my favorite videos.

  • @UwU-rn8xo
    @UwU-rn8xo 8 หลายเดือนก่อน +3

    I remember watching your previous Raytracing Videos like it was yesterday. Its always nice to see when you upload. Keep up the great content

  • @diogomatiasmartins
    @diogomatiasmartins 7 หลายเดือนก่อน +1

    In a future followup, it would super interesting to see you dive into triangle decimation / culling techniques. The UE nanite system is an extremely interesting algorithm, in how it reduces triangle dynamically with distance. I think you giving it a shot and trying to implement it would be a great coding adventure.
    This video itself was great, as all the coding adventures have been!

  • @thechampshrimp
    @thechampshrimp 8 หลายเดือนก่อน +4

    Honestly, I could watch your videos forever. Great visuals, great background music, great explanations and great concepts!

  • @anamoyeee
    @anamoyeee 8 หลายเดือนก่อน +1

    It's always an international holiday for coders when Sebastian Lague uploads. Your videos are awesome!

  • @Alexthepresenter
    @Alexthepresenter 8 หลายเดือนก่อน +3

    Banger as always, thanks Sebastian!

  • @theformalfro
    @theformalfro 8 หลายเดือนก่อน +1

    what always captivates me is the way you visualise everything, especially the debugging. My life would be so much easier if I went past print statements 90% of the time 😂

  • @penguinmonk7661
    @penguinmonk7661 8 หลายเดือนก่อน +11

    HOLY DAMN THIS GUY BLEW UP.
    Context, I watched this guylike 8 years ago(maybe more but it feels like 8, 20k followers thought he was underated af, actually had a chat with him briefly about how to reverse an algorithm for I think it was moving platforms, quite a shock to see him over 1 mill, its like seeing and old friend and being happy for their success, feels good :3.

  • @justputitdown
    @justputitdown 8 หลายเดือนก่อน +1

    Whenever i see a new video released by Sebastian i just want to close off the rest of the world and enjoy it. Sebastian - I have no chance of ever being even a fraction as clever as you, but the way you explain things makes it really easy to follow and understand... Its such a great experience knowing that you will leave the video a little cleverer and more aware of things. The way you tackle problems and overcome them is really helpful. I cant wait to start implementing some aspects of these learnings into ideas i have.
    Thanks for making the internet a better place with your videos!

  • @UtaUtaUtau
    @UtaUtaUtau 8 หลายเดือนก่อน +4

    It would be fun to see you explore HDR buffers and HDR tone mapping for this series, or just color space stuff in general!

  • @Jejkobbb
    @Jejkobbb 8 หลายเดือนก่อน

    Your optimization charts and tests are so satisfying, you should make a game where your job is to optimize a program / process / whatever. I'm sure you could think of something really cool.

  • @Werxzy
    @Werxzy 8 หลายเดือนก่อน +86

    At 40:38 You have a struct that contains two float3s and two ints. If I'm remembering correctly, due to the byte alignment this will actually result in 48 bytes. because unfortunately float3s round up to 16 bytes for alignment and the 2 ints (due to the highest alignment in the struct being 16 bytes) will also take up 16 bytes. I'm not entirely sure how well you can do this, but you might try stuffing the 2 ints into each of the float3s to make two float4s. resulting in a true 32 byte node. Not 100% sure about how much better this is though.

    • @nielsbishere
      @nielsbishere 8 หลายเดือนก่อน +45

      That depends on what language is used. HLSL aligns StructuredBuffer tightly. So in this case no extra padding is added. If it was a cbuffer you'd be right or if it was GLSL. It is still a good idea to move the int before the other float3 though, as this won't have weird behavior if you do want to store it in a cbuffer somehow..

    • @pitust
      @pitust 8 หลายเดือนก่อน +5

      @@nielsbishere This "align up to 16 bytes" behavior is not required: the default setting of "shared" (and "packed", which is similar) leave all details up to the implementation. The option of "std140" does introduce this alignment, however, but the newer "std430" does not.

    • @nielsbishere
      @nielsbishere 8 หลายเดือนก่อน +1

      @@pitust yup. Ssbos with the correct layout are an exception indeed

    • @maxmustermann3938
      @maxmustermann3938 8 หลายเดือนก่อน +1

      @@pitust std430 does align float3 (or rather, vec3, which is the glsl variant) to 16 bytes. But it it doesn't have the 16 byte array stride that std140 has. For example:
      float[4] -> in std140, this is "similar" to float4[4], in std430 it is stored tightly like a single float4
      A similar rule exists for structs in std140, which std430 also gets rid of. But std430 still has the special alignment rule for vec3.

  • @jbrownson
    @jbrownson 7 หลายเดือนก่อน +2

    It’s incredible how well you communicate complex ideas, thanks for your videos, excellent work

  • @MrVinicius5000
    @MrVinicius5000 8 หลายเดือนก่อน +10

    21:11 ♫♪♫♪ I don't want to set the world on fire ♫♪♫♪

  • @diannebadgley2866
    @diannebadgley2866 7 หลายเดือนก่อน +1

    Your videos about binary options trading are always very interesting and useful. I learned a lot of new things and learned to put them into practice.

  • @christiaancoetzee1696
    @christiaancoetzee1696 7 หลายเดือนก่อน +5

    Half an eternity = 8 seconds
    The Sebastian Lague theory

  • @obikantv7887
    @obikantv7887 7 หลายเดือนก่อน +1

    I have watched you evolve your skills over the years and you have in front of me become a god. I started developing a bit before I found you on youtube 5-6 years ago and it's so fascinating to me to see you develop and also see me develop in the process. I love your videos and hope to see you for another 5-6 years making more amazing content like this.

  • @FinaISpartan
    @FinaISpartan 8 หลายเดือนก่อน +6

    When choosing where to split based on the surface area huristic, you should do a binary search instead of checking 5 arbitrary splits along an axis

    • @user-dh8oi2mk4f
      @user-dh8oi2mk4f 8 หลายเดือนก่อน +1

      I don't think the surface area heuristic is monotonic with respect to the split position

    • @musica00-7z
      @musica00-7z 7 หลายเดือนก่อน

      @@user-dh8oi2mk4fUse linear interpolation / marching squares-esque to estimate it

  • @SeanStClair-cr9jl
    @SeanStClair-cr9jl 8 หลายเดือนก่อน +1

    This video is fucking AWESOME. You have such a talent for displaying these metrics, and it is so exciting to see the performance go up, to see the bounding boxes become more ghost-like as you're running all these tests... so cool.

  • @Sven_vh
    @Sven_vh 8 หลายเดือนก่อน +5

    To make the image less noisy you can look into reprojection. There is a great article made by Jacco Bikker (same guy who made the bvh article)

    • @nielsbishere
      @nielsbishere 8 หลายเดือนก่อน

      Or some simple a-svgf

    • @user-dh8oi2mk4f
      @user-dh8oi2mk4f 8 หลายเดือนก่อน

      I'm pretty sure that reprojection just allows for the reuse of render data from frames where the camera is in a different position, and doesn't actually decrease the amount of noise when the camera is static

    • @nielsbishere
      @nielsbishere 8 หลายเดือนก่อน

      @@user-dh8oi2mk4f For realtime previews it's very useful. For offline renders it doesn't reduce the noise. And in fact reprojection would add bias. For that, you should probably use ReSTIR (DI/GI/PT) or a spatial denoiser (adds bias though).

  • @Glampi
    @Glampi 8 หลายเดือนก่อน +1

    One thing that I love about your videos is (the fact that && how) you show the optimization process: you briefly explain the idea behind the changes in code, show the actual changes and my favorite part - show a chart that shows the quantization of how productive that change was. I love seeing charts like that, but the whole process is also very entertaining to follow. How you come up with all these different ideas and what difference they make, love it.

  • @Iuigi_t
    @Iuigi_t 8 หลายเดือนก่อน +7

    How about a kd-tree? It is a more efficient data structure for static scenes. It is so efficient because it can stop as soon as it intersects with something inside a bounding box, as it gives distance sorted boxes. The intersection math is also waay faster!

    • @nielsbishere
      @nielsbishere 8 หลายเดือนก่อน +2

      Build times and splitting triangles can be a problem there, but if it can be baked or is just for a demo it's a good option. It will also force you to build on the cpu

    • @SimonBuchanNz
      @SimonBuchanNz 7 หลายเดือนก่อน

      A quirk is that a triangle can't be split like that (well, it can, but it makes things more complex): a BVH can have each side overlap enough to get the triangles on each side fully contained. It's not a complete loss though, you can generally simply put the triangle on both sides of the tree.

  • @iestynne
    @iestynne 7 หลายเดือนก่อน +2

    Beautiful.
    So satisfying, watching someone that can actually get shit done.

  • @sonik121
    @sonik121 8 หลายเดือนก่อน +4

    HERE WE GOOOOO

  • @delatorrejuanchi
    @delatorrejuanchi 8 หลายเดือนก่อน +2

    I can't even begin to explain how much joy your videos bring me

  • @Oziji
    @Oziji 8 หลายเดือนก่อน +20

    that was a year or so ago??????????!!!

    • @SebastianLague
      @SebastianLague  8 หลายเดือนก่อน +10

      Apparently!

    • @aspectreishauntingeurope
      @aspectreishauntingeurope 8 หลายเดือนก่อน

      hi oziji

    • @GeorgeTsiros
      @GeorgeTsiros 8 หลายเดือนก่อน +1

      @@SebastianLague fruit flies, arrows, bananas, etc, you know how it goes.

    • @dariusreed1943
      @dariusreed1943 8 หลายเดือนก่อน +2

      I measure the passage of time by the coming and going of Sebastian Lague videos

  • @Omnituens
    @Omnituens 8 หลายเดือนก่อน +2

    I love the speed and pacing you go over things. I find a LOT of programming/tech channels on youtube they just speak at an insane pace like they are gonna explode if they stop talking and makes it so hard to watch. Your videos? *chef's kiss*

  • @geokou7645
    @geokou7645 8 หลายเดือนก่อน +4

    This might be very inefficient but I, as a person who doesn’t code, have an idea. What if the rays were emitted from the camera, meaning that you don’t have to render any rays that don’t make it to it?

    • @stubman5927
      @stubman5927 8 หลายเดือนก่อน +3

      he's already doing that, and it is efficient. though it is not so efficient in terms of finding rays that made it to light (it's reversed after all)

    • @nielsbishere
      @nielsbishere 8 หลายเดือนก่อน +1

      ​@stubman5927 luckily that's why NEE, MIS and gang exist. BDPT is also great if caustics are important

  • @bhaskar08
    @bhaskar08 8 หลายเดือนก่อน +1

    Man i am here fast. And I just know this is going to be fun. You never disappoint

  • @antoniofigueroa887
    @antoniofigueroa887 8 หลายเดือนก่อน +12

    Sebastian: uploads a video
    *fifteen treseptagintilion years pass*
    Sebastian: uploads a video
    Edit1: no way I got 11 likes that’s never happened before!

  • @jamesstuedemann5005
    @jamesstuedemann5005 7 หลายเดือนก่อน

    Amazing video! I took a computer graphics class back in college and implemented my own version of BVH trees. I also do remember my professor mentioned KD-trees can be faster with an efficient algorithm. Would be awesome to see the comparison between those approaches!

  • @lejoueurfreetoplay
    @lejoueurfreetoplay 7 หลายเดือนก่อน +3

    21:13 Japanese citizens on august 6 of 1945:

  • @Jan-cb9jo
    @Jan-cb9jo 8 หลายเดือนก่อน +1

    Really relaxing, satisfying and interesting to watch

  • @mrwalter1049
    @mrwalter1049 8 หลายเดือนก่อน +1

    This did not feel like an hour. Well done on the video 👏 Here's to hoping you continue on exploring more and more advanced raytracing topics. This kind of content is to die for.

  • @stoobidthing
    @stoobidthing 7 หลายเดือนก่อน +2

    You will not believe it if I said I've been watching your channel for over 4 years now and I have just realized today that your name is Sebastian *Lague* , always thought it was Sebastian *League* how have I not realized this

  • @UliTroyo
    @UliTroyo 8 หลายเดือนก่อน +1

    Right into my mental model you go. What an excellent explanation!

  • @JoeTheis
    @JoeTheis 7 หลายเดือนก่อน

    Brilliant showcase of iterative development, debugging, visualization, and educational explanation.

  • @MichaelFurtak
    @MichaelFurtak 8 หลายเดือนก่อน +1

    Custom renders of all of your supporters' names in with the dragons was such a great touch. Nice one!

  • @dnoldGames
    @dnoldGames 7 หลายเดือนก่อน +1

    Incredible Video, I love the beautiful explantation cut-aways of all these complex and hard to grasp concepts that are easy understandable thanks to you. Great work :)

  • @Ennar
    @Ennar 7 หลายเดือนก่อน

    I've been watching your videos for some time now, especially coding adventures. One would expect that the amazement I feel would eventually start to drop off with each video, but it simply doesn't. Admittedly, I'm not a programmer, I'm a mathematician with couple of basic courses in c and c++, which I'd like to think puts me closer to noob than ignoramus, but still, the level of elegance in how you break down issues that look very complex into something that looks very tangible is stunning. I hope that people with more expertise in the field enjoy this as much as I am.

  • @DavidLongest
    @DavidLongest 7 หลายเดือนก่อน

    I appreciate that you show what happens when you do something wrong. It helps with visualizing what is going on.

  • @sanderbos4243
    @sanderbos4243 7 หลายเดือนก่อน

    Loved this. I highly recommend using blue noise for picking which pixels to shoot rays from, since it looks significantly better to our eyes. demofox, who's blog post you shouted out in an earlier video of this series, is an absolute expert in the blue noise field, so I highly recommend reading some of his posts. He was so kind to help me use blue noise in my own ray tracer, so I'm sure he'd love to help you out too. :-)

  • @DJstone17
    @DJstone17 7 หลายเดือนก่อน

    That’s some of the highest level content I’ve ever come to see on TH-cam yet.
    Awesome work

  • @josiahjack455
    @josiahjack455 5 หลายเดือนก่อน

    Thanks for this! Made an easy starting point to craft a custom stylized ray trace renderer. Adding support for textures and normals wasn't too bad either. The power of texture arrays is slick

  • @zettabitepragmara4031
    @zettabitepragmara4031 8 หลายเดือนก่อน

    Day's always great when a new Coding Adventure video comes out.
    I can't wait to see all the probability light biasing stuff you mentioned.
    It was one of my more favorite things when tinkering with ray tracing, and I think you'd do a MUCH better job explaining it than some words on a screen

  • @ThibaultM.
    @ThibaultM. 8 หลายเดือนก่อน +2

    Your videos make my day every single time. Good job, keep it up 👍👍

  • @Glubmonster4rl
    @Glubmonster4rl 7 หลายเดือนก่อน +2

    I've never understood anything you've said, nor do I have an interest in coding but i keep coming back.

  • @johannesr8709
    @johannesr8709 8 หลายเดือนก่อน +2

    I woke up sick today and this is exactly what I need rn! Thank you!

  • @viccie211
    @viccie211 7 หลายเดือนก่อน +1

    Loved this video Sebastian! Keep up the great work. It's a complex topic but you always seem to break it down in such a way that I can follow along.

  • @GabrielPettier
    @GabrielPettier 8 หลายเดือนก่อน

    It's been quite some time i didn't dabble in 3D programming & shaders, but this is really great, beautiful results and great explanations.

  • @matzibeater
    @matzibeater 7 หลายเดือนก่อน +1

    Another great video! The visualizations you use and the step-by-step approach make everything so much easier to understand than simply explaining the code and showing the result. There's only one thing I could think of that could possibly be improved on in this one: the distinct lack of cat 😿
    Jokes aside, this video inspired me to do some additional reading on the topic, so here's something I learned that might be worth exploring:
    The current state-of-the-art (or at least crowd favorite?) type of BVH seems to use something called PLOC (Parallel Locally-Ordered Clustering). At least this appears to also be the algorithm implemented by the Radeon RADV Vulkan driver.
    The idea in PLOC is to first order the triangles using a space-filling curve, typically using Morton code (this is also called Z-ordering). This causes triangles close to each other spatially to also be close in index, so the BVH can be built bottom-up efficiently by comparing the surface area of all potential merged nodes within a fixed index range.
    The main advantage of PLOC is supposed to be it's creation speed since most of it can be done in parallel, but it supposedly also results in higher traversal performance. Plus it can be further optimized (also in parallel) by collapsing leaves using SAH. Definitely sounds promising.
    If you want to take a closer look, the paper on it is called "Parallel Locally-Ordered Clustering for Bounding Volume Hierarchy Construction" (Meister and Bittner, 2017), but the best resource I found on it was a blog by Arsène Pérard-Gayot ( madmann91 github io (replaced dots with spaces so YT doesn't get mad)) where it's explained in detail using code snippets.

  • @DanelonNicolas
    @DanelonNicolas 8 หลายเดือนก่อน

    The experience of watching your videos while having dinner is so awesome. Thanks man, as a software developer I really appreciate all the work you've done with the audio, voice over, research, code and incremental changes 🤝

  • @Freegy1998
    @Freegy1998 8 หลายเดือนก่อน

    This is really a great video! I love how your editing got more visual-based rather than code-based, and it made the video riveting despite beeing nearly a hour long

  • @LoveYourParents-363
    @LoveYourParents-363 8 หลายเดือนก่อน +1

    Right on time! I am so happy to see a new video!!

  • @planespottermerijn
    @planespottermerijn 8 หลายเดือนก่อน

    Oh I'd absolutely love love love to see you implement textures in this as well. I think that'd make a really nice and complete product

  • @avwie132
    @avwie132 8 หลายเดือนก่อน

    Your visualizations are world class. And it is awesome that you do so many quantitative tests.

  • @nathanpotter1334
    @nathanpotter1334 8 หลายเดือนก่อน +1

    Was just looking for content on this. Cheers

  • @myth0genesis
    @myth0genesis 8 หลายเดือนก่อน

    Wow! You're doing an amazing job at making tough topics accessibly understandable to a wider array of aspiring graphics programmers! I really appreciate what you're doing here.

  • @BudgiePanic
    @BudgiePanic 8 หลายเดือนก่อน

    This is super cool. I spent the last 3 months building my own ray tracer completely from scratch. The visualizations showing what the transform matrix is doing to the rays and the BVH visualization is very cool.

  • @iffyspeak
    @iffyspeak 8 หลายเดือนก่อน

    i have been waiting for this and i already love it. didn't realize it's been a whole year

  • @doishid
    @doishid 8 หลายเดือนก่อน +1

    thank you sebastian, an absolute pleasure to watch

  • @B-2-Z
    @B-2-Z 8 หลายเดือนก่อน

    I literally watched the first part for the first time yesterday just to see you release this part soon after xD
    I really like that style of presentation. I have very limited knowledge in programming, but as Blender user myself I have at least some insight into Shaders by now. However, you make it quite easy to follow along your process and boiling down hundreds of hours of work and into these very digestible steps and easy to grasp visuals must be quite hard. But it's done very well and seemingly effortless. Quite impressive! I especially like the emphasis on errors and mistakes being things to embrace and learn from - that's a really nice touch.
    You mentioned adding glass and I'd be very interested in seeing you tackle that - or maybe volumes. But Importance sampling seems like the next logical step. Whatever it's gonna be, I hope I won't have to wait a whole year for it :D

  • @alexob3643
    @alexob3643 7 หลายเดือนก่อน

    My favourite TH-cam channel, so cool AND educational