Welcome to Fractal Forums

Fractal Software => Fragmentarium => Topic started by: DarkBeam on November 13, 2016, 07:43:40 PM




Title: A simple teapot isosurface
Post by: DarkBeam on November 13, 2016, 07:43:40 PM
I found the Utah teapot shader on Shadertoy but it looked way too complicated for me.
So I thought that it might be redesigned using far less constants, routines and stuff, of course using more simple shapes! :D
But it still looks pretty realistic.
The code reported here must be shadertoy-ized a little but the hardest work is done; :D

Code:
// Teapot lame isosurface code is released under CC BY-SA 3.0
// Original release 13-11-2016 by DarkBeam at Fractalforums
// all variables must be declared, and set to 0
// (except x,y,z) at the beginning and must be public
// but I suggest to merge everything in an unique routine

DE {
  DEt = teabody();
  if (DEt >1.8) return DEt; // speedup
  DEx = min(spout(),handle());
  DEx = max(DEx,-teahole);
  DEt = min(DEx,DEt); // you might use a smooth min() here
  return max(DEt,-spouthole);
}


teabody {
   // Just some circles stitched together (more or less :P )
   r = x*x+y*y; r = sqrt(r);
   cut0=z-1.8;
   if (cut0>0.0) {
     xtp=r-.6145898;
     return sqrt(cut0*cut0+r*r)-.015;
   } else {
     cut2=2*r-z-0.1;
     cut2=max(cut2,-z+.8);
     if (cut2>0) {
       xtp=-r+.45;
       xtp=0.5*(xtp-abs(xtp));
       ztp=cut0+1.;
       xtp=xtp*xtp; ztp=ztp*ztp;
       w=sqrt(xtp+ztp)-.782623792;
     }else {
       xtp=r-0.95;ztp=cut0;
       xtp=xtp*xtp; ztp=ztp*ztp;
       w=sqrt(xtp+ztp)-.3354102; w = -w;
     }
     teahole=w;
     return abs(w)-.015;
     }  
}

spout {
  xtp = x-.94; ztp=z-.7;
  v = .707106 (xtp+ztp);  u = .707106 (xtp-ztp);
  // v*v causes DE trouble but not in this small interval
  // else modify the v multipliers
  t = sqrt(u*u+y*y*1.6)-.3+.311*v-.12*(v*v);
  t = max (t,abs(v-.7)-.7 );
  spouthole = t;
  t = abs(t-.015)-.015);
  t = max (t,z-1.5 );
  return t;
}

handle {
   cut0=z-1.21;
   if (cut0>0.0) {
     xtp=x+1.11; xtp=xtp*xtp;
     ztp=cut0*cut0;
     w=sqrt(xtp+ztp)-.3354102;
   } else {
     xtp=x+0.6; xtp=xtp*xtp;
     ztp=cut0*cut0;
     w=sqrt(xtp+ztp)-.9454102;
   }
   return sqrt(w*w+y*y)-.1;
}


Title: Re: A simple teapot isosurface
Post by: M Benesi on November 13, 2016, 07:54:39 PM
  Good job Luca!

  initialize variables somewhere? 


Title: Re: A simple teapot isosurface
Post by: DarkBeam on November 13, 2016, 07:56:55 PM
Thanks Matthew :-* but let me attach a preview :embarrass:


Title: Re: A simple teapot isosurface
Post by: M Benesi on November 13, 2016, 08:00:43 PM
Looks like texture is not attached to normals on the object, but instead to something else?  First one is nice!


Title: Re: A simple teapot isosurface
Post by: DarkBeam on November 13, 2016, 08:23:59 PM
Well I don't know it is a mb3d lightmap (the actual iso is clean) :) the second is a cut view that shows the inside and the holes all around :)
Also yes all vars are float and you must declare and initialize them!
I programmed all in assembly (where vars ... don't exist  ;D ) this is a transcript that hopefully is not too messy!!!


Title: Re: A simple teapot isosurface
Post by: Sabine on November 13, 2016, 08:26:39 PM
(http://orig09.deviantart.net/a968/f/2012/015/0/a/cheerleading_squad_by_cookiemagik-d4mf5q1.gif)

You did it, Luca!!! You're my hero  :yes: