Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r539 - in branches/fire: Model/Materials scenes


Chronological Thread 
  • From: vpegorar@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r539 - in branches/fire: Model/Materials scenes
  • Date: Mon, 12 Sep 2005 16:09:39 -0600 (MDT)

Author: vpegorar
Date: Mon Sep 12 16:09:37 2005
New Revision: 539

Modified:
   branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
   branches/fire/scenes/primtest.cc
Log:
Added a flagged mode following the ray packets philosophy but disabling 
refraction computation.

Modified: branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
==============================================================================
--- branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc   
(original)
+++ branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc   Mon 
Sep 12 16:09:37 2005
@@ -9,6 +9,7 @@
 
 using namespace Manta;
 
+//#define DISABLE_REFRACTION
 #define FAST_GRADIENT
 
 
@@ -124,278 +125,453 @@
 // 
--------------------------------------------------------------------------------------
 void InhomogeneousParticipatingMedium::shade(const RenderContext & context, 
RayPacket & rays) const
 {
+       int raysSize = rays.getSize();
+       bool depthSmallerThanMax = rays.getDepth() < 
context.scene->getRenderParameters().maxDepth;
+
        rays.normalizeDirections();
 
-       for(int rayInd = 0; rayInd < rays.getSize(); rayInd++)
-       {
-               RayPacket::Element & e = rays.get(rayInd);
-               Ray & ray = e.ray;
-               Point hitPosition;
-               double t, tenter, texit;
-               int hitLattice[3];
-               float accumTransmittance, hitLatticef[3], 
previousRefractiveIndex;
-               Color accumColor;
+#ifndef DISABLE_REFRACTION
+               for(int rayInd = 0; rayInd < raysSize; rayInd++)
+               {
+                       RayPacket::Element & e = rays.get(rayInd);
+                       Ray & ray = e.ray;
+                       Point hitPosition;
+                       double t, tenter, texit;
+                       int hitLattice[3];
+                       float accumTransmittance, hitLatticef[3], 
previousRefractiveIndex;
+                       Color accumColor;
+
+                       accumColor = Color(RGB(0.0f, 0.0f, 0.0f));
+                       accumTransmittance = 1.0f;
+
+                       previousRefractiveIndex = - 1.0f;
+
+//                     if (e.hitInfo.isInside())       tenter = 0.0;// need 
to figure a way to check if inside or not, assume outside for now
+//                     else
+                               tenter = e.hitInfo.minT();
+
+                               RayPacketData rpData;
+                       RayPacket lRays(rpData, 1, rays.getDepth()+1, 
RayPacket::NormalizedDirections);
+                       lRays.useLocalColors();
+                       RayPacket::Element & lRPE = lRays.get(0);
+                       Ray & lRay = lRPE.ray;
+
+                       lRay.set(ray.origin() + tenter * ray.direction(), 
ray.direction());
+                       lRays.resetHit();
+                       context.scene->getObject()->intersect(context, lRays);
+                       if (lRPE.hitInfo.wasHit())      texit = 
lRPE.hitInfo.minT();
+                       else                                            texit 
= -1.0;
+                       t = 0.0;
 
-               accumColor = Color(RGB(0.0f, 0.0f, 0.0f));
-               accumTransmittance = 1.0f;
+                       while(t < texit)
+                       {
+                               hitPosition = lRay.origin() + t * 
lRay.direction();
+                               hitLatticef[0] = (float)((hitPosition.x() - 
m_Bounds[0].x()) / m_CellSize.x());
+                               hitLatticef[1] = (float)((hitPosition.y() - 
m_Bounds[0].y()) / m_CellSize.y());
+                               hitLatticef[2] = (float)((hitPosition.z() - 
m_Bounds[0].z()) / m_CellSize.z());
+                               hitLattice[0] = (int)floor(hitLatticef[0]);
+                               hitLattice[1] = (int)floor(hitLatticef[1]);
+                               hitLattice[2] = (int)floor(hitLatticef[2]);
+
+                               if (0 <= hitLattice[0] && hitLattice[0] < 
(int)m_DefaultVolume->getNx() - 1 &&
+                                       0 <= hitLattice[1] && hitLattice[1] < 
(int)m_DefaultVolume->getNy() - 1 &&
+                                       0 <= hitLattice[2] && hitLattice[2] < 
(int)m_DefaultVolume->getNz() - 1 )
+                               {
+                                       float wx, wy, wz, wx1, wy1, wz1, 
transmittance, absCoeff;
+                                       Color sourceColor;
+                                       double tIntegration;
+
+                                       wx = hitLatticef[0] - 
(float)hitLattice[0];
+                                       wy = hitLatticef[1] - 
(float)hitLattice[1];
+                                       wz = hitLatticef[2] - 
(float)hitLattice[2];
+                                       wx1 = 1.0f - wx;
+                                       wy1 = 1.0f - wy;
+                                       wz1 = 1.0f - wz;
 
-               previousRefractiveIndex = - 1.0f;
+                                       if (m_RefractiveIndex)
+                                       {
+                                               float refrInd = wx1 * ( wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  
) +
+                                                                             
                                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
                  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                                             
  wx  * ( wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
                  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
 
-//             if (hit.m_Inside)       tenter = 0.0;// need to figure a way 
to check if inside or not, assume outside for now
-//             else
-                       tenter = e.hitInfo.minT();
-
-               RayPacketData rpData;
-               RayPacket lRays(rpData, 1, rays.getDepth()+1, 
RayPacket::NormalizedDirections);
-               lRays.useLocalColors();
-               Ray & lRay = lRays.get(0).ray;
-
-               lRay.set(ray.origin() + tenter * ray.direction(), 
ray.direction());
-               lRays.resetHit();
-               context.scene->getObject()->intersect(context, lRays);
-               if (lRays.get(0).hitInfo.wasHit())      texit = 
lRays.get(0).hitInfo.minT();
-               else                                                          
  texit = -1.0;
-               t = 0.0;
+                                               if (previousRefractiveIndex > 
0.0f && previousRefractiveIndex != refrInd)
+                                               {
+                                                       Vector hitNormal;
+                                                       double cosTheta, 
cosTheta2, eta;
+#ifdef FAST_GRADIENT
+                                                       int hitLRn[3];
 
-               while(t < texit)
-               {
-                       hitPosition = lRay.origin() + t * lRay.direction();
-                       hitLatticef[0] = (float)((hitPosition.x() - 
m_Bounds[0].x()) / m_CellSize.x());
-                       hitLatticef[1] = (float)((hitPosition.y() - 
m_Bounds[0].y()) / m_CellSize.y());
-                       hitLatticef[2] = (float)((hitPosition.z() - 
m_Bounds[0].z()) / m_CellSize.z());
-                       hitLattice[0] = (int)floor(hitLatticef[0]);
-                       hitLattice[1] = (int)floor(hitLatticef[1]);
-                       hitLattice[2] = (int)floor(hitLatticef[2]);
-
-                       if (0 <= hitLattice[0] && hitLattice[0] < 
(int)m_DefaultVolume->getNx() - 1 &&
-                               0 <= hitLattice[1] && hitLattice[1] < 
(int)m_DefaultVolume->getNy() - 1 &&
-                               0 <= hitLattice[2] && hitLattice[2] < 
(int)m_DefaultVolume->getNz() - 1 )
-                       {
-                               float wx, wy, wz, wx1, wy1, wz1, 
transmittance, absCoeff;
-                               Color sourceColor;
-                               double tIntegration;
-
-                               wx = hitLatticef[0] - (float)hitLattice[0];
-                               wy = hitLatticef[1] - (float)hitLattice[1];
-                               wz = hitLatticef[2] - (float)hitLattice[2];
-                               wx1 = 1.0f - wx;
-                               wy1 = 1.0f - wy;
-                               wz1 = 1.0f - wz;
+                                                       hitLRn[0] = 
hitLattice[0] + (int)(wx + 0.5f);
+                                                       hitLRn[1] = 
hitLattice[1] + (int)(wy + 0.5f);
+                                                       hitLRn[2] = 
hitLattice[2] + (int)(wz + 0.5f);
+
+                                                       if              
(hitLRn[0] == 0)                                                              
  hitNormal[0] = (double)((*m_RefractiveIndex)(hitLRn[0]+1, hitLRn[1]  , 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.x();
+                                                       else if (hitLRn[0] == 
m_RefractiveIndex->getNx() - 1)   hitNormal[0] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]-1, hitLRn[1]  , hitLRn[2]  )) /  
m_CellSize.x();
+                                                       else                  
                                                                              
    hitNormal[0] = (double)((*m_RefractiveIndex)(hitLRn[0]+1, hitLRn[1]  , 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]-1, hitLRn[1]  , hitLRn[2]  )) / 
(m_CellSize.x() * 2.0);
+                                                       if              
(hitLRn[1] == 0)                                                              
  hitNormal[1] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]+1, 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.y();
+                                                       else if (hitLRn[1] == 
m_RefractiveIndex->getNy() - 1)   hitNormal[1] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]-1, hitLRn[2]  )) /  
m_CellSize.y();
+                                                       else                  
                                                                              
    hitNormal[1] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]+1, 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]-1, hitLRn[2]  )) / 
(m_CellSize.y() * 2.0);
+                                                       if              
(hitLRn[2] == 0)                                                              
  hitNormal[2] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , 
hitLRn[2]+1) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.z();
+                                                       else if (hitLRn[2] == 
m_RefractiveIndex->getNz() - 1)   hitNormal[2] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]-1)) /  
m_CellSize.z();
+                                                       else                  
                                                                              
    hitNormal[2] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , 
hitLRn[2]+1) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]-1)) / 
(m_CellSize.z() * 2.0);
+#else
+                                                       double tmp[4];
 
-                               if (m_RefractiveIndex)
-                               {
-                                       float refrInd = wx1 * ( wy1 * ( wz1 * 
(*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) +
+                                                               tmp[1] =      
  wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]  ) +
                                                                              
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
                                                                              
          wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) +
-                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
-                                                                       wx  * 
( wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                                               tmp[2] =      
  wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
                                                                              
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
                                                                              
          wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
-                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
-
-                                       if (previousRefractiveIndex > 0.0f && 
previousRefractiveIndex != refrInd)
-                                       {
-                                               Vector hitNormal;
-                                               double cosTheta, cosTheta2, 
eta;
-#ifdef FAST_GRADIENT
-                                               int hitLRn[3];
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                                       if (hitLattice[0] == 
0)
+                                                               tmp[0] = 
tmp[1];
+                                                       else
+                                                               tmp[0] =      
  wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]-1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]-1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]-1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]-1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                                       if (hitLattice[0] == 
m_RefractiveIndex->getNx() - 2)
+                                                               tmp[3] = 
tmp[2];
+                                                       else
+                                                               tmp[3] =      
  wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+2, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+2, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+2, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+2, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                                       hitNormal[0] = (wx1 * 
(tmp[2] - tmp[0]) + wx * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.x());
 
-                                               hitLRn[0] = hitLattice[0] + 
(int)(wx + 0.5f);
-                                               hitLRn[1] = hitLattice[1] + 
(int)(wy + 0.5f);
-                                               hitLRn[2] = hitLattice[2] + 
(int)(wz + 0.5f);
-
-                                               if              (hitLRn[0] == 
0)                                                                
hitNormal[0] = (double)((*m_RefractiveIndex)(hitLRn[0]+1, hitLRn[1]  , 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.x();
-                                               else if (hitLRn[0] == 
m_RefractiveIndex->getNx() - 1)   hitNormal[0] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]-1, hitLRn[1]  , hitLRn[2]  )) /  
m_CellSize.x();
-                                               else                          
                                                                          
hitNormal[0] = (double)((*m_RefractiveIndex)(hitLRn[0]+1, hitLRn[1]  , 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]-1, hitLRn[1]  , hitLRn[2]  )) / 
(m_CellSize.x() * 2.0);
-                                               if              (hitLRn[1] == 
0)                                                                
hitNormal[1] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]+1, 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.y();
-                                               else if (hitLRn[1] == 
m_RefractiveIndex->getNy() - 1)   hitNormal[1] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]-1, hitLRn[2]  )) /  
m_CellSize.y();
-                                               else                          
                                                                          
hitNormal[1] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]+1, 
hitLRn[2]  ) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]-1, hitLRn[2]  )) / 
(m_CellSize.y() * 2.0);
-                                               if              (hitLRn[2] == 
0)                                                                
hitNormal[2] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , 
hitLRn[2]+1) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  )) / 
 m_CellSize.z();
-                                               else if (hitLRn[2] == 
m_RefractiveIndex->getNz() - 1)   hitNormal[2] = 
(double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]  ) - 
(*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]-1)) /  
m_CellSize.z();
-                                               else                          
                                                                          
hitNormal[2] = (double)((*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , 
hitLRn[2]+1) - (*m_RefractiveIndex)(hitLRn[0]  , hitLRn[1]  , hitLRn[2]-1)) / 
(m_CellSize.z() * 2.0);
-#else
-                                               double tmp[4];
-
-                                                       tmp[1] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  
, hitLattice[2]+1) ) +
-                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ;
-                                                       tmp[2] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]+1) ) +
-                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
-                                               if (hitLattice[0] == 0)
-                                                       tmp[0] = tmp[1];
-                                               else
-                                                       tmp[0] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]-1, hitLattice[1]  , hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]-1, hitLattice[1]  
, hitLattice[2]+1) ) +
-                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]-1, hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]-1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
-                                               if (hitLattice[0] == 
m_RefractiveIndex->getNx() - 2)
-                                                       tmp[3] = tmp[2];
-                                               else
-                                                       tmp[3] =        wy1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]+2, hitLattice[1]  , hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+2, hitLattice[1]  
, hitLattice[2]+1) ) +
-                                                                             
  wy  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+2, hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+2, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
-                                               hitNormal[0] = (wx1 * (tmp[2] 
- tmp[0]) + wx * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.x());
-
-                                                       tmp[1] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  
, hitLattice[2]+1) ) +
-                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]+1) ) ;
-                                                       tmp[2] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+1, hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) +
-                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
-                                               if (hitLattice[1] == 0)
-                                                       tmp[0] = tmp[1];
-                                               else
-                                                       tmp[0] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]-1, hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]-1, hitLattice[2]+1) ) +
-                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]-1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]-1, hitLattice[2]+1) ) ;
-                                               if (hitLattice[1] == 
m_RefractiveIndex->getNy() - 2)
-                                                       tmp[3] = tmp[2];
-                                               else
-                                                       tmp[3] =        wx1 * 
( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+2, hitLattice[2]  
) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+2, hitLattice[2]+1) ) +
-                                                                             
  wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]+2, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+2, hitLattice[2]+1) ) ;
-                                               hitNormal[1] = (wy1 * (tmp[2] 
- tmp[0]) + wy * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.y());
-
-                                                       tmp[1] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  
) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) ) +
-                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) ) ;
-                                                       tmp[2] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]+1) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) +
-                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]+1) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
-                                               if (hitLattice[2] == 0)
-                                                       tmp[0] = tmp[1];
-                                               else
-                                                       tmp[0] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]-1) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]-1) ) +
-                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]-1) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]-1) ) ;
-                                               if (hitLattice[2] == 
m_RefractiveIndex->getNz() - 2)
-                                                       tmp[3] = tmp[2];
-                                               else
-                                                       tmp[3] =        wx1 * 
( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]+2) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+2) ) +
-                                                                             
  wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]+2) +
-                                                                             
                  wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+2) ) ;
-                                               hitNormal[2] = (wz1 * (tmp[2] 
- tmp[0]) + wz * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.z());
+                                                               tmp[1] =      
  wx1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) ;
+                                                               tmp[2] =      
  wx1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+1, 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) +
+                                                                             
          wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                                       if (hitLattice[1] == 
0)
+                                                               tmp[0] = 
tmp[1];
+                                                       else
+                                                               tmp[0] =      
  wx1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]-1, 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]-1, hitLattice[2]+1) ) +
+                                                                             
          wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]-1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]-1, hitLattice[2]+1) ) ;
+                                                       if (hitLattice[1] == 
m_RefractiveIndex->getNy() - 2)
+                                                               tmp[3] = 
tmp[2];
+                                                       else
+                                                               tmp[3] =      
  wx1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]+2, 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+2, hitLattice[2]+1) ) +
+                                                                             
          wx  * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+2, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+2, hitLattice[2]+1) ) ;
+                                                       hitNormal[1] = (wy1 * 
(tmp[2] - tmp[0]) + wy * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.y());
+
+                                                               tmp[1] =      
  wx1 * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) ) +
+                                                                             
          wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]  ) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) ) ;
+                                                               tmp[2] =      
  wx1 * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]+1) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) +
+                                                                             
          wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]+1) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ;
+                                                       if (hitLattice[2] == 
0)
+                                                               tmp[0] = 
tmp[1];
+                                                       else
+                                                               tmp[0] =      
  wx1 * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]-1) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]-1) ) +
+                                                                             
          wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]-1) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]-1) ) ;
+                                                       if (hitLattice[2] == 
m_RefractiveIndex->getNz() - 2)
+                                                               tmp[3] = 
tmp[2];
+                                                       else
+                                                               tmp[3] =      
  wx1 * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]+2) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+2) ) +
+                                                                             
          wx  * ( wy1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[1]  
, hitLattice[2]+2) +
+                                                                             
                          wy  * (*m_RefractiveIndex)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+2) ) ;
+                                                       hitNormal[2] = (wz1 * 
(tmp[2] - tmp[0]) + wz * (tmp[3] - tmp[1])) / (2.0 * m_CellSize.z());
 #endif
 
-                                               if (hitNormal.normalize() == 
0.0)
-                                                       hitNormal = 
lRay.direction();
+                                                       if 
(hitNormal.normalize() == 0.0)
+                                                               hitNormal = 
lRay.direction();
 
-                                               cosTheta = - Dot(hitNormal, 
lRay.direction());
-                                               if (cosTheta < 0.0)
-                                               {
-                                                       cosTheta = - cosTheta;
-                                                       hitNormal = - 
hitNormal;
+                                                       cosTheta = - 
Dot(hitNormal, lRay.direction());
+                                                       if (cosTheta < 0.0)
+                                                       {
+                                                               cosTheta = - 
cosTheta;
+                                                               hitNormal = - 
hitNormal;
+                                                       }
+                                                       eta = refrInd / 
previousRefractiveIndex;
+
+                                                       cosTheta2 = 1.0 + 
((cosTheta*cosTheta - 1.0) / (eta*eta));
+
+                                                       if (cosTheta2 < 0.0)  
  // Total reflection
+                                                       {
+                                                               
lRay.set(hitPosition, lRay.direction() + (2.0*cosTheta)*hitNormal);
+                                                       }
+                                                       else                  
                  // Compute transmission
+                                                       {
+                                                               cosTheta2 = 
sqrt(cosTheta2);
+                                                               
lRay.set(hitPosition, (1.0 / eta) * lRay.direction() + (cosTheta / eta - 
cosTheta2) * hitNormal);
+                                                       }
+
+                                                       lRays.resetHit();
+                                                       
context.scene->getObject()->intersect(context, lRays);
+                                                       if 
(lRPE.hitInfo.wasHit())      texit = lRPE.hitInfo.minT();
+                                                       else                  
                          texit = -1.0;
+                                                       t = 0.0;
                                                }
-                                               eta = refrInd / 
previousRefractiveIndex;
 
-                                               cosTheta2 = 1.0 + 
((cosTheta*cosTheta - 1.0) / (eta*eta));
+                                               previousRefractiveIndex = 
refrInd;
+                                       }
 
-                                               if (cosTheta2 < 0.0)    // 
Total reflection
-                                               {
-                                                       lRay.set(hitPosition, 
lRay.direction() + (2.0*cosTheta)*hitNormal);
-                                               }
-                                               else                          
          // Compute transmission
-                                               {
-                                                       cosTheta2 = 
sqrt(cosTheta2);
-                                                       lRay.set(hitPosition, 
(1.0 / eta) * lRay.direction() + (cosTheta / eta - cosTheta2) * hitNormal);
-                                               }
+                                       tIntegration = texit - t;
+                                       if (tIntegration > m_WorldStepSize)
+                                               tIntegration = 
m_WorldStepSize;
 
-                                               lRays.resetHit();
-                                               
context.scene->getObject()->intersect(context, lRays);
-                                               if 
(lRays.get(0).hitInfo.wasHit())      texit = lRays.get(0).hitInfo.minT();
-                                               else                          
                                  texit = -1.0;
-                                               t = 0.0;
+                                       if (m_AbsorptionCoefficient)
+                                       {
+                                               absCoeff =      wx1 * ( wy1 * 
( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                                       wx  * 
( wy1 * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
                                        }
+                                       else
+                                               absCoeff = 0.0f;
 
-                                       previousRefractiveIndex = refrInd;
+                                       if (m_EmittedLight && absCoeff > 0.0f)
+                                       {
+                                               float elValue = wx1 * ( wy1 * 
( wz1 * (*m_EmittedLight)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
                  wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                                             
  wx  * ( wy1 * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
                  wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
+                                               
m_EmittedLightColorMap->Lookup(elValue, sourceColor);
+                                       }
+                                       else
+                                               sourceColor = Color(RGB(0.0f, 
0.0f, 0.0f));
+
+                                       if (absCoeff > 0.0f)
+                                       {
+                                               transmittance = expf(- 
absCoeff * (float)(tIntegration * m_MetersPerUnit));
+                                               accumColor += sourceColor * 
(accumTransmittance * (1.0f - transmittance));
+                                               accumTransmittance *= 
transmittance;
+                                       }
                                }
 
-                               tIntegration = texit - t;
-                               if (tIntegration > m_WorldStepSize)
-                                       tIntegration = m_WorldStepSize;
+                               t += m_WorldStepSize;
+                       }
 
-                               if (m_AbsorptionCoefficient)
-                               {
-                                       absCoeff =      wx1 * ( wy1 * ( wz1 * 
(*m_AbsorptionCoefficient)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) 
+
-                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
-                                                                             
  wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]  , hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
-                                                               wx  * ( wy1 * 
( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
-                                                                             
  wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                  wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
-                               }
-                               else
-                                       absCoeff = 0.0f;
+                       if (m_AdaptationLevelLMS > 0.0f)
+                       {
+                               float r, g, b;
+                               RGBColor rgbColor = accumColor.convertRGB();
 
-                               if (m_EmittedLight && absCoeff > 0.0f)
-                               {
-                                       float elValue = wx1 * ( wy1 * ( wz1 * 
(*m_EmittedLight)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) +
-                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
-                                                                             
          wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]  , hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
-                                                                       wx  * 
( wy1 * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
-                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
-                                                                             
          wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, hitLattice[1]+1, 
hitLattice[2]  ) +
-                                                                             
                          wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
-                                       
m_EmittedLightColorMap->Lookup(elValue, sourceColor);
-                               }
-                               else
-                                       sourceColor = Color(RGB(0.0f, 0.0f, 
0.0f));
+                               r = rgbColor.r();
+                               g = rgbColor.g();
+                               b = rgbColor.b();
+                               ToneMap(&r, &g, &b, m_AdaptationLevelLMS);
+                               accumColor = Color(RGBColor(r, g, b));
+                       }
 
-                               if (absCoeff > 0.0f)
+                       if (depthSmallerThanMax)        // Transmitted ray
+                       {
+                               if (lRPE.hitInfo.wasHit())
                                {
-                                       transmittance = expf(- absCoeff * 
(float)(tIntegration * m_MetersPerUnit));
-                                       accumColor += sourceColor * 
(accumTransmittance * (1.0f - transmittance));
-                                       accumTransmittance *= transmittance;
+                                       if (lRPE.hitInfo.hitMaterial() == 
this)
+                                       {
+                                               lRay.setOrigin(lRay.origin() 
+ lRay.direction() * texit);
+                                               lRays.resetHit();
+                                               
context.renderer->traceRays(context, lRays);
+                                       }
+                                       else
+                                               
lRPE.hitInfo.hitMaterial()->shade(context, lRays);
+
+                                       if (m_AdaptationLevelLMS > 0.0f)      
  accumColor += *(lRPE.color) * accumTransmittance * (Color(RGBColor(1.0f, 
1.0f, 1.0f)) - accumColor);
+                                       else                                  
                          accumColor += *(lRPE.color) * accumTransmittance;
                                }
                        }
 
-                       t += m_WorldStepSize;
+                       rays.setResult(rayInd, accumColor);
                }
+#else
+               int rayInd, transRayInd = 0;
+               int transRayIDs[RayPacket::MaxSize];
+               float accumTransmittances[RayPacket::MaxSize];
+               Color accumColor;
+
+               RayPacketData rayPacketData;
+               RayPacket rayPacket(rayPacketData, raysSize, 
rays.getDepth()+1, RayPacket::NormalizedDirections);
+               rayPacket.useLocalColors();
 
-               if (m_AdaptationLevelLMS > 0.0f)
+               for(rayInd = 0; rayInd < raysSize; rayInd++)
                {
-                       float r, g, b;
-                       RGBColor rgbColor = accumColor.convertRGB();
+                       RayPacket::Element & e = rays.get(rayInd);
+                       Ray & ray = e.ray;
 
-                       r = rgbColor.r();
-                       g = rgbColor.g();
-                       b = rgbColor.b();
-                       ToneMap(&r, &g, &b, m_AdaptationLevelLMS);
-                       accumColor = Color(RGBColor(r, g, b));
+                       double tenter;
+//                     if (e.hitInfo.isInside())       tenter = 0.0;// need 
to figure a way to check if inside or not, assume outside for now
+//                     else
+                               tenter = e.hitInfo.minT();
+
+                       rayPacket.get(rayInd).ray.set(ray.origin() + tenter * 
ray.direction(), ray.direction());
                }
+               rayPacket.resetHit();
+               context.scene->getObject()->intersect(context, rayPacket);
 
-               if (rays.getDepth() < 
context.scene->getRenderParameters().maxDepth)    // Transmitted ray
+               for(rayInd = 0; rayInd < raysSize; rayInd++)
                {
-                       if (lRays.get(0).hitInfo.wasHit())
+                       Point hitPosition;
+                       double t, texit;
+                       int hitLattice[3];
+                       float accumTransmittance, hitLatticef[3];
+
+                       accumColor = Color(RGB(0.0f, 0.0f, 0.0f));
+                       accumTransmittance = 1.0f;
+
+                       Ray & lRay = rayPacket.get(rayInd).ray;
+                       HitInfo & lHit = rayPacket.get(rayInd).hitInfo;
+
+                       if (lHit.wasHit())      texit = lHit.minT();
+                       else                            texit = -1.0;
+                       t = 0.0;
+
+                       while(t < texit)
                        {
-                               if (lRays.get(0).hitInfo.hitMaterial() == 
this)
+                               hitPosition = lRay.origin() + t * 
lRay.direction();
+                               hitLatticef[0] = (float)((hitPosition.x() - 
m_Bounds[0].x()) / m_CellSize.x());
+                               hitLatticef[1] = (float)((hitPosition.y() - 
m_Bounds[0].y()) / m_CellSize.y());
+                               hitLatticef[2] = (float)((hitPosition.z() - 
m_Bounds[0].z()) / m_CellSize.z());
+                               hitLattice[0] = (int)floor(hitLatticef[0]);
+                               hitLattice[1] = (int)floor(hitLatticef[1]);
+                               hitLattice[2] = (int)floor(hitLatticef[2]);
+
+                               if (0 <= hitLattice[0] && hitLattice[0] < 
(int)m_DefaultVolume->getNx() - 1 &&
+                                       0 <= hitLattice[1] && hitLattice[1] < 
(int)m_DefaultVolume->getNy() - 1 &&
+                                       0 <= hitLattice[2] && hitLattice[2] < 
(int)m_DefaultVolume->getNz() - 1 )
                                {
-                                       lRay.setOrigin(lRay.origin() + 
lRay.direction() * texit);
-                                       lRays.resetHit();
-                                       context.renderer->traceRays(context, 
lRays);
+                                       float wx, wy, wz, wx1, wy1, wz1, 
transmittance, absCoeff;
+                                       Color sourceColor;
+                                       double tIntegration;
+
+                                       wx = hitLatticef[0] - 
(float)hitLattice[0];
+                                       wy = hitLatticef[1] - 
(float)hitLattice[1];
+                                       wz = hitLatticef[2] - 
(float)hitLattice[2];
+                                       wx1 = 1.0f - wx;
+                                       wy1 = 1.0f - wy;
+                                       wz1 = 1.0f - wz;
+
+                                       tIntegration = texit - t;
+                                       if (tIntegration > m_WorldStepSize)
+                                               tIntegration = 
m_WorldStepSize;
+
+                                       if (m_AbsorptionCoefficient)
+                                       {
+                                               absCoeff =      wx1 * ( wy1 * 
( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]  , hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                                       wx  * 
( wy1 * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
          wy  * ( wz1 * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                          wz  * (*m_AbsorptionCoefficient)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
+                                       }
+                                       else
+                                               absCoeff = 0.0f;
+
+                                       if (m_EmittedLight && absCoeff > 0.0f)
+                                       {
+                                               float elValue = wx1 * ( wy1 * 
( wz1 * (*m_EmittedLight)(hitLattice[0]  , hitLattice[1]  , hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
                  wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]  , 
hitLattice[1]+1, hitLattice[2]+1) ) ) +
+                                                                             
  wx  * ( wy1 * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, hitLattice[1]  , 
hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]  , hitLattice[2]+1) ) +
+                                                                             
                  wy  * ( wz1 * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]  ) +
+                                                                             
                                  wz  * (*m_EmittedLight)(hitLattice[0]+1, 
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
+                                               
m_EmittedLightColorMap->Lookup(elValue, sourceColor);
+                                       }
+                                       else
+                                               sourceColor = Color(RGB(0.0f, 
0.0f, 0.0f));
+
+                                       if (absCoeff > 0.0f)
+                                       {
+                                               transmittance = expf(- 
absCoeff * (float)(tIntegration * m_MetersPerUnit));
+                                               accumColor += sourceColor * 
(accumTransmittance * (1.0f - transmittance));
+                                               accumTransmittance *= 
transmittance;
+                                       }
                                }
-                               else
-                                       
lRays.get(0).hitInfo.hitMaterial()->shade(context, lRays);
 
-                               if (m_AdaptationLevelLMS > 0.0f)        
accumColor += *(lRays.get(0).color) * accumTransmittance * 
(Color(RGBColor(1.0f, 1.0f, 1.0f)) - accumColor);
-                               else                                          
                  accumColor += *(lRays.get(0).color) * accumTransmittance;
+                               t += m_WorldStepSize;
+                       }
+
+                       if (m_AdaptationLevelLMS > 0.0f)
+                       {
+                               float r, g, b;
+                               RGBColor rgbColor = accumColor.convertRGB();
+
+                               r = rgbColor.r();
+                               g = rgbColor.g();
+                               b = rgbColor.b();
+                               ToneMap(&r, &g, &b, m_AdaptationLevelLMS);
+                               accumColor = Color(RGBColor(r, g, b));
                        }
+
+                       if (depthSmallerThanMax)        // Transmitted ray
+                       {
+                               if (lHit.wasHit())
+                               {
+                                       if (lHit.hitMaterial() == this)
+                                       {
+                                               
rayPacket.get(transRayInd).ray.set(lRay.origin() + lRay.direction() * texit, 
lRay.direction());
+                                               transRayIDs[transRayInd] = 
rayInd;
+                                               
accumTransmittances[transRayInd] = accumTransmittance;
+                                               transRayInd++;
+                                       }
+                                       else
+                                       {
+                                               RayPacketData rpData;
+                                               RayPacket lRays(rpData, 1, 
rayPacket.getDepth(), RayPacket::NormalizedDirections);
+                                               lRays.useLocalColors();
+
+                                               RayPacket::Element & rpe = 
rayPacket.get(rayInd);
+                                               
lRays.get(0).ray.set(rpe.ray.origin(), rpe.ray.direction());
+                                               lRays.resetHit();
+                                               
lRays.get(0).hitInfo.hit(rpe.hitInfo.minT(), rpe.hitInfo.hitMaterial(), 
rpe.hitInfo.hitPrimitive(), rpe.hitInfo.hitTexCoordMapper());
+
+                                               
lHit.hitMaterial()->shade(context, lRays);
+                                               if (m_AdaptationLevelLMS > 
0.0f)        accumColor += *(lRays.get(0).color) * accumTransmittance * 
(Color(RGBColor(1.0f, 1.0f, 1.0f)) - accumColor);
+                                               else                          
                                  accumColor += *(lRays.get(0).color) * 
accumTransmittance;
+                                       }
+                               }
+                       }
+
+                       rays.setResult(rayInd, accumColor);
                }
 
-               rays.setResult(rayInd, accumColor);
-       }
+               if (depthSmallerThanMax)        // Transmitted ray
+               {
+                       rayPacket.resize(transRayInd);
+                       rayPacket.resetHit();
+                       context.renderer->traceRays(context, rayPacket);
+
+                       for(rayInd = 0; rayInd < transRayInd; rayInd++)
+                       {
+                               accumColor = 
*(rays.get(transRayIDs[rayInd]).color);
+                               if (m_AdaptationLevelLMS > 0.0f)        
accumColor += *(rayPacket.get(rayInd).color) * accumTransmittances[rayInd] * 
(Color(RGBColor(1.0f, 1.0f, 1.0f)) - accumColor);
+                               else                                          
                  accumColor += *(rayPacket.get(rayInd).color) * 
accumTransmittances[rayInd];
+                               rays.setResult(transRayIDs[rayInd], 
accumColor);
+                       }
+               }
+#endif
 }

Modified: branches/fire/scenes/primtest.cc
==============================================================================
--- branches/fire/scenes/primtest.cc    (original)
+++ branches/fire/scenes/primtest.cc    Mon Sep 12 16:09:37 2005
@@ -261,9 +261,9 @@
        Material * matIPM = new InhomogeneousParticipatingMedium(       
"../Data/heptane/abskgIN_M00_0450.nrrd",
                                                                              
                                                  
"../Data/heptane/tempIN_M00_0450.nrrd",
                                                                              
                                                  colorMap,
-                                                                             
                                                  NULL, 
//"../Data/heptane/refrIN_M00_0450.nrrd",
+                                                                             
                                                  NULL, 
//"../Data/heptane/refrIN_M00_0450_100.nrrd",
                                                                              
                                                  Point(-0.21, -0.21, 0.19), 
Point(0.21, 0.21, 0.61),
-                                                                             
                                                  0.5, 10.0, 0.3f);
+                                                                             
                                                  1.0, 10.0, 0.3f);
        Material * matL = new Lambertian(Color(RGB(.6,0,0)));
        Primitive * primC = new Cube(matIPM, Point(-0.2, -0.2, 0.2), 0.4, 
0.4, 0.4);
        Primitive * primS = new Sphere(matL, Point(0.0, 0.0, 0.4), 0.1);




  • [MANTA] r539 - in branches/fire: Model/Materials scenes, vpegorar, 09/12/2005

Archive powered by MHonArc 2.6.16.

Top of page