Ray Marching Simple Shapes

preview_player
Показать описание
Twitter: @The_ArtOfCode

Live version:

In this video I'll go over the distance functions to several primitive shapes: sphere, capsule, torus, box and capped cylinder.
These shapes form the building blocks of just about any complicated shape you want to make so it is good to understand how these functions work.

If you just want to copy past a bunch of distance functions, you can find an exhaustive list of them, along with function to manipulate them here:
Рекомендации по теме
Комментарии
Автор

This content is amazing! It's crazy that you're publishing videos this good with such a small following. You're going to blow up really soon I can feel it.

Vincent-kljy
Автор

Just going to echo the sentiment of everyone else here. The first ray marching video was very clear, well organized, and easy to follow. It's worthy of a Patreon subscription.

JosephCatrambone
Автор

I really appreciate you putting in this much effort into these videos

_jonas
Автор

Martin, it is perfect! You is my window to shadertoy!

СергейПавлов-ве
Автор

Super nice just as last time. I've started creating shaders and I'm having a lot a fun. Thanks a lot.

grodzillaaa
Автор

As someone just getting into ray marching and SDF's, your videos are amazing. Thank-you for making them!

Firettruck
Автор

These tutorials are great! Your explanations are thorough and well paced. One minor nit I will pick though is you tend to use single letter variables or abbreviations a lot. It might be a low level language thing or a mathematical background, I don't know. Its not so bad watching the video, but if I go to the live demo it becomes much less readable. Please consider naming variables with readable names.

pmcquay
Автор

i dont know if the raymarching is too easy or you are great at explaining

sayochikun
Автор

Thank you so much for helping me better understand the black magic that is shader programming.

Turmolt
Автор

Never thought a programmer could look so badass

targashsensei
Автор

Thanks A LOT for sharing your great knowledge with us!

AntonioLatronicoDeveloper
Автор

Great tutorial! I hope you can do some more ray marching tutorials, like ray marching heightfields and voxels

peterlous
Автор

Thanks kindly man! It's one of those things where it all makes sense in 2d, start delving into sphere line intersect from circle line intersect... Ok, maybe ray marching is easier to start out with than ray tracing, haha.
Just needed to take that step back and get that overview to get through!
All such simple math to do beautiful things!
Thanks for putting these ray marching vids together!!

TrancorWD
Автор

Ray marching is one of these things that was hard to come up with because it is too simple to believe.

ArnaudMEURET
Автор

Great videos! I really like your videos and the way you explain. Thank you! I guess one could just define the distance functions for points, segments and circles to get (as a level surface i.e. subtracting some d_0) the distance functions for spheres, capsules and thori. Moreover maybe one could construct the cylinder by means of the distance from a line and the distance from two halfspaces (i.e. "planes").

nunzioturtulici
Автор

Very informative, thanks a lot for making these great tutorials.

simplerrrr
Автор

Very useful tutorial! Great graphic explanation! Thank you!

ismaelmagana
Автор

Splendid Tutorial as always!
But just some notes: (I guess theartofcode is aware of all this, but maybe for the learners)
1) All those calculations can be made a lot shorter, for example the cylinder:
#define Cyl(p, r, l) max(length(p.xz)-r, abs(p.y)-l)
This is a Macro, where p is our current point in space, r is the radius and l the length.
As a Function it would be this:
float Cylinder(float3 p, float r, float l)
{
return max(length(p.xz)-r, abs(p.y)-l);
}
2) The Cube shown in this video does not have calculations for the interior! It´s unsigned!
#define Cube(p, s) max(max(abs(p.x)-s.x, abs(p.y)-s.y), abs(p.z)-s.z)
This one is signed, feed it with p=position (xyz) and s=size (xyz); for the interior it will give negative values.

But it´s good you show the math we derived these short versions from, even me learned 1-2 bits!
Thanx, keep on rocking!

hardyTRSI
Автор

Very nice! You should do a tutorial on KIFS next!

gijsb
Автор

For capsule I think there is a simpler method:

proj_length = dot( normalize(ab), ap);
proj_length = clamp(proj_length, 0, length(ab) );
c = a + normalize(ab) * proj_length;

For torus I came up with other method but it's not as clever as from the video:
C = O + normalize( OP * (1, 0, 1) ) * Ri;
d = length(P-C) - Ro;

For cylinder I came up with simpler method too but it's nice to learn more.
float sd_cylinder(vec3 p, vec2 size) {
float y = max(0., abs(p.y)-size.y);
float xz = max( length(p.xz) - size.x, 0.);
return length( vec2(xz, y) );
}


Btw what do you get when you dot product two vectors of non-zero length ( `dot(ap, ab)` )?
Is it kind of like projection of one into another but multiplied by one's length?

andrey