Logo by Pauldelbrot - Contribute your own Logo!


it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit us on facebook
Welcome, Guest. Please login or register. October 25, 2020, 04:20:47 AM

Login with username, password and session length

The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!

Pages: [1]   Go Down
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Raymarching misses fractal?  (Read 1151 times)
0 Members and 1 Guest are viewing this topic.
Forums Newbie
Posts: 1

« on: June 08, 2013, 10:47:14 AM »


I hope this is the right place to ask.
I'd like to reproduce the fractal from this blog post: http://blog.hvidtfeldts.net/index.php/2011/08/distance-estimated-3d-fractals-iii-folding-space/comment-page-1/#comment-20302 section "A Real Fractal". The post uses Raymarchiing and a distance function.
The problem is, that my ray misses the fractal. I don't know what sensible values for "Iteration" and "scale" to set and I guess, that may ray construction is also a little bit off...

Here is my code:

const float Iterations = 4;
const float Scale = 5.0;

Fractal DE:
float distanceFromPoint(vec3 z) {
        vec3 a1 = vec3(1,1,1);
vec3 a2 = vec3(-1,-1,1);
vec3 a3 = vec3(1,-1,-1);
vec3 a4 = vec3(-1,1,-1);
vec3 c;
int n = 0;
float dist, d;
while (n < Iterations) {
c = a1; dist = length(z-a1);
       d = length(z-a2); if (d < dist) { c = a2; dist=d; }
d = length(z-a3); if (d < dist) { c = a3; dist=d; }
d = length(z-a4); if (d < dist) { c = a4; dist=d; }
z = Scale*z-c*(Scale-1.0);

  return = (length(z) ) * pow(Scale, -float(n));

Construction of rays
 vec2 q = gl_FragCoord.xy / u_ws.xy;
  q = -1.0 + 2.0 * q;
  q.x *= u_aspect;
  vec3 planePoint = vec3(q.xy, 0.0);
  vec3 ro = vec3(0.0, 0.0, 1.3); //eye-position
  vec3 rd = normalize(planePoint - ro);

  vec4 debugColor = vec4(vec3(0.1).xyz, 1.0);
  vec4 color = vec4(trace(ro, rd));

I hope someone can give me a hint.

« Last Edit: June 08, 2013, 02:50:06 PM by fractalnoob » Logged
Forums Newbie
Posts: 9

« Reply #1 on: June 21, 2013, 06:35:43 AM »

I found that scale 2.0 produces the Sierpinski Pyramid.

Also, length(z) on the last line of the distance function is the distance to a point in space.

Unless you have a very high iteration count you wont see anything as most rays wont get close enough to any points.

Use (length(z)-radius) to get the distance to a sphere instead (radius 1.5 seems to be about optimal for this one).

Pages: [1]   Go Down
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Major Raymarching Optimization Mandelbulb Implementation keldor314 8 6551 Last post December 27, 2013, 08:48:22 PM
by Syntopia
raymarching optimization using golden ratio ... General Discussion cKleinhuis 4 2763 Last post December 29, 2012, 12:21:32 PM
by cKleinhuis
Fast fake montecarlo for raymarching - Now with fragmentarium script! Fragmentarium « 1 2 3 4 » eiffie 45 11755 Last post December 20, 2013, 05:44:53 PM
VTune Results; cRenderWorker::RayMarching -> OpenMP or Threading Building Blocks Mandelbulber mancoast 8 1252 Last post July 31, 2016, 02:57:32 PM
by mancoast
VTune Results; cRenderWorker::RayRecursion; VolumetricShader vs. RayMarching Mandelbulber mancoast 6 1559 Last post August 02, 2016, 11:26:17 PM
by Buddhi

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.102 seconds with 27 queries. (Pretty URLs adds 0.008s, 2q)