[2582] | 1 |
|
---|
| 2 | // Written by Vlastimil Havran, December 2007
|
---|
| 3 |
|
---|
| 4 | // This macro allows to use the ray shooting written by
|
---|
| 5 | // Vlastimil Havran, 2007-2008
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | #include "VssRay.h"
|
---|
| 9 | #include "KdTree.h"
|
---|
| 10 | #include "Preprocessor.h"
|
---|
| 11 | #include "IntersectableWrapper.h"
|
---|
[2603] | 12 | #include "Environment.h"
|
---|
[2582] | 13 |
|
---|
| 14 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
[2592] | 15 | #include "ktbconf.h"
|
---|
[2582] | 16 | #include "timer.h"
|
---|
| 17 | #include "ktball.h"
|
---|
| 18 | #include "ktb.h"
|
---|
[2592] | 19 | #ifdef _USE_HAVRAN_SSE
|
---|
| 20 |
|
---|
[2582] | 21 | #include "raypack.h"
|
---|
[2592] | 22 | #endif // _USE_HAVRAN_SSE
|
---|
[2582] | 23 | #endif // USE_HAVRAN_RAYCASTER
|
---|
[2655] | 24 |
|
---|
[2592] | 25 | #include "HavranRayCaster.h"
|
---|
[2582] | 26 |
|
---|
| 27 | #define DEBUG_RAYCAST 0
|
---|
| 28 |
|
---|
| 29 | namespace GtpVisibilityPreprocessor {
|
---|
| 30 |
|
---|
[2592] | 31 | #ifdef _USE_HAVRAN_SSE
|
---|
[2582] | 32 | // static rays
|
---|
[2629] | 33 | GALIGN16 RayPacket2x2
|
---|
[2582] | 34 | HavranRayCaster::raypack;
|
---|
[2592] | 35 | #endif // _USE_HAVRAN_SSE
|
---|
[2629] | 36 |
|
---|
[2582] | 37 |
|
---|
| 38 | HavranRayCaster::HavranRayCaster(const Preprocessor &preprocessor):
|
---|
| 39 | RayCaster(preprocessor), mKtbtree(0)
|
---|
| 40 | {
|
---|
| 41 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
| 42 | mKtbtree = new CKTB();
|
---|
| 43 | #endif
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | HavranRayCaster::~HavranRayCaster()
|
---|
| 48 | {
|
---|
| 49 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
| 50 | delete mKtbtree;
|
---|
| 51 | mKtbtree = 0;
|
---|
| 52 | #endif // USE_HAVRAN_RAYCASTER
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | void
|
---|
| 56 | HavranRayCaster::Build(ObjectContainer &objlist)
|
---|
| 57 | {
|
---|
| 58 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
[2603] | 59 | char buff[256];
|
---|
| 60 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
| 61 | string filename(buff);
|
---|
| 62 | const string kdfile = ReplaceSuffix(filename, ".obj", ".kdh");
|
---|
[2582] | 63 |
|
---|
[2603] | 64 | if (!ImportBinTree(kdfile, objlist)) {
|
---|
[2629] | 65 | cout << "\nKd-tree for Havran ray caster imported."<<endl<<flush;
|
---|
[2603] | 66 | }
|
---|
[2629] | 67 | else {
|
---|
| 68 | CTimer timer;
|
---|
| 69 | cout << "\nBuilding up kd-tree for Havran ray caster ..."<<endl<<flush;
|
---|
| 70 |
|
---|
| 71 | timer.Start();
|
---|
| 72 | mKtbtree->BuildUp(objlist);
|
---|
| 73 | timer.Stop();
|
---|
| 74 | cout << "\nBuilding up kd-tree is finished, user time = "
|
---|
| 75 | << timer.UserTime() << " real time = " << timer.RealTime()
|
---|
| 76 | << endl;
|
---|
| 77 | ExportBinTree(kdfile);
|
---|
| 78 | }
|
---|
[2582] | 79 | #endif
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[2592] | 82 | bool
|
---|
| 83 | HavranRayCaster::ExportBinTree(const string &filename)
|
---|
| 84 | {
|
---|
[2655] | 85 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
[2592] | 86 | return mKtbtree->ExportBinTree(filename);
|
---|
[2655] | 87 | #endif
|
---|
[2592] | 88 | }
|
---|
[2582] | 89 |
|
---|
[2592] | 90 | bool
|
---|
| 91 | HavranRayCaster::ImportBinTree(const string &filename, ObjectContainer &objects)
|
---|
| 92 | {
|
---|
[2655] | 93 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
[2592] | 94 | return mKtbtree->ImportBinTree(filename, objects);
|
---|
[2655] | 95 | #endif
|
---|
[2592] | 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
[2582] | 99 | // Using packet of 4 rays supposing that these are coherent
|
---|
| 100 | // We give a box to which each ray is clipped to before the
|
---|
| 101 | // ray shooting is computed !
|
---|
[2602] | 102 | void HavranRayCaster::CastRaysPacket4(const Vector3 &minBox,
|
---|
| 103 | const Vector3 &maxBox,
|
---|
| 104 | const Vector3 origin4[],
|
---|
| 105 | const Vector3 direction4[],
|
---|
| 106 | int result4[],
|
---|
| 107 | float dist4[])
|
---|
[2582] | 108 | {
|
---|
| 109 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
[2602] | 110 | #ifdef _USE_HAVRAN_SSE
|
---|
[2582] | 111 | for (int i = 0; i < 4; i++) {
|
---|
| 112 | result4[i] = -1;
|
---|
| 113 | raypack.SetLoc(i, origin4[i]);
|
---|
| 114 | raypack.SetDir(i, direction4[i]);
|
---|
[2583] | 115 | }
|
---|
| 116 |
|
---|
[2582] | 117 | // The same operations for packets of rays, if implemented by
|
---|
| 118 | // a particular ASDS, otherwise it is emulated by decomposition
|
---|
| 119 | // of a packet to individual rays and traced individually.
|
---|
[2602] | 120 | mKtbtree->FindNearestI(raypack, minBox, maxBox);
|
---|
[2582] | 121 |
|
---|
| 122 | for (int i = 0; i < 4; i++) {
|
---|
| 123 | // if ray intersects an object, we set the pointer to
|
---|
| 124 | // this object
|
---|
| 125 | Intersectable* intersectable;
|
---|
[2592] | 126 | if ( (intersectable = raypack.GetObject(i)) ) {
|
---|
| 127 | // $$JB this is very hacky - > should be replaced with fetching the index of the triangle
|
---|
[2602] | 128 | // $$VH - this is object ID - is this the triangle index ???
|
---|
[2592] | 129 | result4[i] = intersectable->mId;
|
---|
| 130 | dist4[i] = raypack.GetT(i);
|
---|
| 131 | }
|
---|
[2582] | 132 | }
|
---|
[2583] | 133 |
|
---|
[2582] | 134 | return;
|
---|
[2592] | 135 | #else // _USE_HAVRAN_SSE
|
---|
| 136 | // Compute the result ray by ray
|
---|
| 137 | SimpleRay sray;
|
---|
| 138 | for (int i = 0; i < 4; i++) {
|
---|
| 139 | sray.mOrigin = origin4[i];
|
---|
| 140 | sray.mDirection = direction4[i];
|
---|
[2602] | 141 | mKtbtree->FindNearestI(sray, minBox, maxBox);
|
---|
[2592] | 142 | if (SimpleRay::IntersectionRes[0].intersectable) {
|
---|
| 143 | // This is object ID - is this the triangle index ???
|
---|
| 144 | result4[i] = SimpleRay::IntersectionRes[0].intersectable->mId;
|
---|
| 145 | dist4[i] = SimpleRay::IntersectionRes[0].tdist;
|
---|
| 146 | }
|
---|
| 147 | else {
|
---|
| 148 | result4[i] = -1; // no intersection
|
---|
| 149 | }
|
---|
| 150 | } // for i;
|
---|
| 151 |
|
---|
| 152 | #endif // _USE_HAVRAN_SSE
|
---|
[2602] | 153 | #endif // USE_HAVRAN_RAYCASTER
|
---|
[2582] | 154 | }
|
---|
| 155 |
|
---|
[2592] | 156 |
|
---|
[2582] | 157 | int HavranRayCaster::CastRay(const SimpleRay &simpleRay,
|
---|
| 158 | VssRayContainer &vssRays,
|
---|
| 159 | const AxisAlignedBox3 &box,
|
---|
| 160 | const bool castDoubleRay,
|
---|
| 161 | const bool pruneInvalidRays)
|
---|
| 162 | {
|
---|
| 163 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
| 164 |
|
---|
| 165 | int hits = 0;
|
---|
| 166 | Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
|
---|
| 167 |
|
---|
| 168 | // inside test for bounding box
|
---|
| 169 | // enlarge box slightly so the view point fits for sure
|
---|
| 170 | // AxisAlignedBox3 sbox = box;
|
---|
| 171 | // sbox.Enlarge(Vector3(-Limits::Small));
|
---|
| 172 | // $$ JB moved here from Validate routine
|
---|
| 173 |
|
---|
| 174 | // if (!box.IsInside(simpleRay.mOrigin)) {
|
---|
| 175 | // cout<<"out of box "<<simpleRay.mOrigin<<" "<<box<<endl;
|
---|
| 176 | // return 0;
|
---|
| 177 | // }
|
---|
| 178 |
|
---|
| 179 | // ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
[2592] | 180 | bool result;
|
---|
| 181 | if ((result = mKtbtree->FindNearestI(simpleRay))) {
|
---|
[2582] | 182 | hitA.mObject = SimpleRay::IntersectionRes[0].intersectable;
|
---|
| 183 | float tdist = SimpleRay::IntersectionRes[0].tdist;
|
---|
| 184 | hitA.mPoint = simpleRay.Extrap(tdist);
|
---|
| 185 | hitA.mNormal = SimpleRay::IntersectionRes[0].intersectable->GetNormal(0);
|
---|
| 186 | //hitA.mNormal = (dynamic_cast< TriangleIntersectable *>
|
---|
| 187 | // (hitA.mObject))->GetNormal(0);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | if (castDoubleRay) {
|
---|
| 192 | Vector3 *v = (Vector3*)(&simpleRay.mDirection);
|
---|
| 193 | *v = -(*v);
|
---|
| 194 | // ray.mFlags &= ~Ray::CULL_BACKFACES;
|
---|
| 195 | if (mKtbtree->FindNearestI(simpleRay)) {
|
---|
| 196 | hitB.mObject = SimpleRay::IntersectionRes[0].intersectable;
|
---|
| 197 | float tdist = SimpleRay::IntersectionRes[0].tdist;
|
---|
| 198 | hitB.mPoint = simpleRay.Extrap(tdist);
|
---|
| 199 | hitB.mNormal = SimpleRay::IntersectionRes[0].intersectable->GetNormal(0);
|
---|
| 200 | //hitB.mNormal = (dynamic_cast< TriangleIntersectable *>
|
---|
| 201 | // (hitB.mObject))->GetNormal(0);
|
---|
| 202 | }
|
---|
| 203 | // restore the direction to the original
|
---|
| 204 | *v = -simpleRay.mDirection;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[2592] | 207 | #ifdef _PROCESS_RAY
|
---|
[2582] | 208 | // This code is also in IntelRayCaster.cpp
|
---|
| 209 | return ProcessRay(
|
---|
| 210 | simpleRay,
|
---|
| 211 | hitA,
|
---|
| 212 | hitB,
|
---|
| 213 | vssRays,
|
---|
| 214 | box,
|
---|
| 215 | castDoubleRay,
|
---|
| 216 | pruneInvalidRays
|
---|
| 217 | );
|
---|
[2592] | 218 | #else // _PROCESS_RAY
|
---|
| 219 | return result;
|
---|
| 220 | #endif // _PROCESS_RAY
|
---|
| 221 |
|
---|
| 222 | #else
|
---|
[2582] | 223 | return 0;
|
---|
[2592] | 224 | #endif // USE_HAVRAN_RAYCASTER
|
---|
[2582] | 225 | }
|
---|
| 226 |
|
---|
| 227 | void HavranRayCaster::CastRays16(SimpleRayContainer &rays,
|
---|
| 228 | VssRayContainer &vssRays,
|
---|
| 229 | const AxisAlignedBox3 &sbox,
|
---|
| 230 | const bool castDoubleRay,
|
---|
| 231 | const bool pruneInvalidRays)
|
---|
| 232 | {
|
---|
| 233 | CastRays16(rays, 0, vssRays, sbox, castDoubleRay, pruneInvalidRays);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 |
|
---|
| 237 | void HavranRayCaster::CastRays16(SimpleRayContainer &rays,
|
---|
| 238 | int offset,
|
---|
| 239 | VssRayContainer &vssRays,
|
---|
| 240 | const AxisAlignedBox3 &sbox,
|
---|
| 241 | const bool castDoubleRays,
|
---|
| 242 | const bool pruneInvalidRays)
|
---|
| 243 | {
|
---|
| 244 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
| 245 |
|
---|
| 246 | #if DEBUG_RAYCAST
|
---|
| 247 | Debug << "C16 " << flush;
|
---|
| 248 | #endif
|
---|
| 249 |
|
---|
[2635] | 250 | #if 1
|
---|
[2592] | 251 | // This is shooting ray by ray
|
---|
| 252 | SimpleRayContainer::const_iterator sit, sit_end = rays.end();
|
---|
| 253 |
|
---|
[2582] | 254 | // no acceleration for ray bundles implemented right now
|
---|
| 255 | for (sit = rays.begin(); sit != sit_end; ++ sit)
|
---|
| 256 | {
|
---|
| 257 | CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays);
|
---|
| 258 | }
|
---|
| 259 | #else
|
---|
[2592] | 260 | // Use special algorithm for 16 rays at once
|
---|
[2582] | 261 | if (castDoubleRays) {
|
---|
[2592] | 262 |
|
---|
| 263 | #if 0 // ------------------------------------------------
|
---|
[2582] | 264 | // Special routine to cast double sided rays
|
---|
| 265 | mKtbtree->SetOffset(0);
|
---|
[2592] | 266 | #ifdef _USE_HAVRAN_SSE
|
---|
[2582] | 267 | mKtbtree->FindNearestI_16twoDir(rays);
|
---|
| 268 | #else
|
---|
[2592] | 269 | mKtbtree->FindNearestI_16twoDirNoSSE(rays);
|
---|
| 270 | #endif
|
---|
| 271 | #else // -------------------------------------------------
|
---|
[2582] | 272 | // Here we decompose shooting into two phases
|
---|
[2592] | 273 |
|
---|
| 274 | // Here we shoot first backward rays and forward ones
|
---|
[2582] | 275 | SimpleRayContainer::iterator sit = rays.begin() + offset;
|
---|
| 276 | SimpleRayContainer::const_iterator sit_end = rays.begin() + offset + 16;
|
---|
| 277 | for ( ; sit != sit_end; ++ sit)
|
---|
| 278 | {
|
---|
| 279 | (*sit).mDirection = - (*sit).mDirection;
|
---|
| 280 | }
|
---|
[2592] | 281 | // backward rays to be shot - saving with offset 16
|
---|
| 282 | #ifdef _USE_HAVRAN_SSE
|
---|
| 283 | mKtbtree->SetOffset(0);
|
---|
| 284 | mKtbtree->FindNearestI_16oneDir(rays, offset, 16);
|
---|
[2582] | 285 | #else
|
---|
| 286 | mKtbtree->SetOffset(16);
|
---|
[2592] | 287 | mKtbtree->FindNearestI_16oneDirNoSSE(rays, offset);
|
---|
| 288 | #endif // _USE_HAVRAN_SSE
|
---|
[2582] | 289 | sit = rays.begin() + offset;
|
---|
| 290 | for ( ; sit != sit_end; ++ sit)
|
---|
| 291 | {
|
---|
| 292 | (*sit).mDirection = - (*sit).mDirection;
|
---|
| 293 | }
|
---|
| 294 | // forward rays to be shot
|
---|
[2592] | 295 | #ifdef _USE_HAVRAN_SSE
|
---|
[2582] | 296 | mKtbtree->SetOffset(0);
|
---|
[2592] | 297 | mKtbtree->FindNearestI_16oneDir(rays, offset, 0);
|
---|
| 298 | #else
|
---|
| 299 | mKtbtree->SetOffset(0);
|
---|
| 300 | mKtbtree->FindNearestI_16oneDirNoSSE(rays, offset);
|
---|
| 301 | #endif // _USE_HAVRAN_SSE
|
---|
| 302 | #endif // ------------------------------------------------
|
---|
| 303 | } // cast double rays
|
---|
[2582] | 304 | else {
|
---|
[2592] | 305 | // ONLY single rays
|
---|
[2582] | 306 | // Shoot all 16 rays at the same time using a special algorithm
|
---|
| 307 | mKtbtree->SetOffset(0);
|
---|
[2592] | 308 | #ifdef _USE_HAVRAN_SSE
|
---|
| 309 | mKtbtree->FindNearestI_16oneDir(rays, offset, 0);
|
---|
| 310 | #else
|
---|
| 311 | mKtbtree->FindNearestI_16oneDirNoSSE(rays, offset);
|
---|
| 312 | #endif // _USE_HAVRAN_SSE
|
---|
[2582] | 313 | }
|
---|
| 314 | #endif
|
---|
| 315 |
|
---|
[2592] | 316 |
|
---|
[2582] | 317 | for (int i=0, k=offset; i < 16; i++, k++)
|
---|
| 318 | {
|
---|
| 319 | Intersection hitA(rays[k].mOrigin), hitB(rays[k].mOrigin);
|
---|
| 320 |
|
---|
| 321 | #if DEBUG_RAYCAST
|
---|
| 322 | Debug<<"FH\n"<<flush;
|
---|
| 323 | #endif
|
---|
| 324 |
|
---|
| 325 | Intersectable *intersect = SimpleRay::IntersectionRes[i].intersectable;
|
---|
| 326 |
|
---|
| 327 | if (intersect)
|
---|
| 328 | {
|
---|
| 329 | hitA.mObject = intersect;
|
---|
| 330 | // Get the normal of that face
|
---|
| 331 | hitA.mNormal = intersect->GetNormal(0);
|
---|
| 332 |
|
---|
| 333 | //-rays[index+i].mDirection; // $$ temporary
|
---|
| 334 | float tdist = SimpleRay::IntersectionRes[i].tdist;
|
---|
| 335 | hitA.mPoint = rays[k].Extrap(tdist);
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | #if DEBUG_RAYCAST
|
---|
| 339 | Debug<<"BH\n"<<flush;
|
---|
| 340 | #endif
|
---|
| 341 |
|
---|
| 342 | if (castDoubleRays)
|
---|
| 343 | {
|
---|
| 344 | Intersectable *intersect =
|
---|
[2592] | 345 | SimpleRay::IntersectionRes[i+16].intersectable;
|
---|
[2582] | 346 |
|
---|
| 347 | if (intersect)
|
---|
| 348 | {
|
---|
[2592] | 349 | hitB.mObject = intersect;
|
---|
| 350 | hitB.mNormal = intersect->GetNormal(0);;
|
---|
| 351 | float tdist = SimpleRay::IntersectionRes[16+i].tdist;
|
---|
| 352 | hitB.mPoint = rays[k].Extrap(-tdist);
|
---|
[2582] | 353 | }
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | #if DEBUG_RAYCAST
|
---|
| 357 | Debug<<"PR\n"<<flush;
|
---|
| 358 | #endif
|
---|
| 359 |
|
---|
[2592] | 360 | #ifdef _PROCESS_RAY
|
---|
[2582] | 361 | ProcessRay(rays[k],
|
---|
[2592] | 362 | hitA,
|
---|
| 363 | hitB,
|
---|
| 364 | vssRays,
|
---|
| 365 | sbox,
|
---|
| 366 | castDoubleRays,
|
---|
| 367 | pruneInvalidRays
|
---|
| 368 | );
|
---|
[2582] | 369 | #endif
|
---|
| 370 | } // for
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 | #if DEBUG_RAYCAST
|
---|
| 374 | Debug<<"C16F\n"<<flush;
|
---|
| 375 | #endif
|
---|
| 376 |
|
---|
| 377 | #endif // USE_HAVRAN_RAYCASTER
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 |
|
---|
| 381 |
|
---|
| 382 | void
|
---|
| 383 | HavranRayCaster::CastSimpleForwardRays(
|
---|
| 384 | SimpleRayContainer &rays,
|
---|
| 385 | const AxisAlignedBox3 &sbox
|
---|
| 386 | )
|
---|
| 387 | {
|
---|
[2655] | 388 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
| 389 |
|
---|
[2582] | 390 | int hit_triangles[16];
|
---|
| 391 | float dist[16];
|
---|
| 392 | Vector3 normals[16];
|
---|
| 393 | Vector3 min = sbox.Min();
|
---|
| 394 | Vector3 max = sbox.Max();
|
---|
| 395 |
|
---|
| 396 | int packets = rays.size() / 16;
|
---|
| 397 |
|
---|
| 398 | int i, j, k = 0;
|
---|
| 399 | Vector3 dir;
|
---|
| 400 |
|
---|
| 401 | // By groups of rays
|
---|
| 402 | for (i=0; i < packets; i++) {
|
---|
| 403 | int offset = i * 16;
|
---|
[2592] | 404 | mKtbtree->FindNearestI_16oneDir(rays, offset, 0);
|
---|
[2582] | 405 | // ??? What to do with the results ? These are
|
---|
| 406 | // not used at the moment also in IntelRayCaster.cpp
|
---|
| 407 | } // for
|
---|
| 408 |
|
---|
| 409 |
|
---|
| 410 | for (; k < rays.size(); k++) {
|
---|
| 411 | double normal[3];
|
---|
| 412 | mKtbtree->FindNearestI(rays[k]);
|
---|
| 413 | // ??? What to do with the results ? These are
|
---|
| 414 | // not used at the moment also in IntelRayCaster.cpp
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[2655] | 417 | #endif // USE_HAVRAN_RAYCASTER
|
---|
[2582] | 418 | return;
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | void HavranRayCaster::CastRays(
|
---|
| 422 | SimpleRayContainer &rays,
|
---|
| 423 | VssRayContainer &vssRays,
|
---|
| 424 | const AxisAlignedBox3 &sbox,
|
---|
| 425 | const bool castDoubleRay,
|
---|
| 426 | const bool pruneInvalidRays )
|
---|
| 427 | {
|
---|
| 428 | int buckets = rays.size()/16;
|
---|
| 429 | int offset = 0;
|
---|
| 430 |
|
---|
| 431 | #if 0
|
---|
| 432 | int time = GetTime();
|
---|
| 433 | CastSimpleForwardRays(rays, sbox);
|
---|
| 434 | cout<<1e-3*2*rays.size()/TimeDiff(time, GetTime())<<" Mrays/sec"<<endl;
|
---|
| 435 | #endif
|
---|
[2592] | 436 |
|
---|
| 437 | // Cast only by 16 rays at once
|
---|
[2582] | 438 | for (int i=0; i < buckets; i++, offset+=16) {
|
---|
| 439 | CastRays16(rays, offset, vssRays, sbox,
|
---|
| 440 | castDoubleRay, pruneInvalidRays);
|
---|
| 441 |
|
---|
[2638] | 442 | preprocessor->UpdateDynamicObjects();
|
---|
[2582] | 443 | if ((int)rays.size() > 100000 && i % (100000/16) == 0)
|
---|
| 444 | cout<<"\r"<<offset<<"/"<<(int)rays.size()<<"\r";
|
---|
| 445 | }
|
---|
| 446 |
|
---|
[2592] | 447 | // Cast the rest of the rays
|
---|
[2582] | 448 | for (; offset < (int)rays.size(); offset++)
|
---|
| 449 | CastRay(rays[offset], vssRays, sbox, castDoubleRay, pruneInvalidRays);
|
---|
[2592] | 450 |
|
---|
| 451 | return;
|
---|
[2582] | 452 | }
|
---|
| 453 |
|
---|
[2592] | 454 | #ifdef _USE_HAVRAN_SSE
|
---|
[2582] | 455 | // BUG1 41579 196948 1064111
|
---|
| 456 | // BUG2 254 1672 10869
|
---|
| 457 |
|
---|
| 458 | // Just for testing concept
|
---|
| 459 | void
|
---|
| 460 | HavranRayCaster::CastRaysPacket2x2(RayPacket2x2 &raysPack,
|
---|
[2592] | 461 | bool castDoubleRay,
|
---|
| 462 | const bool pruneInvalidRays)
|
---|
[2582] | 463 | {
|
---|
| 464 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
[2592] | 465 | #ifdef _USE_HAVRAN_SSE
|
---|
[2582] | 466 |
|
---|
| 467 | if (castDoubleRay) {
|
---|
| 468 | // cast forward rays
|
---|
| 469 | mKtbtree->FindNearestI(raysPack);
|
---|
| 470 | for (int i = 0; i < 4; i++)
|
---|
| 471 | raysPack.SetDir(i, -raysPack.GetDir(i));
|
---|
| 472 | // cast backward rays
|
---|
| 473 | mKtbtree->FindNearestI(raysPack);
|
---|
| 474 | // reverse the rays back
|
---|
| 475 | for (int i = 0; i < 4; i++)
|
---|
| 476 | raysPack.SetDir(i, -raysPack.GetDir(i));
|
---|
| 477 | }
|
---|
| 478 | else {
|
---|
| 479 | // only rays forwards
|
---|
| 480 | mKtbtree->FindNearestI(raysPack);
|
---|
| 481 | #if 0
|
---|
| 482 | // Only verification of correctness by casting single rays
|
---|
| 483 | static int cntBugs = 0;
|
---|
| 484 | SimpleRay ray;
|
---|
| 485 | int cntErrors = 0, cntDistErrors = 0;
|
---|
| 486 | bool newBug = false;
|
---|
| 487 | for (int i = 0; i < 4; i++) {
|
---|
| 488 | ray.mOrigin = raysPack.GetLoc(i);
|
---|
| 489 | ray.mDirection = raysPack.GetDir(i);
|
---|
| 490 | mKtbtree->FindNearestI(ray);
|
---|
| 491 | if (raysPack.GetObject(i) != SimpleRay::IntersectionRes[0].intersectable) {
|
---|
| 492 | float dist = (raysPack.GetT(i) - SimpleRay::IntersectionRes[0].tdist);
|
---|
| 493 | if (fabs(dist) > 0.001f) {
|
---|
| 494 | cntErrors++; newBug = true;
|
---|
| 495 | cntBugs++;
|
---|
| 496 | cout << " BUG1 d= " << dist;
|
---|
| 497 | }
|
---|
| 498 | }
|
---|
| 499 | else {
|
---|
| 500 | float dist = 0.f;
|
---|
| 501 | if (raysPack.GetObject(i) && SimpleRay::IntersectionRes[0].intersectable)
|
---|
| 502 | if (fabs((dist=(fabs (raysPack.GetT(i) - SimpleRay::IntersectionRes[0].tdist)))) > 1.f) {
|
---|
| 503 | cntDistErrors++; newBug = true; cntBugs++;
|
---|
| 504 | cout << " BUG2 distdf= " << dist ;
|
---|
| 505 | }
|
---|
| 506 | }
|
---|
| 507 | } // for
|
---|
| 508 | if (newBug) cout << " CB= " << cntBugs << "\n";
|
---|
| 509 | #endif
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | return;
|
---|
[2592] | 513 | #endif // _USE_HAVRAN_SSE
|
---|
[2582] | 514 | #endif // USE_HAVRAN_RAYCASTER
|
---|
| 515 | }
|
---|
[2629] | 516 |
|
---|
| 517 |
|
---|
| 518 |
|
---|
| 519 |
|
---|
[2592] | 520 | #endif // _USE_HAVRAN_SSE
|
---|
[2582] | 521 |
|
---|
| 522 |
|
---|
| 523 | } // the namespace
|
---|