Тёмный

Ray Marching, and making 3D Worlds with Math 

SimonDev
Подписаться 185 тыс.
Просмотров 237 тыс.
50% 1

Built this entire video on raymarching in shaders using shaders, ray marching, and signed distance functions.
🛒 Recommended books (on Amazon): www.amazon.com/hz/wishlist/ls...
❤️ Support me on Patreon: / simondevyt
🌍 My Gamedev Courses: simondev.teachable.com/
Disclaimer: Commission is earned from qualifying purchases on Amazon links.
Follow me on:
Twitter: / iced_coffee_dev
Instagram: / beer_and_code
In this video, I cover ray marching and some of the cool stuff you can do with it in shaders. We cover basic scene construction, unions/intersections/subtractions, doing smooth minimums, normal generation and soft shadows, and anything else that seems kinda neat about the technique.
Ray Marching: en.wikipedia.org/wiki/Ray_mar...
Great Resource for Ray Marching and SDF's: iquilezles.org/
Smooth Maximum: en.wikipedia.org/wiki/Smooth_...

Наука

Опубликовано:

 

28 авг 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 350   
@simondev758
@simondev758 Месяц назад
Patrons can now vote for the next video! Thank you for your support. ❤ Support me on Patreon: www.patreon.com/simondevyt 🌍 Live Demo + Courses: simondev.io
@stickguy9109
@stickguy9109 Год назад
For the first time I understood what this magic "ray marching" is and how it works. You are good at explaining things
@johanngambolputty5351
@johanngambolputty5351 Год назад
Even if I ever understood before, this might be the time it actually sticks :) for some reason I always mixed it up with tracing, or maybe something to do with section searches
@dutchdykefinger
@dutchdykefinger Год назад
​@@johanngambolputty5351 well technically you're still tracing rays, right? certainly it's ray casting, the term they used in 3d games back in the 90s to collision check your projectile trajectories and the such, which is just 1 ray. [ray tracing] is a routine that casts a ray for every angle your "caster" can "see". in 3d rendering often a camera, so the camera settings dictate the position and the angles the caster limits itself to, the pixels it traces are projected into angles depending on FOV/perspective values from the camera, they ARE the set/array of angles to process basically. it's still raycasting too, raycasting a lot in fact, raycasting is still the integral part that does the work. (a 1080p image is about 2 million pixels, so ~2 million rays if just 1 ray for every pixel, modern path tracing do many many more per pixel) there's also bounces for light ofcourse and the such, but for the sake of simplicity let's keep it at 1 bounce. [path tracing] is a more complex raytracing that can also do reverse tracing for caustics and the such, has way more rays for more modern PBR rendering methods, z distance information feedback for post processing and the such, essentially raytracing on crack. [ray marching] i consider it to be a variant/derivate of ray tracing, i'm not sure how disputed that is, but i'd put it under that moniker. but it is smart/dynamic, rather than checking everything, it makes bigger jumps, and you can reduce the amount of cycles by a great deal just working with minimum lenghts set on a higher value , but very small object intersections aren't "seen" because the ray jumps over them, this disadvantage is exploited as an advantage in the demos in this video by interpolating and blending the missing parts together the "looking over it" principle is also used in metaballs, but metaballs calculate a lot of shit on the way, this method actually drops data and fills in the gaps, it has a bit less control, but you could put extra data in vectors and use those with proximity for all kinds of effects too i don't think the vector lengths (jump distances) strictly have to be dynamic for it to be ray marching, they could be static and just have it jump the same distance every time as a crude version until it hits something it's not ray marching if you only shoot 1 ray either, so it's just grid-snapped ray casting strictly taken, but the distributed is implied although there may be differentiation in terminology these days perhaps, but that was also understood as ray marching back in the day ray marching is a de facto collision detection algorithm, as is ray tracing, because they're all raycasting and the rays are looking for something to bounce on, that precisely is what collision detection is, finding an intersection. as with many code, raymarching differs a lot between CPU based (serial functional programming) and GPU based (parallel logical programming), they need a quite different approach. the crude version of ray marching basically is raytracing, but the ray casting it does, is snapped to a grid with the grid's rotation relative to the individual ray's angle so it always traces over a striaght line (which is exactly what "local coordinates" are) short story long: i consider raymarching a variant of raytracing, i'd define them as: "distributed raycasting algorithms" when in doubt, use the term ray casting, that's the underlying principle for all of them, including ray casting itself obviously, so you can never be wrong then ;) even simple pixel-based detection is essentially just crude ray casting with the vectors being snapped to integer values, using global coordinates, and dropping all the benefits of unit vectors, when you think about it, right? lol i just had an epiphany, never even thought of it about like that myself even.
@johanngambolputty5351
@johanngambolputty5351 Год назад
@@dutchdykefinger True, its a clever sort of tracing that you can do if you use distance fields instead of polygons, especially since the step size is not just dynamic but optimal (largest while guaranteed not to hit anything). I'm not familiar with this stuff, so I just imagined constant step sizes for tracing (against polygon primitives)... though I'm sure it can get way more clever
@Chribit
@Chribit Год назад
I‘ve actually been working on a graphics engine using signed distance fields as primitives instead of triangles for ~2 years now - super hyped to see it become more and more mainstream recently :D
@keyb
@keyb Год назад
Ooooh sounds cool! Do you have any demos or code bases you can share?
@Chribit
@Chribit Год назад
@@keyb not yet unfortunately. The first year was mainly reading papers, understanding the heaps of theory and finding a sensible way of actually making it performant. There are bunch of challenges i wanted / had to solve first: - how do i make dynamic scenes with SDFs instead of scenes hardcoded into a shader? - how do i avoid as many branches as possible? - how do i completely avoid the default render pipeline? - how would instancing work? - how can i drastically improve performance? - etc. And the second year was mostly occupied by learning vulkan tbh. But i‘ve been making some major strides recently and i‘m hoping to finish a 2D version before end of the year. That will allow me to make some tools to drastically accelerate my dev process and it will all snowball from there. End-goal is a full 3d engine for real time rendering :D I can bookmark this video and let you know in this thread when something showable is abailable if you want? :)
@simondev758
@simondev758 Год назад
Super cool! Got a demo I can watch of it in action?
@Chribit
@Chribit Год назад
@@simondev758 not yet unfortunately :D See comment above yours hahaha I‘d be happy to send you a demo as soon as something showable is ready, hopefully near the end of this year :)
@keyb
@keyb Год назад
​@@Chribit Yes please! It sounds like a ton of work (especially in the sense of optimizations) so you still probably have a while to go. Whenever you do get a working model please let me know!
@BalintCsala
@BalintCsala Год назад
Great video, but small correction on a common misconception: Ray marching is just doing raytracing but numerically (so instead of having an equation tell you how far you need to go, you just go in small steps and check if you are inside a shape at any point), it doesn't necessarily involve SDFs (e.g. screenspace reflections also use raymarching, but not SDFs). The special name for this is sphere tracing.
@stdcall
@stdcall Год назад
yeah, the naive ray marching function steps a point towards the target and returns when it ends up inside an entity/object
@diodin8587
@diodin8587 6 месяцев назад
Do you mean sphere tracing is just ray marching with SDFs?
@BalintCsala
@BalintCsala 6 месяцев назад
​@@diodin8587basically, if you open up the wikipedia page of ray marching there's a section on it.
@cucumberedpickle
@cucumberedpickle Год назад
I've seen a lot of videos about raymarching before, but this is the first time I've "gotten it". The graphics you used to explain it make so much sense.
@magnusm4
@magnusm4 Год назад
I remember this blend mechanic being used in a Valve tech demo from around 2003 where they made blobs able to combine and melt together like here. Later used years later for Portal 2. Insane they came up with this already back then.
@TheJeremyKentBGross
@TheJeremyKentBGross 2 месяца назад
I believe they used a 2D version for text on signs in Team Fortress 2. I vaguely recall reading about it back in the 2ks.
@guaje
@guaje Год назад
It's great to see more content like this. Loved your explanation of the central differences method.
@uquantum
@uquantum 9 месяцев назад
Wonderful Simon, came here from another one of your shader vids, mind-blown that you made the actual video using ray-marching, now picking jaw up from table
@gtnbssn
@gtnbssn Год назад
I have started the glsl course a couple weeks back and am learning so much! Thank you!!
@simondev758
@simondev758 Год назад
Awesome!
@cl10k
@cl10k Год назад
Your vids are so incredibly good! I always get excited when a new one comes out. Pure gold!
@RobinPayot
@RobinPayot Год назад
Amazing video, well done on the explanations! The 3D scene really helps to understand, maybe explaining a bit more the code part would be even better
@simondev758
@simondev758 Год назад
Yeah, I think if I were to redo it, I'd add some animations around computing things like the normal/shadows in the same way that I did for the raymarching. Next time!
@Shamysoza92
@Shamysoza92 Год назад
Now THIS is how you sell a course. Great content!
@aquanton
@aquanton Год назад
this was the single coolest video I've seen on RU-vid for a while
@Luka116_
@Luka116_ Год назад
I love your editing & teaching style! Thank you for making such informative and fun content for free ^_^
@younghsiang2509
@younghsiang2509 Год назад
This is really a cool video, the way objects transition between frames are just amazing! Wondering how that could be made.
@awesomecronk7183
@awesomecronk7183 Год назад
I like the explanation! I'm working on my own ray marching based graphics engine right now and, while your demo here is far more polished, I'm getting places.
@DickLarsson
@DickLarsson Год назад
Simon. I totally love the stuff you teach us. LEGEND! 💙
@williamjuicebutter6648
@williamjuicebutter6648 Год назад
This is the best content on youtube! Thank you!
@Matkins85
@Matkins85 Год назад
Nice video! I love playing with SDFs too. One point I think is worth mentioning, which I'm sure you understand but perhaps some viewers won't. It's a misconception that using modulo to repeat the space, and get seemingly infinite copies of your SDF, is for free. From a performance point of view its far from free. It's because then more rays are getting slowed down, and more frequently so, by passing near to surfaces. It is a neat trick though, and if your SDF is fast anyway then its not an issue.
@simondev758
@simondev758 Год назад
Agreed, the performance cost is definitely real. I was mostly thinking in terms of implementation cost for a lot of these effects, but yeah the ray marching loop can't early out as easily.
@simoniacdemoniac7525
@simoniacdemoniac7525 5 месяцев назад
I purchased your course. You really explain things well!
@nordie92
@nordie92 Год назад
Nice stuff, nice explanation, nice voice. Love it
@tomg0
@tomg0 Год назад
An awesome, well-made video. Love it
@icimojojojo
@icimojojojo Год назад
That's an amazing video Simon, thanks a lot for sharing your knowledges with us !
@lordlightspeed
@lordlightspeed 2 месяца назад
for smoothmin(a, b, k), using smoothmax(a, b, -k) also works and is possibly slightly easier to write in code.
@ArtisanAspirationWorks
@ArtisanAspirationWorks Год назад
I was really envisioning this for an attack in my 3d plaforming game as an obstacle. Thx
@Madlion
@Madlion Год назад
This is quite cool, ive added these in Unreal engine and u can even blend with the mesh generated SDF
@BobsiTutorial
@BobsiTutorial Год назад
Really great video! Might implement this into my devlog game somehow 🙂 Great explaining and awesome video and visuals.
@simondev758
@simondev758 Год назад
Let me know if you do!
@filipathtc
@filipathtc Год назад
This is a really good explanation!
@andermium
@andermium Год назад
I love my recommended, what an amazing video! I feel like there's a good chance this would work well with Geometric Algebra, but I don't know enough of either subjects to really say something about it.
@akfamili279
@akfamili279 Год назад
I'm your old fan, thanks for updating the program so honestly! You are a hero to me! Yoom view bot king! Definitely the best in the business
@SuboptimalEng
@SuboptimalEng Год назад
This is awesome! The first thing I’m gonna do (once I get a job) is buy your shader course!
@nikbivation
@nikbivation Год назад
wow very good explanation, made it easy!!
@ngoc-64mtcothi53
@ngoc-64mtcothi53 Год назад
Don't give up mate, that was my first day to use soft soft and i will work on it for a long ti!
@ShiroiAkumaSama
@ShiroiAkumaSama Год назад
I won't ever try to write actual code, yet this video was still very interesting and understandable and it might teach me what I can use smooth min and max for in Blender.
@nutzeeer
@nutzeeer Год назад
This is really cool! A lot can be imagined with math
@Rennu_the_linux_guy
@Rennu_the_linux_guy Год назад
CodeParade's marble marcher uses ray marching, if you haven't heard of it, it's really cool, you roll a marble along a fractal which is sometimes morphing around in real time
@Rene-uz3eb
@Rene-uz3eb Год назад
Great video, thanks. Made me realize that I need a distance function
@VoidloniXaarii
@VoidloniXaarii Год назад
Wow this was so interesting! You also mentioned csg ❤
@mayank9rana
@mayank9rana Год назад
fire video, thanks bro
@alirezaakhavi9943
@alirezaakhavi9943 11 месяцев назад
really amazing informative technical and beautiful tutorial thank you very much enjoyed it alot! subbed :)
@AuroraLex
@AuroraLex Год назад
In VRChat there is a famous world called Treehouse in the shade, that uses ray marching. Its really beautiful!
@idrogomate1507
@idrogomate1507 Год назад
Yoo tnx dude, everytNice tutorialng works. I LIKE IT
@rafaelsantiagoaltoe6606
@rafaelsantiagoaltoe6606 Год назад
phew. That is a cool thing, I will have a deeper look later. Thanks
@UrodCyka
@UrodCyka 11 месяцев назад
Spore-like games would benefit heavily with ray marching, its always something ive thought about. you could build a cell and have the individual cell parts combine using ray marching or make cellular animations of two spheres dividing or even have creature parts be put together using ray marching. Ray marching gives endless opportunities
@Mcbuzzerr
@Mcbuzzerr Год назад
As soon as we went 3D everything started going over my head 😅 Fun visuals tho :)
@TruthAndLoyalty
@TruthAndLoyalty Год назад
You can't help but love listening to Bob from Bob's Burgers explain programming concepts.
@Skeffles
@Skeffles Год назад
Fascinating, especially when the shapes merge into each other.
@NowKnownMAWO
@NowKnownMAWO Год назад
Very nice video! I would like to use this technic in a game!
@mexicanmax227
@mexicanmax227 Год назад
I love you Simon. You’ve turned me into a smartass. Thank you 😃
@simondev758
@simondev758 Год назад
Hah
@kilroy987
@kilroy987 Год назад
When I look at a subject crooked with a thinking face, I know I've learned something.
@yharry2188
@yharry2188 Год назад
Thank you so much, I’m learning tNice tutorials in quarantine and you made it very simple I really appreciate it, thank you for going over every little
@Joao-uj9km
@Joao-uj9km Год назад
Wow! Thanks for the video :)
@ScryGL
@ScryGL Год назад
Wonderful! I know how to do lighting/reflections/combining geometry but I think my code quality could use help for putting together larger more complex scenes. I'll take a look at your course :)
@alireza4734
@alireza4734 3 месяца назад
Every single sentence is worth writing down on the notebook. Thanks
@thyongamer
@thyongamer 6 месяцев назад
This is the rendering engine for PS4/5 Dreams. It’s amazing.
@0AnimeAddicts
@0AnimeAddicts Год назад
I love soft soft so so so so much!
@arashvahabpour942
@arashvahabpour942 8 месяцев назад
Such a neat video!
@rewatbeat
@rewatbeat Год назад
because in the intro for example I want to make an acoustic soft, but later I want to make a distortion or any other effects in that sa
@qualle987123
@qualle987123 Месяц назад
Very cool video. I would have love to have it a bit longer and more in depth though.
@codytyson8460
@codytyson8460 Год назад
The videos only get better
@hanneshinrichs
@hanneshinrichs Год назад
Basically this is what "Dreams" for the PS4/PS5 is made of
@Slayergg.
@Slayergg. Год назад
TNice tutorialS IS WHAT I NEEDED BRO, thank you for taking the ti and doing tNice tutorials for most of that are starting with tNice tutorials beautiful tNice tutorialng called
@AntonioCorrenti
@AntonioCorrenti Год назад
Amazing stuff! Now I'm curious about how SDFGI works!
@simondev758
@simondev758 Год назад
Me too!
@AntonioCorrenti
@AntonioCorrenti Год назад
@@simondev758 just found this ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ARlbxXxB1UQ.html
@autbo
@autbo Год назад
The game called "Dreams" on the PS4 works exactly like this, except it has a "flake" effect to the surface to give it a painterly look.
@zxuiji
@zxuiji Год назад
3:07, That wire frame cube is your clue to doing super cheap 2d ray tracing on 3d environments, and you only need to do it on 1 side, the rest just need that one side's ray positions to be multiplied against either 1 or -1
@BarcelonaMove
@BarcelonaMove Год назад
Mindblown again
@DemsW
@DemsW Год назад
Great video and explanations/visuals, makes me want to mess around with it. Would be nice to talk about the limitations and why it's not as popular as the usual rendering techniques Maybe a game like portal that does weird things with visuals could benefit from this.
@simondev758
@simondev758 Год назад
Dreams on PS4/PS5 uses this technique extensively.
@sinantk4036
@sinantk4036 Год назад
you record with hardware outside of the program. Great tutorial btw it was very detailed but still just right for beginners.
@escher4401
@escher4401 Год назад
This should be at the #SoME2
@kalpolproductions8558
@kalpolproductions8558 6 месяцев назад
Best video ive seen today. yosh
@sjoerdhogervorst5857
@sjoerdhogervorst5857 Год назад
using soft, can't wait to get my hands on it.
@PamirTea
@PamirTea Год назад
Mindblowing 😍
@boogeyman8099
@boogeyman8099 Год назад
I would love to see an interactive VR experience that delves into ray matching.
@KillFrenzy96
@KillFrenzy96 Год назад
There's worlds in VRChat featuring Raymarching shaders that you can experience in VR. It's quite fascinating. One of the worlds was called "Treehouse In The Shade".
@boogeyman8099
@boogeyman8099 Год назад
@@KillFrenzy96 thank you so much!
@emrelermi1399
@emrelermi1399 Год назад
Muito bom, vou atualizar. Very good. I will update.
@theSlavenIvanov
@theSlavenIvanov Год назад
Great Stuff!
@mySDK3333
@mySDK3333 Год назад
There's a software called MagicaCSG that's so easy and intuitive to use to make 3D models.
@ReBufff
@ReBufff Год назад
"Until next time, cheers"
@Jellyjam14blas
@Jellyjam14blas Год назад
Awesome! :D
@user-xy4bs1nm3k
@user-xy4bs1nm3k Год назад
god damn it that is cool - lemme watch it 20 more times so I can understand it lol
@Scratchydoesmusic
@Scratchydoesmusic 7 месяцев назад
oh yeah i heard codeparade talking about this in his marble marcher videos
@vampirejs758
@vampirejs758 Год назад
Question: Can the minecraft clone you made be remade completely in glsl? Like the terrain generatjon and stuff
@simondev758
@simondev758 Год назад
I think it could, but that'd be a major challenge. Maybe for a day when I'm super bored heh
@TunaFunDev
@TunaFunDev Месяц назад
Its all great but it wouldnt be imposible to have collision working on these shapes right?
@haruruben
@haruruben 7 месяцев назад
Subscribed!!
@freakfreak786
@freakfreak786 Год назад
Great video and explaination. I got a question tho: Did you hear about webGPU? Are you planing on learning/using it?
@simondev758
@simondev758 Год назад
Definitely planning on playing with it
@mehradghast775
@mehradghast775 Год назад
omg that how I feel!
@jensBendig
@jensBendig Год назад
I feel intrigued to code a ray-Marcher…!
@EpicVoiceShitposting
@EpicVoiceShitposting Год назад
..you had me on radius
@trannguyenanan5067
@trannguyenanan5067 Год назад
and I will find my way back there too!
@nyghl
@nyghl Год назад
Hi Simon! I love your videos, the topics, the way you explain things, the graphics and the general flow of the video as well. The only thing I can recommend is a great microphone or improved sound quality for your voice! With all those high quality things in your videos, imo the sound quality is the only thing that is distracting at the moment. Much loves and please keep what you are doing
@simondev758
@simondev758 Год назад
Thanks, I think I need to find a better recording location too heh
@nyghl
@nyghl Год назад
@@simondev758 Yeah, that could work as well 😅
@adibhanna
@adibhanna Год назад
this is amazing! how do you do all these sick animations?
@simondev758
@simondev758 Год назад
All done in shader, pretty much everything you see is based on what I explain in this video and the next (lerp).
@PotatoTheProgrammer
@PotatoTheProgrammer 22 дня назад
if i had a game that uses only primitive shapes with basic png textures, would ray marching be faster than regular triangle rendering? also is giving ray marched objects textures even possible? also is transparency possible?
@brennonwilliams9181
@brennonwilliams9181 Год назад
Watched it twice. Need a lay down and a cup of tea now. Simon, are these transitions, intersections, adds, subs being performed purely in the shader?
@simondev758
@simondev758 Год назад
100% done in shaders yes
@AntonioNoack
@AntonioNoack Год назад
yes, they are. Inigo Quilez has excellent tutorials about it. You can see hundreds, if not thousands of samples of SDFs on ShaderToy. The platform was created by him partially as well.
@brennonwilliams9181
@brennonwilliams9181 Год назад
@@simondev758 think you just sold me on the course. Awesome.
@brennonwilliams9181
@brennonwilliams9181 Год назад
@@AntonioNoack thanks! I will check it out
@simonhatch4628
@simonhatch4628 Год назад
@@brennonwilliams9181 Heh awesome. And yes, definitely check out Inigo's site, it's in the description, amazing resource for ray marching & sdf's.
@ThachDo
@ThachDo Год назад
Thanks for the intuitive video. May I know how to determine the necessary number of points to render a distance field of a scene?
@simondev758
@simondev758 Год назад
Most implementations set a max # of iterations, usually about 100 or so get's you a good result, a lot less depending on the scene.
@ThachDo
@ThachDo Год назад
@@simondev758 at each point/iteration, we have a different set of scanning angles around the point, right? So how about the scanning resolution per sample point usually?
@rcjinAZ
@rcjinAZ Год назад
Very clever.
@amireasy6419
@amireasy6419 24 дня назад
Are the rays send by the pixels on the screen or its just a virtuell ray that it sends
@WistrelChianti
@WistrelChianti Год назад
I think my brain fell over half way on this one
@preludelight
@preludelight Год назад
Hey Simon, fantastic explanations and excellent visuals to go along with! You mentioned at the end that the code is up on your github, but I wasn't able to find it. Am I looking in the wrong spot? Cheers!
@simondev758
@simondev758 Год назад
I probably forgot to upload it, lemme go find the code and do that.
@weisbrja
@weisbrja Год назад
@@simondev758Not to come off as rude, but did you upload it yet? I also couldn't find it and I'd be super interested...
@preludelight
@preludelight Год назад
@@simondev758 Just casually dropping by to remind you to upload this code. Cheers :)
@Asdayasman
@Asdayasman Год назад
What's the SDF of that chrome window at the end?
@JavaScripting64
@JavaScripting64 Год назад
Nice!
@Andrew90046zero
@Andrew90046zero Год назад
Was the raymarching being computed in vertex/frag shaders? Or did you use compute shaders? Or some other part of the GPU?
@simondev758
@simondev758 Год назад
These were done in the fragment shaders.
Далее
How Big Budget AAA Games Render Clouds
10:45
Просмотров 256 тыс.
The ONE Texture Every Game NEEDS
9:00
Просмотров 247 тыс.
An introduction to Raymarching
34:03
Просмотров 115 тыс.
Signed Distance Functions & Ray-Marching
24:14
Просмотров 26 тыс.
Ray Tracing: How NVIDIA Solved the Impossible!
16:11
Просмотров 787 тыс.
I Tried Making an FPS Game in JavaScript
8:19
Просмотров 124 тыс.
Coding Adventure: Ray Marching
5:06
Просмотров 1 млн
How to Make 3D Fractals
7:48
Просмотров 1,6 млн
How do Major Video Games Render Grass?
9:33
Просмотров 367 тыс.
I Made A Blob Shooting Game With Ray Marching
13:33
Просмотров 35 тыс.
Giving Personality to Procedural Animations using Math
15:30
Странный чехол из Technodeus ⚡️
0:44
POPVIBE V5000 Ghost inhale check ✅
0:13
Просмотров 107 тыс.