|
|
Well, reflect_caustic() simulates reflected caustics in the Superpatch.
It is far from complete, but right now I'm out of ideas/time/motivation
to make any improvements. The only thing I am considering is to add
the possibility to do refracted caustics.
Anyway, check it out if ya care. Everything is pretty much trial and error,
but in theory you can get fairly good results (I posted an image in
binaries.images some time ago)
Margus
//Object - declared object to be sampled
//Light - position of the light source
//SamplesIn - number of times the object is to be sampled in X, Y and Z directions
(vector or float)
//Rnd - random jittering of sample rays
//C - color of the light_sources
//F - falloff of the light_sources
//R - radius of the light_sources
//Fd - fade distance of the ligh_sources
//Fp - fade power of the light sources
#macro rand_ext(M,D,Seed)
(M+(rand(Seed)-.5)*2*D)
#end
#macro v_mirror(R,N)
#local nN=vnormalize(N);
#local par=vdot( R, nN );
#local perp=R-par*nN;
vnormalize(par*nN-perp)
#end
#macro reflect_caustic(Object,Light,SamplesIn,Rnd,C,F,R,Fd,Fp)
#declare Seed=seed(1);
#declare Samples=SamplesIn+<0,0,0>; //force SamplesIn to vector
#declare Min=min_extent(Object);
#declare Max=max_extent(Object);
#declare Ext=Max-Min; //size of the bounding box
#declare J=Ext/Samples; //XYZ jump of the sample ray
#declare T=Max-J/2; //first trace vector
#declare LC=0; //light count
#while(T.z>Min.z)
//create a random vector (mean = 0, max deviation = J * Rnd)
#declare
Jitter=<rand_ext(0,J.x*Rnd,Seed),rand_ext(0,J.y*Rnd,Seed),rand_ext(0,J.z*Rnd,Seed)>;
//translate trace vector relative to origin & add randomness
#declare Dir=(T-Light)+Jitter;
#declare N=<0,0,0>;
#declare Trace=trace(Object,Light,Dir,N);
#if(N.x!=0|N.y!=0|N.z!=0)
light_source{Trace+.001*N color C
spotlight point_at Trace+v_mirror(Light-Trace,N) falloff F
radius R
fade_distance Fd fade_power Fp}
#declare LC=LC+1;
#end
//make the macro scan the bounding box by increments specified by Samples
#if(T.x>=Min.x)
#declare T=T-<J.x,0,0>;
#else #declare T=<Max.x,T.y-J.y,T.z>;
#end
#if(T.y<=Min.y)
#declare T=<T.x,Max.y,T.z-J.z>;
#end
#end
#debug concat(str(LC,0,0)," light sources\n")
#end
Post a reply to this message
|
|