Text archives Help
- From: vpegorar@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r540 - branches/fire/Model/Materials
- Date: Mon, 12 Sep 2005 16:23:11 -0600 (MDT)
Author: vpegorar
Date: Mon Sep 12 16:23:10 2005
New Revision: 540
Modified:
branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
Log:
Just removed extra tab.
Modified: branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
==============================================================================
--- branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc
(original)
+++ branches/fire/Model/Materials/InhomogeneousParticipatingMedium.cc Mon
Sep 12 16:23:10 2005
@@ -131,447 +131,447 @@
rays.normalizeDirections();
#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;
+ 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;
- 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;
+ accumColor = Color(RGB(0.0f, 0.0f, 0.0f));
+ accumTransmittance = 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) ) ) ;
+ previousRefractiveIndex = - 1.0f;
- if (previousRefractiveIndex >
0.0f && previousRefractiveIndex != refrInd)
- {
- Vector hitNormal;
- double cosTheta,
cosTheta2, eta;
-#ifdef FAST_GRADIENT
- int hitLRn[3];
+// 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;
- 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];
+ 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;
- tmp[1] =
wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0] , hitLattice[1] ,
hitLattice[2] ) +
+ 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) ) ;
- tmp[2] =
wy1 * ( wz1 * (*m_RefractiveIndex)(hitLattice[0]+1, hitLattice[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 (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());
+
wz * (*m_RefractiveIndex)(hitLattice[0]+1,
hitLattice[1]+1, hitLattice[2]+1) ) ) ;
- 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());
+ if (previousRefractiveIndex > 0.0f &&
previousRefractiveIndex != refrInd)
+ {
+ Vector hitNormal;
+ double cosTheta, cosTheta2,
eta;
+#ifdef FAST_GRADIENT
+ int hitLRn[3];
+
+ 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());
#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;
- }
- 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;
+ cosTheta = - Dot(hitNormal,
lRay.direction());
+ if (cosTheta < 0.0)
+ {
+ cosTheta = - cosTheta;
+ hitNormal = -
hitNormal;
}
+ eta = refrInd /
previousRefractiveIndex;
- previousRefractiveIndex =
refrInd;
- }
-
- tIntegration = texit - t;
- if (tIntegration > m_WorldStepSize)
- tIntegration =
m_WorldStepSize;
+ cosTheta2 = 1.0 +
((cosTheta*cosTheta - 1.0) / (eta*eta));
- 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 (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);
+ }
- 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);
+ lRays.resetHit();
+
context.scene->getObject()->intersect(context, lRays);
+ if (lRPE.hitInfo.wasHit())
texit = lRPE.hitInfo.minT();
+ else
texit = -1.0;
+ t = 0.0;
}
- 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;
- }
+ previousRefractiveIndex = refrInd;
}
- t += m_WorldStepSize;
- }
+ tIntegration = texit - t;
+ if (tIntegration > m_WorldStepSize)
+ tIntegration = 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 (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 (depthSmallerThanMax) // Transmitted ray
- {
- if (lRPE.hitInfo.wasHit())
+ if (m_EmittedLight && absCoeff > 0.0f)
{
- 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);
+ 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 (m_AdaptationLevelLMS > 0.0f)
accumColor += *(lRPE.color) * accumTransmittance * (Color(RGBColor(1.0f,
1.0f, 1.0f)) - accumColor);
- else
accumColor += *(lRPE.color) * accumTransmittance;
+ if (absCoeff > 0.0f)
+ {
+ transmittance = expf(- absCoeff *
(float)(tIntegration * m_MetersPerUnit));
+ accumColor += sourceColor *
(accumTransmittance * (1.0f - transmittance));
+ accumTransmittance *= transmittance;
}
}
- rays.setResult(rayInd, accumColor);
+ t += m_WorldStepSize;
}
-#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();
- for(rayInd = 0; rayInd < raysSize; rayInd++)
+ if (m_AdaptationLevelLMS > 0.0f)
{
- RayPacket::Element & e = rays.get(rayInd);
- Ray & ray = e.ray;
+ float r, g, b;
+ RGBColor rgbColor = accumColor.convertRGB();
- 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());
+ r = rgbColor.r();
+ g = rgbColor.g();
+ b = rgbColor.b();
+ ToneMap(&r, &g, &b, m_AdaptationLevelLMS);
+ accumColor = Color(RGBColor(r, g, b));
}
- rayPacket.resetHit();
- context.scene->getObject()->intersect(context, rayPacket);
- for(rayInd = 0; rayInd < raysSize; rayInd++)
+ if (depthSmallerThanMax) // Transmitted ray
{
- 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 (lRPE.hitInfo.wasHit())
{
- 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 )
+ if (lRPE.hitInfo.hitMaterial() == this)
{
- 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;
- }
+ lRay.setOrigin(lRay.origin() +
lRay.direction() * texit);
+ lRays.resetHit();
+ context.renderer->traceRays(context,
lRays);
}
+ else
+
lRPE.hitInfo.hitMaterial()->shade(context, lRays);
- t += m_WorldStepSize;
+ if (m_AdaptationLevelLMS > 0.0f)
accumColor += *(lRPE.color) * accumTransmittance * (Color(RGBColor(1.0f,
1.0f, 1.0f)) - accumColor);
+ else
accumColor += *(lRPE.color) * accumTransmittance;
}
+ }
- 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));
- }
+ 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();
+
+ for(rayInd = 0; rayInd < raysSize; rayInd++)
+ {
+ RayPacket::Element & e = rays.get(rayInd);
+ Ray & ray = e.ray;
+
+ 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);
+
+ for(rayInd = 0; rayInd < raysSize; rayInd++)
+ {
+ 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;
- if (depthSmallerThanMax) // Transmitted ray
+ 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 )
{
- if (lHit.wasHit())
+ 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)
{
- 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();
+ 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;
- 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());
+ 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));
-
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;
- }
+ if (absCoeff > 0.0f)
+ {
+ transmittance = expf(- absCoeff *
(float)(tIntegration * m_MetersPerUnit));
+ accumColor += sourceColor *
(accumTransmittance * (1.0f - transmittance));
+ accumTransmittance *= transmittance;
}
}
- rays.setResult(rayInd, accumColor);
+ t += m_WorldStepSize;
}
- if (depthSmallerThanMax) // Transmitted ray
+ if (m_AdaptationLevelLMS > 0.0f)
{
- rayPacket.resize(transRayInd);
- rayPacket.resetHit();
- context.renderer->traceRays(context, rayPacket);
+ float r, g, b;
+ RGBColor rgbColor = accumColor.convertRGB();
- for(rayInd = 0; rayInd < transRayInd; rayInd++)
+ 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())
{
- 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);
+ 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);
+ }
+
+ 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
}
- [MANTA] r540 - branches/fire/Model/Materials, vpegorar, 09/12/2005
Archive powered by MHonArc 2.6.16.