GENERAL > Projects

Raymarching Beginners' Thread

(1/7) > >>

rbz:


Here a project page for everyone to start learning raymarching with distance fields or also called sphere tracing.

This thread is inspired on pouet page with same name, where beginners already made great progress.

Well, I'm also a beginner on this subject but I was managed to understand it's principle reading a great article by @lx:
http://code4k.blogspot.com/2009/10/potatro-and-raymarching-story-of.html#more

So, I've made an example using RenderMonkey 1.82 that use opengl and directx for you to start, it's a colorful rotated cube :).

Also there's an exe with my current progress.

Our function tool box (all code came from pouet):

--- Code: ---float3 RotateXAxis(float3 p, float angle)
{
    return float3(p.x, p.y * cos(angle) + p.z * sin(angle), p.z * cos(angle) - p.y * sin(angle));
}

float3 RotateYAxis(float3 p, float angle)
{
    return float3(p.x * cos(angle) + p.z * sin(angle), p.y, p.z * cos(angle) - p.x * sin(angle));
}

float3 RotateZAxis(float3 p, float angle)
{
    return float3(p.x * cos(angle) + p.y * sin(angle), p.y * cos(angle) - p.x * sin(angle), p.z);
}

float capsule(float3 p, float r, float c) {
   return lerp(length(p.xz)-r, length(float3(p.x,abs(p.y)-c,p.z))-r, step(c,abs(p.y)));
}

float plane(float3 p)
{
   return abs(p.y);
}

float sphere(float3 p, float r)
{
   return length(p) - r;
}

float cube(float3 p, float r)
{
   return max(max(abs(p.x) - r, abs(p.y) - r), abs(p.z) - r);
}

//distance to a rounded cube:
float distToCBox( float3 p, float3 box, float rad )
{
   return length( max( abs(p) - box + float3(rad,rad,rad), 0.0 ) ) - rad;
}

float3 GetNormal(float3 p)
{
   float eps = 0.1f;

   return
      normalize(
         float3(
            distance(p + float3(eps, 0, 0)) - distance(p - float3(eps, 0, 0)),
            distance(p + float3(0, eps, 0)) - distance(p - float3(0, eps, 0)),
            distance(p + float3(0, 0, eps)) - distance(p - float3(0, 0, eps))));
}

//negative d -> sss, positive d -> ao
float ao(vec3 p, vec3 n, float d, float i) {
   float o,s=sign(d);
   for (o=s*.5+.5;i>0.;i--) {
      o-=(i*d-f(p+n*i*d*s))/exp2(i);
   }
   return o;
}

// p pos, l direction to light - normalized, d stepwidth, i number of steps
float shadow(vec3 p, vec3 l, float d, float i) {
   float o;
   for (o = 0.; i > 0.; i--) {
      o += f(p+l*i*d);
   }
   return clamp(o, 0.0, 1.0);
}

float perlin(vec3 p) {
vec3 i = floor(p);
vec4 a = dot(i, vec3(1., 57., 21.)) + vec4(0., 57., 21., 78.);
vec3 f = cos((p-i)*acos(-1.))*(-.5)+.5;
a = mix(sin(cos(a)*a),sin(cos(1.+a)*(1.+a)), f.x);
a.xy = mix(a.xz, a.yw, f.y);
return mix(a.x, a.y, f.z);
}


--- End code ---


Choose your preferred api (dx9 or ogl) and start raymarching!

Shockwave:
That looks great, the twister looks like it's made out of plastacine. :)

I've been reading the Pouet thread a bit, it would be cool if some other people here got interested in this.

efecto:
Interesting stuff and I've been trying meself, but somehow I'm limited to planes, spheres and cylinders.
Cubes just don't work :(
Probably something in the calling code before the shader.

It's on my todo list but first concentrate on destruction entry

Xetick:
The pouet thread(s) are a wealth of information when it comes to raymarching.

For the ones that want to see some example of what can be done with raymarching


The following two are essentially a bunch of sin/cos values and thats the fun part with it. The work/reward ration is really good with raymarching. Once you have something working it requires very little work to make interesting scenes.



This isn't realtime though, 1fps I heard. But has global illumination. I really like the design and how this is synced to the music.
http://www.youtube.com/watch?v=BtEQ2cz-NfM

Haven't looked into it that much but it's certainly on my list of things to do

combatking0:
I've always wanted to try 3D rendering software, but found the big contenders (including "Maya") to be too processor intensive and fiddly to use.

I think I'll give RenderMonkey a try.

Does the term raymarching refer to a lighting effect or a distortion effect?

Navigation

[0] Message Index

[#] Next page

Go to full version