• Welcome to Dark Bit Factory & Gravity.
 

What are you working on at the moment?

Started by Shockwave, October 28, 2006

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

hellfire

Just some lines of code to chill out after work.

(a marched cube with perturbed rays)
Challenge Trophies Won:

Clyde

Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Kirl

www.kirl.nl
Challenge Trophies Won:

Stonemonkey


Raizor

That looks great Hellfire, would love to see it in motion :)

How exactly do you perturb a ray? I've never heard of doing that before.
raizor

Challenge Trophies Won:

jace_stknights

Challenge Trophies Won:

Jim

QuoteHow exactly do you perturb a ray
Poke it with a stick.
Jim
Challenge Trophies Won:

benny!

Kewl screeny Hellfire ... need to see this in motion, too!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

marlon


hellfire

#529
Quote from: benny! on March 15, 2012Kewl screeny Hellfire ... need to see this in motion, too!
Here you are:


And another one using a torus instead of a cube:
Challenge Trophies Won:

Kirl

#530
Youtube says video is private!  :protest:


[EDIT] Excellent stuff, would love to hear some theory on this one too. Is it done like your time challenge entry by rendering the cube at various timeframes?
www.kirl.nl
Challenge Trophies Won:

Dr.Death

Proud member of DAWN

benny!

K++ for sharing video.

Honestly, this kind of stuff attracts me a lot. Cannot stop looking at the video. True computer art! Do you plan to do anything with the FX yet?

Anyway, great work - as always!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Stonemonkey


hellfire

#534
Quote from: benny!Cannot stop looking at the video. True computer art!
Thanks :)

Quote from: benny!Do you plan to do anything with the FX yet?
No, it was just for fun.
And most 4kb-intros are already full of this stuff since a couple of years :)

Quote from: Kirl on March 15, 2012would love to hear some theory on this one too.
It's just raymarching a cube which twists around multiple axes.
Raymarching steps along a ray from the camera through each pixel of the screen and tries to find the intersection with the object.
In contrast to raytracing it doesn't compute the exact intersection point with any of those ray/something-intersection-formulars.
Instead it computes the minimum distance to the object at the current position and advances along the ray by this "safe" distance iteratively:

// the ray: pos + t * dir
vec3 pos= currentPixelOnScreen;
vec3 dir= normalize(pos - cameraPosition);
float t= 0.0;

vec3 curPos;
const float EPS = 0.01;
const float maxDistance= 10.0; // we certainly didn't hit a unit-cube when we are here.

for (int it=0; it < maximumIterations; it++)
{
    curPos= pos + dir * t;
    float dist= minimumDistanceToCube( curPos );

    // curPos is near enough to the cube?
    if ( abs( dist ) < EPS )
      break;

    // ray didn't hit anything?
    if ( t > maxDistance )
      break;

    // advance along ray
    t += dist;
}

if ( t < maxDistance )
  doSomeFancyShading( curPos );


And to find the minimum distance of a ray with an axis-aligned box at the center:

float minimumDistanceToCube( vec3 pos )
{
  // cube reaches from -1..+1 in all directions
  vec3 dist= abs( pos ) - vec3(1.0, 1.0, 1.0);

  // negative distances are inside the cube: clamp to 0
  dist= max( dist, 0.0 );

  // get maximum of dist.xyz
  return max( max(dist.x, dist.y), dist.z );
}

(so we're not rotating the cube but the camera)

To twist the cube around one axis you can simply rotate "pos".
"pos" always rotates around the cube's center (because it's at 0,0,0).

float minimumDistanceToTwistedCube(vec3 pos)
{
        // rotation angle according to "x"
        float rx= sin(pos.x + time)*scale;

        // 2d rotation matrix around x
vec3 tmp= pos;
float c = cos(rx);
float s = sin(rx);
        // pos.x keeps constant when rotating around the x axis
pos.y = c * tmp.y - s * tmp.z;
pos.z = s * tmp.y + c * tmp.z;

        // distance to center
vec3 dist= abs(pos) - vec3(1.0, 1.0, 1.0);

        // negative distances are inside the cube: clamp to 0
        dist= max( dist, 0.0 );

       // get euclidian distance to smooth distance at the edges
       // and use a much smaller step size to safely catch the twisted edges
       return length( dist ) * 0.2;
}


The version in the video just rotates around the x, y and z axis simultaneously.
Challenge Trophies Won:

Raizor

Looks great in motion Hellfire!
raizor

Challenge Trophies Won:

Voltage

Nice colour selection.  The reflections really add a lot to the effect too.

Looks amazing as usual hellfire.  Have you tried adding "blending"?  http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm

This would look awesome blended with something.
Challenge Trophies Won:

Kirl

Excellent, thanks for the mini-masterclass in awesomeness! 

2nd K+ from me today!  :buddies:
www.kirl.nl
Challenge Trophies Won:

Pot Noodle


axon

Quote from: Ferris on February 28, 2012

A current WIP for a certain party in Easter. Gonna be an invite so I'll actually have to finish it this time too :P

There will also be a huge-ass Displayhack article on it after it's done describing workflow/custom tools/effect implementations/why it's going to be open-source :)

looking forward to this...