Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ../yafaray-0.1.2~git110209/src/yafraycore/
- diff -ru src/yafraycore//kdtree.cc ../yafaray-0.1.2~git110209/src/yafraycore//kdtree.cc
- --- src/yafraycore//kdtree.cc 2011-02-12 17:55:55.000000000 +0100
- +++ ../yafaray-0.1.2~git110209/src/yafraycore//kdtree.cc 2011-02-07 00:35:21.000000000 +0100
- @@ -654,15 +654,17 @@
- returns the closest hit within dist
- */
- -bool triKdTree_t::Intersect(const ray_t &ray, PFLOAT dist, triangle_t **tr, PFLOAT &Z, intersectData_t &data) const
- +bool triKdTree_t::Intersect(const ray_t &ray, PFLOAT dist, triangle_t **tr, PFLOAT &Z, void *udat) const
- {
- Z=dist;
- PFLOAT a, b, t; // entry/exit/splitting plane signed distance
- PFLOAT t_hit;
- - if( !treeBound.cross(ray, a, b, dist) ) { return false; }
- + if (!treeBound.cross(ray, a, b, dist))
- + { return false; }
- - intersectData_t currentData, tempData;
- + unsigned char udat1[PRIM_DAT_SIZE], udat2[PRIM_DAT_SIZE];
- + void *c_udat=(void*)udat1, *t_udat=(void*)udat2;
- vector3d_t invDir(1.0/ray.dir.x, 1.0/ray.dir.y, 1.0/ray.dir.z); //was 1.f!
- bool hit = false;
- @@ -749,13 +751,15 @@
- {
- triangle_t *mp = currNode->onePrimitive;
- - if (mp->intersect(ray, &t_hit, tempData))
- + if (mp->intersect(ray, &t_hit, t_udat))
- {
- if(t_hit < Z && t_hit >= ray.tmin)
- {
- Z = t_hit;
- *tr = mp;
- - currentData = tempData;
- + void *swap = t_udat;
- + t_udat = c_udat;
- + c_udat = swap;
- hit = true;
- }
- }
- @@ -768,13 +772,15 @@
- {
- triangle_t *mp = prims[i];
- - if (mp->intersect(ray, &t_hit, tempData))
- + if (mp->intersect(ray, &t_hit, t_udat))
- {
- if(t_hit < Z && t_hit >= ray.tmin)
- {
- Z = t_hit;
- *tr = mp;
- - currentData = tempData;
- + void *swap = t_udat;
- + t_udat = c_udat;
- + c_udat = swap;
- hit = true;
- }
- }
- @@ -783,7 +789,11 @@
- if(hit && Z <= stack[exPt].t)
- {
- - data = currentData;
- + float nu = ((float*)c_udat)[0];
- + float nv = ((float*)c_udat)[1];
- + float *temp = (float*)udat;
- + temp[0] = nu;
- + temp[1] = nv;
- return true;
- }
- @@ -793,7 +803,11 @@
- } // while
- - data = currentData;
- + float nu = ((float*)c_udat)[0];
- + float nv = ((float*)c_udat)[1];
- + float *temp = (float*)udat;
- + temp[0] = nu;
- + temp[1] = nv;
- return hit; //false;
- }
- @@ -807,7 +821,7 @@
- if (!treeBound.cross(ray, a, b, dist))
- return false;
- - intersectData_t bary;
- + unsigned char udat[PRIM_DAT_SIZE];
- vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
- KdStack stack[KD_MAX_STACK];
- @@ -893,7 +907,7 @@
- if (nPrimitives == 1)
- {
- triangle_t *mp = currNode->onePrimitive;
- - if (mp->intersect(ray, &t_hit, bary))
- + if (mp->intersect(ray, &t_hit, (void*)udat))
- {
- if(t_hit < dist && t_hit >= 0.f ) // '>=' ?
- {
- @@ -908,7 +922,7 @@
- for (u_int32 i = 0; i < nPrimitives; ++i)
- {
- triangle_t *mp = prims[i];
- - if (mp->intersect(ray, &t_hit, bary))
- + if (mp->intersect(ray, &t_hit, (void*)udat))
- {
- if(t_hit < dist && t_hit >= 0.f )
- {
- @@ -940,7 +954,7 @@
- if (!treeBound.cross(ray, a, b, dist))
- return false;
- - intersectData_t bary;
- + double udat[PRIM_DAT_SIZE];
- vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
- int depth=0;
- @@ -1032,7 +1046,7 @@
- if (nPrimitives == 1)
- {
- triangle_t *mp = currNode->onePrimitive;
- - if (mp->intersect(ray, &t_hit, bary))
- + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
- {
- if(t_hit < dist && t_hit >= ray.tmin ) // '>=' ?
- {
- @@ -1045,7 +1059,7 @@
- if(depth>=maxDepth) return true;
- point3d_t h=ray.from + t_hit*ray.dir;
- surfacePoint_t sp;
- - mp->getSurface(sp, h, bary);
- + mp->getSurface(sp, h, (void*)&udat[0]);
- filt *= mat->getTransparency(state, sp, ray.dir);
- ++depth;
- }
- @@ -1058,7 +1072,7 @@
- for (u_int32 i = 0; i < nPrimitives; ++i)
- {
- triangle_t *mp = prims[i];
- - if (mp->intersect(ray, &t_hit, bary))
- + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
- {
- if(t_hit < dist && t_hit >= ray.tmin)
- {
- @@ -1071,7 +1085,7 @@
- if(depth>=maxDepth) return true;
- point3d_t h=ray.from + t_hit*ray.dir;
- surfacePoint_t sp;
- - mp->getSurface(sp, h, bary);
- + mp->getSurface(sp, h, (void*)&udat[0]);
- filt *= mat->getTransparency(state, sp, ray.dir);
- ++depth;
- }
- diff -ru src/yafraycore//ray_kdtree.cc ../yafaray-0.1.2~git110209/src/yafraycore//ray_kdtree.cc
- --- src/yafraycore//ray_kdtree.cc 2011-02-12 17:55:55.000000000 +0100
- +++ ../yafaray-0.1.2~git110209/src/yafraycore//ray_kdtree.cc 2011-02-03 14:57:22.000000000 +0100
- @@ -156,7 +156,7 @@
- // std::cout << "kd-tree destructor: freeing nodes...";
- y_free(nodes);
- // std::cout << "done!\n";
- - //y_free(prims); //überflüssig?
- + //y_free(prims); //�berfl�ssig?
- }
- // ============================================================
- @@ -688,17 +688,18 @@
- returns the closest hit within dist
- */
- template<class T>
- -bool kdTree_t<T>::Intersect(const ray_t &ray, PFLOAT dist, T **tr, PFLOAT &Z, intersectData_t &data) const
- +bool kdTree_t<T>::Intersect(const ray_t &ray, PFLOAT dist, T **tr, PFLOAT &Z, void *udat) const
- {
- Z=dist;
- -
- +// std::cout << "kdTree_t::Intersect: Z="<<Z<<"\n";
- PFLOAT a, b, t; // entry/exit/splitting plane signed distance
- PFLOAT t_hit;
- if (!treeBound.cross(ray, a, b, dist))
- { return false; }
- - intersectData_t currentData, tempData;
- + unsigned char udat1[PRIM_DAT_SIZE], udat2[PRIM_DAT_SIZE];
- + void *c_udat=(void*)&udat1[0], *t_udat=(void*)&udat2[0];
- vector3d_t invDir(1.0/ray.dir.x, 1.0/ray.dir.y, 1.0/ray.dir.z); //was 1.f!
- // int rayId = curMailboxId++;
- bool hit = false;
- @@ -779,54 +780,56 @@
- stack[exPt].pb[prevAxis] = ray.from[prevAxis] + t * ray.dir[prevAxis];
- }
- + // Check for intersections inside leaf node
- u_int32 nPrimitives = currNode->nPrimitives();
- - if (nPrimitives == 1)
- - {
- + if (nPrimitives == 1) {
- T *mp = currNode->onePrimitive;
- - if (mp->intersect(ray, &t_hit, tempData))
- - {
- - if(t_hit < Z && t_hit >= ray.tmin)
- +// if (mp->lastMailboxId != rayId) {
- +// mp->lastMailboxId = rayId;
- + if (mp->intersect(ray, &t_hit, t_udat))
- {
- - Z = t_hit;
- - *tr = mp;
- - currentData = tempData;
- - hit = true;
- +// std::cout<<"kdTree_t: hit! t="<<t_hit<<" Z="<<Z<<"\n";
- + if(t_hit < Z && t_hit >= ray.tmin /*0.f*/ /*stack[enPt].t*/)
- + {
- + Z = t_hit;
- + *tr = mp;
- + std::swap(t_udat, c_udat);
- + hit = true;
- + }
- }
- - }
- +// }
- }
- - else
- - {
- + else {
- T **prims = currNode->primitives;
- for (u_int32 i = 0; i < nPrimitives; ++i) {
- T *mp = prims[i];
- - if (mp->intersect(ray, &t_hit, tempData))
- - {
- - if(t_hit < Z && t_hit >= ray.tmin)
- +// if (mp->lastMailboxId != rayId) {
- +// mp->lastMailboxId = rayId;
- + if (mp->intersect(ray, &t_hit, t_udat))
- {
- - Z = t_hit;
- - *tr = mp;
- - currentData = tempData;
- - hit = true;
- +// std::cout<<"kdTree_t: hit! t="<<t_hit<<" Z="<<Z<<"\n";
- + if(t_hit < Z && t_hit >= ray.tmin /*0.f*/ /*stack[enPt].t*/)
- + {
- + Z = t_hit;
- + *tr = mp;
- + std::swap(t_udat, c_udat);
- + hit = true;
- + }
- }
- - }
- +// }
- }
- }
- - if(hit && Z <= stack[exPt].t)
- - {
- - data = currentData;
- - return true;
- - }
- + if(hit && Z <= stack[exPt].t){ memcpy(udat, c_udat, PRIM_DAT_SIZE); return true;}
- enPt = exPt;
- currNode = stack[exPt].node;
- exPt = stack[enPt].prev;
- } // while
- -
- - data = currentData;
- -
- - return hit;
- +// if(hit) return true;
- + memcpy(udat, c_udat, PRIM_DAT_SIZE);
- + return hit; //false;
- }
- template<class T>
- @@ -838,8 +841,10 @@
- if (!treeBound.cross(ray, a, b, dist))
- return false;
- - intersectData_t bary;
- + unsigned char udat[PRIM_DAT_SIZE];
- vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
- +// int rayId = curMailboxId++;
- +// bool hit = false;
- rKdStack<T> stack[KD_MAX_STACK];
- const rkdTreeNode<T> *farChild, *currNode;
- @@ -919,41 +924,48 @@
- // Check for intersections inside leaf node
- u_int32 nPrimitives = currNode->nPrimitives();
- - if (nPrimitives == 1)
- - {
- + if (nPrimitives == 1) {
- T *mp = currNode->onePrimitive;
- - if (mp->intersect(ray, &t_hit, bary))
- - {
- - if(t_hit < dist && t_hit > ray.tmin )
- +// if (mp->lastMailboxId != rayId) {
- +// mp->lastMailboxId = rayId;
- + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
- {
- - *tr = mp;
- - return true;
- +// hit = true;
- + if(t_hit < dist && t_hit > 0.f ) // '>=' ?
- + {
- + *tr = mp;
- + return true;
- + }
- }
- - }
- +// }
- }
- - else
- - {
- + else {
- T **prims = currNode->primitives;
- - for (u_int32 i = 0; i < nPrimitives; ++i)
- - {
- + for (u_int32 i = 0; i < nPrimitives; ++i) {
- T *mp = prims[i];
- - if (mp->intersect(ray, &t_hit, bary))
- +// if (mp->lastMailboxId != rayId) {
- +// mp->lastMailboxId = rayId;
- + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
- {
- - if(t_hit < dist && t_hit > ray.tmin )
- + if(t_hit < dist && t_hit > 0.f )
- {
- +// hit = true;
- *tr = mp;
- return true;
- }
- }
- +// }
- }
- }
- +// if(hit && dist <= stack[exPt].t) return true;
- +
- enPt = exPt;
- currNode = stack[exPt].node;
- exPt = stack[enPt].prev;
- } // while
- -
- +// if(hit) return true;
- return false;
- }
- @@ -970,10 +982,12 @@
- if (!treeBound.cross(ray, a, b, dist))
- return false;
- - intersectData_t bary;
- + /* unsigned char */double udat[PRIM_DAT_SIZE];
- vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
- -
- +// int rayId = curMailboxId++;
- +// bool hit = false;
- int depth=0;
- +// filt = color_t(1.0);
- #if ( HAVE_PTHREAD && defined (__GNUC__) )
- std::set<const T *, std::less<const T *>, __gnu_cxx::__mt_alloc<const T *> > filtered;
- #else
- @@ -1057,13 +1071,15 @@
- // Check for intersections inside leaf node
- u_int32 nPrimitives = currNode->nPrimitives();
- - if (nPrimitives == 1)
- - {
- +// PFLOAT tmax = (stack[exPt].t < dist) ? stack[exPt].t : dist;
- +// PFLOAT tmin = (stack[enPt].t > ray.tmin) ? stack[enPt].t : ray.tmin;
- + if (nPrimitives == 1) {
- T *mp = currNode->onePrimitive;
- - if (mp->intersect(ray, &t_hit, bary))
- + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
- {
- - if(t_hit < dist && t_hit >= ray.tmin )
- + if(t_hit < /* tmax */ dist && t_hit >= /* tmin */ ray.tmin ) // '>=' ?
- {
- +// *tr = mp;
- const material_t *mat = mp->getMaterial();
- if(!mat->isTransparent() ) return true;
- if(filtered.insert(mp).second)
- @@ -1071,22 +1087,22 @@
- if(depth>=maxDepth) return true;
- point3d_t h=ray.from + t_hit*ray.dir;
- surfacePoint_t sp;
- - mp->getSurface(sp, h, bary);
- + mp->getSurface(sp, h, (void*)&udat[0]);
- filt *= mat->getTransparency(state, sp, ray.dir);
- ++depth;
- }
- }
- }
- }
- - else
- - {
- + else {
- T **prims = currNode->primitives;
- for (u_int32 i = 0; i < nPrimitives; ++i) {
- T *mp = prims[i];
- - if (mp->intersect(ray, &t_hit, bary))
- + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
- {
- - if(t_hit < dist && t_hit >= ray.tmin )
- + if(t_hit < /* tmax */ dist && t_hit >= /* tmin */ ray.tmin )
- {
- +// *tr = mp;
- const material_t *mat = mp->getMaterial();
- if(!mat->isTransparent() ) return true;
- if(filtered.insert(mp).second)
- @@ -1094,7 +1110,7 @@
- if(depth>=maxDepth) return true;
- point3d_t h=ray.from + t_hit*ray.dir;
- surfacePoint_t sp;
- - mp->getSurface(sp, h, bary);
- + mp->getSurface(sp, h, (void*)&udat[0]);
- filt *= mat->getTransparency(state, sp, ray.dir);
- ++depth;
- }
- @@ -1103,12 +1119,14 @@
- }
- }
- +// if(hit && dist <= stack[exPt].t) return true;
- +
- enPt = exPt;
- currNode = stack[exPt].node;
- exPt = stack[enPt].prev;
- } // while
- -
- +// if(hit) return true;
- return false;
- }
- diff -ru src/yafraycore//scene.cc ../yafaray-0.1.2~git110209/src/yafraycore//scene.cc
- --- src/yafraycore//scene.cc 2011-02-12 17:55:55.000000000 +0100
- +++ ../yafaray-0.1.2~git110209/src/yafraycore//scene.cc 2011-02-08 22:35:36.000000000 +0100
- @@ -794,7 +794,7 @@
- bool scene_t::intersect(const ray_t &ray, surfacePoint_t &sp) const
- {
- PFLOAT dis, Z;
- - intersectData_t data;
- + unsigned char udat[PRIM_DAT_SIZE];
- if(ray.tmax<0) dis=std::numeric_limits<PFLOAT>::infinity();
- else dis=ray.tmax;
- // intersect with tree:
- @@ -802,18 +802,18 @@
- {
- if(!tree) return false;
- triangle_t *hitt=0;
- - if( ! tree->Intersect(ray, dis, &hitt, Z, data) ){ return false; }
- + if( ! tree->Intersect(ray, dis, &hitt, Z, (void*)&udat[0]) ){ return false; }
- point3d_t h=ray.from + Z*ray.dir;
- - hitt->getSurface(sp, h, data);
- + hitt->getSurface(sp, h, (void*)&udat[0]);
- sp.origin = hitt;
- }
- else
- {
- if(!vtree) return false;
- primitive_t *hitprim=0;
- - if( ! vtree->Intersect(ray, dis, &hitprim, Z, data) ){ return false; }
- + if( ! vtree->Intersect(ray, dis, &hitprim, Z, (void*)&udat[0]) ){ return false; }
- point3d_t h=ray.from + Z*ray.dir;
- - hitprim->getSurface(sp, h, data);
- + hitprim->getSurface(sp, h, (void*)&udat[0]);
- sp.origin = hitprim;
- }
- ray.tmax = Z;
- diff -ru src/yafraycore//std_primitives.cc ../yafaray-0.1.2~git110209/src/yafraycore//std_primitives.cc
- --- src/yafraycore//std_primitives.cc 2011-02-12 17:55:55.000000000 +0100
- +++ ../yafaray-0.1.2~git110209/src/yafraycore//std_primitives.cc 2011-02-03 14:57:22.000000000 +0100
- @@ -30,7 +30,7 @@
- return bound_t(center - r, center + r);
- }
- -bool sphere_t::intersect(const ray_t &ray, PFLOAT *t, intersectData_t &data) const
- +bool sphere_t::intersect(const ray_t &ray, PFLOAT *t, void *userdata) const
- {
- vector3d_t vf = ray.from - center;
- PFLOAT ea = ray.dir*ray.dir;
- @@ -52,7 +52,7 @@
- return true;
- }
- -void sphere_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
- +void sphere_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
- {
- vector3d_t normal = hit - center;
- sp.orcoP = normal;
- diff -ru src/yafraycore//triangle.cc ../yafaray-0.1.2~git110209/src/yafraycore//triangle.cc
- --- src/yafraycore//triangle.cc 2011-02-12 17:55:55.000000000 +0100
- +++ ../yafaray-0.1.2~git110209/src/yafraycore//triangle.cc 2011-02-08 22:35:36.000000000 +0100
- @@ -3,17 +3,22 @@
- __BEGIN_YAFRAY
- -void triangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
- +void triangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
- {
- - sp.Ng = vector3d_t(normal).normalize();
- - data.calcB0();
- -
- + sp.Ng = vector3d_t(normal);
- +#ifdef _OLD_TRIINTERSECT
- +#error "_OLD_TRIINTERSECT currently not supported. Please remove #define"
- +#endif
- + PFLOAT *dat = (PFLOAT*)userdata;
- + // gives the index in triangle array, according to my latest informations
- + // it _should be_ safe to rely on array-like contiguous memory in std::vector<>!
- int tri_index = this - &(mesh->triangles.front());
- - float u = data.b0, v = data.b1, w = data.b2;
- -
- + // the "u" and "v" in triangle intersection code are actually "v" and "w" when u=>p1, v=>p2, w=>p3
- + PFLOAT v=dat[0], w=dat[1];
- + PFLOAT u=1.0 - v - w;
- if(mesh->is_smooth || mesh->normals_exported)
- {
- - vector3d_t va( (na > 0) ? mesh->normals[na] : normal ), vb( (nb > 0) ? mesh->normals[nb] : normal ), vc( (nc > 0) ? mesh->normals[nc] : normal );
- + vector3d_t va(na>0? mesh->normals[na] : normal), vb(nb>0? mesh->normals[nb] : normal), vc(nc>0? mesh->normals[nc] : normal);
- sp.N = u*va + v*vb + w*vc;
- sp.N.normalize();
- }
- @@ -31,7 +36,6 @@
- sp.hasOrco = false;
- sp.orcoNg = sp.Ng;
- }
- -
- if(mesh->has_uv)
- {
- std::vector<int>::const_iterator uvi = mesh->uv_offsets.begin() + 3*tri_index;
- @@ -53,31 +57,30 @@
- invdet = 1.f/det;
- vector3d_t dp1 = mesh->points[pa] - mesh->points[pc];
- vector3d_t dp2 = mesh->points[pb] - mesh->points[pc];
- - sp.dPdU = (dv2 * dp1 - dv1 * dp2) * invdet;
- - sp.dPdV = (du1 * dp2 - du2 * dp1) * invdet;
- + sp.dPdU = (dv2 * invdet) * dp1 - (dv1 * invdet) * dp2;
- + sp.dPdV = (du1 * invdet) * dp2 - (du2 * invdet) * dp1;
- }
- else
- {
- - vector3d_t dp1 = mesh->points[pb] - mesh->points[pa];
- - vector3d_t dp2 = mesh->points[pc] - mesh->points[pa];
- - createCS((dp2 ^ dp1).normalize(), sp.dPdU, sp.dPdV);
- + sp.dPdU = vector3d_t(0.f);
- + sp.dPdV = vector3d_t(0.f);
- }
- }
- else
- {
- // implicit mapping, p1 = 0/0, p2 = 1/0, p3 = 0/1 => U = u, V = v; (arbitrary choice)
- - vector3d_t dp1 = mesh->points[pa] - mesh->points[pc];
- - vector3d_t dp2 = mesh->points[pb] - mesh->points[pc];
- - sp.U = v + w;
- - sp.V = w;
- - sp.dPdU = dp2 - dp1;
- - sp.dPdV = -dp2;
- + sp.U = u;
- + sp.V = v;
- + sp.dPdU = mesh->points[pb] - mesh->points[pa];
- + sp.dPdV = mesh->points[pc] - mesh->points[pa];
- }
- sp.dPdU.normalize();
- sp.dPdV.normalize();
- sp.object = mesh;
- + sp.sU = u;
- + sp.sV = v;
- sp.primNum = tri_index;
- sp.material = material;
- sp.P = hit;
- @@ -154,7 +157,7 @@
- // vTriangle_t methods, mosty c&p...
- //==========================================
- -bool vTriangle_t::intersect(const ray_t &ray, PFLOAT *t, intersectData_t &data) const
- +bool vTriangle_t::intersect(const ray_t &ray, PFLOAT *t, void *userdata) const
- {
- //Tomas Möller and Ben Trumbore ray intersection scheme
- const point3d_t &a=mesh->points[pa], &b=mesh->points[pb], &c=mesh->points[pc];
- @@ -173,8 +176,8 @@
- v = (ray.dir*qvec) * inv_det;
- if ((v<0.0) || ((u+v)>1.0) ) return false;
- *t = edge2 * qvec * inv_det;
- - data.b1 = u;
- - data.b2 = v;
- + PFLOAT *dat = (PFLOAT*)userdata;
- + dat[0]=u; dat[1]=v;
- return true;
- }
- @@ -191,16 +194,16 @@
- return bound_t(l, h);
- }
- -void vTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
- +void vTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
- {
- sp.Ng = vector3d_t(normal);
- - data.calcB0();
- + PFLOAT *dat = (PFLOAT*)userdata;
- // gives the index in triangle array, according to my latest informations
- // it _should be_ safe to rely on array-like contiguous memory in std::vector<>!
- int tri_index= this - &(mesh->triangles.front());
- // the "u" and "v" in triangle intersection code are actually "v" and "w" when u=>p1, v=>p2, w=>p3
- - float u = data.b0, v = data.b1, w = data.b2;
- -
- + PFLOAT v=dat[0], w=dat[1];
- + PFLOAT u=1.0 - v - w;
- if(mesh->is_smooth)
- {
- vector3d_t va(na>0? mesh->normals[na] : normal), vb(nb>0? mesh->normals[nb] : normal), vc(nc>0? mesh->normals[nc] : normal);
- @@ -259,7 +262,8 @@
- sp.dPdU = mesh->points[pb] - mesh->points[pa];
- sp.dPdV = mesh->points[pc] - mesh->points[pa];
- }
- -
- + sp.sU = u;
- + sp.sV = v;
- sp.primNum = tri_index;
- sp.material = material;
- sp.P = hit;
- @@ -348,7 +352,7 @@
- // bsTriangle_t methods
- //==========================================
- -bool bsTriangle_t::intersect(const ray_t &ray, PFLOAT *t, intersectData_t &data) const
- +bool bsTriangle_t::intersect(const ray_t &ray, PFLOAT *t, void *userdata) const
- {
- const point3d_t *an=&mesh->points[pa], *bn=&mesh->points[pb], *cn=&mesh->points[pc];
- PFLOAT tc = 1.f - ray.time;
- @@ -372,10 +376,9 @@
- v = (ray.dir*qvec) * inv_det;
- if ((v<0.0) || ((u+v)>1.0) ) return false;
- *t = edge2 * qvec * inv_det;
- -
- - data.b1 = u;
- - data.b1 = v;
- - data.t = ray.time;
- + PFLOAT *dat = (PFLOAT*)userdata;
- + dat[0]=u; dat[1]=v;
- + dat[3]=ray.time;
- return true;
- }
- @@ -411,22 +414,22 @@
- return bound_t(l, h);
- }
- -void bsTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
- +void bsTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
- {
- - data.calcB0();
- + PFLOAT *dat = (PFLOAT*)userdata;
- // recalculating the points is not really the nicest solution...
- const point3d_t *an=&mesh->points[pa], *bn=&mesh->points[pb], *cn=&mesh->points[pc];
- - float time = data.t;
- - float tc = 1.f - time;
- - float b1 = tc*tc, b2 = 2.f*time*tc, b3 = time*time;
- + PFLOAT time = dat[3];
- + PFLOAT tc = 1.f - time;
- + PFLOAT b1 = tc*tc, b2 = 2.f*time*tc, b3 = time*time;
- const point3d_t a = b1*an[0] + b2*an[1] + b3*an[2];
- const point3d_t b = b1*bn[0] + b2*bn[1] + b3*bn[2];
- const point3d_t c = b1*cn[0] + b2*cn[1] + b3*cn[2];
- sp.Ng = ((b-a)^(c-a)).normalize();
- // the "u" and "v" in triangle intersection code are actually "v" and "w" when u=>p1, v=>p2, w=>p3
- - float u = data.b0, v = data.b1, w = data.b2;
- -
- + PFLOAT v=dat[0], w=dat[1];
- + PFLOAT u=1.0 - v - w;
- //todo: calculate smoothed normal...
- /* if(mesh->is_smooth)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement