Text archives Help
- From:
- To:
- Subject: [Manta] r2336 - trunk/Model/Materials
- Date: Wed, 22 Oct 2008 10:27:08 -0600 (MDT)
Author: brownlee
Date: Wed Oct 22 10:27:06 2008
New Revision: 2336
Modified:
trunk/Model/Materials/Volume.cc
trunk/Model/Materials/Volume.h
Log:
forgot to commit volume file. This is an intermediary step to make the
volume material also a primitive, this will allow the volume primitive to
collect a hit list
Modified: trunk/Model/Materials/Volume.cc
==============================================================================
--- trunk/Model/Materials/Volume.cc (original)
+++ trunk/Model/Materials/Volume.cc Wed Oct 22 10:27:06 2008
@@ -333,14 +333,12 @@
}
course_hash = new_course_hash;
- cout << "course hash: ";
size_t num_bits = sizeof(course_hash)*8;
- for(size_t i = 0; i < num_bits; i++)
- if (course_hash & ( 1ULL << i ))
- cout << 1;
- else
- cout << 0;
- cout << "\n";
+ // for(size_t i = 0; i < num_bits; i++)
+ // if (course_hash & ( 1ULL << i ))
+ // cout << 1;
+ // else
+ // cout << 0;
}
Modified: trunk/Model/Materials/Volume.h
==============================================================================
--- trunk/Model/Materials/Volume.h (original)
+++ trunk/Model/Materials/Volume.h Wed Oct 22 10:27:06 2008
@@ -19,6 +19,8 @@
#include <Interface/RayPacket.h>
#include <Interface/SampleGenerator.h>
#include <Interface/Scene.h>
+#include <Model/Primitives/PrimitiveCommon.h>
+#include <Model/Intersections/AxisAlignedBox.h>
#include <cassert>
#include <float.h>
@@ -141,7 +143,7 @@
};
template<class T>
- class Volume : public Material
+ class Volume : public PrimitiveCommon, public Material
{
protected:
class HVIsectContext {
@@ -164,7 +166,7 @@
vector<mcT> cellVector_mc; // color hashes
Volume(GridArray3<T>* data, RGBAColorMap* colorMap, const BBox&
bounds,
- double cellStepSize, int depth,
+ double cellStepSize, int depth, Primitive* child = NULL,
double forceDataMin = -FLT_MAX, double forceDataMax = -FLT_MAX);
virtual ~Volume();
void setBounds(BBox bounds);
@@ -174,6 +176,102 @@
virtual void preprocess(const PreprocessContext& context);
virtual void shade(const RenderContext & context, RayPacket& rays)
const;
virtual void attenuateShadows(const RenderContext& context,
RayPacket& shadowRays) const;
+ virtual void intersect(const RenderContext& context, RayPacket& rays)
const
+ {
+ float vol_t_min[rays.end()];
+ float vol_t_max[rays.end()];
+ float vol_t_child[rays.end()];
+ bool intersected[rays.end()];
+ // This is so our t values have the same scale as other prims, e.g.,
TexTriangle
+ rays.normalizeDirections();
+
+ // Intersection algorithm requires inverse directions computed.
+ rays.computeInverseDirections();
+ rays.computeSigns();
+
+ // Iterate over each ray.
+ for (int i=rays.begin();i<rays.end();++i) {
+ intersected[i] = false;
+ Real tmin, tmax;
+ // Check for an intersection.
+ if (Intersection::intersectAaBox( _bbox,
+ tmin,
+ tmax,
+ rays.getRay(i),
+ rays.getSigns(i),
+ rays.getInverseDirection(i))){
+ // Check to see if we are inside the box.
+ //if (tmin > T_EPSILON)
+
+ // rays.hit( i, tmin, getMaterial(), this, getTexCoordMapper()
);
+ // And use the max intersection if we are.
+ //else
+ //rays.hit( i, tmax, getMaterial(), this, getTexCoordMapper() );
+ vol_t_min[i] = tmin;
+ vol_t_max[i] = tmax;
+ intersected[i] = true;
+ if (_child) {
+ //if we have already hit something inside volume
+ // assume it is child so we don't want to intersect it again
+
+ //TODO: might be better to setup a child ray packet
+ if (rays.wasHit(i) && (rays.getMinT(i) <
+ tmax)) {
+ rays.hit(i, tmin, this, this, getTexCoordMapper() );
+ }
+ }
+ }
+ }
+ if (_child) {
+ _child->intersect(context, rays);
+ }
+ for (int i=rays.begin();i<rays.end();++i) {
+ if (!intersected[i])
+ continue;
+ //put tmin, tmax and child_min onto scratchpad
+ rays.getScratchpad<Real>(0)[i] = vol_t_min[i];
+ rays.getScratchpad<Real>(1)[i] = vol_t_max[i];
+ if (!_child || fabs(rays.getMinT(i) - vol_t_min[i]) < T_EPSILON)
+ rays.getScratchpad<Real>(2)[i] = vol_t_max[i];
+ else
+ rays.getScratchpad<Real>(2)[i] = rays.getMinT(i);
+ rays.hit(i, vol_t_min[i], this, this, getTexCoordMapper() );
+ }
+ }
+virtual void computeNormal(const RenderContext&, RayPacket& rays) const
+{
+ rays.computeHitPositions();
+ for(int i=rays.begin(); i<rays.end(); i++) {
+ Vector hp = rays.getHitPosition(i);
+ if (Abs(hp.x() - _bbox[0][0]) < 0.0001)
+ rays.setNormal(i, Vector(-1, 0, 0 ));
+
+ else if (Abs(hp.x() - _bbox[1][0]) < 0.0001)
+ rays.setNormal(i, Vector( 1, 0, 0 ));
+
+ else if (Abs(hp.y() - _bbox[0][1]) < 0.0001)
+ rays.setNormal(i, Vector( 0,-1, 0 ));
+
+ else if (Abs(hp.y() - _bbox[1][1]) < 0.0001)
+ rays.setNormal(i, Vector( 0, 1, 0 ));
+
+ else if (Abs(hp.z() - _bbox[0][2]) < 0.0001)
+ rays.setNormal(i, Vector( 0, 0,-1 ));
+
+ else
+ rays.setNormal(i, Vector( 0, 0, 1 ));
+ }
+}
+
+ BBox getBounds();
+
+virtual void computeBounds(const PreprocessContext&, BBox& bbox_) const
+{
+ // bbox.extendByPoint(Point(xmin, ymin, zmin));
+ // bbox.extendByPoint(Point(xmax, ymax, zmax));
+ bbox_.extendByPoint( _bbox[0] );
+ bbox_.extendByPoint( _bbox[1] );
+}
GridArray3<T>* _data;
float getValue(int x, int y, int z);
GridArray3<VMCell>* macrocells;
@@ -192,6 +290,7 @@
int _nx,_ny,_nz;
RGBAColorMap* _colorMap;
BBox _bounds;
+ BBox _bbox;
Vector _datadiag;
Vector _sdiag;
Vector _hierdiag;
@@ -205,14 +304,15 @@
float _dataMax;
float _colorScalar;
float _maxDistance;
+ Primitive* _child;
};
template<class T>
Volume<T>::Volume(GridArray3<T>* data, RGBAColorMap* colorMap,
const BBox& bounds, double cellStepSize,
- int depth,
+ int depth, Primitive* child,
double forceDataMin, double forceDataMax)
- : _data(data), _colorMap(colorMap)
+ : _data(data), _colorMap(colorMap), _child(child)
{
//slightly expand the bounds.
_bounds[0] = bounds[0] - bounds.diagonal().length()*T_EPSILON;
@@ -359,6 +459,12 @@
delete[] _izsize;
}
+template<class T>
+BBox Volume<T>::getBounds()
+{
+ return _bounds;
+}
+
template<class T>
void Volume<T>::setBounds(BBox bounds)
{
@@ -366,6 +472,7 @@
_bounds[0] = bounds[0] - bounds.diagonal().length()*T_EPSILON;
_bounds[1] = bounds[1] + bounds.diagonal().length()*T_EPSILON;
Vector diag = _bounds.diagonal();
+ _bbox = bounds;
_cellSize = diag*Vector( 1.0 / (double)(_data->getNx()-1),
1.0 / (double)(_data->getNy()-1),
@@ -488,7 +595,6 @@
const Vector& cellcorner, const Vector& celldir,
HVIsectContext &isctx) const
{
-
int cx=_xsize[depth];
int cy=_ysize[depth];
int cz=_zsize[depth];
@@ -508,7 +614,6 @@
// If we have valid samples
if(gx<nx-1 && gy<ny-1 && gz<nz-1){
-
float rhos[8];
rhos[0]=data(gx, gy, gz);
rhos[1]=data(gx, gy, gz+1);
@@ -661,7 +766,6 @@
new_iz=0;
else if(new_iz>=new_cz)
new_iz=new_cz-1;
-
double new_dtdx=dtdx*_ixsize[depth-1];
double new_dtdy=dtdy*_iysize[depth-1];
double new_dtdz=dtdz*_izsize[depth-1];
@@ -762,12 +866,13 @@
}
}
-#define RAY_TERMINATION 0.9
+#define RAY_TERMINATION 0.98
template<class T>
void Volume<T>::shade(const RenderContext & context, RayPacket& rays)
const
- {
+{
rays.normalizeDirections();
rays.computeHitPositions();
+
float t_inc = _stepSize;
@@ -791,6 +896,18 @@
origin = rays.getHitPosition(rayIndex);
tMins[rayIndex] = rays.getMinT(rayIndex);
}
+ if (!(_bounds.contains(rays.getHitPosition(rayIndex))))
+ {
+ float tmin, tmax;
+ Intersection::intersectAaBox( _bounds,
+ tmin,
+ tmax,
+ rays.getRay(rayIndex),
+ rays.getSigns(rayIndex),
+
rays.getInverseDirection(rayIndex));
+ tMins[rayIndex] = tmin;
+ origin = rays.getOrigin(rayIndex) +
rays.getDirection(rayIndex)*tmin;
+ }
lRays1.setRay(rayIndex, origin, rays.getDirection(rayIndex));
alphas[rayIndex] = 0;
@@ -929,7 +1046,6 @@
alphas[rayIndex] = isctx.alpha;
totals[rayIndex] = isctx.total;
}
-
const bool depth = (rays.getDepth() <
context.scene->getRenderParameters().maxDepth);
int start = -1;
for(int i = rays.begin(); i < rays.end(); i++) {
@@ -955,7 +1071,7 @@
//let's trace these rays
lRays1.resize(start, i);
context.sample_generator->setupChildPacket(context, rays,
lRays1);
- context.renderer->traceRays(context, lRays1);
+ //context.renderer->traceRays(context, lRays1);
for(int k = start; k < i; k++) {
Color bgColor(RGB(0,0,0));
if (depth)
@@ -970,7 +1086,7 @@
}
if (start >= 0) {
//let's trace just these active rays
- lRays1.resize(start, rays.end());
+ // lRays1.resize(start, rays.end());
context.sample_generator->setupChildPacket(context, rays, lRays1);
context.renderer->traceRays(context, lRays1);
- [Manta] r2336 - trunk/Model/Materials, brownlee, 10/22/2008
Archive powered by MHonArc 2.6.16.