Text archives Help
- From: "Thiago Ize" <thiago@sci.utah.edu>
- To: manta@sci.utah.edu
- Subject: [Manta] r2055 - in trunk: Core/Math Engine/Shadows Interface Model/Readers scenes
- Date: Tue, 12 Feb 2008 18:03:26 -0700 (MST)
Author: thiago
Date: Tue Feb 12 18:03:25 2008
New Revision: 2055
Modified:
trunk/Core/Math/CheapRNG.h
trunk/Core/Math/MT_RNG.cc
trunk/Core/Math/MT_RNG.h
trunk/Engine/Shadows/HardShadows.cc
trunk/Interface/RandomNumberGenerator.h
trunk/Model/Readers/PlyReader.cc
trunk/scenes/triangleSceneViewer.cc
Log:
scenes/triangleSceneViewer.cc:
-The interpolate normals option requires that useFaceNormals not be
set. Requiring it, as it was before, makes no sense.
-LoadModel now also takes a material. This is useful if you want to
use your own material when loading a model. Of course, you would
still need to modify the actual scene code to load your
material. But hopefully this makes it easier.
-Added a #ifdef'ed out area light. If that becomes popular, that can
be made into an option (I'm guessing it will).
Core/Math/MT_RNG.cc:
-Made the seed function several times faster.
Core/Math/MT_RNG.h
Core/Math/CheapRNG.h:
-Made member functions non-virtual. The idea being that some
compilers might still be making virtual function calls even when
it's not needed. Since these classes will never be derived from,
this should be fine.
Model/Readers/PlyReader.cc:
-Removed a compiler warning. Also replaced tabs with spaces.
Interface/RandomNumberGenerator.h:
-left a comment saying that nextFloat should be inlined. Doing so
makes the cornell scene 1.25x faster in my tests. Only reason not
to is that it might break some derived random number generators,
such as KorobovRNG.
Engine/Shadows/HardShadows.cc:
-Fixed a bug where invalid rays were not being set to valid
values. This caused some ray packets to appear to not be in shadow.
Modified: trunk/Core/Math/CheapRNG.h
==============================================================================
--- trunk/Core/Math/CheapRNG.h (original)
+++ trunk/Core/Math/CheapRNG.h Tue Feb 12 18:03:25 2008
@@ -84,7 +84,7 @@
rng->seed(0);
}
- virtual void seed(unsigned int seed_val) {
+ void seed(unsigned int seed_val) {
val = seed_val;
#ifdef MANTA_SSE
// TODO(boulos): Find a better way to seed this. Normally you
@@ -98,12 +98,12 @@
#endif
}
- virtual unsigned int nextInt() {
+ unsigned int nextInt() {
val = 1664525*val + 1013904223;
return val;
}
- virtual void nextIntPacket(Packet<unsigned int>& results, RayPacket&
rays) {
+ void nextIntPacket(Packet<unsigned int>& results, RayPacket& rays) {
#ifdef MANTA_SSE
for (int i = 0; i < Packet<unsigned int>::MaxSize; i+=4) {
val_sse = _mm_add_epi32(_mm_set_epi32(2531011, 10395331, 13737667,
1),
Modified: trunk/Core/Math/MT_RNG.cc
==============================================================================
--- trunk/Core/Math/MT_RNG.cc (original)
+++ trunk/Core/Math/MT_RNG.cc Tue Feb 12 18:03:25 2008
@@ -30,6 +30,8 @@
#include <stdio.h> // used only for test_print
#include <Core/Math/MT_RNG.h>
+#include <MantaSSE.h>
+#include <Core/Math/SSEDefs.h>
using namespace Manta;
@@ -54,9 +56,25 @@
/* the generator Line 25 of Table 1 in */
/* [KNUTH 1981, The Art of Computer Programming */
/* Vol. 2 (2nd Ed.), pp102] */
- mt[0]= seed;
- for (mti=1; mti<MT_RNG_N; mti++)
- mt[mti] = (69069 * mt[mti-1]);
+
+ //To speed things up, we manually unroll 4 times. MT_RNG_N is
+ //divisable by 4, so this is ok.
+ ASSERT(MT_RNG_N/4 == 0);
+
+ mt[0] = seed;
+ mt[1] = 69069*seed;
+ mt[2] = 69069*69069*seed;
+ mt[3] = 69069*69069*69069*seed;
+
+ //Note: writing this loop in sse with _mm_mullo_epi32 actually ends up
+ //being 2x slower than the non-sse version below because the
+ //_mm_mullo_epi32 instruction becomes many assembly instructions.
+ for (mti=4; mti<MT_RNG_N; mti+=4) {
+ mt[mti] = (69069*69069*69069*69069) * mt[mti-4];
+ mt[mti+1] = (69069*69069*69069*69069) * mt[mti-3];
+ mt[mti+2] = (69069*69069*69069*69069) * mt[mti-2];
+ mt[mti+3] = (69069*69069*69069*69069) * mt[mti-1];
+ }
}
unsigned int MT_RNG::nextInt()
Modified: trunk/Core/Math/MT_RNG.h
==============================================================================
--- trunk/Core/Math/MT_RNG.h (original)
+++ trunk/Core/Math/MT_RNG.h Tue Feb 12 18:03:25 2008
@@ -48,7 +48,7 @@
MT_RNG(): mti(MT_RNG_N+1) {}
static void create(RandomNumberGenerator*& rng ) { rng = new MT_RNG(); }
void seed(unsigned int seed);
- virtual unsigned int nextInt();
+ unsigned int nextInt();
void test_print(); // prints some random numbers to the console
};
Modified: trunk/Engine/Shadows/HardShadows.cc
==============================================================================
--- trunk/Engine/Shadows/HardShadows.cc (original)
+++ trunk/Engine/Shadows/HardShadows.cc Tue Feb 12 18:03:25 2008
@@ -156,6 +156,19 @@
sse_t validOx=set4(0), validOy=set4(0), validOz=set4(0);
sse_t validDx=set4(0), validDy=set4(0), validDz=set4(0);
sse_t validTimes=set4(0);
+
+ if (first >= 0) {
+ validOx = set4(shadowData->origin[0][first]);
+ validOy = set4(shadowData->origin[1][first]);
+ validOz = set4(shadowData->origin[2][first]);
+
+ validDx = set4(shadowData->direction[0][first]);
+ validDy = set4(shadowData->direction[0][first]);
+ validDz = set4(shadowData->direction[0][first]);
+
+ validTimes = set4(shadowData->time[first]);
+ }
+
int firstSSE = first;
for(;i<e;i+=4){
__m128 normalx = _mm_load_ps(&sourceData->ffnormal[0][i]);
Modified: trunk/Interface/RandomNumberGenerator.h
==============================================================================
--- trunk/Interface/RandomNumberGenerator.h (original)
+++ trunk/Interface/RandomNumberGenerator.h Tue Feb 12 18:03:25 2008
@@ -111,6 +111,8 @@
return ( (double)nextInt() * (1./4294967296.) );
}
+ //TODO (thiago): Figure out how to inline this so that the HUGE
+ //calling overhead can dissapear.
virtual float nextFloat() {
return ( (float)nextInt() * (float)((1./4294967296.)) );
}
Modified: trunk/Model/Readers/PlyReader.cc
==============================================================================
--- trunk/Model/Readers/PlyReader.cc (original)
+++ trunk/Model/Readers/PlyReader.cc Tue Feb 12 18:03:25 2008
@@ -47,22 +47,22 @@
long vertexIndex;
ply_get_argument_element(argument, NULL, &vertexIndex);
- if (vertexIndex + vertices_start == mesh->vertices.size()+1) {
- addVertex(mesh);
+ if (static_cast<unsigned long>(vertexIndex) + vertices_start ==
mesh->vertices.size()+1) {
+ addVertex(mesh);
}
if (strcmp(name, "x") == 0)
- vertexData.point[0] = ply_get_argument_value(argument);
+ vertexData.point[0] = ply_get_argument_value(argument);
else if (strcmp(name, "y") == 0)
- vertexData.point[1] = ply_get_argument_value(argument);
+ vertexData.point[1] = ply_get_argument_value(argument);
else if (strcmp(name, "z") == 0)
- vertexData.point[2] = ply_get_argument_value(argument);
+ vertexData.point[2] = ply_get_argument_value(argument);
else if (strcmp(name, "diffuse_red") == 0)
- vertexData.color.setR(ply_get_argument_value(argument) /
maxColorValue);
+ vertexData.color.setR(ply_get_argument_value(argument) /
maxColorValue);
else if (strcmp(name, "diffuse_green") == 0)
- vertexData.color.setG(ply_get_argument_value(argument) /
maxColorValue);
+ vertexData.color.setG(ply_get_argument_value(argument) /
maxColorValue);
else if (strcmp(name, "diffuse_blue") == 0)
- vertexData.color.setB(ply_get_argument_value(argument) /
maxColorValue);
+ vertexData.color.setB(ply_get_argument_value(argument) /
maxColorValue);
return 1;
}
@@ -87,7 +87,7 @@
//do this once only to add last vertex.
if (polyIndex == 0 && polyVertex == -1) {
- addVertex(data->mesh);
+ addVertex(data->mesh);
}
currVertexIndex = static_cast<int>(ply_get_argument_value(argument));
@@ -118,13 +118,13 @@
}
if (coloredTriangleMode) {
//TODO: handle colored triangles.
-// group->add(new VertexColoredTriangle(mat,
-// vertices[firstVertexIndex].point,
-// vertices[prevVertexIndex].point,
-// vertices[currVertexIndex].point,
-//
Color(vertices[firstVertexIndex].color),
-// Color(vertices[prevVertexIndex].color),
-//
Color(vertices[currVertexIndex].color)));
+// group->add(new VertexColoredTriangle(mat,
+// vertices[firstVertexIndex].point,
+// vertices[prevVertexIndex].point,
+// vertices[currVertexIndex].point,
+// Color(vertices[firstVertexIndex].color),
+// Color(vertices[prevVertexIndex].color),
+// Color(vertices[currVertexIndex].color)));
}
prevVertexIndex = currVertexIndex;
break;
@@ -157,12 +157,12 @@
if (!ply_read_header(ply)) return false;
nVertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb,
- mesh, 0);
+ mesh, 0);
ply_set_read_cb(ply, "vertex", "y", vertex_cb,
- mesh, 0);
+ mesh, 0);
ply_set_read_cb(ply, "vertex", "z", vertex_cb,
- mesh, 0);
+ mesh, 0);
//get vertex color property
p_ply_property property;
@@ -171,11 +171,11 @@
property = ply_find_property(ply_find_element(ply, "vertex"),
"diffuse_red");
ply_set_read_cb(ply, "vertex", "diffuse_red", vertex_cb,
- mesh, 0);
+ mesh, 0);
ply_set_read_cb(ply, "vertex", "diffuse_blue", vertex_cb,
- mesh, 0);
+ mesh, 0);
ply_set_read_cb(ply, "vertex", "diffuse_green", vertex_cb,
- mesh, 0);
+ mesh, 0);
/*if we add other color types, need to try getting their property
@@ -190,7 +190,7 @@
/*
//TODO: we might not want to overwrite the matl passed in to us...
defaultMaterial = new Lambertian(new TriVerTexture());
- coloredTriangleMode = true;
+ coloredTriangleMode = true;
e_ply_type type;
ply_get_property_info(property, NULL, &type, NULL, NULL);
if (type)
@@ -203,7 +203,7 @@
case PLY_UCHAR: maxColorValue=511;
break;
case PLY_DOUBLE:
- case PLY_FLOAT: maxColorValue=1;
+ case PLY_FLOAT: maxColorValue=1;
break;
default: maxColorValue=1; //shouldn't get here. Need to
//add case for this new type
@@ -222,9 +222,9 @@
if (defaultMaterial)
{ } //do nothing
else if (m)
- defaultMaterial = m;
+ defaultMaterial = m;
else
- defaultMaterial = new Lambertian(Color(RGBColor(1,1,1)));
+ defaultMaterial = new Lambertian(Color(RGBColor(1,1,1)));
mesh->materials.push_back(defaultMaterial);
Modified: trunk/scenes/triangleSceneViewer.cc
==============================================================================
--- trunk/scenes/triangleSceneViewer.cc (original)
+++ trunk/scenes/triangleSceneViewer.cc Tue Feb 12 18:03:25 2008
@@ -5,6 +5,7 @@
#include <Core/Util/Preprocessor.h>
#include <Interface/LightSet.h>
#include <Interface/Scene.h>
+#include <Interface/Context.h>
#include <Model/AmbientLights/ArcAmbient.h>
#include <Model/Backgrounds/ConstantBackground.h>
#include <Model/Backgrounds/LinearBackground.h>
@@ -12,8 +13,11 @@
#include <Model/Groups/Group.h>
#include <Model/Groups/KDTree.h>
#include <Model/Groups/ObjGroup.h>
+#include <Model/Materials/Lambertian.h>
#include <Model/Lights/PointLight.h>
+#include <Model/Lights/AreaLight.h>
#include <Model/MiscObjects/KeyFrameAnimation.h>
+#include <Model/Primitives/Parallelogram.h>
#include <Model/Readers/PlyReader.h>
#include <Model/Textures/Constant.h>
#include <Core/Math/MinMax.h>
@@ -52,11 +56,13 @@
throw IllegalArgument("scene primtest", i, args);
}
-Mesh* LoadModel(std::string modelName, MeshTriangle::TriangleType
triangleType, bool useFaceNormals, bool interpolateNormals ) {
+Mesh* LoadModel(std::string modelName, Material *matl,
+ MeshTriangle::TriangleType triangleType, bool useFaceNormals,
+ bool interpolateNormals ) {
Mesh* frame = NULL;
if (!strncmp(modelName.c_str()+modelName.length()-4, ".ply", 4)) {
frame = new Mesh;
- if (!readPlyFile(modelName, AffineTransform::createIdentity(), frame, 0,
triangleType))
+ if (!readPlyFile(modelName, AffineTransform::createIdentity(), frame,
matl, triangleType))
printf("error loading or reading ply file: %s\n", modelName.c_str());
}
else if (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
@@ -68,12 +74,14 @@
// the mesh and then if you ask it to build smooth normals, it does
// so (but only if they're not there already). It seems like we
// should throw some errors for some of these combinations...
+ // NOTE(thiago): calling useFaceNormals and interpolateNormals at the
+ // same time is the only contradictory option.
if (useFaceNormals) {
frame->discardVertexNormals();
-
- if (interpolateNormals && !frame->hasVertexNormals())
- frame->interpolateNormals();
}
+ if (interpolateNormals && !frame->hasVertexNormals())
+ frame->interpolateNormals();
+
return frame;
}
@@ -164,7 +172,8 @@
for (size_t i=0; i < fileNames.size(); ++i) {
modelName = fileNames[i];
cout << "loading " << modelName <<endl;
- Mesh* frame = LoadModel(modelName, triangleType, useFaceNormals,
interpolateNormals);
+ Mesh* frame = LoadModel(modelName, NULL, triangleType,
+ useFaceNormals, interpolateNormals);
animation->push_back(frame);
}
@@ -173,7 +182,8 @@
} else {
// If we're just a single mesh, load it directly instead of using
// the animation class.
- Mesh* singleFrame = LoadModel(fileNames[0], triangleType,
useFaceNormals, interpolateNormals);
+ Mesh* singleFrame = LoadModel(fileNames[0], NULL, triangleType,
+ useFaceNormals, interpolateNormals);
as->setGroup(singleFrame);
as->rebuild();
group->add(as);
@@ -188,9 +198,27 @@
scene->setObject(group);
LightSet* lights = new LightSet();
- lights->add(new PointLight(Vector(900,400,100), Color(RGB(1,1,1))*1));
- Color cup(RGB(0.3, 0.3, 0.3));
- Color cdown(RGB(0.62, 0.62, 0.62));
+ BBox bbox;
+ PreprocessContext dummyContext;
+ group->computeBounds(dummyContext, bbox);
+ Vector lightOrigin = bbox[1] + bbox.diagonal()*.3;
+#if 0
+ Color area_light_color = Color(RGB(1,1,1))*20;
+ Real areaLightDim = bbox.diagonal().length()*.30;
+
+ Parallelogram* area_light_geometry =
+ new Parallelogram(new Lambertian(area_light_color),
+ lightOrigin, Vector(areaLightDim,0,0),
+ Vector(0,0,areaLightDim));
+// group->add(area_light_geometry);
+
+ lights->add(new AreaLight(area_light_geometry, area_light_color));
+#else
+ lights->add(new PointLight(lightOrigin, Color(RGB(1,1,1))*1));
+#endif
+
+ Color cup(RGB(0.2, 0.2, 0.2));
+ Color cdown(RGB(0.1, 0.1, 0.1));
Vector up(0,1,0);
lights->setAmbientLight(new ArcAmbient(cup, cdown, up));
scene->setLights(lights);
- [Manta] r2055 - in trunk: Core/Math Engine/Shadows Interface Model/Readers scenes, Thiago Ize, 02/12/2008
Archive powered by MHonArc 2.6.16.