Text archives Help
- From: brownlee@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1555 - in trunk: DynLT scenes
- Date: Wed, 25 Jul 2007 02:03:15 -0600 (MDT)
Author: brownlee
Date: Wed Jul 25 02:03:13 2007
New Revision: 1555
Modified:
trunk/DynLT/DynLTCGT.cc
trunk/DynLT/DynLTCGT.h
trunk/DynLT/DynLTGridSpheres.cc
trunk/DynLT/DynLTGridSpheres.h
trunk/DynLT/DynLTParticles.cc
trunk/DynLT/DynLTParticles.h
trunk/DynLT/DynLTWorker.cc
trunk/scenes/dynlt.cc
Log:
dynlt code running with CGT, added a few options for specifying colormap,
etc. Still have a bug when spheres are too large
Modified: trunk/DynLT/DynLTCGT.cc
==============================================================================
--- trunk/DynLT/DynLTCGT.cc (original)
+++ trunk/DynLT/DynLTCGT.cc Wed Jul 25 02:03:13 2007
@@ -7,17 +7,36 @@
DynLTCGT::DynLTCGT(ParticleNRRD& pnrrd, DynLTQueue* queue, float* spheres,
int nspheres, int nvars, int ncells, int depth,
- Real radius, int ridx, RegularColorMap* cmap, int cidx)
- : DynLTGridSpheres(queue, spheres, nspheres, nvars, ncells, depth,
radius, ridx, cmap, cidx)
+ Real radius, int ridx, RegularColorMap* cmap, int cidx, int
textureMode)
+ : DynLTGridSpheres(queue, spheres, nspheres, nvars, ncells, depth,
radius, ridx, cmap, cidx,textureMode)
{
//ParticleNRRD pnrrd(nrrdFile);
- grid = new ParticleGrid(pnrrd, radius, -1, cidx, this);
+ grid = new ParticleGrid(pnrrd, radius, -1, cidx, this, this);
}
void DynLTCGT::intersect(const RenderContext& context,
RayPacket& packet) const
{
- grid->intersect(context, packet);
+ bool common_origin = false;
+ if (packet.end() - packet.begin() < 2)
+ common_origin = true;
+ else
+ {
+ for (int i = packet.begin() + 1; i < packet.end(); i++)
+ common_origin &= (packet.getOrigin(i-1) ==
packet.getOrigin(i));
+ }
+ if (packet.getDepth() > 0)
+ common_origin = false;
+ //test for common origin
+ if (common_origin)
+ {
+ grid->intersect(context, packet);
+ }
+ else
+ // if not common origin, use gridspheres intersection
+ DynLTGridSpheres::intersect(context, packet);
+ //computeNormal(context, packet);
+ //computeTexCoords2(context, packet);
}
void DynLTCGT::preprocess(const PreprocessContext& context)
Modified: trunk/DynLT/DynLTCGT.h
==============================================================================
--- trunk/DynLT/DynLTCGT.h (original)
+++ trunk/DynLT/DynLTCGT.h Wed Jul 25 02:03:13 2007
@@ -19,8 +19,6 @@
using namespace SCIRun;
-#define XRES 16
-#define YRES 16
using namespace std;
namespace Manta {
@@ -31,7 +29,7 @@
virtual void preprocess(const PreprocessContext&);
DynLTCGT(ParticleNRRD& pnrrd, DynLTQueue* queue, float* spheres,
int nspheres, int nvars, int ncells, int depth,
- Real radius, int ridx, RegularColorMap* cmap, int cidx);
+ Real radius, int ridx, RegularColorMap* cmap, int cidx,
int textureMode);
virtual void intersect(const RenderContext& context,
RayPacket& packet) const;
private:
Modified: trunk/DynLT/DynLTGridSpheres.cc
==============================================================================
--- trunk/DynLT/DynLTGridSpheres.cc (original)
+++ trunk/DynLT/DynLTGridSpheres.cc Wed Jul 25 02:03:13 2007
@@ -1,4 +1,5 @@
-
+#include <Interface/ShadowAlgorithm.h>
+#include <Interface/Context.h>
#include <Core/Color/RegularColorMap.h>
#include <DynLT/DynLTContext.h>
#include <DynLT/DynLTGridSpheres.h>
@@ -19,7 +20,7 @@
DynLTGridSpheres::DynLTGridSpheres(DynLTQueue* queue,
float* spheres, int nspheres, int nvars,
int ncells, int depth, Real radius,
- int ridx, RegularColorMap* cmap, int
cidx) :
+ int ridx, RegularColorMap* cmap, int
cidx, int textureModen) :
queue(queue), GridSpheres(spheres, nspheres, nvars, ncells, depth, radius,
ridx, cmap, cidx)
{
@@ -42,9 +43,9 @@
texgen[i]=0;
#endif
}
-
+ textureMode = textureModen;
// XXX: hard coded for now
- textureMode=AmbientOcclusion;
+ // textureMode=AmbientOcclusion;
//textureMode=GlobalIllumination;
}
@@ -95,7 +96,7 @@
for (unsigned int i=sub.begin(); i<sub.end(); ++i) {
Real luminance=computeLuminance(i, sub, particle);
for (int j=0; j < Color::NumComponents; ++j)
- ambient[j][i]=luminance;
+ ambient[j][i]=luminance*luminance*luminance*luminance;
}
} else {
// Request texture generation, if necessary
@@ -152,11 +153,80 @@
i=end;
}
+ //POWERS OF AMBIENCE UNITE! //Carson: 7/24/07
+ //for(int i = rays.begin(); i < rays.end(); i++)
+ // {
+ // float a = ambient[0][i];
+ // ambient[0][i] = ambient[1][i] = ambient[2][i] = a*a*a*a;
+ //}
// Shade the rays
- GridSpheres::lambertianShade(context, rays, ambient);
+ lambertianShadeCD(context, rays, ambient);
+// for(int i = rays.begin(); i < rays.end(); i++)
+// {
+/// float a = ambient[0][i];
+// rays.setColor(i, Color(RGB(1,1,1))*a*a*a*a*a);
+// }
}
+void DynLTGridSpheres::lambertianShadeCD(const RenderContext& context,
RayPacket& rays,
+ ColorArray& totalLight) const
+{
+ ColorArray totalLight1;
+ for(int i = rays.begin(); i < rays.end(); i++)
+ totalLight1[0][i] = totalLight1[1][i] = totalLight1[2][i] = 0;
+ // Compute normals
+ rays.computeNormals(context);
+
+ // Compute colors
+ Packet<Color> diffuse;
+ mapDiffuseColors(diffuse, rays);
+
+ // Normalize directions for proper dot product computation
+ rays.normalizeDirections();
+
+ ShadowAlgorithm::StateBuffer shadowState;
+ do {
+ RayPacketData shadowData;
+ RayPacket shadowRays(shadowData, RayPacket::UnknownShape, 0, 0,
+ rays.getDepth(), 0);
+
+ // Call the shadow algorithm (SA) to generate shadow rays. We may not be
+ // able to compute all of them, so we pass along a buffer for the SA
+ // object to store it's state. The firstTime flag tells the SA to fill
+ // in the state rather than using anything in the state buffer. Most
+ // SAs will only need to store an int or two in the statebuffer.
+ context.shadowAlgorithm->computeShadows(context, shadowState,
activeLights,
+ rays, shadowRays);
+
+ // Normalize directions for proper dot product computation
+ shadowRays.normalizeDirections();
+
+ for (int i=shadowRays.begin(); i < shadowRays.end(); ++i) {
+ if (!shadowRays.wasHit(i)) {
+ // Not in shadow, so compute the direct and specular contributions
+ Vector normal=rays.getNormal(i);
+ Vector shadowdir=shadowRays.getDirection(i);
+ ColorComponent cos_theta=Dot(shadowdir, normal);
+ Color light=shadowRays.getColor(i);
+ for (int j=0; j < Color::NumComponents; ++j)
+ totalLight1[j][i] += light[j]*cos_theta;
+ }
+ }
+ } while(!shadowState.done());
+ //TODO: way to get kd,ka from context?
+ float kd = 0.5;
+ float ka = 0.8;
+ // Sum up diffuse/specular contributions
+ for (int i=rays.begin(); i < rays.end(); ++i) {
+ Color result;
+ for (int j=0;j<Color::NumComponents; ++j)
+
result[j]=totalLight1[j][i]*diffuse.colordata[j][i]*kd*totalLight[j][i]
+totalLight[j][i]*diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+}
+
+
void DynLTGridSpheres::shadeGlobal(const RenderContext& context,
RayPacket& rays) const
{
@@ -190,13 +260,17 @@
ColorArray ambient;
activeLights->getAmbientLight()->computeAmbient(context, rays,
ambient);
#endif
-
+ GridSpheres::shade(context, sub);
for (unsigned int i=sub.begin(); i<sub.end(); ++i) {
#ifdef USE_AMBIENT
Real luminance=computeLuminance(i, sub, particle);
- luminance += 0.3*ambient[0][i] + 0.6*ambient[1][i] +
0.1*ambient[2][i];
-
- sub.setColor(i, diffuse.get(i)*luminance);
+ //luminance = 1.0 - luminance;
+ //luminance *= luminance*luminance*luminance;
+ luminance += ambient[0][i] + 0.6*ambient[1][i] + 0.1*ambient[2][i];
+ //luminance += 0.2;
+ //luminance *= luminance*luminance;
+ //sub.setColor(i, sub.getColor(i)*0.5 +
0.5*sub.getColor(i)*diffuse.get(i)*luminance);
+ sub.setColor(i, diffuse.get(i)*luminance);
#else
Real luminance=computeLuminance(i, sub, particle);
sub.setColor(i, diffuse.get(i)*luminance);
@@ -249,6 +323,7 @@
Real DynLTGridSpheres::computeLuminance(unsigned int ray_idx, RayPacket&
rays,
unsigned int particle) const
{
+ static int particlen = particle;
// Wrap in x (assumes xres is a power of two)
Real x=rays.getTexCoords2(ray_idx, 0)*XRES;
int lx=static_cast<int>(x) & (XRES - 1);
@@ -280,7 +355,7 @@
plts[particle]->texture[hx][ly]*wx);
Real b=(plts[particle]->texture[lx][hy]*(1 - wx) +
plts[particle]->texture[hx][hy]*wx);
-
+// cout << "particle: " << particle << " lx ly " << lx << " " << ly <<
endl;
return a*(1 - wy) + b*wy;
}
Modified: trunk/DynLT/DynLTGridSpheres.h
==============================================================================
--- trunk/DynLT/DynLTGridSpheres.h (original)
+++ trunk/DynLT/DynLTGridSpheres.h Wed Jul 25 02:03:13 2007
@@ -18,8 +18,8 @@
using namespace SCIRun;
-#define XRES 16
-#define YRES 16
+#define XRES 2
+#define YRES 2
namespace Manta {
class DynLTContext;
@@ -51,7 +51,7 @@
DynLTGridSpheres(DynLTQueue* queue, float* spheres,
int nspheres, int nvars, int ncells, int depth,
- Real radius, int ridx, RegularColorMap* cmap, int cidx);
+ Real radius, int ridx, RegularColorMap* cmap, int cidx,
int textureMode);
~DynLTGridSpheres(void);
void shade(const RenderContext& context, RayPacket& rays) const;
@@ -150,6 +150,8 @@
void shadeGlobal(const RenderContext& context, RayPacket& rays) const;
Real computeLuminance(unsigned int ray_idx, RayPacket& rays,
unsigned int particle) const;
+void lambertianShadeCD(const RenderContext& context, RayPacket& rays,
+ ColorArray& totalLight) const;
void invalidateTextures(void)
{
Modified: trunk/DynLT/DynLTParticles.cc
==============================================================================
--- trunk/DynLT/DynLTParticles.cc (original)
+++ trunk/DynLT/DynLTParticles.cc Wed Jul 25 02:03:13 2007
@@ -19,7 +19,7 @@
DynLTParticles::DynLTParticles(const string& filename, int ncells, int depth,
Real radius, int ridx, RegularColorMap* cmap,
- int cidx, DynLTQueue* queue, int min, int
max) :
+ int cidx, DynLTQueue* queue, int min, int
max, int textureMode) :
tstep(0)
{
// Check for a single timestep
@@ -29,7 +29,7 @@
ParticleNRRD pnrrd(filename);
add(new DynLTGridSpheres(queue, pnrrd.getParticleData(),
pnrrd.getNParticles(), pnrrd.getNVars(), ncells,
- depth, radius, ridx, cmap, cidx));
+ depth, radius, ridx, cmap, cidx, textureMode));
return;
}
@@ -55,7 +55,7 @@
ParticleNRRD pnrrd(fname);
add(new DynLTGridSpheres(queue, pnrrd.getParticleData(),
pnrrd.getNParticles(), pnrrd.getNVars(), ncells,
- depth, radius, ridx, cmap, cidx));
+ depth, radius, ridx, cmap, cidx, textureMode));
++nloaded;
}
@@ -66,7 +66,7 @@
//overloaded constructor to use CGT instead of gridspheres
DynLTParticles::DynLTParticles(int type, const string& filename, int ncells,
int depth,
Real radius, int ridx, RegularColorMap* cmap,
- int cidx, DynLTQueue* queue, int min, int
max) :
+ int cidx, DynLTQueue* queue, int min, int
max, int textureMode) :
tstep(0)
{
// Check for a single timestep
@@ -76,7 +76,7 @@
ParticleNRRD pnrrd(filename);
add(new DynLTCGT(pnrrd, queue, pnrrd.getParticleData(),
pnrrd.getNParticles(), pnrrd.getNVars(), ncells,
- depth, radius, ridx, cmap, cidx));
+ depth, radius, ridx, cmap, cidx, textureMode));
return;
}
@@ -102,7 +102,7 @@
ParticleNRRD pnrrd(fname);
add(new DynLTCGT(pnrrd, queue, pnrrd.getParticleData(),
pnrrd.getNParticles(), pnrrd.getNVars(), ncells,
- depth, radius, ridx, cmap, cidx));
+ depth, radius, ridx, cmap, cidx, textureMode));
++nloaded;
}
Modified: trunk/DynLT/DynLTParticles.h
==============================================================================
--- trunk/DynLT/DynLTParticles.h (original)
+++ trunk/DynLT/DynLTParticles.h Wed Jul 25 02:03:13 2007
@@ -18,10 +18,10 @@
public:
DynLTParticles(const string& filename, int ncells, int depth, Real
radius,
int ridx, RegularColorMap* cmap, int cidx, DynLTQueue*
queue,
- int min=0, int max=INT_MAX);
+ int min=0, int max=INT_MAX, int textureMode = 0);
DynLTParticles(int type, const string& filename, int ncells, int depth,
Real radius,
int ridx, RegularColorMap* cmap, int cidx, DynLTQueue*
queue,
- int min=0, int max=INT_MAX);
+ int min=0, int max=INT_MAX, int textureMode = 0);
~DynLTParticles(void);
Modified: trunk/DynLT/DynLTWorker.cc
==============================================================================
--- trunk/DynLT/DynLTWorker.cc (original)
+++ trunk/DynLT/DynLTWorker.cc Wed Jul 25 02:03:13 2007
@@ -385,7 +385,7 @@
}
RayPacketData raydata;
- RayPacket rays(raydata, RayPacket::UnknownShape, 0, size, 0, 0);
+ RayPacket rays(raydata, RayPacket::UnknownShape, 0, size, 1, 0);
// Fill in the hit positions and surface normals at sample points
for (int i=rays.begin(); i<rays.end(); ++i) {
@@ -435,14 +435,14 @@
// We need normalized directions for proper dot product
computation
shadowRays.normalizeDirections();
- for(int i=shadowRays.begin(); i < shadowRays.end(); i++){
+ for(int i=rays.begin(); i < rays.end(); i++){
if(!shadowRays.wasHit(i)){
// Not in shadow, so compute the direct lighting
contributions.
Vector normal = rays.getFFNormal(i);
Vector shadowdir = shadowRays.getDirection(i);
ColorComponent cos_theta = Dot(shadowdir, normal);
Color light = shadowRays.getColor(i);
- diffuse += atten.get(i)*light.luminance()*cos_theta;
+ diffuse += atten.get(i)*light.luminance()*2.0*cos_theta;
}
}
} while(!shadowState.done());
@@ -552,12 +552,12 @@
break;
// Update the ray packet configuration, loop to next depth
- rays.setDepth(rays.getDepth() + 1);
+ //rays.setDepth(rays.getDepth() + 1);
rays.resize(validRays);
}
// Store the result
- dynplt->texture[u][v] += ambient + diffuse;
+ dynplt->texture[u][v] += ambient + diffuse;
}
// Normalize the texel
Modified: trunk/scenes/dynlt.cc
==============================================================================
--- trunk/scenes/dynlt.cc (original)
+++ trunk/scenes/dynlt.cc Wed Jul 25 02:03:13 2007
@@ -65,6 +65,11 @@
double ly=10.;
double lz=10.;
int gridType = 1;
+ string shadeType = "ambient";
+ int shadeTypeInt = DynLTGridSpheres::AmbientOcclusion;
+ string colorMapType = "InvRainbowIso";
+ float kd = 0.5;
+ float ka = 1.0;
int argc=static_cast<int>(args.size());
for(int i=0; i<argc; ++i) {
@@ -162,7 +167,13 @@
} else if (arg=="-gridtype") {
if (!getIntArg(i, args, gridType))
throw IllegalArgument("scene dynlt -gridtype", i, args);
- } else {
+ } else if (arg=="-shadetype") {
+ if (!getStringArg(i, args, shadeType))
+ throw IllegalArgument("scene dynlt -shadetype", i , args);
+ } else if (arg=="-colormap") {
+ if (!getStringArg(i, args, colorMapType))
+ throw IllegalArgument("scene dynlt -colormap", i, args);
+ } else {
cerr<<"Valid options for scene dynlt:\n";
// cerr<<" -bv <string> bounding volume
{bvh|grid|group}\n";
cerr<<" -cidx <int> data value index for
color mapping\n";
@@ -186,8 +197,20 @@
#endif
cerr<<" -timed [<double> [<int> <int>]] texgen thread range and
runtime (in seconds)\n";
cerr<<" -gridtype <int> 1 for default, 2 for CGT";
+ cerr<<" -shadetype <string> type of shading
{ambient|global}\n";
+ cerr<<" -colormap <string> type of colormap,
InvRainbowIso, \
+ InvRainbow, \
+ Rainbow, \
+ InvGreyScale, \
+ InvBlackBody, \
+ BlackBody, \
+ GreyScale\n";
}
}
+ if (shadeType == "ambient")
+ shadeTypeInt = DynLTGridSpheres::AmbientOcclusion;
+ else
+ shadeTypeInt = DynLTGridSpheres::GlobalIllumination;
if (!world)
world=new Group();
@@ -235,7 +258,7 @@
DynLTContext* dpltctx=new DynLTContext(context.manta_interface,
queue, scene, ngroups, nsamples,
max_depth, dilate, bg, runtime,
- minproc, maxproc /*, kd, ka */);
+ minproc, maxproc , kd, ka );
DynLTWorker* worker=new DynLTWorker(dpltctx, 0);
context.manta_interface->registerParallelPreRenderCallback(Callback::create(worker,
&DynLTWorker::timedRun));
@@ -255,7 +278,7 @@
#endif
// Create color map
- unsigned int type=RegularColorMap::parseType("InvRainbowIso");
+ unsigned int type=RegularColorMap::parseType(colorMapType.c_str());
RegularColorMap* cmap=new RegularColorMap(type);
Object* tsteps = NULL;
@@ -263,13 +286,13 @@
{
// Load particle data, add particles to group
tsteps=new DynLTParticles(fname, ncells, depth, radius,
- ridx, cmap, cidx, queue);
+ ridx, cmap, cidx, queue, 0,
INT_MAX, shadeTypeInt);
queue->resizeHeapIdx(((DynLTParticles*)tsteps)->getNParticles(0));
}
else //CGT
{
//TODO: insert CGT grid stuff here
- tsteps = new DynLTParticles(1, fname, ncells, depth, radius, ridx,
cmap, cidx, queue);
+ tsteps = new DynLTParticles(1, fname, ncells, depth, radius, ridx,
cmap, cidx, queue, 0, INT_MAX, shadeTypeInt);
queue->resizeHeapIdx(((DynLTParticles*)tsteps)->getNParticles(0));
}
@@ -278,14 +301,15 @@
scene->setBackground(bg);
else
// scene->setBackground(new ConstantBackground(Color(RGB(0, 0, 0))));
- scene->setBackground(new ConstantBackground(Color(RGB(1, 1, 1))));
+ scene->setBackground(new ConstantBackground(Color(RGB(0.3, 0.3, 0.3))));
scene->setObject(tsteps);
// Add lights
LightSet* lights=new LightSet();
lights->add(new PointLight(Vector(lx, ly, lz), Color(RGB(1, 1, 1))));
-
- lights->setAmbientLight(new ConstantAmbient(Color(RGB(0.4, 0.4, 0.4))));
+ lights->add(new PointLight(Vector(-lx, -ly, -lz),
Color(RGB(.0,0.1,0.9))));
+ lights->add(new
PointLight(Cross(Vector(lx,ly,lz),(Vector(-lx,-ly,-lz))),
Color(RGB(0.5,0.6,0.0))));
+ lights->setAmbientLight(new ConstantAmbient(Color(RGB(0.6, 0.7, 0.8))));
scene->setLights(lights);
// Dissertation --> Figure 6.14
- [MANTA] r1555 - in trunk: DynLT scenes, brownlee, 07/25/2007
Archive powered by MHonArc 2.6.16.