*reserved RayObject align offset 0 for private usage inside each structure
point is that other structures like trees can then distiguish between other nodes or rayobject primitives withouth needing any other variable. (Note yet used but will reduce memory by a nice factor (linear to the number of primitives))
This commit is contained in:
@@ -58,13 +58,15 @@
|
||||
only 2 are used:
|
||||
|
||||
addr&2 - type of object
|
||||
0 RayFace
|
||||
1 RayObject (generic with API callbacks)
|
||||
2 unused
|
||||
0 Self (reserved for each structure)
|
||||
1 RayFace
|
||||
2 RayObject (generic with API callbacks)
|
||||
3 unused
|
||||
|
||||
0 was choosed to RayFace because thats the one where speed will be needed.
|
||||
|
||||
0 means it's reserved and has it own meaning inside each ray acceleration structure
|
||||
(this way each structure can use the allign offset to determine if a node represents a
|
||||
RayObject primitive, which can be used to save memory)
|
||||
|
||||
You actually don't need to care about this if you are only using the API
|
||||
described on RE_raytrace.h
|
||||
*/
|
||||
@@ -101,10 +103,13 @@ typedef struct RayObjectAPI
|
||||
} RayObjectAPI;
|
||||
|
||||
//TODO use intptr_t
|
||||
#define RayObject_align(o) ((RayObject*)(((int)o)&(~3)))
|
||||
#define RayObject_unalign(o) ((RayObject*)(((int)o)|1))
|
||||
#define RayObject_isFace(o) ((((int)o)&3) == 0)
|
||||
#define RayObject_align(o) ((RayObject*)(((int)o)&(~3)))
|
||||
#define RayObject_unalignRayFace(o) ((RayObject*)(((int)o)|1))
|
||||
#define RayObject_unalignRayAPI(o) ((RayObject*)(((int)o)|2))
|
||||
|
||||
#define RayObject_isAligned(o) ((((int)o)&3) == 0)
|
||||
#define RayObject_isRayFace(o) ((((int)o)&3) == 1)
|
||||
#define RayObject_isRayAPI(o) ((((int)o)&3) == 2)
|
||||
|
||||
/*
|
||||
* Extend min/max coords so that the rayobject is inside them
|
||||
|
||||
@@ -255,7 +255,7 @@ static int intersect_rayface(RayFace *face, Isect *is)
|
||||
|
||||
is->hit.ob = face->ob;
|
||||
is->hit.face = face->face;
|
||||
is->last_hit = (RayObject*)face;
|
||||
is->last_hit = (RayObject*) RayObject_unalignRayFace(face);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -289,15 +289,16 @@ int RE_rayobject_raycast(RayObject *r, Isect *i)
|
||||
|
||||
int RE_rayobject_intersect(RayObject *r, Isect *i)
|
||||
{
|
||||
if(RayObject_isFace(r))
|
||||
if(RayObject_isRayFace(r))
|
||||
{
|
||||
return intersect_rayface( (RayFace*) r, i);
|
||||
return intersect_rayface( (RayFace*) RayObject_align(r), i);
|
||||
}
|
||||
else
|
||||
else if(RayObject_isRayAPI(r))
|
||||
{
|
||||
r = RayObject_align( r );
|
||||
return r->api->raycast( r, i );
|
||||
}
|
||||
else assert(0);
|
||||
}
|
||||
|
||||
void RE_rayobject_add(RayObject *r, RayObject *o)
|
||||
@@ -320,19 +321,20 @@ void RE_rayobject_free(RayObject *r)
|
||||
|
||||
void RE_rayobject_merge_bb(RayObject *r, float *min, float *max)
|
||||
{
|
||||
if(RayObject_isFace(r))
|
||||
if(RayObject_isRayFace(r))
|
||||
{
|
||||
RayFace *face = (RayFace*)r;
|
||||
RayFace *face = (RayFace*) RayObject_align(r);
|
||||
DO_MINMAX( face->v1, min, max );
|
||||
DO_MINMAX( face->v2, min, max );
|
||||
DO_MINMAX( face->v3, min, max );
|
||||
if(face->v4) DO_MINMAX( face->v4, min, max );
|
||||
}
|
||||
else
|
||||
else if(RayObject_isRayAPI(r))
|
||||
{
|
||||
r = RayObject_align( r );
|
||||
r->api->bb( r, min, max );
|
||||
}
|
||||
else assert(0);
|
||||
}
|
||||
|
||||
#ifdef RE_RAYCOUNTER
|
||||
|
||||
@@ -69,7 +69,7 @@ RayObject *RE_rayobject_bvh_create(int size)
|
||||
obj->bvh = BLI_bvhtree_new(size, FLT_EPSILON, 4, 6);
|
||||
|
||||
INIT_MINMAX(obj->bb[0], obj->bb[1]);
|
||||
return RayObject_unalign((RayObject*) obj);
|
||||
return RayObject_unalignRayAPI((RayObject*) obj);
|
||||
}
|
||||
|
||||
static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
|
||||
|
||||
@@ -74,7 +74,7 @@ RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4],
|
||||
Mat4CpyMat4(obj->target2global, transform);
|
||||
Mat4Invert(obj->global2target, obj->target2global);
|
||||
|
||||
return RayObject_unalign((RayObject*) obj);
|
||||
return RayObject_unalignRayAPI((RayObject*) obj);
|
||||
}
|
||||
|
||||
static int RayObject_instance_intersect(RayObject *o, Isect *isec)
|
||||
|
||||
@@ -128,5 +128,5 @@ RayObject* RE_rayobject_mesh_create(Mesh *mesh, void *ob)
|
||||
face->face = (void*)i;
|
||||
}
|
||||
|
||||
return RayObject_unalign((RayObject*) rm);
|
||||
return RayObject_unalignRayAPI((RayObject*) rm);
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ RayObject *RE_rayobject_octree_create(int ocres, int size)
|
||||
oc->ro_nodes_used = 0;
|
||||
|
||||
|
||||
return RayObject_unalign((RayObject*) oc);
|
||||
return RayObject_unalignRayAPI((RayObject*) oc);
|
||||
}
|
||||
|
||||
|
||||
@@ -631,7 +631,7 @@ static void RayObject_octree_done(RayObject *tree)
|
||||
|
||||
for(c=0; c<oc->ro_nodes_used; c++)
|
||||
{
|
||||
assert( RayObject_isFace(oc->ro_nodes[c]) );
|
||||
assert( RayObject_isRayFace(oc->ro_nodes[c]) );
|
||||
octree_fill_rayface(oc, (RayFace*)oc->ro_nodes[c]);
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,9 @@ RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi)
|
||||
face->ob = obi;
|
||||
face->face = vlr;
|
||||
|
||||
RE_rayobject_add( raytree, (RayObject*)face++ );
|
||||
RE_rayobject_add( raytree, RayObject_unalignRayFace(face) );
|
||||
|
||||
face++;
|
||||
}
|
||||
}
|
||||
RE_rayobject_done( raytree );
|
||||
@@ -311,7 +313,8 @@ static void makeraytree_single(Render *re)
|
||||
face->ob = obi;
|
||||
face->face = vlr;
|
||||
|
||||
RE_rayobject_add( raytree, (RayObject*)face++ );
|
||||
RE_rayobject_add( raytree, RayObject_unalignRayFace(face) );
|
||||
face++;
|
||||
}
|
||||
}
|
||||
RE_rayobject_done( raytree );
|
||||
|
||||
Reference in New Issue
Block a user