ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/noise3.c
(Generate patch)

Comparing ray/src/rt/noise3.c (file contents):
Revision 1.2 by greg, Fri Mar 3 12:25:34 1989 UTC vs.
Revision 1.5 by greg, Fri May 24 14:23:33 1991 UTC

# Line 30 | Line 30 | static char SCCSid[] = "$SunId$ LBL";
30                                          r0*((t-2.0)*t+1.0)*t + \
31                                          r1*(t-1.0)*t*t )
32  
33 < double  *noise3(), noise3coef(), argument(), frand();
33 > static char  *noise_name[4] = {"noise3a", "noise3b", "noise3c", "noise3"};
34 > static char  fnoise_name[] = "fnoise3";
35 > static char  hermite_name[] = "hermite";
36  
37 + double  *noise3(), fnoise3(), argument(), frand();
38 +
39   static long  xlim[3][2];
40   static double  xarg[3];
41  
42   #define  EPSILON        .0001           /* error allowed in fractal */
43  
44 < #define  frand3(x,y,z)  frand((long)((12.38*(x)-22.30*(y)-42.63*(z))/EPSILON))
44 > #define  frand3(x,y,z)  frand(17*(x)+23*(y)+29*(z))
45  
42 double  fnoise3();
46  
47 <
48 < double
49 < l_noise3()                      /* compute 3-dimensional noise function */
47 > static double
48 > l_noise3(nam)                   /* compute a noise function */
49 > register char  *nam;
50   {
51 <        return(noise3coef(D));
51 >        register int  i;
52 >        double  x[3];
53 >                                        /* get point */
54 >        x[0] = argument(1);
55 >        x[1] = argument(2);
56 >        x[2] = argument(3);
57 >                                        /* make appropriate call */
58 >        if (nam == fnoise_name)
59 >                return(fnoise3(x));
60 >        i = 4;
61 >        while (i--)
62 >                if (nam == noise_name[i])
63 >                        return(noise3(x)[i]);
64 >        eputs("Bad call to l_noise3()!\n");
65 >        quit(1);
66   }
67  
68  
69   double
70 < l_noise3a()                     /* compute x slope of noise function */
70 > l_hermite()                     /* library call for hermite interpolation */
71   {
72 <        return(noise3coef(A));
72 >        double  t;
73 >        
74 >        t = argument(5);
75 >        return( hermite(argument(1), argument(2),
76 >                        argument(3), argument(4), t) );
77   }
78  
79  
80 < double
60 < l_noise3b()                     /* compute y slope of noise function */
80 > setnoisefuncs()                 /* add noise functions to library */
81   {
82 <        return(noise3coef(B));
63 < }
82 >        register int  i;
83  
84 <
85 < double
86 < l_noise3c()                     /* compute z slope of noise function */
87 < {
88 <        return(noise3coef(C));
84 >        funset(hermite_name, 5, ':', l_hermite);
85 >        funset(fnoise_name, 3, ':', l_noise3);
86 >        i = 4;
87 >        while (i--)
88 >                funset(noise_name[i], 3, ':', l_noise3);
89   }
90  
91  
73 double
74 l_fnoise3()                     /* compute fractal noise function */
75 {
76        double  x[3];
77
78        x[0] = argument(1);
79        x[1] = argument(2);
80        x[2] = argument(3);
81
82        return(fnoise3(x));
83 }
84
85
86 static double
87 noise3coef(coef)                /* return coefficient of noise function */
88 int  coef;
89 {
90        double  x[3];
91
92        x[0] = argument(1);
93        x[1] = argument(2);
94        x[2] = argument(3);
95
96        return(noise3(x)[coef]);
97 }
98
99
92   double *
93   noise3(xnew)                    /* compute the noise function */
94   register double  xnew[3];
# Line 153 | Line 145 | register long  s;
145  
146  
147   double
156 l_hermite()                     /* library call for hermite interpolation */
157 {
158        double  t;
159        
160        t = argument(5);
161        return( hermite(argument(1), argument(2),
162                        argument(3), argument(4), t) );
163 }
164
165
166 double
148   fnoise3(p)                      /* compute fractal noise function */
149 < register double  p[3];
149 > double  p[3];
150   {
151          double  floor();
152 <        double  v[3], beg[3], fval[8], s, fc;
153 <        int  closing, branch;
152 >        long  t[3], v[3], beg[3];
153 >        double  fval[8], fc;
154 >        int  branch;
155 >        register long  s;
156          register int  i, j;
157                                                  /* get starting cube */
158 <        for (i = 0; i < 3; i++)
159 <                beg[i] = floor(p[i]);
158 >        s = (long)(1.0/EPSILON);
159 >        for (i = 0; i < 3; i++) {
160 >                t[i] = s*p[i];
161 >                beg[i] = s*floor(p[i]);
162 >        }
163          for (j = 0; j < 8; j++) {
164                  for (i = 0; i < 3; i++) {
165                          v[i] = beg[i];
166                          if (j & 1<<i)
167 <                                v[i] += 1.0;
167 >                                v[i] += s;
168                  }
169                  fval[j] = frand3(v[0],v[1],v[2]);
170          }
185        s = 1.0;
171                                                  /* compute fractal */
172          for ( ; ; ) {
173 <                s *= 0.5;
173 >                fc = 0.0;
174 >                for (j = 0; j < 8; j++)
175 >                        fc += fval[j];
176 >                fc *= 0.125;
177 >                if ((s >>= 1) == 0)
178 >                        return(fc);             /* close enough */
179                  branch = 0;
190                closing = 0;
180                  for (i = 0; i < 3; i++) {       /* do center */
181                          v[i] = beg[i] + s;
182 <                        if (p[i] > v[i]) {
182 >                        if (t[i] > v[i]) {
183                                  branch |= 1<<i;
184 <                                if (p[i] - v[i] > EPSILON)
196 <                                        closing++;
197 <                        } else if (v[i] - p[i] > EPSILON)
198 <                                closing++;
184 >                        }
185                  }
186 <                fc = 0.0;
201 <                for (j = 0; j < 8; j++)
202 <                        fc += fval[j];
203 <                fc = 0.125*fc + s*frand3(v[0],v[1],v[2]);
204 <                if (closing == 0)
205 <                        return(fc);             /* close enough */
186 >                fc += s*EPSILON*frand3(v[0],v[1],v[2]);
187                  fval[~branch & 7] = fc;
188                  for (i = 0; i < 3; i++) {       /* do faces */
189                          if (branch & 1<<i)
# Line 213 | Line 194 | register double  p[3];
194                          for (j = 0; j < 8; j++)
195                                  if (~(j^branch) & 1<<i)
196                                          fc += fval[j];
197 <                        fc = 0.25*fc + s*frand3(v[0],v[1],v[2]);
197 >                        fc = 0.25*fc + s*EPSILON*frand3(v[0],v[1],v[2]);
198                          fval[~(branch^1<<i) & 7] = fc;
199                          v[i] = beg[i] + s;
200                  }
# Line 230 | Line 211 | register double  p[3];
211                                  v[j] -= s;
212                          fc = fval[branch & ~(1<<i)];
213                          fc += fval[branch | 1<<i];
214 <                        fc = 0.5*fc + s*frand3(v[0],v[1],v[2]);
214 >                        fc = 0.5*fc + s*EPSILON*frand3(v[0],v[1],v[2]);
215                          fval[branch^1<<i] = fc;
216                          j = (i+1)%3;
217                          v[j] = beg[j] + s;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines