Text archives Help
- From: "Solomon Boulos" <boulos@cs.utah.edu>
- To: manta@sci.utah.edu
- Subject: [Manta] r2168 - in trunk: Engine/PixelSamplers scenes
- Date: Fri, 4 Apr 2008 20:47:35 -0600 (MDT)
Author: boulos
Date: Fri Apr 4 20:47:34 2008
New Revision: 2168
Modified:
trunk/Engine/PixelSamplers/ClusterSampler.cc
trunk/scenes/triangleSceneViewer.cc
Log:
Engine/PixelSamplers/ClusterSampler.cc
Up min_shading_samples to 16 for now.
Add the ability to use the UniformRandomGenerator for comparison.
Since this is a per pixel method, sample_count is always the sample_id.
Bugfix: need to call setAllFlags before shooting the rays again.
CleanFix: counts are ints not bools.
CleanFix: Separate avgPrimColor from final color calculation.
Add an efficiency metric and a debugging case of just averaging the
shading rays results.
scenes/triangleSceneViewer.cc
A a simple phong overload material too.
Modified: trunk/Engine/PixelSamplers/ClusterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/ClusterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/ClusterSampler.cc Fri Apr 4 20:47:34
2008
@@ -5,6 +5,7 @@
#include <Core/Util/Args.h>
#include <Engine/PixelSamplers/ClusterSampler.h>
#include <Engine/SampleGenerators/Stratified2D.h>
+#include <Engine/SampleGenerators/UniformRandomGenerator.h>
#include <Interface/Camera.h>
#include <Interface/Context.h>
#include <Interface/Fragment.h>
@@ -44,13 +45,16 @@
// Compute nx and ny
findFactorsNearRoot(num_samples, nx, ny);
- min_shading_samples = 4;
+ min_shading_samples = 16;
maxSqrt = Ceil(Sqrt(static_cast<Real>(num_samples)));
+ //cerr << "maxSqrt = " << maxSqrt;
antialiasGenerator = new Stratified2D(num_samples);
+ //antialiasGenerator = new UniformRandomGenerator();
sampleGenerators = new SampleGenerator*[maxSqrt];
for (int i = 0; i < maxSqrt; i++) {
int samples = (i+1) * (i+1);
sampleGenerators[i] = new Stratified2D(samples);
+ //sampleGenerators[i] = new UniformRandomGenerator();
}
}
@@ -137,8 +141,8 @@
// NOTE(boulos): Setup region_id first
int sample_count = 0;
for(int xs = 0; xs < nx; xs++) {
- for(int ys = 0; ys < ny; ys++) {
- rays.data->sample_id[sample_count] = xs * ny + ys;
+ for(int ys = 0; ys < ny; ys++) {
+ rays.data->sample_id[sample_count] = sample_count;
rays.data->region_id[sample_count] = pixel_id;
sample_count++;
}
@@ -153,7 +157,7 @@
sample_count = 0;
for(int xs = 0; xs < nx; xs++) {
- for(int ys = 0; ys < ny; ys++) {
+ for(int ys = 0; ys < ny; ys++) {
Real x_sample = (xs + r1.get(sample_count)) * inx;
Real y_sample = (ys + r2.get(sample_count)) * iny;
px = (fx+x_sample)*ci.xscale+ci.xoffset;
@@ -163,13 +167,12 @@
}
}
- rays.resize(sample_count);
-
// Copied from rayTracer traceEyeRays
context.camera->makeRays(context, rays);
rays.initializeImportance();
rays.resetHits();
+ rays.setAllFlags(flags);
context.scene->getObject()->intersect(context, rays);
// Build clusters and determine how many shading rays are needed.
@@ -180,7 +183,7 @@
const Primitive* prims[RayPacket::MaxSize];
bzero(visited, sizeof(bool) * RayPacket::MaxSize);
- bzero(counts, sizeof(bool) * RayPacket::MaxSize);
+ bzero(counts, sizeof(int) * RayPacket::MaxSize);
for (int i = rays.begin(); i < rays.end(); i++) {
if (visited[i]) continue;
@@ -209,9 +212,9 @@
sample_count = 0;
// Again setup the region id first.
for(int xs = 0; xs < sqrtRays; xs++) {
- for(int ys = 0; ys < sqrtRays; ys++) {
- shading_rays.data->sample_id[sample_count] = xs * sqrtRays + ys;
- rays.data->region_id[sample_count] = pixel_id;
+ for(int ys = 0; ys < sqrtRays; ys++) {
+ shading_rays.data->sample_id[sample_count] = sample_count;
+ shading_rays.data->region_id[sample_count] = pixel_id;
sample_count++;
}
}
@@ -223,7 +226,7 @@
Real inv_sqrt = 1.f/static_cast<Real>(sqrtRays);
sample_count = 0;
for(int xs = 0; xs < sqrtRays; xs++) {
- for(int ys = 0; ys < sqrtRays; ys++) {
+ for(int ys = 0; ys < sqrtRays; ys++) {
Real x_sample = (xs + r1.get(sample_count)) * inv_sqrt;
Real y_sample = (ys + r2.get(sample_count)) * inv_sqrt;
px = (fx+x_sample)*ci.xscale+ci.xoffset;
@@ -232,6 +235,8 @@
sample_count++;
}
}
+ shading_rays.resetHits();
+ shading_rays.setAllFlags(flags);
context.renderer->traceEyeRays(context, shading_rays);
// Now the results of our shading_rays have come back, determine
@@ -258,13 +263,25 @@
// Go through all the unique prims and determine the average
// shading results
Color final_color = Color::black();
-
+#if 1
for (int i = 0; i < uniquePrims; i++) {
if (shade_counts[i]) {
- final_color += (primColor[i] * counts[i] * inv_samples /
static_cast<Real>(shade_counts[i]));
+ Color avgPrimColor = primColor[i] /
static_cast<Real>(shade_counts[i]);
+ final_color += avgPrimColor * (counts[i] * inv_samples);
}
-
}
+#else
+#if 0
+ // Efficiency metric
+ fragment.setColor(frag_index, Color::white() *
static_cast<Real>(realNumRays)/static_cast<Real>(num_samples));
+#else
+ // Just the result from the shading rays
+ for (int i = shading_rays.begin(); i < shading_rays.end(); i++) {
+ final_color += shading_rays.getColor(i);
+ }
+ final_color *= (inv_sqrt * inv_sqrt);
+#endif
+#endif
fragment.setColor(frag_index, final_color);
}
mutable_context.sample_generator = original_samplegen;
Modified: trunk/scenes/triangleSceneViewer.cc
==============================================================================
--- trunk/scenes/triangleSceneViewer.cc (original)
+++ trunk/scenes/triangleSceneViewer.cc Fri Apr 4 20:47:34 2008
@@ -16,6 +16,7 @@
#include <Model/Groups/RecursiveGrid.h>
#include <Model/Materials/Flat.h>
#include <Model/Materials/Lambertian.h>
+#include <Model/Materials/Phong.h>
#include <Model/Lights/PointLight.h>
#include <Model/Lights/AreaLight.h>
#include <Model/MiscObjects/KeyFrameAnimation.h>
@@ -162,6 +163,10 @@
matlName == "lambertian" ||
matlName == "diffuse") {
overrideMatl = new Lambertian(Color::white() * 0.8);
+ } else if (matlName == "phong") {
+ overrideMatl = new Phong(Color::white() * 0.8,
+ Color::white(),
+ 32, 1.f);
} else {
throw IllegalArgument("scene triangleSceneViewer -overrideMatl
unknown material", i, args);
}
- [Manta] r2168 - in trunk: Engine/PixelSamplers scenes, Solomon Boulos, 04/04/2008
Archive powered by MHonArc 2.6.16.