*Some debug

*Some more integration with bli bvh (just testing stuff)
This commit is contained in:
2009-05-31 02:35:58 +00:00
parent 92811f0f67
commit 4b50590945
4 changed files with 40 additions and 24 deletions

View File

@@ -45,6 +45,7 @@ void RE_rayobject_free(RayObject *r);
/* RayObject constructors */
RayObject* RE_rayobject_octree_create(int ocres, int size);
RayObject* RE_rayobject_bvh_create(int size);
//RayObject* RayObject_derivedmesh_create(struct DerivedMesh*, void *ob);
RayObject* RE_rayobject_mesh_create(struct Mesh*, void *ob);
@@ -54,9 +55,12 @@ struct Isect
{
float start[3];
float vec[3];
float labda;
float dist; /* length of vec, configured by RE_rayobject_raycast */
/* float end[3]; - not used */
float labda, u, v;
float u, v;
struct
{

View File

@@ -27,8 +27,10 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <assert.h>
#include <stdio.h>
#include "BKE_utildefines.h"
#include "BLI_arithb.h"
#include "RE_raytrace.h"
#include "render_types.h"
@@ -264,6 +266,7 @@ static int intersect_rayface(RayFace *face, Isect *is)
is->hit.ob = face->ob;
is->hit.face = face->face;
is->last_hit = (RayObject*)face;
return 1;
}
@@ -272,6 +275,19 @@ static int intersect_rayface(RayFace *face, Isect *is)
int RE_rayobject_raycast(RayObject *r, Isect *i)
{
static int casted_rays = 0;
if(casted_rays++ % (1<<20) == 0)
printf("Casting %d rays\n", casted_rays);
i->vec[0] *= i->labda;
i->vec[1] *= i->labda;
i->vec[2] *= i->labda;
i->labda = 1.0f; //RE_RAYTRACE_MAXDIST; //len;
i->dist = VecLength(i->vec);
assert(i->mode==RE_RAY_SHADOW);
if(i->mode==RE_RAY_SHADOW && i->last_hit && RE_rayobject_intersect(i->last_hit, i))
return 1;
@@ -280,27 +296,14 @@ int RE_rayobject_raycast(RayObject *r, Isect *i)
int RE_rayobject_intersect(RayObject *r, Isect *i)
{
assert(i->mode==RE_RAY_SHADOW);
if(RayObject_isFace(r))
{
return intersect_rayface( (RayFace*) r, i);
}
else
{
//TODO should be done somewhere else
// float len = Normalize( i->vec );
int hit;
i->vec[0] *= i->labda;
i->vec[1] *= i->labda;
i->vec[2] *= i->labda;
i->labda = 1.0f; //RE_RAYTRACE_MAXDIST; //len;
r = RayObject_align( r );
hit = r->api->raycast( r, i );
// i->labda /= len;
return hit;
return r->api->raycast( r, i );
}
}

View File

@@ -65,7 +65,7 @@ RayObject *RE_rayobject_bvh_create(int size)
assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */
obj->rayobj.api = &bvh_api;
obj->bvh = BLI_bvhtree_new(size, 0.0, 4, 6);
obj->bvh = BLI_bvhtree_new(size, 0.0, 2, 6);
return RayObject_unalign((RayObject*) obj);
}
@@ -78,19 +78,23 @@ static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTr
if(RE_rayobject_intersect(face,isect))
{
hit->index = index;
// hit.distance = TODO
if(isect->mode == RE_RAY_SHADOW)
hit->dist = 0;
}
}
static int RayObject_bvh_intersect(RayObject *o, Isect *isec)
{
BVHObject *obj = (BVHObject*)o;
float dir[3];
VECCOPY( dir, isec->vec );
Normalize( dir );
// float dir[3];
// VECCOPY( dir, isec->vec );
// Normalize( dir );
BVHTreeRayHit hit;
hit.index = 0;
hit.dist = isec->labda*isec->dist;
//BLI_bvhtree_ray_cast returns -1 on non hit (in case we dont give a Hit structure
return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, NULL, bvh_callback, isec) != -1;
return BLI_bvhtree_ray_cast(obj->bvh, isec->start, isec->vec, 0.0, &hit, bvh_callback, isec) != 0;
}
static void RayObject_bvh_add(RayObject *o, RayObject *ob)

View File

@@ -122,6 +122,7 @@ void makeraytree(Render *re)
double lasttime= PIL_check_seconds_timer();
int v, totv = 0, totface = 0;
RayFace *faces, *cur_face;
int tot_quads = 0;
//TODO (for now octree only supports RayFaces so we need to create them)
//
@@ -144,7 +145,9 @@ void makeraytree(Render *re)
}
}
re->raytree = RE_rayobject_octree_create( re->r.ocres, totface );
printf("RE_rayobject_*_create( %d )\n", totface);
// re->raytree = RE_rayobject_octree_create( re->r.ocres, totface );
re->raytree = RE_rayobject_bvh_create( totface );
//Fill rayfaces
re->rayfaces = (RayObject*)MEM_callocN(totface*sizeof(RayFace), "render faces");
@@ -182,7 +185,7 @@ void makeraytree(Render *re)
cur_face->v1 = vlr->v1->co;
cur_face->v2 = vlr->v2->co;
cur_face->v3 = vlr->v3->co;
cur_face->v4 = vlr->v4 ? vlr->v4->co : NULL;
cur_face->v4 = vlr->v4 ? tot_quads++, vlr->v4->co : NULL;
cur_face->ob = (void*)obi;
cur_face->face = vlr;
@@ -194,7 +197,9 @@ void makeraytree(Render *re)
}
}
printf("call RE_rayobject_done( %dtri, %dquads )\n", totface-tot_quads, tot_quads);
RE_rayobject_done( re->raytree );
printf("return RE_rayobject_done( )\n");
//TODO vlr_face_coords, vlr_check_intersect, vlr_get_transform, re);
re->i.infostr= NULL;