POV-Ray : Newsgroups : povray.general : Translate by turbulence : Re: Translate by turbulence (Yay! I've done it!) Server Time
6 Aug 2024 06:19:20 EDT (-0400)
  Re: Translate by turbulence (Yay! I've done it!)  
From: TinCanMan
Date: 12 Jul 2002 21:10:14
Message: <3d2f7df6$1@news.povray.org>
Hooray! I macroed myself a method to translate by turbulence!
I don't guarantee how well this works, especially for large turbulence
values, but it will work for what I want to do.  Thanks to Christoph for
pointing me to vturbulence() which was the key to making it work.

-tgq

Have a try at the following scene and play with the numbers if you want to
see it in action.  The translated sphere is raised off the plane a bit
because of y direction turbulence.
//start
camera{
  up y
  right x*image_width/image_height
  angle 45
  location <30,30,-30>
  look_at 0
}

light_source{y*1000 rgb 1}

#declare tTurb=0.50;
#declare tLamb=1.2;
#declare tOcta=5;
#declare tOmeg=0.25;

plane{y 0
  pigment{checker rgb 1 rgb 0
    translate -y/2
    warp{
      turbulence tTurb
      octaves tOcta
      lambda tLamb
      omega tOmeg
    }
    scale 20
  }
}

//P0 = Point to translate
//Acc = Accuracy
#macro turb_translate (tTurb,tOcta,tLamb,tOmeg,P0,Acc)
  #local PC=P0;
  #local Dir=<0,0,0>;
  #local V0=vlength(vturbulence(tLamb, tOmeg, tOcta, P0)*tTurb);
  #local Step=V0/2;
  #macro AB(PC,Step,d,Dir,V0)
    #local P1=PC+Step*d;
    #local V1=vlength(P1+vturbulence(tLamb, tOmeg, tOcta, P1)*tTurb-P0);
    #if (V1<V0 | d.x=1)
      #local Dir=d;
      #local V0=V1;
    #end
  #end
  #while (V0>Acc)
    #local DrP=Dir;
    AB(PC,Step, x,Dir,V0)
    AB(PC,Step,-x,Dir,V0)
    AB(PC,Step, y,Dir,V0)
    AB(PC,Step,-y,Dir,V0)
    AB(PC,Step, z,Dir,V0)
    AB(PC,Step,-z,Dir,V0)
    #if (vlength(DrP+Dir)=0)
      #local Step=Step/2;
    #else
      #local Step=V0/2;
    #end
    #local PC=PC+Step*Dir;
  #end
  PC
#end

#declare TPt=<0,0,0>;
sphere{TPt 1 pigment{rgb <1,0,0>}}
sphere{0 1 pigment{rgb <1,0,0>} translate
turb_translate(tTurb,tOcta,tLamb,tOmeg,TPt,0.001)*20}
//end


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.