Add support for int8/int16 types. Addresses issues #9 and #42.

This commit is contained in:
Matt Pharr
2011-07-21 06:57:40 +01:00
parent 2d573acd17
commit bba7211654
64 changed files with 2317 additions and 885 deletions

View File

@@ -190,7 +190,9 @@ int main(int argc, char *argv[]) {
nodes[i].bounds[1].v[1] = b[4];
nodes[i].bounds[1].v[2] = b[5];
READ(nodes[i].offset, 1);
READ(nodes[i].primsAxis, 1);
READ(nodes[i].nPrimitives, 1);
READ(nodes[i].splitAxis, 1);
READ(nodes[i].pad, 1);
}
// And then read the triangles

View File

@@ -50,21 +50,11 @@ struct Triangle {
struct LinearBVHNode {
uniform float3 bounds[2];
uniform unsigned int offset; // num primitives for leaf, second child for interior
uniform unsigned int primsAxis; // 0:7 nPrimitives, 8:15 split axis, 16:31 padding
uniform unsigned int8 nPrimitives;
uniform unsigned int8 splitAxis;
uniform unsigned int16 pad;
};
static inline uniform int nPrims(const reference LinearBVHNode node) {
return (node.primsAxis & 0xff);
}
static inline uniform int axis(const reference LinearBVHNode node) {
return ((node.primsAxis >> 8) & 0xff);
}
static inline uniform bool isInterior(const reference LinearBVHNode node) {
return nPrims(node) == 0;
}
static inline float3 Cross(const float3 v1, const float3 v2) {
float v1x = v1.x, v1y = v1.y, v1z = v1.z;
float v2x = v2.x, v2y = v2.y, v2z = v2.z;
@@ -199,7 +189,7 @@ bool BVHIntersect(const LinearBVHNode nodes[], const Triangle tris[],
// Check ray against BVH node
LinearBVHNode node = nodes[nodeNum];
if (any(BBoxIntersect(node.bounds, ray))) {
uniform unsigned int nPrimitives = nPrims(node);
uniform unsigned int nPrimitives = node.nPrimitives;
if (nPrimitives > 0) {
// Intersect ray with primitives in leaf BVH node
uniform unsigned int primitivesOffset = node.offset;
@@ -213,7 +203,7 @@ bool BVHIntersect(const LinearBVHNode nodes[], const Triangle tris[],
}
else {
// Put far BVH node on _todo_ stack, advance to near node
if (r.dirIsNeg[axis(node)]) {
if (r.dirIsNeg[node.splitAxis]) {
todo[todoOffset++] = nodeNum + 1;
nodeNum = node.offset;
}

View File

@@ -75,30 +75,20 @@ struct Ray {
namespace ispc {
struct Triangle {
float3 p[3];
int id;
int32_t id;
};
struct LinearBVHNode {
float3 bounds[2];
unsigned int offset; // primitives for leaf, second child for interior
unsigned int primsAxis; // 0:7 nPrimitives, 8:15 split axis, 16:31 padding
int32_t offset; // primitives for leaf, second child for interior
uint8_t nPrimitives;
uint8_t splitAxis;
uint16_t pad;
};
}
using namespace ispc;
inline int nPrims(const LinearBVHNode &node) {
return (node.primsAxis & 0xff);
}
inline int axis(const LinearBVHNode &node) {
return ((node.primsAxis >> 8) & 0xff);
}
inline bool isInterior(const LinearBVHNode &node) {
return nPrims(node) == 0;
}
inline float3 Cross(const float3 &v1, const float3 &v2) {
float v1x = v1.x, v1y = v1.y, v1z = v1.z;
float v2x = v2.x, v2y = v2.y, v2z = v2.z;
@@ -230,7 +220,7 @@ bool BVHIntersect(const LinearBVHNode nodes[], const Triangle tris[],
// Check ray against BVH node
const LinearBVHNode &node = nodes[nodeNum];
if (BBoxIntersect(node.bounds, ray)) {
unsigned int nPrimitives = nPrims(node);
unsigned int nPrimitives = node.nPrimitives;
if (nPrimitives > 0) {
// Intersect ray with primitives in leaf BVH node
unsigned int primitivesOffset = node.offset;
@@ -244,7 +234,7 @@ bool BVHIntersect(const LinearBVHNode nodes[], const Triangle tris[],
}
else {
// Put far BVH node on _todo_ stack, advance to near node
if (r.dirIsNeg[axis(node)]) {
if (r.dirIsNeg[node.splitAxis]) {
todo[todoOffset++] = nodeNum + 1;
nodeNum = node.offset;
}