src/raytracer.cc
branchpyrit
changeset 49 558fde7da82a
parent 48 a4913301c626
child 50 14a727b70d07
equal deleted inserted replaced
48:a4913301c626 49:558fde7da82a
   233 			Float ao_intensity = miss / ao_samples;
   233 			Float ao_intensity = miss / ao_samples;
   234 			col = col * ao_intensity;
   234 			col = col * ao_intensity;
   235 		}
   235 		}
   236 
   236 
   237 		return col;
   237 		return col;
   238 	}
       
   239 }
       
   240 
       
   241 static inline void samplepixel(Colour &c, Vector3 &dir, RenderrowData* d, const int &oversample)
       
   242 {
       
   243 	if (oversample <= 0)
       
   244 	{
       
   245 		// no oversampling
       
   246 		dir.normalize();
       
   247 		Ray ray(d->eye, dir);
       
   248 		c = d->rt->raytrace(ray, 0, NULL);
       
   249 	}
       
   250 	else
       
   251 	if (oversample <= 3)
       
   252 	{
       
   253 		// grid oversampling
       
   254 		c = Colour(0,0,0);
       
   255 		static const int gridsamples[] = {5,9,16};
       
   256 		static const Float osa5x[] = {0.0, -0.4, +0.4, +0.4, -0.4};
       
   257 		static const Float osa5y[] = {0.0, -0.4, -0.4, +0.4, +0.4};
       
   258 		static const Float osa9x[] = {-0.34,  0.00, +0.34,
       
   259 			-0.34,  0.00, +0.34, -0.34,  0.00, +0.34};
       
   260 		static const Float osa9y[] = {-0.34, -0.34, -0.34,
       
   261 				0.00,  0.00,  0.00, +0.34, +0.34, +0.34};
       
   262 		static const Float osa16x[] = {-0.375, -0.125, +0.125, +0.375,
       
   263 			-0.375, -0.125, +0.125, +0.375, -0.375, -0.125, +0.125, +0.375,
       
   264 			-0.375, -0.125, +0.125, +0.375};
       
   265 		static const Float osa16y[] = {-0.375, -0.375, -0.375, -0.375,
       
   266 			-0.125, -0.125, -0.125, -0.125, +0.125, +0.125, +0.125, +0.125,
       
   267 			+0.375, +0.375, +0.375, +0.375};
       
   268 		static const Float *osaSx[] = {osa5x, osa9x, osa16x};
       
   269 		static const Float *osaSy[] = {osa5y, osa9y, osa16y};
       
   270 		const int samples = gridsamples[oversample-1];
       
   271 		const Float *osax = osaSx[oversample-1];
       
   272 		const Float *osay = osaSy[oversample-1];
       
   273 		for (int i = 0; i < samples; i++)
       
   274 		{
       
   275 			Vector3 tmpdir = dir + osax[i]*d->dx + osay[i]*d->dy;
       
   276 			tmpdir.normalize();
       
   277 			Ray ray(d->eye, tmpdir);
       
   278 			c += d->rt->raytrace(ray, 0, NULL);
       
   279 		}
       
   280 		c = c * (1.0/samples);
       
   281 	}
       
   282 	else
       
   283 	{
       
   284 		// stochastic oversampling
       
   285 		// ...todo
       
   286 	}
   238 	}
   287 }
   239 }
   288 
   240 
   289 #if 0
   241 #if 0
   290 static void *renderrow(void *data)
   242 static void *renderrow(void *data)
   466 			Colour col = raytrace(ray, 0, NULL);
   418 			Colour col = raytrace(ray, 0, NULL);
   467 			sampler->saveSample(sample, col);
   419 			sampler->saveSample(sample, col);
   468 
   420 
   469 			delete prev;
   421 			delete prev;
   470 			prev = sample;
   422 			prev = sample;
   471 		}
   423 			sampnum--;
       
   424 			if ((sampnum % 1000) == 0)
       
   425 				dbgmsg(2, "\b\b\b\b\b\b\b\b%8d", sampnum);
       
   426 		}
       
   427 		dbgmsg(2, "\n");
   472 	}
   428 	}
   473 
   429 
   474 	// wait for workers
   430 	// wait for workers
   475 	// ...
   431 	// ...
   476 
   432