Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r461 - in branches/itanium2: Core/Color Engine/Control Interface Model/Cameras Model/Materials


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r461 - in branches/itanium2: Core/Color Engine/Control Interface Model/Cameras Model/Materials
  • Date: Sat, 30 Jul 2005 17:24:16 -0600 (MDT)

Author: boulos
Date: Sat Jul 30 17:24:15 2005
New Revision: 461

Modified:
   branches/itanium2/Core/Color/ColorSpace.h
   branches/itanium2/Engine/Control/RTRT.cc
   branches/itanium2/Interface/RayPacket.h
   branches/itanium2/Interface/RenderParameters.h
   branches/itanium2/Model/Cameras/PinholeCamera.cc
   branches/itanium2/Model/Materials/Dielectric.cc
Log:
Adding Color.Mean to ColorSpaces (for use with
ray-tree pruning to determine importance).

Dielectric now implements ray-tree pruning and 
kills rays when they have less importance than
.01.  Pinhole Camera also initializes rays with
an importance of 1.0, which should be done in
all code that generates rays that will be shaded.

The default max_depth (RenderParameters.h) is 
now 15.

The default thread stack size (RTRT.cc) is now
8MB to accomodate deeper ray trees.


Modified: branches/itanium2/Core/Color/ColorSpace.h
==============================================================================
--- branches/itanium2/Core/Color/ColorSpace.h   (original)
+++ branches/itanium2/Core/Color/ColorSpace.h   Sat Jul 30 17:24:15 2005
@@ -146,6 +146,14 @@
       return *this;
     }
 
+      double Mean() const
+      {
+          double sum = 0.0;
+          for (int i = 0; i < NumComponents; i++)
+              sum += (double)data[i];
+          return sum*(1./double(NumComponents));
+      }
+
     // Apply functor
     ColorSpace<Traits> attenuate(ComponentType scale) const {
       using SCIRun::Exp;

Modified: branches/itanium2/Engine/Control/RTRT.cc
==============================================================================
--- branches/itanium2/Engine/Control/RTRT.cc    (original)
+++ branches/itanium2/Engine/Control/RTRT.cc    Sat Jul 30 17:24:15 2005
@@ -49,7 +49,7 @@
 using SCIRun::Time;
 using SCIRun::split_string;
 
-#define RENDER_THREAD_STACKSIZE 1024*1024
+#define RENDER_THREAD_STACKSIZE 8*1024*1024
 
 namespace Manta {
   RTRTInterface* createRTRT()
@@ -58,7 +58,7 @@
 }
 
 bool bool_or(const bool& b1, const bool& b2) {
-       return b1 || b2;
+        return b1 || b2;
 }
 void registerKnownComponents(RTRTInterface* rtrt);
 }
@@ -95,7 +95,7 @@
     Channel* channel = *iter;
     delete channel->display;
     for(vector<Image*>::iterator iter = channel->images.begin();
-                               iter != channel->images.end(); iter++)
+                                iter != channel->images.end(); iter++)
       delete *iter;
   }
   delete currentImageTraverser;
@@ -108,7 +108,7 @@
 {
   if(newNumWorkers <= 0)
     throw IllegalValue<int>("RTRT::changeNumWorkers, number of workers 
should be > 0", newNumWorkers);
-       
+
   workersWanted=newNumWorkers;
 }
 
@@ -118,7 +118,7 @@
 }
 
 void RTRT::addOneShotCallback(Whence whence, long frame,
-                                                                             
                                          CallbackBase_2Data<int, int>* 
callback)
+                                                                             
                                           CallbackBase_2Data<int, int>* 
callback)
 {
 #if NOTFINISHED
   // What about adding callbacks during anim cycle?
@@ -166,33 +166,33 @@
     throw InvalidState("renderLoop started while it is already running", 
__FILE__, __LINE__ );
   running=true;
   runningLock.unlock();
-       
+
   // Preprocess
   LightSet* lights = scene->getLights();
   PreprocessContext context(this, lights);
   lights->preprocess(context);
   scene->getBackground()->preprocess(context);
   scene->getObject()->preprocess(context);
-       
+
   if(!currentImageCreator)
     throw InvalidState("Image type was not selected", __FILE__, __LINE__ );
-       
+
 #if NOTFINISHED
   check for existence of other components;
 #endif
-               
-               if(workersWanted <= 0){
-                       runningLock.unlock();
-                       throw IllegalValue<int>("workersWanted should be 
positive", workersWanted);
-               }
-       
+
+                if(workersWanted <= 0){
+                        runningLock.unlock();
+                        throw IllegalValue<int>("workersWanted should be 
positive", workersWanted);
+                }
+
   if(workersRendering != 0){
     runningLock.unlock();
     throw IllegalValue<int>("workersRendering should be zero", 
workersRendering);
   }
-       
+
   workersRendering=workersWanted;
-       
+
   // Start up all of the Worker threads.
   workers.resize(workersWanted);
   changedFlags.resize(workersWanted);
@@ -201,7 +201,7 @@
       ostringstream name;
       name << "RTRT Worker " << i;
       Thread* t = new Thread(new Worker(this, i, false), name.str().c_str(),
-                                                                             
                                   0, Thread::NotActivated);
+                                                                             
                                    0, Thread::NotActivated);
       t->setStackSize(RENDER_THREAD_STACKSIZE);
       t->activate(false);
       workers[i] = t;
@@ -231,30 +231,30 @@
     if(proc == 0){
       animFrameState.frameNumber++;
       switch(timeMode){
-                               case RealTime:
-                                       animFrameState.frameTime = 
Time::currentSeconds() * timeScale;
-                                       break;
-                               case FixedRate:
-                                       animFrameState.frameTime = 
static_cast<double>(animFrameState.frameNumber) / frameRate;
-                                       break;
-                               case Static:
-                                       break;
+                                case RealTime:
+                                        animFrameState.frameTime = 
Time::currentSeconds() * timeScale;
+                                        break;
+                                case FixedRate:
+                                        animFrameState.frameTime = 
static_cast<double>(animFrameState.frameNumber) / frameRate;
+                                        break;
+                                case Static:
+                                        break;
       }
-      
+
       // Update the number of workers to be used for the animation and
       // image display portion
       workersAnimAndImage = workersRendering;
     }
-               
+
     // Start of non-rendering portion of the loop. Make callbacks
     // that could possibly change state and get everything set up to
     // render the next frame
     barrier1.wait(workersRendering);
-               
+
     // Copy over the frame state
     if(proc == 0)
       renderFrameState = animFrameState;
-               
+
     // Do callbacks
     changed=false;
     //callbackLock.readLock();
@@ -262,56 +262,56 @@
     doSerialAnimationCallbacks(changed, proc, workersAnimAndImage);
     if(proc == 0)
       postTransactions(changed);
-               
+
     if(!firstFrame){
       for(int index = 0;index < static_cast<int>(channels.size());index++){
-                               Channel* channel = channels[index];
-                               RenderContext myContext(this, index, proc, 
workersAnimAndImage,
-                                                                             
                                                  &animFrameState,
-                                                                             
                                                  currentLoadBalancer, 
currentPixelSampler,
-                                                                             
                                                  currentRenderer, 
currentShadowAlgorithm,
-                                                                             
                                                  channel->camera, scene);
-                               currentImageTraverser->setupFrame(myContext);
+                                Channel* channel = channels[index];
+                                RenderContext myContext(this, index, proc, 
workersAnimAndImage,
+                                                                             
                                                   &animFrameState,
+                                                                             
                                                   currentLoadBalancer, 
currentPixelSampler,
+                                                                             
                                                   currentRenderer, 
currentShadowAlgorithm,
+                                                                             
                                                   channel->camera, scene);
+                                currentImageTraverser->setupFrame(myContext);
       }
     }
     //callbackLock.readUnlock();
-               
+
     // P0 resize images for next frame
     if(proc == 0)
       resizeImages(animFrameState.frameNumber);
-               
+
     // Update the number of workers to be used for the rendering of this 
frame
     if(proc == 0){
       // Copy the number out of memory - we want to read it only once
       // in case it changes
       int newWorkers = workersWanted;
       if(newWorkers > workersRendering){
-                               // We must start new threads, if the number 
increased.  Mark
-                               // these threads as "latecomers", which will 
skip to the rendering
-                               // section of this loop for the first frame
-                               workersChanged = true;
-                               workers.resize(newWorkers);
-                               int oldworkers = workersRendering;
-                               workersRendering = workersWanted;
-                               for(int i=oldworkers;i<newWorkers;i++){
-                                       ostringstream name;
-                                       name << "RTRT Worker " << i;
-                                       workers[i] = new Thread(new 
Worker(this, i, true), name.str().c_str(),
-                                                                             
                                                          0, 
Thread::NotActivated);
-                                       
workers[i]->setStackSize(RENDER_THREAD_STACKSIZE);
-                                       workers[i]->activate(false);
-                               }
+                                // We must start new threads, if the number 
increased.  Mark
+                                // these threads as "latecomers", which will 
skip to the rendering
+                                // section of this loop for the first frame
+                                workersChanged = true;
+                                workers.resize(newWorkers);
+                                int oldworkers = workersRendering;
+                                workersRendering = workersWanted;
+                                for(int i=oldworkers;i<newWorkers;i++){
+                                        ostringstream name;
+                                        name << "RTRT Worker " << i;
+                                        workers[i] = new Thread(new 
Worker(this, i, true), name.str().c_str(),
+                                                                             
                                                           0, 
Thread::NotActivated);
+                                        
workers[i]->setStackSize(RENDER_THREAD_STACKSIZE);
+                                        workers[i]->activate(false);
+                                }
       } else if(newWorkers < workersRendering) {
-                               workersChanged = true;
-                               workersRendering = workersWanted;
+                                workersChanged = true;
+                                workersRendering = workersWanted;
       } else {
-                               // Don't set it to false if it is already 
false - avoids
-                               // flushing the other caches
-                               if(workersChanged)
-                                       workersChanged = false;
+                                // Don't set it to false if it is already 
false - avoids
+                                // flushing the other caches
+                                if(workersChanged)
+                                        workersChanged = false;
       }
     }
-               
+
     // New scope to control variable lifetimes
     {
       // Reduce on changed flag
@@ -322,102 +322,102 @@
       barrier2.wait(numProcs);
       changed=false;
       for(int i=0;i<numProcs;i++){
-                               if(changedFlags[i].changed){
-                                       changed=true;
-                                       break;
-                               }
+                                if(changedFlags[i].changed){
+                                        changed=true;
+                                        break;
+                                }
       }
-                       
+
       if(changed != lastChanged || firstFrame){
         if(proc == 0)
           doIdleModeCallbacks(changed, firstFrame, pipelineNeedsSetup,
                               proc, numProcs);
-                               barrier2.wait(numProcs);
+                                barrier2.wait(numProcs);
         lastChanged = changed;
       }
       if(firstFrame)
         firstFrame=false;
-      
+
       // P0 process deletions
       if(proc == 0){
-                               //callbackLock.readLock();
-                               processDeletions();
-                               //callbackLock.readUnlock();
+                                //callbackLock.readLock();
+                                processDeletions();
+                                //callbackLock.readUnlock();
       }
-                       
+
       if(pipelineNeedsSetup){
-                               // Negotiate the image pipeline for each 
channel
-                               if(proc == 0){
-                                       setupPipelines(numProcs);
-                                       
resizeImages(renderFrameState.frameNumber);
-                               }
-                               for(int index = 0;index < 
static_cast<int>(channels.size());index++){
-                                       Channel* channel = channels[index];
-                                       RenderContext myContext(this, index, 
proc, workersAnimAndImage,
-                                                                             
                                                          &animFrameState,
-                                                                             
                                                          
currentLoadBalancer, currentPixelSampler,
-                                                                             
                                                          currentRenderer, 
currentShadowAlgorithm,
-                                                                             
                                                          channel->camera, 
scene);
-                                       
currentImageTraverser->setupFrame(myContext);
-                               }
-                               barrier3.wait(numProcs);
-                               pipelineNeedsSetup = false;
+                                // Negotiate the image pipeline for each 
channel
+                                if(proc == 0){
+                                        setupPipelines(numProcs);
+                                        
resizeImages(renderFrameState.frameNumber);
+                                }
+                                for(int index = 0;index < 
static_cast<int>(channels.size());index++){
+                                        Channel* channel = channels[index];
+                                        RenderContext myContext(this, index, 
proc, workersAnimAndImage,
+                                                                             
                                                           &animFrameState,
+                                                                             
                                                           
currentLoadBalancer, currentPixelSampler,
+                                                                             
                                                           currentRenderer, 
currentShadowAlgorithm,
+                                                                             
                                                           channel->camera, 
scene);
+                                        
currentImageTraverser->setupFrame(myContext);
+                                }
+                                barrier3.wait(numProcs);
+                                pipelineNeedsSetup = false;
       }
-                       
+
       // Image display, if image is valid
       for(ChannelListType::iterator iter = channels.begin();
-                                       iter != channels.end(); iter++){
-                               Channel* channel = *iter;
-                               long displayFrame = 
(renderFrameState.frameNumber-1)%channel->pipelineDepth;
-                               Image* image = channel->images[displayFrame];
-                               if(image && image->isValid()){
-                                       DisplayContext myContext(proc, 
workersAnimAndImage);
-                                       
channel->display->displayImage(myContext, image);
-                               }
+                                        iter != channels.end(); iter++){
+                                Channel* channel = *iter;
+                                long displayFrame = 
(renderFrameState.frameNumber-1)%channel->pipelineDepth;
+                                Image* image = channel->images[displayFrame];
+                                if(image && image->isValid()){
+                                        DisplayContext myContext(proc, 
workersAnimAndImage);
+                                        
channel->display->displayImage(myContext, image);
+                                }
       }
-                       
+
       // Possibly change # of workers
       if(proc == 0 && workersRendering < numProcs){
-                               for(int i = workersRendering; i<numProcs; 
i++){
-                                       // Clean up after worker.  Don't 
attempt to join with self
-                                       if(i != 0)
-                                               workers[i]->join();
-                               }
-                               workers.resize(workersRendering == 
0?1:workersRendering);
+                                for(int i = workersRendering; i<numProcs; 
i++){
+                                        // Clean up after worker.  Don't 
attempt to join with self
+                                        if(i != 0)
+                                                workers[i]->join();
+                                }
+                                workers.resize(workersRendering == 
0?1:workersRendering);
       }
       if(proc >= workersRendering)
-                               break;
+                                break;
     }
 skipToRendering:
-                       // Pre-render callbacks
-                       //callbackLock.readLock();
-                       doParallelPreRenderCallbacks(proc, workersRendering);
+                        // Pre-render callbacks
+                        //callbackLock.readLock();
+                        doParallelPreRenderCallbacks(proc, workersRendering);
     doSerialPreRenderCallbacks(proc, workersRendering);
     //callbackLock.readUnlock();
-               
+
     if(workersChanged){
       barrier3.wait(workersRendering);
       if(proc == 0)
-                               changedFlags.resize(workersRendering);
+                                changedFlags.resize(workersRendering);
     }
-               
+
 #if NOTFINISHED
     //if(!idle){
 #endif
     {
       for(int index = 0;index < static_cast<int>(channels.size());index++){
-                               Channel* channel = channels[index];
-                               long renderFrame = 
renderFrameState.frameNumber%channel->pipelineDepth;
-                               Image* image = channel->images[renderFrame];
-                               RenderContext myContext(this, index, proc, 
workersRendering, &renderFrameState,
-                                                                             
                                                  currentLoadBalancer, 
currentPixelSampler,
-                                                                             
                                                  currentRenderer, 
currentShadowAlgorithm,
-                                                                             
                                                  channel->camera, scene);
-                               currentImageTraverser->renderImage(myContext, 
image);
+                                Channel* channel = channels[index];
+                                long renderFrame = 
renderFrameState.frameNumber%channel->pipelineDepth;
+                                Image* image = channel->images[renderFrame];
+                                RenderContext myContext(this, index, proc, 
workersRendering, &renderFrameState,
+                                                                             
                                                   currentLoadBalancer, 
currentPixelSampler,
+                                                                             
                                                   currentRenderer, 
currentShadowAlgorithm,
+                                                                             
                                                   channel->camera, scene);
+                                
currentImageTraverser->renderImage(myContext, image);
       }
     }
 #if NOTFINISHED
-               how to set rendering complete flag?;
+                how to set rendering complete flag?;
     } else {
       //callbackLock.readLock();
       idle callbacks;
@@ -464,19 +464,19 @@
     transaction_lock.lock();
     changed = true;
     for(TransactionListType::iterator iter = transactions.begin();
-                               iter != transactions.end(); iter++){
+                                iter != transactions.end(); iter++){
       TransactionBase* transaction = *iter;
       if(verbose_transactions){
-                               cerr << "Apply transaction: " << 
transaction->getName() << " : ";
-                               transaction->printValue(cerr);
-                               cerr << " : ";
-                               transaction->printOp(cerr);
-                               cerr << " : ";
+                                cerr << "Apply transaction: " << 
transaction->getName() << " : ";
+                                transaction->printValue(cerr);
+                                cerr << " : ";
+                                transaction->printOp(cerr);
+                                cerr << " : ";
       }
       transaction->apply();
       if(verbose_transactions){
-                               transaction->printValue(cerr);
-                               cerr << '\n';
+                                transaction->printValue(cerr);
+                                cerr << '\n';
       }
       delete transaction;
     }
@@ -539,17 +539,17 @@
 {
   string name;
   vector<string> args;
-       
-       // Parse the arg string.
+
+        // Parse the arg string.
   parseSpec(spec, name, args);
-       
-       // Search for an image display with the name.
+
+        // Search for an image display with the name.
   ImageDisplayMapType::iterator iter = imageDisplays.find(name);
   if(iter == imageDisplays.end())
     return 0;
 
-       // Create the channel with the image display.
-       return createChannel( (*iter->second)(args), camera, stereo, xres, 
yres );
+        // Create the channel with the image display.
+        return createChannel( (*iter->second)(args), camera, stereo, xres, 
yres );
 }
 
 int RTRT::createChannel(ImageDisplay *image_display, Camera* camera, bool 
stereo, int xres, int yres)
@@ -567,15 +567,15 @@
   channel->pipelineDepth = 2;
   channel->images.resize(channel->pipelineDepth);
   channel->camera = camera;
-       
-       // Setup images for pipeline.
+
+        // Setup images for pipeline.
   for(int i=0;i<channel->pipelineDepth;i++)
     channel->images[i] = 0;
-  
-       pipelineNeedsSetup = true;
-  
-       // Add the channel to the renderer.
-       channels.push_back(channel);
+
+        pipelineNeedsSetup = true;
+
+        // Add the channel to the renderer.
+        channels.push_back(channel);
   return channel->id;
 }
 
@@ -603,7 +603,7 @@
 
 void RTRT::setCamera(int channel, Camera *camera ) {
 
-       channels[channel]->camera = camera;
+        channels[channel]->camera = camera;
 }
 
 void RTRT::getResolution(int channel, bool& stereo, int& xres, int& yres)
@@ -624,76 +624,76 @@
 
 void RTRT::setupPipelines(int numProcs)
 {
-       // Total number of channels.
+        // Total number of channels.
   int numChannels = static_cast<int>(channels.size());
-  
-       // Create a setup context.
-       SetupContext globalcontext(this, numChannels, 0, numProcs,
+
+        // Create a setup context.
+        SetupContext globalcontext(this, numChannels, 0, numProcs,
                              currentLoadBalancer, currentPixelSampler,
                              currentRenderer);
-                                                                             
                                   
-       // Setup the image traverser.
+
+        // Setup the image traverser.
   currentImageTraverser->setupBegin(globalcontext, numChannels);
-       
-       // Proceess setup callbacks.
+
+        // Proceess setup callbacks.
   for(vector<SetupCallback*>::iterator iter = setupCallbacks.begin(); iter 
!= setupCallbacks.end(); iter++)
-               (*iter)->setupBegin(globalcontext, numChannels);
-               
-       // Setup each channel.
+                (*iter)->setupBegin(globalcontext, numChannels);
+
+        // Setup each channel.
   for(int index = 0;index < static_cast<int>(channels.size());index++){
     Channel* channel = channels[index];
     SetupContext context(this, index, numChannels, 0, numProcs,
                          channel->stereo, channel->xres, channel->yres,
-                                                                             
                   currentLoadBalancer, currentPixelSampler,
+                                                                             
                    currentLoadBalancer, currentPixelSampler,
                          currentRenderer);
-                                                                             
                   
-               // Setup the channel iteratively, until context.isChanged() 
is false.
+
+                // Setup the channel iteratively, until context.isChanged() 
is false.
     int iteration = 100;
     do {
       context.setChanged(false);
       context.clearMasterWindow();
-                       
-                       // Call setup callbacks.
+
+                        // Call setup callbacks.
       for(vector<SetupCallback*>::iterator iter = setupCallbacks.begin(); 
iter != setupCallbacks.end(); iter++)
-                               (*iter)->setupDisplayChannel(context);
-                               
-                       // Setup the image display.
+                                (*iter)->setupDisplayChannel(context);
+
+                        // Setup the image display.
       channel->display->setupDisplayChannel(context);
-                       
-                       // Setup the image traverser.
+
+                        // Setup the image traverser.
       currentImageTraverser->setupDisplayChannel(context);
-                       
+
     } while(context.isChanged() && --iteration > 0);
-               
-               // Check to for errors.
+
+                // Check to for errors.
     if(!iteration)
       throw InternalError("Pipeline/resolution negotiation failed", 
__FILE__, __LINE__ );
     context.getResolution(channel->stereo, channel->xres, channel->yres);

-               if(channel->xres <= 0)
+
+                if(channel->xres <= 0)
       throw IllegalValue<int>("Resolution should be positive", 
channel->xres);
     if(channel->yres <= 0)
       throw IllegalValue<int>("Resolution should be positive", 
channel->yres);
     if(context.getMinDepth() > context.getMaxDepth())
       throw InternalError("Pipeline depth negotiation failed", __FILE__, 
__LINE__ );
-       
+
     int depth = context.getMinDepth();
     if(depth == 1 && context.getMaxDepth() > 1)
       depth = 2; // Prefer double-buffering
-    
-               //cerr << "RTRT::setupPipelines:: depth = "<< depth << "\n";
-    
-               // Set the pipeline depth.
-               channel->pipelineDepth = depth;
+
+                //cerr << "RTRT::setupPipelines:: depth = "<< depth << "\n";
+
+                // Set the pipeline depth.
+                channel->pipelineDepth = depth;
     unsigned long osize = channel->images.size();
     for(unsigned long i=depth;i<osize;i++)
       delete channel->images[i];
-                       
-               // Zero pointers to images.
+
+                // Zero pointers to images.
     for(unsigned long i=osize;i<static_cast<unsigned long>(depth);i++)
       channel->images[i]=0;
-               
-               // Specify the number of frames needed for the entire 
pipeline.
+
+                // Specify the number of frames needed for the entire 
pipeline.
     channel->images.resize(depth);
   }
 }
@@ -701,7 +701,7 @@
 void RTRT::resizeImages(long frame)
 {
 
-       
+
   for(ChannelListType::iterator iter = channels.begin();
       iter != channels.end(); iter++){
     Channel* channel = *iter;
@@ -714,13 +714,13 @@
     if(!channel->images[which] || channel->stereo != stereo
        || channel->xres != xres || channel->yres != yres){
       if(channel->images[which])
-                               delete channel->images[which];
+                                delete channel->images[which];
       ImageCreator creator = channel->imageCreator;
       if(!creator)
-                               creator = currentImageCreator;
+                                creator = currentImageCreator;
       channel->images[which] = (creator)(currentImageCreatorArgs,
-                                                                             
                                                                              
     channel->stereo,
-                                                                             
                                                                              
     channel->xres, channel->yres);
+                                                                             
                                                                              
      channel->stereo,
+                                                                             
                                                                              
      channel->xres, channel->yres);
     } else {
       if (channel->pipelineDepth > 1)
         channel->images[which]->setValid(false);
@@ -817,7 +817,7 @@
 }
 
 void RTRT::setPixelSampler( PixelSampler *sampler_ ) {
-       currentPixelSampler = sampler_;
+        currentPixelSampler = sampler_;
 };
 
 bool RTRT::selectPixelSampler(const string& spec)
@@ -829,7 +829,7 @@
   if(iter == pixelSamplers.end())
     return false;
   currentPixelSampler = (*iter->second)(args);
-       pipelineNeedsSetup = true;
+        pipelineNeedsSetup = true;
   return true;
 }
 
@@ -978,7 +978,7 @@
 
 Scene *RTRT::getScene() {
 
-       return scene;
+        return scene;
 }
 
 bool RTRT::readScene(const string& spec)
@@ -986,7 +986,7 @@
   string name;
   vector<string> args;
   parseSpec(spec, name, args);
-       
+
   // Pull off the suffix...
   string::size_type dot = name.rfind('.');
   string suffix;
@@ -996,22 +996,22 @@
     suffix = name.substr(dot+1);
   }
   Scene* newScene = 0;
-       
+
   std::cerr << "Scene suffix: " << suffix << std::endl;
-  
+
   if((suffix == "mo") || (suffix == "so") || (suffix == "dylib")) {
     // Do this twice - once silently and once printing errors
     std::cerr << "Reading .mo or .so scene" << std::endl;
-    
+
     newScene = readMOScene(name, args, false);
     if(!newScene)
       readMOScene(name, args, true);
   } else {
     // Try reading it as an MO
     std::cerr << "Appending .mo to scene" << std::endl;
-    
+
     newScene = readMOScene(name+".mo", args, false);
-               
+
     if(!newScene){
       readMOScene(name+".mo", args, true);
     }
@@ -1059,7 +1059,7 @@
 }
 
 Scene* RTRT::readMOScene(const string& name, const vector<string>& args,
-                                                                             
                   bool printErrors)
+                                                                             
                    bool printErrors)
 {
   vector<string> dirs = split_string(scenePath, ':');
   for(vector<string>::iterator dir = dirs.begin(); dir != dirs.end(); dir++){
@@ -1067,22 +1067,22 @@
     struct stat statbuf;
     if(stat(fullname.c_str(), &statbuf) != 0){
       if(printErrors){
-                               cerr << "Error reading " << fullname << ": " 
<< strerror(errno) << '\n';
+                                cerr << "Error reading " << fullname << ": " 
<< strerror(errno) << '\n';
       }
       continue;
     }
     void* handle=dlopen(fullname.c_str(), RTLD_NOW);
     if(!handle){
       if(printErrors){
-                               cerr << "Error opening scene: " << fullname 
<< '\n';
-                               cerr << dlerror() << '\n';
+                                cerr << "Error opening scene: " << fullname 
<< '\n';
+                                cerr << dlerror() << '\n';
       }
       continue;
     }
     void* scene_fn=dlsym(handle, "make_scene");
     if(!scene_fn){
       if(printErrors){
-                               cerr << "Scene file found, but make_scene() 
function not found\n";
+                                cerr << "Scene file found, but make_scene() 
function not found\n";
       }
       // If we get here, we fail so that we don't keep searching the path
       // for another scene
@@ -1095,7 +1095,7 @@
     Scene* scene=(*make_scene)(context, args);
     if(!scene){
       if(printErrors)
-                               cerr << "scene " << name << " did not produce 
a scene\n";
+                                cerr << "scene " << name << " did not 
produce a scene\n";
       return 0;
     }
     return scene;
@@ -1166,37 +1166,37 @@
 
 void RTRT::shootOneRay( Color &result_color, RayPacket &result_rays, Real 
image_x, Real image_y, int channel_index ) {
 
-       // Only shoot one ray.
-       result_rays.resize( 1 );
+        // Only shoot one ray.
+        result_rays.resize( 1 );
 
-       // Set the image space coordinates of the pixel.
-       result_rays.setPixel(0, 0, image_x, image_y, &result_color );
-       result_rays.setFlag ( RayPacket::HaveImageCoordinates );
-       
-       // Get a pointer to the channel.
-       Channel *channel = channels[ channel_index ];
-       
-       // Create a render context.
-       RenderContext render_context(this, channel_index, workersRendering, 
workersRendering+1, 0,
-                                                                             
                               currentLoadBalancer, currentPixelSampler,
-                                                                             
                                           currentRenderer, 
currentShadowAlgorithm,
-                                                                             
                                           channel->camera, scene );
-
-       // Send this to the renderer.
-       currentRenderer->traceEyeRays( render_context, result_rays );
-       
-       // Check to see if the ray hit anything.
-       if (result_rays.hitInfo(0).wasHit()) {
-       
-               // Compute hit positions.
-               result_rays.computeHitPositions();
-       
-               // Compute the normal.
-               result_rays.computeNormals( render_context );
-               
-               // Shade.
-               result_rays.hitInfo(0).hitMaterial()->shade( render_context, 
result_rays );
-       }
+        // Set the image space coordinates of the pixel.
+        result_rays.setPixel(0, 0, image_x, image_y, &result_color );
+        result_rays.setFlag ( RayPacket::HaveImageCoordinates );
+
+        // Get a pointer to the channel.
+        Channel *channel = channels[ channel_index ];
+
+        // Create a render context.
+        RenderContext render_context(this, channel_index, workersRendering, 
workersRendering+1, 0,
+                                                                             
                                currentLoadBalancer, currentPixelSampler,
+                                                                             
                                            currentRenderer, 
currentShadowAlgorithm,
+                                                                             
                                            channel->camera, scene );
+
+        // Send this to the renderer.
+        currentRenderer->traceEyeRays( render_context, result_rays );
+
+        // Check to see if the ray hit anything.
+        if (result_rays.hitInfo(0).wasHit()) {
+
+                // Compute hit positions.
+                result_rays.computeHitPositions();
+
+                // Compute the normal.
+                result_rays.computeNormals( render_context );
+
+                // Shade.
+                result_rays.hitInfo(0).hitMaterial()->shade( render_context, 
result_rays );
+        }
 }
 
 

Modified: branches/itanium2/Interface/RayPacket.h
==============================================================================
--- branches/itanium2/Interface/RayPacket.h     (original)
+++ branches/itanium2/Interface/RayPacket.h     Sat Jul 30 17:24:15 2005
@@ -86,6 +86,8 @@
       Color   ambientLight;
       Color   light;
 
+        double importance; // for ray pruning
+
       int shadowBegin, shadowEnd;
       int whichEye;
       int signMask[3]; // This is set at the same time as inverse direction.

Modified: branches/itanium2/Interface/RenderParameters.h
==============================================================================
--- branches/itanium2/Interface/RenderParameters.h      (original)
+++ branches/itanium2/Interface/RenderParameters.h      Sat Jul 30 17:24:15 
2005
@@ -6,7 +6,7 @@
   class RenderParameters {
   public:
     RenderParameters() {
-      maxDepth = 5;
+      maxDepth = 15;
     }
     int maxDepth;
   private:

Modified: branches/itanium2/Model/Cameras/PinholeCamera.cc
==============================================================================
--- branches/itanium2/Model/Cameras/PinholeCamera.cc    (original)
+++ branches/itanium2/Model/Cameras/PinholeCamera.cc    Sat Jul 30 17:24:15 
2005
@@ -27,19 +27,19 @@
     string arg = args[i];
     if(arg == "-eye"){
       if(!getPointArg(i, args, eye))
-       throw IllegalArgument("PinholeCamera -eye", i, args);
+        throw IllegalArgument("PinholeCamera -eye", i, args);
       gotEye = true;
     } else if(arg == "-lookat"){
       if(!getPointArg(i, args, lookat))
-       throw IllegalArgument("PinholeCamera -lookat", i, args);
+        throw IllegalArgument("PinholeCamera -lookat", i, args);
       gotLookat = true;
     } else if(arg == "-up"){
       if(!getVectorArg(i, args, up))
-       throw IllegalArgument("PinholeCamera -up", i, args);
+        throw IllegalArgument("PinholeCamera -up", i, args);
       gotUp = true;
     } else if(arg == "-fov"){
       if(!getDoubleArg(i, args, hfov))
-       throw IllegalArgument("PinholeCamera -fov", i, args);
+        throw IllegalArgument("PinholeCamera -fov", i, args);
       gotFov = true;
     } else if(arg == "-normalizeRays"){
       normalizeRays = true;
@@ -58,11 +58,11 @@
 
 void PinholeCamera::output( std::ostream &os ) {
 
-       os << "pinhole( -eye " << eye 
-                 << " -lookat " << lookat 
-                                               << " -up " << up 
-                                               << " -fov " << hfov << " )" 
-                                               << std::endl;
+        os << "pinhole( -eye " << eye
+                  << " -lookat " << lookat
+                                                << " -up " << up
+                                                << " -fov " << hfov << " )"
+                                                << std::endl;
 }
 
 Camera* PinholeCamera::create(const vector<string>& args)
@@ -76,28 +76,28 @@
   vfov = hfov;
   direction=lookat-eye;
   nearZ=direction.length();
-  
+
   Vector n = direction;
   n.normalize();

+
   for(i=0; i<3; i++)
     uvn[2][i] = n[i];
-  
+
   v=Cross(direction, up);
   if(v.length2() == 0.0){
     std::cerr << __FILE__ << " line: " << __LINE__ << " Ambiguous up 
direciton...\n";
   }
   v.normalize();
-  
+
   for(i=0; i<3; i++)
-    uvn[1][i] = v[i]; 
-  
+    uvn[1][i] = v[i];
+
   u=Cross(v, direction);
   u.normalize();
-  
+
   for(i=0; i<3; i++)
     uvn[0][i] = u[i];
-  
+
   height=nearZ*tan(vfov*0.5*M_PI/180.0);
   u*=height;
   width=nearZ*tan(hfov*0.5*M_PI/180.0);
@@ -114,6 +114,7 @@
       Vector raydir(v*e.imageX+u*e.imageY+direction);
       raydir.normalize();
       e.ray.set(eye, raydir);
+      e.importance = 1.0;
     }
     rays.setFlag(RayPacket::NormalizedDirections);
   } else {
@@ -121,6 +122,7 @@
       RayPacket::Element& e = rays.get(i);
       Vector raydir(v*e.imageX+u*e.imageY+direction);
       e.ray.set(eye, raydir);
+      e.importance = 1.0;
     }
   }
 }
@@ -149,7 +151,7 @@
 {
   Vector d = (lookat - eye) * scale;
   eye    += d;
-       // lookat += d; // Maybe we need two types of dolly. // Maybe not.
+        // lookat += d; // Maybe we need two types of dolly. // Maybe not.
   setup();
 }
 
@@ -205,23 +207,23 @@
 {
   // translate camera center to origin
   Vector trans(-eye.x(), -eye.y(), -eye.z());
-  Point p1 = point + trans; 
-  
+  Point p1 = point + trans;
+
   // rotate to align with camera axis
-  Point p2((uvn[0][0]*p1.x() + uvn[0][1]*p1.y() + uvn[0][2]*p1.z()), 
-                (uvn[1][0]*p1.x() + uvn[1][1]*p1.y() + uvn[1][2]*p1.z()),
-                (uvn[2][0]*p1.x() + uvn[2][1]*p1.y() + uvn[2][2]*p1.z()));
-  
+  Point p2((uvn[0][0]*p1.x() + uvn[0][1]*p1.y() + uvn[0][2]*p1.z()),
+                 (uvn[1][0]*p1.x() + uvn[1][1]*p1.y() + uvn[1][2]*p1.z()),
+                 (uvn[2][0]*p1.x() + uvn[2][1]*p1.y() + uvn[2][2]*p1.z()));
+
   // project the point to the image plane using simlar triangles
   // the viewZ is just a ratio to tell whether point is valid or not
   // if returned viewZ>1, it means that the point lied beyong the image plane
-  // and is visible to camera, else it is not 
-  // It is not a sufficient condition though, the x and y coordinates should 
lie within the 
+  // and is visible to camera, else it is not
+  // It is not a sufficient condition though, the x and y coordinates should 
lie within the
   // width and height of the image, so returned coordinates are in the 
normalized space [-1,1]
   if(fabs(p2.z())<0.0001) // check for inconsistencies
     return Point(0,0,0);
   else
-    return Point((p2.x()*nearZ/p2.z())/(width/2.0), 
-                 (p2.y()*nearZ/p2.z())/(height/2.0), 
+    return Point((p2.x()*nearZ/p2.z())/(width/2.0),
+                 (p2.y()*nearZ/p2.z())/(height/2.0),
                   p2.z()/nearZ);
 }

Modified: branches/itanium2/Model/Materials/Dielectric.cc
==============================================================================
--- branches/itanium2/Model/Materials/Dielectric.cc     (original)
+++ branches/itanium2/Model/Materials/Dielectric.cc     Sat Jul 30 17:24:15 
2005
@@ -86,8 +86,11 @@
   Vector refl_dirs[RayPacket::MaxSize];
   Vector refr_dirs[RayPacket::MaxSize];
   float fresnel_coeffs[RayPacket::MaxSize]; // might be better to compute
+  Color beers_colors[RayPacket::MaxSize];
+  double beers_coeffs[RayPacket::MaxSize];
   bool internally_reflected[RayPacket::MaxSize];
   bool apply_beers[RayPacket::MaxSize];
+  bool kill_ray[RayPacket::MaxSize];
 
   int num_internal = 0;
   int num_branch   = 0;
@@ -95,6 +98,17 @@
   for(int i=0;i<rays.getSize();i++)
   {
       RayPacket::Element& e = rays.get(i);
+
+      if ( e.importance < 0.05 )
+      {
+          kill_ray[i] = true;
+          continue;
+      }
+      else
+      {
+          kill_ray[i] = false;
+      }
+
       Vector N = e.normal;
       double n_dot_v = Dot(N, e.ray.direction());
       double eta_tmp;
@@ -105,16 +119,19 @@
           eta_tmp = n_values[i]/nt_values[i];
           eta_tmp_inv = 1.0 / eta_tmp;
           n_dot_v = -n_dot_v;
+          apply_beers[i] = false;
+          beers_coeffs[i] = 1.0;// allows blind multiplication
       }
       else
       {
           N = -N;
           eta_tmp = nt_values[i]/n_values[i];
           eta_tmp_inv = 1.0 / eta_tmp;
+          apply_beers[i] = true;
+          beers_colors[i] = sigma_a_values[i].Pow(e.hitInfo.minT());
+          beers_coeffs[i] = beers_colors[i].Mean();
       }
 
-      apply_beers[i] = !was_incoming;
-
       double cosine = 1.0 + (n_dot_v*n_dot_v - 
1.0)*(eta_tmp_inv*eta_tmp_inv);
       if ( cosine <= 0.0 )
       {
@@ -167,19 +184,24 @@
   for (int i = 0; i < rays.getSize(); i++)
   {
       RayPacket::Element& e = rays.get(i);
+      if (kill_ray[i])
+          continue;
 
       if (internally_reflected[i])
       {
           RayPacket::Element& r = internal_rays.get(internal_counter);
           r.ray.set(e.hitPosition, refl_dirs[i]);
+          r.importance = e.importance * beers_coeffs[i];
           internal_counter++;
       }
       else
       {
           RayPacket::Element& refl = reflected_rays.get(branch_counter);
           refl.ray.set(e.hitPosition, refl_dirs[i]);
+          refl.importance = e.importance * fresnel_coeffs[i] * 
beers_coeffs[i];
           RayPacket::Element& refr = refracted_rays.get(branch_counter);
           refr.ray.set(e.hitPosition, refr_dirs[i]);
+          refr.importance = e.importance * (1. - fresnel_coeffs[i]) * 
beers_coeffs[i];
           branch_counter++;
       }
   }
@@ -195,6 +217,12 @@
   for (int i = 0; i < rays.getSize(); i++)
   {
       RayPacket::Element& e = rays.get(i);
+      if (kill_ray[i])
+      {
+          rays.setResult(i, Color::black());
+          continue;
+      }
+
       if (internally_reflected[i])
       {
           RayPacket::Element& r = internal_rays.get(internal_counter);
@@ -215,7 +243,7 @@
 
       if (apply_beers[i])
       {
-          *e.color *= sigma_a_values[i].Pow(e.hitInfo.minT());
+          *e.color *= beers_colors[i];
       }
   }
 }




  • [MANTA] r461 - in branches/itanium2: Core/Color Engine/Control Interface Model/Cameras Model/Materials, boulos, 07/30/2005

Archive powered by MHonArc 2.6.16.

Top of page