Shader Coding: Ray Marching Tips & Tricks

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 91

  • @icaroamorim3123
    @icaroamorim3123 5 років тому +41

    This channel is pure gold.

  • @Podis4
    @Podis4 5 років тому +13

    I truly enjoy your work on Ray-Marching. You have a way of explaining it to where it makes sense. I would love to see how you would map textures to these 3D objects!

  • @antoinedevldn
    @antoinedevldn 4 роки тому +2

    Honestly this is hands down the best tool tip of ray marching that exist online

  • @antoinedevldn
    @antoinedevldn 5 років тому +5

    So I just arrived from work, bought sushi and then BAM go a notif on this :)
    So relaxing and pleasing.

  • @piyushverma7255
    @piyushverma7255 5 років тому +7

    Oh boy! new Art of Code video!

  • @whythosenames
    @whythosenames 5 років тому +4

    Best day when the art of code releases a new video! I think it is so amazing how you can do this with just a few lines of glsl and just the distance to an object :)

  • @nunzioturtulici9636
    @nunzioturtulici9636 Рік тому

    I love your channel and I'm learning a lot. Love your videos, thanks! As regards the issue about the "sinned" plane, I believe the real problem isn't in the ray marching algorithm but it is that the deformation of the plane distance field is not the real distance field of the "sinned" plane (i.e. it doesn't give the true distance from a point to that set). Actually it is really simple to find and to compute, but I think one could find the true distance field of that object and keep the algorithm in its original form, but maybe this function would be a bit messy. Thanks for the video!

  • @Condog64
    @Condog64 5 років тому +1

    Love the channel! I really enjoy the pairing of educational information with a more relaxed style of communication.

  • @prietjepruck
    @prietjepruck Рік тому

    Again a great tutorial. Thanks

  • @donaldviszneki8251
    @donaldviszneki8251 5 років тому

    My favorite video so far!

  • @СергейПавлов-в2е
    @СергейПавлов-в2е 3 роки тому

    Really useful!
    Respect from Russia! 🪆

  • @helo3153
    @helo3153 4 роки тому

    This is so interesting, praise uploader!

  • @etiennep.1593
    @etiennep.1593 5 років тому

    Very helpful stuff ! I already wait your next raymarching tips !

  • @ac12484
    @ac12484 4 роки тому

    Very helpful about the waves! I was gonna do the experiment about this, now I don’t need to :)

    • @ac12484
      @ac12484 4 роки тому

      You could make the minimum for a step for curvy plane to be the distance between camera and top of the waves (if the camera is still above the weights)

  • @darkuser654321
    @darkuser654321 5 років тому

    Top quality work Martijn! Thanks for making this!

  • @Heisenberg2097
    @Heisenberg2097 5 років тому +1

    Great information and great performance. As usual. But another observation I made today is how balanced you talk at different levels of depth regarding different levels of knowledge of different viewers. I had so many math heavy lectures on CG with lecturers that just didn't know or care that computer science is not mathmatics. THUMBS UP!!!

  • @HylianEvil
    @HylianEvil 5 років тому +1

    Thank you so much

  • @danielle-bm1kq
    @danielle-bm1kq 3 роки тому

    Martine... I absolutely adore these videos; thank you so much for making them. Do you plan on making a video to illustrate how to structure the raymarching code such that distinct colors can be assigned to each object?

  • @LordSoulSicarious
    @LordSoulSicarious 3 роки тому +1

    This has been solid gold for getting a better conceptual grasp on some of the techniques I've been experimenting with recently. I'm curious if you have any tips regarding culling and optimisation for larger/more complex scenes.
    Ray Marching's biggest issue is needing to constantly calculate distances to every primitive in the scene, so obviously culling to minimise the number of distance calculations (some of which are quite expensive) would be desirable. However, I haven't yet been able to figure out a solution beyond manually adding/removing objects from the list of items sent to the distance estimator via loading triggers. Have you managed to find a way to implement occlusion/frustrum culling, or perhaps dividing space into cells, similar to collision detection techniques?

  • @SeanaldMcDonald
    @SeanaldMcDonald Рік тому

    Do you have any thoughts on or examples of using SDFs to model clouds? I've made shader that uses a coverage map sdf texture that gives the lateral shapes of the clouds, and I want to be able to create the vertical detail and give it the blobby appearance. I know people usually use 3D noises like perlin-worly for stuff like this, but I for the overall blobby shape, it would be nice to be able to nail it down with SDFs, and only use the 3D noises within a limited distance from the surface.

  • @bejoscha
    @bejoscha 5 років тому +1

    Thanks!

  • @christopher8116
    @christopher8116 4 роки тому +1

    We need a tutorial on Parametric UV`s.

  • @jorge2017a1
    @jorge2017a1 5 років тому

    muy buen video e interesante los tips!!!

  • @superscatboy
    @superscatboy 5 років тому +41

    "This is very ugly. We don't want this."
    You sound just like my parents.

  • @nraynaud
    @nraynaud 2 роки тому

    the "planes" you define are technically half-spaces, hence the working booleans.

  • @crs1py751
    @crs1py751 5 років тому +1

    very useful as always. thanks ;)

  • @CoolJosh3k
    @CoolJosh3k 5 років тому +3

    Can you do wrapping of a 2D texture onto a 3D object, like a sphere or cube?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +5

      Yeah that would definitely be a good topic for a video. I'll start thinking about it!

    • @CoolJosh3k
      @CoolJosh3k 5 років тому +1

      The Art of Code That would be awesome! Having trouble finding good info on it, especially for HLSL/CG.

  • @haythamc6988
    @haythamc6988 5 років тому

    Such a surprise!

  • @realcygnus
    @realcygnus 5 років тому +1

    nice

  • @MS-ph2ol
    @MS-ph2ol 3 роки тому

    Have you ever worked with compute shaders? If so, do you know how ray marching could benefit from GPGPU vs. being stuck on a per pixel loop (fragment shaders)?

  • @BenEllisAkaGru
    @BenEllisAkaGru 3 роки тому

    I notice you get some artifacts around the bottom of the box and on the horizon (when the box overlaps the horizon), it's particularly noticeable if you put the camera near the ground. Why does this happen?

  • @sirflimflam
    @sirflimflam 5 років тому +14

    Be honest with me here. You're actually a wizard, aren't you? You're dressing this all up as if it's merely math, but I'm on to you, sir...

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +20

      Thats right, in middle earth they call me Gandalf the Bald. ;)

  • @carlosdubusm
    @carlosdubusm 4 роки тому +1

    I love your videos. I have a question. What causes the black pixels around the edges of the box? See what I mean here: imgur.com/a/9C2mJyr Is it because of the box distance formula and lighting? I saw that you did ambient occlusion in another video. Maybe that can solve that issue? Thanks!

  • @mr.mirchick7672
    @mr.mirchick7672 2 роки тому

    My friend make 2d Ray marching in Mindustry game. He name is Domovoy or Домовой.

  • @floerwig2194
    @floerwig2194 Рік тому

    Huii, wtf. That video was helpfull

  • @sergeipavlov1117
    @sergeipavlov1117 4 роки тому

    It is f*cking great!

  • @elfurciax
    @elfurciax 3 роки тому

    Great content! i have a question, if i want to implement a raymarching system to trace a set of dots like a mandelbulb how could i do that? i mean in this tutorials you are using some functions to get the boundaries of objects like a sphere or a cube adding some distortions like the rotations. btw thank you very much for your content!

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  3 роки тому

      You would have to use a distance function for the mandelbulb. If you search on shadertoy, I'm sure you can find one.

  • @lazy_rayy
    @lazy_rayy 5 років тому

    That's really great learning way! Many Thanks!
    Is actually it possible to use signed distance field for collision detection between simple polygonal figures? It will be not efficient to send all transform data to the shader. but could it work at all?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +1

      Yeah I think you could use sdf to do collision detection of polygonal meshes. You'd do the sdf calculation in a regular script though, not inside of a shader.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  4 роки тому

      Perhaps you could use a distance-field approximation of a polygonal object and use it to do collisions. I'd have to think about it.

  • @joshuah2234
    @joshuah2234 5 років тому

    So, how does this affect the processing power of the computer; is it more expensive / taxing on the hardware to render these crazy shapes with a shader rather than just modeling them using 3D modeling software? I imagined that it's less taxing because you're not changing the poly count of the cube, just changing how it's rendered. Is this right?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому

      This is actually more expensive than rendering normal 3d mesh objects. It does have the advantage that the shapes are purely procedural so you can do things (like blend shapes) that you couldn't do with mesh objects. I would not recommend this is to make a video game for instance

    • @DB009
      @DB009 4 роки тому

      @@TheArtofCodeIsCool why not for a video game? im planning to use raymarching for a project that renders fractals. however i was thinking I might just use this technique for lighting in certain scenes in other projects nothing too crazy just raytracing is a bit slow for me. I could be wrong but for some reason I cant seem to get samples fast enough to make real use of raytracing and baked lights arent good for me since i want real time movement in the long run . raymarching seems like a good bet

  • @icaroamorim3123
    @icaroamorim3123 5 років тому

    how do I march to a a skybox.
    In other words, how do I make a 2D shader works inside of a cube where i can rotate the camera and each face of the cube I see a different part of the shader

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +1

      That is a very good question and should be the topic of a future video. You would have to match the unity camera with the camera in your shader.

  • @GmZorZ
    @GmZorZ 4 роки тому

    hiya. not sure if this should be done differently in my case but i have tried to apply the sine wave on my own ray tracer and i feel like im stuck, i alter the distance of the intersected object and it seems to affect the shape well enough, however my normals do not make sense (black/possibly inverted at certain areas). would you know a way to get around this?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  4 роки тому

      You have a link?

    • @GmZorZ
      @GmZorZ 3 роки тому

      @@TheArtofCodeIsCool heya! long time, i guess i was looking for a good displacement mapping implementation for path tracing.. is ray marching a good approach at tackling displaced surfaces? using texture UV coords that is

  • @princessakokosowa9880
    @princessakokosowa9880 5 років тому

    hey, I've got a question for you if you don't mind. I'll be kind of long one. AFAIK, ShaderToy is basically a some sort of a rendering engine (WebGL based?) that just lets you frivolously code shaders giving you some of its inputs e.g. time, resolution, and outputs your transformations of these. if so, would this actually mean that I'm able to reuse the shader code everywhere I want to unless the render doesn't support it?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому

      Yeah pretty much. Check my video on how to convert from ShaderToy to Unity for instance.

    • @princessakokosowa9880
      @princessakokosowa9880 5 років тому

      ​@@TheArtofCodeIsCool tks, I'll take a look at it.

  • @ThylineTheGay
    @ThylineTheGay 3 роки тому

    if raymarching is so good, why is it not more popular?

    • @WXKFA
      @WXKFA 3 роки тому

      Ray marching is just a lighter version of ray tracing but it's still too expensive to spam it. The test is done for each fragment, or for every pixel, on your screen. Games use ray marching for shader effects that produce visual effects that justify the costs, e.g screen space reflections.

    • @ThylineTheGay
      @ThylineTheGay 3 роки тому

      @@WXKFA still, why don't games and rendering engines use it instead of raytracing? it seems a lot faster

    • @WXKFA
      @WXKFA 3 роки тому

      @@ThylineTheGay In certain situations it is slower. If you march along the surface or march in a hole without actually hitting anything your stepsize would be very small or your result inaccurate. Regardless, ray marching is used in games and it does replace ray tracing in some cases but due to its flaws you can't replace ray tracing with it.

    • @ThylineTheGay
      @ThylineTheGay 3 роки тому

      @@WXKFA hmm ok

  • @tommai78101
    @tommai78101 5 років тому

    Hello, you didn't mention how to decrease the raymarching steps as it oversteps away from the surface of the plane. How should you decrease the raymarching steps per iteration when calculating the step radius from where you are in the step to the closest plane distance?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому

      I havent really looked into that but off the top of my head its just adding a value to the SURF_DIST based on the distance you have marched from the origin. So something like
      if(dS

    • @tommai78101
      @tommai78101 5 років тому

      @@TheArtofCodeIsCool Thanks for the information. Understood what to do now. Hope to see you continue with new videos for this channel.

  • @philbateman1989
    @philbateman1989 4 роки тому

    I still don't follow what makes the 3D shape inside the object. I get the concept of ray marching as you explained, but where does the 3D shape come from??

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  4 роки тому

      From the distance function of that shape. I did a video explaining these: ray marching simple shapes.

  • @minecraftermad
    @minecraftermad 4 роки тому

    i was wondering how i could get the 2 spheres to mold into eachother like clay? i have a test project on p5.js with basically your shade code in it (assets/shader.frag)
    editor.p5js.org/jklw10/sketches/U9WYDv28w

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  4 роки тому

      You can use a smooth min function instead of a normal min function. I did a video on smooth min, check it out!

  • @DB009
    @DB009 4 роки тому

    wow that "fudgy" trick you showed to fix marching size artifacts for the wavy planes fixed a bug I had in a seperate raymarcher I made form a tutorial i found via google tutorial! imgur.com/BMusdWO (this is it fixed) . cant thank you enough for this series man. im converting the shader toy raymarcher into unity

  • @viveks9048
    @viveks9048 5 років тому +1

    Thanks for this video
    I can see this shader is using raymarching(because of the variable ro),
    but I don't understand anything else. can you clarify how they are getting the clouds?
    www.shadertoy.com/view/3l23Rh

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому +1

      That's a whole topic on its own. I'm sure I'll do a video about it at some point!

    • @viveks9048
      @viveks9048 5 років тому +1

      @@TheArtofCodeIsCool awesome, looking out for that tutorial

  • @westparezal
    @westparezal 3 роки тому

    Obviously he is Alien. Can`t find another explain about his skills)

  • @raconvid6521
    @raconvid6521 4 роки тому

    How to fix all raymarching bugs
    1. Ray tracing.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  4 роки тому

      hmm not sure about that one. Also, there are many thing you can do with ray marching that you can't with ray tracing.

  • @programaths
    @programaths 5 років тому

    The big question: who down-voted this ?!

    • @4.0.4
      @4.0.4 5 років тому +1

      Curious, I see no downvotes yet. But I believe bots produce random downvotes (also upvotes) to mimic organic traffic. Maybe whichever bot you saw the downvote of got banned.

    • @programaths
      @programaths 5 років тому

      @@4.0.4 Nice try, but good you removed your down-vote :-D :-D :-D

  • @LarsHHoog
    @LarsHHoog 5 років тому +1

    Please, please do not have background music. It makes it very hard to hear what you say. Also, that humming sound. Ouch

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому

      Sound is admittedly my weak point. I don't really hear a humming sound though?

    • @TheNewton
      @TheNewton 5 років тому

      @@TheArtofCodeIsCool for most video editors or audio tools look for "ducking" , it lowers the music when you speak.

    • @LarsHHoog
      @LarsHHoog 5 років тому

      @@TheArtofCodeIsCool There is music the first 80 seconds and then a 120 Hz constant tone. Later 190 Hz and 300 Hz are also there.
      If you bring your audio track into Audacity or Adobe Audition and look at the frequency view. manual.audacityteam.org/man/spectrogram_view.html

  • @telotawa
    @telotawa 5 років тому

    maybe actually use a real distance measurement instead of the shitty one there?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 років тому

      You mean for the sine height field? I guess you could, be my guest :)