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.3 by greg, Tue Oct 30 21:03:49 1990 UTC

# Line 37 | Line 37 | static double  xarg[3];
37  
38   #define  EPSILON        .0001           /* error allowed in fractal */
39  
40 < #define  frand3(x,y,z)  frand((long)((12.38*(x)-22.30*(y)-42.63*(z))/EPSILON))
40 > #define  frand3(x,y,z)  frand(17*(x)+23*(y)+29*(z))
41  
42   double  fnoise3();
43  
# Line 165 | Line 165 | l_hermite()                    /* library call for hermite interpolatio
165  
166   double
167   fnoise3(p)                      /* compute fractal noise function */
168 < register double  p[3];
168 > double  p[3];
169   {
170          double  floor();
171 <        double  v[3], beg[3], fval[8], s, fc;
172 <        int  closing, branch;
171 >        long  t[3], v[3], beg[3], s;
172 >        double  fval[8], fc;
173 >        int  branch;
174          register int  i, j;
175                                                  /* get starting cube */
176 <        for (i = 0; i < 3; i++)
177 <                beg[i] = floor(p[i]);
176 >        s = (long)(1.0/EPSILON);
177 >        for (i = 0; i < 3; i++) {
178 >                t[i] = s*p[i];
179 >                beg[i] = s*floor(p[i]);
180 >        }
181          for (j = 0; j < 8; j++) {
182                  for (i = 0; i < 3; i++) {
183                          v[i] = beg[i];
184                          if (j & 1<<i)
185 <                                v[i] += 1.0;
185 >                                v[i] += s;
186                  }
187                  fval[j] = frand3(v[0],v[1],v[2]);
188          }
185        s = 1.0;
189                                                  /* compute fractal */
190          for ( ; ; ) {
191 <                s *= 0.5;
191 >                s >>= 1;
192                  branch = 0;
190                closing = 0;
193                  for (i = 0; i < 3; i++) {       /* do center */
194                          v[i] = beg[i] + s;
195 <                        if (p[i] > v[i]) {
195 >                        if (t[i] > v[i]) {
196                                  branch |= 1<<i;
197 <                                if (p[i] - v[i] > EPSILON)
196 <                                        closing++;
197 <                        } else if (v[i] - p[i] > EPSILON)
198 <                                closing++;
197 >                        }
198                  }
199                  fc = 0.0;
200                  for (j = 0; j < 8; j++)
201                          fc += fval[j];
202 <                fc = 0.125*fc + s*frand3(v[0],v[1],v[2]);
203 <                if (closing == 0)
202 >                fc *= 0.125;
203 >                if (s < 1)
204                          return(fc);             /* close enough */
205 +                fc += s*EPSILON*frand3(v[0],v[1],v[2]);
206                  fval[~branch & 7] = fc;
207                  for (i = 0; i < 3; i++) {       /* do faces */
208                          if (branch & 1<<i)
# Line 213 | Line 213 | register double  p[3];
213                          for (j = 0; j < 8; j++)
214                                  if (~(j^branch) & 1<<i)
215                                          fc += fval[j];
216 <                        fc = 0.25*fc + s*frand3(v[0],v[1],v[2]);
216 >                        fc = 0.25*fc + s*EPSILON*frand3(v[0],v[1],v[2]);
217                          fval[~(branch^1<<i) & 7] = fc;
218                          v[i] = beg[i] + s;
219                  }
# Line 230 | Line 230 | register double  p[3];
230                                  v[j] -= s;
231                          fc = fval[branch & ~(1<<i)];
232                          fc += fval[branch | 1<<i];
233 <                        fc = 0.5*fc + s*frand3(v[0],v[1],v[2]);
233 >                        fc = 0.5*fc + s*EPSILON*frand3(v[0],v[1],v[2]);
234                          fval[branch^1<<i] = fc;
235                          j = (i+1)%3;
236                          v[j] = beg[j] + s;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines