SLG: optimized VolumeComputation class (uses array instead of vector class) test_partecipatingmedia
authorDavid Bucciarelli <dade@ngi.it>
Wed Mar 31 11:17:10 2010 +0200 (2010-03-31)
branchtest_partecipatingmedia
changeset 165d44428290a13
parent 164 4a6558043325
child 166 68a6e70445f9
SLG: optimized VolumeComputation class (uses array instead of vector class)
samples/smallluxgpu/volume.cpp
samples/smallluxgpu/volume.h
scenes/classroom/classroom-hdr-vol.scn
scenes/classroom/render-fast-hdr-vol.cfg
     1.1 --- a/samples/smallluxgpu/volume.cpp	Wed Mar 31 10:47:48 2010 +0200
     1.2 +++ b/samples/smallluxgpu/volume.cpp	Wed Mar 31 11:17:10 2010 +0200
     1.3 @@ -24,16 +24,30 @@
     1.4  
     1.5  using namespace std;
     1.6  
     1.7 +VolumeComputation::VolumeComputation(VolumeIntegrator *vol) {
     1.8 +	float maxRayLen = vol->GetMaxRayLength();
     1.9 +	const unsigned int maxSampleCount = Ceil2Int(maxRayLen / vol->GetStepSize()) + 1;
    1.10 +
    1.11 +	rays = new Ray[maxSampleCount];
    1.12 +	currentRayIndex = new unsigned int[maxSampleCount];
    1.13 +	scatteredLight = new Spectrum[maxSampleCount];
    1.14 +
    1.15 +	Reset();
    1.16 +}
    1.17 +
    1.18 +VolumeComputation::~VolumeComputation() {
    1.19 +	delete rays;
    1.20 +	delete currentRayIndex;
    1.21 +	delete scatteredLight;
    1.22 +}
    1.23  
    1.24  void SingleScatteringIntegrator::GenerateLiRays(const Scene *scene, Sample *sample,
    1.25  		const Ray &ray, VolumeComputation *comp) const {
    1.26  	comp->Reset();
    1.27  
    1.28  	float t0, t1;
    1.29 -	if (!region.IntersectP(ray, &t0, &t1)) {
    1.30 -		comp->rays.resize(0);
    1.31 +	if (!region.IntersectP(ray, &t0, &t1))
    1.32  		return;
    1.33 -	}
    1.34  
    1.35  	// Prepare for volume integration stepping
    1.36  	const float distance = t1 - t0;
    1.37 @@ -46,8 +60,6 @@
    1.38  	const float offset = sample->GetLazyValue();
    1.39  	t0 += offset * step;
    1.40  
    1.41 -	comp->rays.resize(0);
    1.42 -	comp->scatteredLight.resize(0);
    1.43  	Point pPrev;
    1.44  	// I intentionally leave scattering out because it is a lot easier to use
    1.45  	Spectrum stepeTau = Exp(-step * (sig_a /*+ sig_s*/));
    1.46 @@ -76,15 +88,15 @@
    1.47  
    1.48  			// Select a point on the light surface
    1.49  			float lightPdf;
    1.50 -			Ray lightRay;
    1.51  			Spectrum lightColor = light->Sample_L(scene->objects, p, NULL,
    1.52  					sample->GetLazyValue(), sample->GetLazyValue(), sample->GetLazyValue(),
    1.53 -					&lightPdf, &lightRay);
    1.54 +					&lightPdf, &(comp->rays[comp->rayCount]));
    1.55  
    1.56  			if ((lightPdf > 0.f) && !lightColor.Black()) {
    1.57 -				comp->rays.push_back(lightRay);
    1.58 -				comp->scatteredLight.push_back(Tr * sig_s * lightColor * Transmittance(lightRay) *
    1.59 -					(scene->lights.size() * step / (4.f * M_PI * lightPdf)));
    1.60 +				comp->scatteredLight[comp->rayCount] = Tr * sig_s * lightColor *
    1.61 +						Transmittance(comp->rays[comp->rayCount]) *
    1.62 +						(scene->lights.size() * step / (4.f * M_PI * lightPdf));
    1.63 +				comp->rayCount++;
    1.64  			}
    1.65  		}
    1.66  
     2.1 --- a/samples/smallluxgpu/volume.h	Wed Mar 31 10:47:48 2010 +0200
     2.2 +++ b/samples/smallluxgpu/volume.h	Wed Mar 31 11:17:10 2010 +0200
     2.3 @@ -33,22 +33,18 @@
     2.4  
     2.5  class VolumeComputation {
     2.6  public:
     2.7 -	VolumeComputation(VolumeIntegrator *vol) {
     2.8 -		vi = vol;
     2.9 -
    2.10 -		Reset();
    2.11 -	}
    2.12 +	VolumeComputation(VolumeIntegrator *vol);
    2.13 +	~VolumeComputation();
    2.14  
    2.15  	void AddRays(RayBuffer *rayBuffer) {
    2.16 -		currentRayIndex.resize(rays.size());
    2.17 -		for (unsigned int i = 0; i < rays.size(); ++i)
    2.18 +		for (unsigned int i = 0; i < rayCount; ++i)
    2.19  			currentRayIndex[i] = rayBuffer->AddRay(rays[i]);
    2.20  	}
    2.21  
    2.22  	Spectrum CollectResults(const RayBuffer *rayBuffer) {
    2.23  		// Add scattered light
    2.24  		Spectrum radiance;
    2.25 -		for (unsigned int i = 0; i < rays.size(); ++i) {
    2.26 +		for (unsigned int i = 0; i < rayCount; ++i) {
    2.27  			const RayHit *h = rayBuffer->GetRayHit(currentRayIndex[i]);
    2.28  			if (h->Miss()) {
    2.29  				// The light source is visible, add scattered light
    2.30 @@ -59,23 +55,21 @@
    2.31  		return radiance;
    2.32  	}
    2.33  
    2.34 -	unsigned int GetRayCount() const { return rays.size(); }
    2.35 +	unsigned int GetRayCount() const { return rayCount; }
    2.36  	const Spectrum &GetEmittedLight() const { return emittedLight; }
    2.37  
    2.38  	friend class SingleScatteringIntegrator;
    2.39  
    2.40  protected:
    2.41  	void Reset() {
    2.42 -		rays.resize(0);
    2.43 -		scatteredLight.resize(0);
    2.44 +		rayCount = 0;
    2.45  		emittedLight = Spectrum();
    2.46  	}
    2.47  
    2.48 -	VolumeIntegrator *vi;
    2.49 -
    2.50 -	vector<Ray> rays;
    2.51 -	vector<unsigned int> currentRayIndex;
    2.52 -	vector<Spectrum> scatteredLight;
    2.53 +	unsigned int rayCount;
    2.54 +	Ray *rays;
    2.55 +	unsigned int *currentRayIndex;
    2.56 +	Spectrum *scatteredLight;
    2.57  	Spectrum emittedLight;
    2.58  
    2.59  };
    2.60 @@ -84,6 +78,9 @@
    2.61  public:
    2.62  	virtual ~VolumeIntegrator() { }
    2.63  
    2.64 +	virtual float GetMaxRayLength() const = 0;
    2.65 +	virtual float GetStepSize() const = 0;
    2.66 +
    2.67  	virtual Spectrum Transmittance(const Ray &ray) const = 0;
    2.68  	virtual void GenerateLiRays(const Scene *scene, Sample *sample,	const Ray &ray,
    2.69  		VolumeComputation *comp) const = 0;
    2.70 @@ -100,6 +97,12 @@
    2.71  		lightEmission = emission;
    2.72  	}
    2.73  
    2.74 +	float GetMaxRayLength() const {
    2.75 +		return Distance(region.pMin, region.pMax);
    2.76 +	}
    2.77 +
    2.78 +	float GetStepSize() const  { return stepSize; }
    2.79 +
    2.80  	Spectrum Transmittance(const Ray &ray) const {
    2.81  		return Exp(-HomogenousTau(ray));
    2.82  	}
     3.1 --- a/scenes/classroom/classroom-hdr-vol.scn	Wed Mar 31 10:47:48 2010 +0200
     3.2 +++ b/scenes/classroom/classroom-hdr-vol.scn	Wed Mar 31 11:17:10 2010 +0200
     3.3 @@ -1,4 +1,4 @@
     3.4 -scene.camera.lookat = -6.078912 0.763888 -0.244332 3.862433 -0.287569 -0.49751
     3.5 +scene.camera.lookat = -6.078912 -1.287569 -0.244332 3.862433 8.763888 -0.49751
     3.6  scene.camera.lensradius = 0.005
     3.7  scene.camera.focaldistance = 4.0
     3.8  scene.materials.matte.chair = 0.56 0.56 0.56
     3.9 @@ -28,11 +28,11 @@
    3.10  scene.infinitelight.file = scenes/simple-mat/sky.exr|scenes/classroom/portal.ply
    3.11  scene.infinitelight.gain = 1.0 1.0 1.0
    3.12  scene.infinitelight.shift = -0.375 0.0
    3.13 -scene.materials.light.sun = 300.0 300.0 300.0
    3.14 +scene.materials.light.sun = 300.0 300.0 220.0
    3.15  scene.objects.sun.sun = scenes/classroom/sun.ply
    3.16  scene.partecipatingmedia.singlescatering.enable = 1
    3.17  scene.partecipatingmedia.singlescatering.bbox = -6.521816 -1.891238 -0.975730  0.208195 2.360468 1.024271
    3.18  scene.partecipatingmedia.singlescatering.stepsize = 4.0
    3.19  scene.partecipatingmedia.singlescatering.absorption = 0.0 0.0 0.0
    3.20 -scene.partecipatingmedia.singlescatering.scattering = 0.85 0.85 0.85
    3.21 +scene.partecipatingmedia.singlescatering.scattering = 1.15 1.15 1.15
    3.22  #scene.partecipatingmedia.singlescatering.emission = 0.01 0.01 0.01
     4.1 --- a/scenes/classroom/render-fast-hdr-vol.cfg	Wed Mar 31 10:47:48 2010 +0200
     4.2 +++ b/scenes/classroom/render-fast-hdr-vol.cfg	Wed Mar 31 11:17:10 2010 +0200
     4.3 @@ -1,11 +1,11 @@
     4.4 -image.width = 640
     4.5 -image.height = 480
     4.6 +image.width = 1280
     4.7 +image.height = 720
     4.8  #image.filename = classroom.exr
     4.9  # Use a value > 0 to enable batch mode
    4.10  batch.halttime = 0
    4.11  scene.file = scenes/classroom/classroom-hdr-vol.scn
    4.12 -scene.fieldofview = 45
    4.13 -opencl.latency.mode = 1
    4.14 +scene.fieldofview = 60
    4.15 +opencl.latency.mode = 0
    4.16  opencl.nativethread.count = 2
    4.17  opencl.cpu.use = 0
    4.18  opencl.gpu.use = 1