POV-Ray : Newsgroups : povray.unofficial.patches : radiosity samples: 255x255x255 probably isn't enough : Re: radiosity samples: 255x255x255 probably isn't enough Server Time
30 Jun 2024 20:31:41 EDT (-0400)
  Re: radiosity samples: 255x255x255 probably isn't enough  
From: Apache
Date: 7 Jan 2003 12:48:05
Message: <3e1b12d5$1@news.povray.org>
> It is fairly obvious that using bytes to store the directions is just a
> hack to save memory.  Apart from the accuracy problem it also costs some
> computation time to unpack the directions for every radiosity sample
> taken.
No need to save memory with this, because we're having more and more RAM
every year :-) And IIRC computers nowadays work as fast with integers
(16bits) as with bytes (8bits).

> Without any information on how the samples were generated this suffers
> from the same problem as the original set of sample directions.

It's a bit like this:

save first sample, offset = 0 (this one is on the exact center of the disk)
samplescalculated = 1
minimumtrials = 1000
repeat until (samplescalculated equals 8000) {
    trialcounter = 0
    besttrialdistance = 10   (doesn't really matter, must be > 2)
    repeat until (trialcounter equals samplecount \
      and trialcounter is greater or equals minimumtrials) {
        create random sample on disk
        if (distance from random sample to nearest sample saved <
besttrialdistance) {
            besttrialdistance = distance random sample to nearest sample
saved
            save random sample, offset = samplescalculated
            trialcounter = 0
        }
    }
    samplescalculated ++
}

save all samples saved to disk

done


Anyhow. The first test with this test set really sucks :-(    Extreme
artifacts!



Here's the source code of the monster:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>


#define SAMPLESAMOUNT       (12000)
#define MINRETRIES          (1000)
#define DISTRIBUTEROUNDS    (200)
#define DISTRIBUTESTEPSIZE  (0.01)
#define PI                  (3.141592653589793238)
#define XMEAN               (127.5)
#define YMEAN               (127.5)
#define XSCALE              (127.5)
#define YSCALE              (127.5)
#define ZSCALE              (127.5)
#define RANDOMVALUE         ((double)rand() / (double)(RAND_MAX))

int main(void) {
  FILE*     filehandle1;
  double*   x              = (double*) malloc(SAMPLESAMOUNT *
sizeof(double));
  double*   y              = (double*) malloc(SAMPLESAMOUNT *
sizeof(double));
  int       i              = 0;


  /******* CREATE DISTRIBUTION *******/

  x[0] = 0.0;
  y[0] = 0.0;

  for (i = 1; i < SAMPLESAMOUNT; i++) {
    int    i2;
    double xnew;
    double ynew;
    double olddist = 0.0;
    int    retry   = 0;

    printf("\rSETUP DISTRIBUTION   : %d of %d", i, SAMPLESAMOUNT);

    for (retry = 0; (retry < i) || (retry < MINRETRIES); retry++) {
      int    j       = 0;
      double mindist = 1001.0;
      double phi     = 2*PI*RANDOMVALUE;
      double sqrtr   = sqrt(RANDOMVALUE);
      xnew           = cos(phi)*sqrtr;
      ynew           = sin(phi)*sqrtr;

      /** determine distance of new sample to nearest existing sample **/
      for (j = 0; j < i; j++) {
        double dx = xnew - x[j];
        double dy = ynew - y[j];
        double d2 = dx*dx + dy*dy;
        if (d2 < mindist) {
          mindist = d2;
        }
      }

      /** if new sample is farther away than the previous one, save it **/
      if (mindist > olddist) {
        x[i]    = xnew;
        y[i]    = ynew;
        olddist = mindist;
        retry   = 0;
      }
    }

  }
  printf("\rsetup distribution   : done                 \r\n");

  /******* WRITE SAMPLES TO DISK *******/

  printf("SAVE SAMPLES TO DISK...");
  filehandle1 = fopen("newraddata.inc", "w");

  fprintf(filehandle1, "#declare Thing1 = union {\r\n");
  for (i = 0; i < SAMPLESAMOUNT; i++) {
    double z = sqrt(1-x[i]*x[i]-y[i]*y[i]);
    fprintf(filehandle1, "  sphere {<%d, %d, %d>, 1.0} //count %d\r\n",
(int)(.5+XMEAN+XSCALE*x[i]), (int)(.5+YMEAN+YSCALE*y[i]),
(int)(.5+ZSCALE*z), i+1);
  }
  fprintf(filehandle1, "}\r\n");

  fclose(filehandle1);
  printf("\rsave samples to disk : done                \r\n\007");

  free(x);
  free(y);

  return (0);
}


Post a reply to this message

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