Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.10 KB | None | 0 0
  1. ../yafaray-0.1.2~git110209/src/yafraycore/
  2. diff -ru src/yafraycore//kdtree.cc ../yafaray-0.1.2~git110209/src/yafraycore//kdtree.cc
  3. --- src/yafraycore//kdtree.cc 2011-02-12 17:55:55.000000000 +0100
  4. +++ ../yafaray-0.1.2~git110209/src/yafraycore//kdtree.cc 2011-02-07 00:35:21.000000000 +0100
  5. @@ -654,15 +654,17 @@
  6. returns the closest hit within dist
  7. */
  8.  
  9. -bool triKdTree_t::Intersect(const ray_t &ray, PFLOAT dist, triangle_t **tr, PFLOAT &Z, intersectData_t &data) const
  10. +bool triKdTree_t::Intersect(const ray_t &ray, PFLOAT dist, triangle_t **tr, PFLOAT &Z, void *udat) const
  11. {
  12. Z=dist;
  13. PFLOAT a, b, t; // entry/exit/splitting plane signed distance
  14. PFLOAT t_hit;
  15.  
  16. - if( !treeBound.cross(ray, a, b, dist) ) { return false; }
  17. + if (!treeBound.cross(ray, a, b, dist))
  18. + { return false; }
  19.  
  20. - intersectData_t currentData, tempData;
  21. + unsigned char udat1[PRIM_DAT_SIZE], udat2[PRIM_DAT_SIZE];
  22. + void *c_udat=(void*)udat1, *t_udat=(void*)udat2;
  23. vector3d_t invDir(1.0/ray.dir.x, 1.0/ray.dir.y, 1.0/ray.dir.z); //was 1.f!
  24. bool hit = false;
  25.  
  26. @@ -749,13 +751,15 @@
  27. {
  28. triangle_t *mp = currNode->onePrimitive;
  29.  
  30. - if (mp->intersect(ray, &t_hit, tempData))
  31. + if (mp->intersect(ray, &t_hit, t_udat))
  32. {
  33. if(t_hit < Z && t_hit >= ray.tmin)
  34. {
  35. Z = t_hit;
  36. *tr = mp;
  37. - currentData = tempData;
  38. + void *swap = t_udat;
  39. + t_udat = c_udat;
  40. + c_udat = swap;
  41. hit = true;
  42. }
  43. }
  44. @@ -768,13 +772,15 @@
  45. {
  46. triangle_t *mp = prims[i];
  47.  
  48. - if (mp->intersect(ray, &t_hit, tempData))
  49. + if (mp->intersect(ray, &t_hit, t_udat))
  50. {
  51. if(t_hit < Z && t_hit >= ray.tmin)
  52. {
  53. Z = t_hit;
  54. *tr = mp;
  55. - currentData = tempData;
  56. + void *swap = t_udat;
  57. + t_udat = c_udat;
  58. + c_udat = swap;
  59. hit = true;
  60. }
  61. }
  62. @@ -783,7 +789,11 @@
  63.  
  64. if(hit && Z <= stack[exPt].t)
  65. {
  66. - data = currentData;
  67. + float nu = ((float*)c_udat)[0];
  68. + float nv = ((float*)c_udat)[1];
  69. + float *temp = (float*)udat;
  70. + temp[0] = nu;
  71. + temp[1] = nv;
  72. return true;
  73. }
  74.  
  75. @@ -793,7 +803,11 @@
  76.  
  77. } // while
  78.  
  79. - data = currentData;
  80. + float nu = ((float*)c_udat)[0];
  81. + float nv = ((float*)c_udat)[1];
  82. + float *temp = (float*)udat;
  83. + temp[0] = nu;
  84. + temp[1] = nv;
  85.  
  86. return hit; //false;
  87. }
  88. @@ -807,7 +821,7 @@
  89. if (!treeBound.cross(ray, a, b, dist))
  90. return false;
  91.  
  92. - intersectData_t bary;
  93. + unsigned char udat[PRIM_DAT_SIZE];
  94. vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
  95.  
  96. KdStack stack[KD_MAX_STACK];
  97. @@ -893,7 +907,7 @@
  98. if (nPrimitives == 1)
  99. {
  100. triangle_t *mp = currNode->onePrimitive;
  101. - if (mp->intersect(ray, &t_hit, bary))
  102. + if (mp->intersect(ray, &t_hit, (void*)udat))
  103. {
  104. if(t_hit < dist && t_hit >= 0.f ) // '>=' ?
  105. {
  106. @@ -908,7 +922,7 @@
  107. for (u_int32 i = 0; i < nPrimitives; ++i)
  108. {
  109. triangle_t *mp = prims[i];
  110. - if (mp->intersect(ray, &t_hit, bary))
  111. + if (mp->intersect(ray, &t_hit, (void*)udat))
  112. {
  113. if(t_hit < dist && t_hit >= 0.f )
  114. {
  115. @@ -940,7 +954,7 @@
  116. if (!treeBound.cross(ray, a, b, dist))
  117. return false;
  118.  
  119. - intersectData_t bary;
  120. + double udat[PRIM_DAT_SIZE];
  121. vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
  122. int depth=0;
  123.  
  124. @@ -1032,7 +1046,7 @@
  125. if (nPrimitives == 1)
  126. {
  127. triangle_t *mp = currNode->onePrimitive;
  128. - if (mp->intersect(ray, &t_hit, bary))
  129. + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
  130. {
  131. if(t_hit < dist && t_hit >= ray.tmin ) // '>=' ?
  132. {
  133. @@ -1045,7 +1059,7 @@
  134. if(depth>=maxDepth) return true;
  135. point3d_t h=ray.from + t_hit*ray.dir;
  136. surfacePoint_t sp;
  137. - mp->getSurface(sp, h, bary);
  138. + mp->getSurface(sp, h, (void*)&udat[0]);
  139. filt *= mat->getTransparency(state, sp, ray.dir);
  140. ++depth;
  141. }
  142. @@ -1058,7 +1072,7 @@
  143. for (u_int32 i = 0; i < nPrimitives; ++i)
  144. {
  145. triangle_t *mp = prims[i];
  146. - if (mp->intersect(ray, &t_hit, bary))
  147. + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
  148. {
  149. if(t_hit < dist && t_hit >= ray.tmin)
  150. {
  151. @@ -1071,7 +1085,7 @@
  152. if(depth>=maxDepth) return true;
  153. point3d_t h=ray.from + t_hit*ray.dir;
  154. surfacePoint_t sp;
  155. - mp->getSurface(sp, h, bary);
  156. + mp->getSurface(sp, h, (void*)&udat[0]);
  157. filt *= mat->getTransparency(state, sp, ray.dir);
  158. ++depth;
  159. }
  160. diff -ru src/yafraycore//ray_kdtree.cc ../yafaray-0.1.2~git110209/src/yafraycore//ray_kdtree.cc
  161. --- src/yafraycore//ray_kdtree.cc 2011-02-12 17:55:55.000000000 +0100
  162. +++ ../yafaray-0.1.2~git110209/src/yafraycore//ray_kdtree.cc 2011-02-03 14:57:22.000000000 +0100
  163. @@ -156,7 +156,7 @@
  164. // std::cout << "kd-tree destructor: freeing nodes...";
  165. y_free(nodes);
  166. // std::cout << "done!\n";
  167. - //y_free(prims); //überflüssig?
  168. + //y_free(prims); //�berfl�ssig?
  169. }
  170.  
  171. // ============================================================
  172. @@ -688,17 +688,18 @@
  173. returns the closest hit within dist
  174. */
  175. template<class T>
  176. -bool kdTree_t<T>::Intersect(const ray_t &ray, PFLOAT dist, T **tr, PFLOAT &Z, intersectData_t &data) const
  177. +bool kdTree_t<T>::Intersect(const ray_t &ray, PFLOAT dist, T **tr, PFLOAT &Z, void *udat) const
  178. {
  179. Z=dist;
  180. -
  181. +// std::cout << "kdTree_t::Intersect: Z="<<Z<<"\n";
  182. PFLOAT a, b, t; // entry/exit/splitting plane signed distance
  183. PFLOAT t_hit;
  184.  
  185. if (!treeBound.cross(ray, a, b, dist))
  186. { return false; }
  187.  
  188. - intersectData_t currentData, tempData;
  189. + unsigned char udat1[PRIM_DAT_SIZE], udat2[PRIM_DAT_SIZE];
  190. + void *c_udat=(void*)&udat1[0], *t_udat=(void*)&udat2[0];
  191. vector3d_t invDir(1.0/ray.dir.x, 1.0/ray.dir.y, 1.0/ray.dir.z); //was 1.f!
  192. // int rayId = curMailboxId++;
  193. bool hit = false;
  194. @@ -779,54 +780,56 @@
  195. stack[exPt].pb[prevAxis] = ray.from[prevAxis] + t * ray.dir[prevAxis];
  196. }
  197.  
  198. + // Check for intersections inside leaf node
  199. u_int32 nPrimitives = currNode->nPrimitives();
  200. - if (nPrimitives == 1)
  201. - {
  202. + if (nPrimitives == 1) {
  203. T *mp = currNode->onePrimitive;
  204. - if (mp->intersect(ray, &t_hit, tempData))
  205. - {
  206. - if(t_hit < Z && t_hit >= ray.tmin)
  207. +// if (mp->lastMailboxId != rayId) {
  208. +// mp->lastMailboxId = rayId;
  209. + if (mp->intersect(ray, &t_hit, t_udat))
  210. {
  211. - Z = t_hit;
  212. - *tr = mp;
  213. - currentData = tempData;
  214. - hit = true;
  215. +// std::cout<<"kdTree_t: hit! t="<<t_hit<<" Z="<<Z<<"\n";
  216. + if(t_hit < Z && t_hit >= ray.tmin /*0.f*/ /*stack[enPt].t*/)
  217. + {
  218. + Z = t_hit;
  219. + *tr = mp;
  220. + std::swap(t_udat, c_udat);
  221. + hit = true;
  222. + }
  223. }
  224. - }
  225. +// }
  226. }
  227. - else
  228. - {
  229. + else {
  230. T **prims = currNode->primitives;
  231. for (u_int32 i = 0; i < nPrimitives; ++i) {
  232. T *mp = prims[i];
  233. - if (mp->intersect(ray, &t_hit, tempData))
  234. - {
  235. - if(t_hit < Z && t_hit >= ray.tmin)
  236. +// if (mp->lastMailboxId != rayId) {
  237. +// mp->lastMailboxId = rayId;
  238. + if (mp->intersect(ray, &t_hit, t_udat))
  239. {
  240. - Z = t_hit;
  241. - *tr = mp;
  242. - currentData = tempData;
  243. - hit = true;
  244. +// std::cout<<"kdTree_t: hit! t="<<t_hit<<" Z="<<Z<<"\n";
  245. + if(t_hit < Z && t_hit >= ray.tmin /*0.f*/ /*stack[enPt].t*/)
  246. + {
  247. + Z = t_hit;
  248. + *tr = mp;
  249. + std::swap(t_udat, c_udat);
  250. + hit = true;
  251. + }
  252. }
  253. - }
  254. +// }
  255. }
  256. }
  257.  
  258. - if(hit && Z <= stack[exPt].t)
  259. - {
  260. - data = currentData;
  261. - return true;
  262. - }
  263. + if(hit && Z <= stack[exPt].t){ memcpy(udat, c_udat, PRIM_DAT_SIZE); return true;}
  264.  
  265. enPt = exPt;
  266. currNode = stack[exPt].node;
  267. exPt = stack[enPt].prev;
  268.  
  269. } // while
  270. -
  271. - data = currentData;
  272. -
  273. - return hit;
  274. +// if(hit) return true;
  275. + memcpy(udat, c_udat, PRIM_DAT_SIZE);
  276. + return hit; //false;
  277. }
  278.  
  279. template<class T>
  280. @@ -838,8 +841,10 @@
  281. if (!treeBound.cross(ray, a, b, dist))
  282. return false;
  283.  
  284. - intersectData_t bary;
  285. + unsigned char udat[PRIM_DAT_SIZE];
  286. vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
  287. +// int rayId = curMailboxId++;
  288. +// bool hit = false;
  289.  
  290. rKdStack<T> stack[KD_MAX_STACK];
  291. const rkdTreeNode<T> *farChild, *currNode;
  292. @@ -919,41 +924,48 @@
  293.  
  294. // Check for intersections inside leaf node
  295. u_int32 nPrimitives = currNode->nPrimitives();
  296. - if (nPrimitives == 1)
  297. - {
  298. + if (nPrimitives == 1) {
  299. T *mp = currNode->onePrimitive;
  300. - if (mp->intersect(ray, &t_hit, bary))
  301. - {
  302. - if(t_hit < dist && t_hit > ray.tmin )
  303. +// if (mp->lastMailboxId != rayId) {
  304. +// mp->lastMailboxId = rayId;
  305. + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
  306. {
  307. - *tr = mp;
  308. - return true;
  309. +// hit = true;
  310. + if(t_hit < dist && t_hit > 0.f ) // '>=' ?
  311. + {
  312. + *tr = mp;
  313. + return true;
  314. + }
  315. }
  316. - }
  317. +// }
  318. }
  319. - else
  320. - {
  321. + else {
  322. T **prims = currNode->primitives;
  323. - for (u_int32 i = 0; i < nPrimitives; ++i)
  324. - {
  325. + for (u_int32 i = 0; i < nPrimitives; ++i) {
  326. T *mp = prims[i];
  327. - if (mp->intersect(ray, &t_hit, bary))
  328. +// if (mp->lastMailboxId != rayId) {
  329. +// mp->lastMailboxId = rayId;
  330. + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
  331. {
  332. - if(t_hit < dist && t_hit > ray.tmin )
  333. + if(t_hit < dist && t_hit > 0.f )
  334. {
  335. +// hit = true;
  336. *tr = mp;
  337. return true;
  338. }
  339. }
  340. +// }
  341. }
  342. }
  343.  
  344. +// if(hit && dist <= stack[exPt].t) return true;
  345. +
  346. enPt = exPt;
  347. currNode = stack[exPt].node;
  348. exPt = stack[enPt].prev;
  349.  
  350. } // while
  351. -
  352. +// if(hit) return true;
  353. return false;
  354. }
  355.  
  356. @@ -970,10 +982,12 @@
  357. if (!treeBound.cross(ray, a, b, dist))
  358. return false;
  359.  
  360. - intersectData_t bary;
  361. + /* unsigned char */double udat[PRIM_DAT_SIZE];
  362. vector3d_t invDir(1.f/ray.dir.x, 1.f/ray.dir.y, 1.f/ray.dir.z);
  363. -
  364. +// int rayId = curMailboxId++;
  365. +// bool hit = false;
  366. int depth=0;
  367. +// filt = color_t(1.0);
  368. #if ( HAVE_PTHREAD && defined (__GNUC__) )
  369. std::set<const T *, std::less<const T *>, __gnu_cxx::__mt_alloc<const T *> > filtered;
  370. #else
  371. @@ -1057,13 +1071,15 @@
  372.  
  373. // Check for intersections inside leaf node
  374. u_int32 nPrimitives = currNode->nPrimitives();
  375. - if (nPrimitives == 1)
  376. - {
  377. +// PFLOAT tmax = (stack[exPt].t < dist) ? stack[exPt].t : dist;
  378. +// PFLOAT tmin = (stack[enPt].t > ray.tmin) ? stack[enPt].t : ray.tmin;
  379. + if (nPrimitives == 1) {
  380. T *mp = currNode->onePrimitive;
  381. - if (mp->intersect(ray, &t_hit, bary))
  382. + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
  383. {
  384. - if(t_hit < dist && t_hit >= ray.tmin )
  385. + if(t_hit < /* tmax */ dist && t_hit >= /* tmin */ ray.tmin ) // '>=' ?
  386. {
  387. +// *tr = mp;
  388. const material_t *mat = mp->getMaterial();
  389. if(!mat->isTransparent() ) return true;
  390. if(filtered.insert(mp).second)
  391. @@ -1071,22 +1087,22 @@
  392. if(depth>=maxDepth) return true;
  393. point3d_t h=ray.from + t_hit*ray.dir;
  394. surfacePoint_t sp;
  395. - mp->getSurface(sp, h, bary);
  396. + mp->getSurface(sp, h, (void*)&udat[0]);
  397. filt *= mat->getTransparency(state, sp, ray.dir);
  398. ++depth;
  399. }
  400. }
  401. }
  402. }
  403. - else
  404. - {
  405. + else {
  406. T **prims = currNode->primitives;
  407. for (u_int32 i = 0; i < nPrimitives; ++i) {
  408. T *mp = prims[i];
  409. - if (mp->intersect(ray, &t_hit, bary))
  410. + if (mp->intersect(ray, &t_hit, (void*)&udat[0]))
  411. {
  412. - if(t_hit < dist && t_hit >= ray.tmin )
  413. + if(t_hit < /* tmax */ dist && t_hit >= /* tmin */ ray.tmin )
  414. {
  415. +// *tr = mp;
  416. const material_t *mat = mp->getMaterial();
  417. if(!mat->isTransparent() ) return true;
  418. if(filtered.insert(mp).second)
  419. @@ -1094,7 +1110,7 @@
  420. if(depth>=maxDepth) return true;
  421. point3d_t h=ray.from + t_hit*ray.dir;
  422. surfacePoint_t sp;
  423. - mp->getSurface(sp, h, bary);
  424. + mp->getSurface(sp, h, (void*)&udat[0]);
  425. filt *= mat->getTransparency(state, sp, ray.dir);
  426. ++depth;
  427. }
  428. @@ -1103,12 +1119,14 @@
  429. }
  430. }
  431.  
  432. +// if(hit && dist <= stack[exPt].t) return true;
  433. +
  434. enPt = exPt;
  435. currNode = stack[exPt].node;
  436. exPt = stack[enPt].prev;
  437.  
  438. } // while
  439. -
  440. +// if(hit) return true;
  441. return false;
  442. }
  443.  
  444. diff -ru src/yafraycore//scene.cc ../yafaray-0.1.2~git110209/src/yafraycore//scene.cc
  445. --- src/yafraycore//scene.cc 2011-02-12 17:55:55.000000000 +0100
  446. +++ ../yafaray-0.1.2~git110209/src/yafraycore//scene.cc 2011-02-08 22:35:36.000000000 +0100
  447. @@ -794,7 +794,7 @@
  448. bool scene_t::intersect(const ray_t &ray, surfacePoint_t &sp) const
  449. {
  450. PFLOAT dis, Z;
  451. - intersectData_t data;
  452. + unsigned char udat[PRIM_DAT_SIZE];
  453. if(ray.tmax<0) dis=std::numeric_limits<PFLOAT>::infinity();
  454. else dis=ray.tmax;
  455. // intersect with tree:
  456. @@ -802,18 +802,18 @@
  457. {
  458. if(!tree) return false;
  459. triangle_t *hitt=0;
  460. - if( ! tree->Intersect(ray, dis, &hitt, Z, data) ){ return false; }
  461. + if( ! tree->Intersect(ray, dis, &hitt, Z, (void*)&udat[0]) ){ return false; }
  462. point3d_t h=ray.from + Z*ray.dir;
  463. - hitt->getSurface(sp, h, data);
  464. + hitt->getSurface(sp, h, (void*)&udat[0]);
  465. sp.origin = hitt;
  466. }
  467. else
  468. {
  469. if(!vtree) return false;
  470. primitive_t *hitprim=0;
  471. - if( ! vtree->Intersect(ray, dis, &hitprim, Z, data) ){ return false; }
  472. + if( ! vtree->Intersect(ray, dis, &hitprim, Z, (void*)&udat[0]) ){ return false; }
  473. point3d_t h=ray.from + Z*ray.dir;
  474. - hitprim->getSurface(sp, h, data);
  475. + hitprim->getSurface(sp, h, (void*)&udat[0]);
  476. sp.origin = hitprim;
  477. }
  478. ray.tmax = Z;
  479. diff -ru src/yafraycore//std_primitives.cc ../yafaray-0.1.2~git110209/src/yafraycore//std_primitives.cc
  480. --- src/yafraycore//std_primitives.cc 2011-02-12 17:55:55.000000000 +0100
  481. +++ ../yafaray-0.1.2~git110209/src/yafraycore//std_primitives.cc 2011-02-03 14:57:22.000000000 +0100
  482. @@ -30,7 +30,7 @@
  483. return bound_t(center - r, center + r);
  484. }
  485.  
  486. -bool sphere_t::intersect(const ray_t &ray, PFLOAT *t, intersectData_t &data) const
  487. +bool sphere_t::intersect(const ray_t &ray, PFLOAT *t, void *userdata) const
  488. {
  489. vector3d_t vf = ray.from - center;
  490. PFLOAT ea = ray.dir*ray.dir;
  491. @@ -52,7 +52,7 @@
  492. return true;
  493. }
  494.  
  495. -void sphere_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
  496. +void sphere_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
  497. {
  498. vector3d_t normal = hit - center;
  499. sp.orcoP = normal;
  500. diff -ru src/yafraycore//triangle.cc ../yafaray-0.1.2~git110209/src/yafraycore//triangle.cc
  501. --- src/yafraycore//triangle.cc 2011-02-12 17:55:55.000000000 +0100
  502. +++ ../yafaray-0.1.2~git110209/src/yafraycore//triangle.cc 2011-02-08 22:35:36.000000000 +0100
  503. @@ -3,17 +3,22 @@
  504.  
  505. __BEGIN_YAFRAY
  506.  
  507. -void triangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
  508. +void triangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
  509. {
  510. - sp.Ng = vector3d_t(normal).normalize();
  511. - data.calcB0();
  512. -
  513. + sp.Ng = vector3d_t(normal);
  514. +#ifdef _OLD_TRIINTERSECT
  515. +#error "_OLD_TRIINTERSECT currently not supported. Please remove #define"
  516. +#endif
  517. + PFLOAT *dat = (PFLOAT*)userdata;
  518. + // gives the index in triangle array, according to my latest informations
  519. + // it _should be_ safe to rely on array-like contiguous memory in std::vector<>!
  520. int tri_index = this - &(mesh->triangles.front());
  521. - float u = data.b0, v = data.b1, w = data.b2;
  522. -
  523. + // the "u" and "v" in triangle intersection code are actually "v" and "w" when u=>p1, v=>p2, w=>p3
  524. + PFLOAT v=dat[0], w=dat[1];
  525. + PFLOAT u=1.0 - v - w;
  526. if(mesh->is_smooth || mesh->normals_exported)
  527. {
  528. - vector3d_t va( (na > 0) ? mesh->normals[na] : normal ), vb( (nb > 0) ? mesh->normals[nb] : normal ), vc( (nc > 0) ? mesh->normals[nc] : normal );
  529. + vector3d_t va(na>0? mesh->normals[na] : normal), vb(nb>0? mesh->normals[nb] : normal), vc(nc>0? mesh->normals[nc] : normal);
  530. sp.N = u*va + v*vb + w*vc;
  531. sp.N.normalize();
  532. }
  533. @@ -31,7 +36,6 @@
  534. sp.hasOrco = false;
  535. sp.orcoNg = sp.Ng;
  536. }
  537. -
  538. if(mesh->has_uv)
  539. {
  540. std::vector<int>::const_iterator uvi = mesh->uv_offsets.begin() + 3*tri_index;
  541. @@ -53,31 +57,30 @@
  542. invdet = 1.f/det;
  543. vector3d_t dp1 = mesh->points[pa] - mesh->points[pc];
  544. vector3d_t dp2 = mesh->points[pb] - mesh->points[pc];
  545. - sp.dPdU = (dv2 * dp1 - dv1 * dp2) * invdet;
  546. - sp.dPdV = (du1 * dp2 - du2 * dp1) * invdet;
  547. + sp.dPdU = (dv2 * invdet) * dp1 - (dv1 * invdet) * dp2;
  548. + sp.dPdV = (du1 * invdet) * dp2 - (du2 * invdet) * dp1;
  549. }
  550. else
  551. {
  552. - vector3d_t dp1 = mesh->points[pb] - mesh->points[pa];
  553. - vector3d_t dp2 = mesh->points[pc] - mesh->points[pa];
  554. - createCS((dp2 ^ dp1).normalize(), sp.dPdU, sp.dPdV);
  555. + sp.dPdU = vector3d_t(0.f);
  556. + sp.dPdV = vector3d_t(0.f);
  557. }
  558. }
  559. else
  560. {
  561. // implicit mapping, p1 = 0/0, p2 = 1/0, p3 = 0/1 => U = u, V = v; (arbitrary choice)
  562. - vector3d_t dp1 = mesh->points[pa] - mesh->points[pc];
  563. - vector3d_t dp2 = mesh->points[pb] - mesh->points[pc];
  564. - sp.U = v + w;
  565. - sp.V = w;
  566. - sp.dPdU = dp2 - dp1;
  567. - sp.dPdV = -dp2;
  568. + sp.U = u;
  569. + sp.V = v;
  570. + sp.dPdU = mesh->points[pb] - mesh->points[pa];
  571. + sp.dPdV = mesh->points[pc] - mesh->points[pa];
  572. }
  573.  
  574. sp.dPdU.normalize();
  575. sp.dPdV.normalize();
  576.  
  577. sp.object = mesh;
  578. + sp.sU = u;
  579. + sp.sV = v;
  580. sp.primNum = tri_index;
  581. sp.material = material;
  582. sp.P = hit;
  583. @@ -154,7 +157,7 @@
  584. // vTriangle_t methods, mosty c&p...
  585. //==========================================
  586.  
  587. -bool vTriangle_t::intersect(const ray_t &ray, PFLOAT *t, intersectData_t &data) const
  588. +bool vTriangle_t::intersect(const ray_t &ray, PFLOAT *t, void *userdata) const
  589. {
  590. //Tomas Möller and Ben Trumbore ray intersection scheme
  591. const point3d_t &a=mesh->points[pa], &b=mesh->points[pb], &c=mesh->points[pc];
  592. @@ -173,8 +176,8 @@
  593. v = (ray.dir*qvec) * inv_det;
  594. if ((v<0.0) || ((u+v)>1.0) ) return false;
  595. *t = edge2 * qvec * inv_det;
  596. - data.b1 = u;
  597. - data.b2 = v;
  598. + PFLOAT *dat = (PFLOAT*)userdata;
  599. + dat[0]=u; dat[1]=v;
  600. return true;
  601. }
  602.  
  603. @@ -191,16 +194,16 @@
  604. return bound_t(l, h);
  605. }
  606.  
  607. -void vTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
  608. +void vTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
  609. {
  610. sp.Ng = vector3d_t(normal);
  611. - data.calcB0();
  612. + PFLOAT *dat = (PFLOAT*)userdata;
  613. // gives the index in triangle array, according to my latest informations
  614. // it _should be_ safe to rely on array-like contiguous memory in std::vector<>!
  615. int tri_index= this - &(mesh->triangles.front());
  616. // the "u" and "v" in triangle intersection code are actually "v" and "w" when u=>p1, v=>p2, w=>p3
  617. - float u = data.b0, v = data.b1, w = data.b2;
  618. -
  619. + PFLOAT v=dat[0], w=dat[1];
  620. + PFLOAT u=1.0 - v - w;
  621. if(mesh->is_smooth)
  622. {
  623. vector3d_t va(na>0? mesh->normals[na] : normal), vb(nb>0? mesh->normals[nb] : normal), vc(nc>0? mesh->normals[nc] : normal);
  624. @@ -259,7 +262,8 @@
  625. sp.dPdU = mesh->points[pb] - mesh->points[pa];
  626. sp.dPdV = mesh->points[pc] - mesh->points[pa];
  627. }
  628. -
  629. + sp.sU = u;
  630. + sp.sV = v;
  631. sp.primNum = tri_index;
  632. sp.material = material;
  633. sp.P = hit;
  634. @@ -348,7 +352,7 @@
  635. // bsTriangle_t methods
  636. //==========================================
  637.  
  638. -bool bsTriangle_t::intersect(const ray_t &ray, PFLOAT *t, intersectData_t &data) const
  639. +bool bsTriangle_t::intersect(const ray_t &ray, PFLOAT *t, void *userdata) const
  640. {
  641. const point3d_t *an=&mesh->points[pa], *bn=&mesh->points[pb], *cn=&mesh->points[pc];
  642. PFLOAT tc = 1.f - ray.time;
  643. @@ -372,10 +376,9 @@
  644. v = (ray.dir*qvec) * inv_det;
  645. if ((v<0.0) || ((u+v)>1.0) ) return false;
  646. *t = edge2 * qvec * inv_det;
  647. -
  648. - data.b1 = u;
  649. - data.b1 = v;
  650. - data.t = ray.time;
  651. + PFLOAT *dat = (PFLOAT*)userdata;
  652. + dat[0]=u; dat[1]=v;
  653. + dat[3]=ray.time;
  654. return true;
  655. }
  656.  
  657. @@ -411,22 +414,22 @@
  658. return bound_t(l, h);
  659. }
  660.  
  661. -void bsTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, intersectData_t &data) const
  662. +void bsTriangle_t::getSurface(surfacePoint_t &sp, const point3d_t &hit, void *userdata) const
  663. {
  664. - data.calcB0();
  665. + PFLOAT *dat = (PFLOAT*)userdata;
  666. // recalculating the points is not really the nicest solution...
  667. const point3d_t *an=&mesh->points[pa], *bn=&mesh->points[pb], *cn=&mesh->points[pc];
  668. - float time = data.t;
  669. - float tc = 1.f - time;
  670. - float b1 = tc*tc, b2 = 2.f*time*tc, b3 = time*time;
  671. + PFLOAT time = dat[3];
  672. + PFLOAT tc = 1.f - time;
  673. + PFLOAT b1 = tc*tc, b2 = 2.f*time*tc, b3 = time*time;
  674. const point3d_t a = b1*an[0] + b2*an[1] + b3*an[2];
  675. const point3d_t b = b1*bn[0] + b2*bn[1] + b3*bn[2];
  676. const point3d_t c = b1*cn[0] + b2*cn[1] + b3*cn[2];
  677.  
  678. sp.Ng = ((b-a)^(c-a)).normalize();
  679. // the "u" and "v" in triangle intersection code are actually "v" and "w" when u=>p1, v=>p2, w=>p3
  680. - float u = data.b0, v = data.b1, w = data.b2;
  681. -
  682. + PFLOAT v=dat[0], w=dat[1];
  683. + PFLOAT u=1.0 - v - w;
  684. //todo: calculate smoothed normal...
  685. /* if(mesh->is_smooth)
  686. {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement