| 1 | // Copyright 2009-2021 Intel Corporation |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "object.h" |
| 7 | #include "../common/ray.h" |
| 8 | |
| 9 | namespace embree |
| 10 | { |
| 11 | namespace isa |
| 12 | { |
| 13 | template<bool mblur> |
| 14 | struct ObjectIntersector1 |
| 15 | { |
| 16 | typedef Object Primitive; |
| 17 | |
| 18 | static const bool validIntersectorK = false; |
| 19 | |
| 20 | struct Precalculations { |
| 21 | __forceinline Precalculations() {} |
| 22 | __forceinline Precalculations (const Ray& ray, const void *ptr) {} |
| 23 | }; |
| 24 | |
| 25 | static __forceinline void intersect(const Precalculations& pre, RayHit& ray, IntersectContext* context, const Primitive& prim) |
| 26 | { |
| 27 | AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); |
| 28 | |
| 29 | /* perform ray mask test */ |
| 30 | #if defined(EMBREE_RAY_MASK) |
| 31 | if ((ray.mask & accel->mask) == 0) |
| 32 | return; |
| 33 | #endif |
| 34 | |
| 35 | accel->intersect(ray,prim.geomID(),prim.primID(),context); |
| 36 | } |
| 37 | |
| 38 | static __forceinline bool occluded(const Precalculations& pre, Ray& ray, IntersectContext* context, const Primitive& prim) |
| 39 | { |
| 40 | AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); |
| 41 | /* perform ray mask test */ |
| 42 | #if defined(EMBREE_RAY_MASK) |
| 43 | if ((ray.mask & accel->mask) == 0) |
| 44 | return false; |
| 45 | #endif |
| 46 | |
| 47 | accel->occluded(ray,prim.geomID(),prim.primID(),context); |
| 48 | return ray.tfar < 0.0f; |
| 49 | } |
| 50 | |
| 51 | static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim) |
| 52 | { |
| 53 | AccelSet* accel = (AccelSet*)context->scene->get(prim.geomID()); |
| 54 | context->geomID = prim.geomID(); |
| 55 | context->primID = prim.primID(); |
| 56 | return accel->pointQuery(query, context); |
| 57 | } |
| 58 | |
| 59 | template<int K> |
| 60 | static __forceinline void intersectK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayHitK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) |
| 61 | { |
| 62 | assert(false); |
| 63 | } |
| 64 | |
| 65 | template<int K> |
| 66 | static __forceinline vbool<K> occludedK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayK<K>& ray, IntersectContext* context, const Primitive* prim, size_t num, size_t& lazy_node) |
| 67 | { |
| 68 | assert(false); |
| 69 | return valid; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | template<int K, bool mblur> |
| 74 | struct ObjectIntersectorK |
| 75 | { |
| 76 | typedef Object Primitive; |
| 77 | |
| 78 | struct Precalculations { |
| 79 | __forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {} |
| 80 | }; |
| 81 | |
| 82 | static __forceinline void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, IntersectContext* context, const Primitive& prim) |
| 83 | { |
| 84 | vbool<K> valid = valid_i; |
| 85 | AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); |
| 86 | |
| 87 | /* perform ray mask test */ |
| 88 | #if defined(EMBREE_RAY_MASK) |
| 89 | valid &= (ray.mask & accel->mask) != 0; |
| 90 | if (none(valid)) return; |
| 91 | #endif |
| 92 | accel->intersect(valid,ray,prim.geomID(),prim.primID(),context); |
| 93 | } |
| 94 | |
| 95 | static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, IntersectContext* context, const Primitive& prim) |
| 96 | { |
| 97 | vbool<K> valid = valid_i; |
| 98 | AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID()); |
| 99 | |
| 100 | /* perform ray mask test */ |
| 101 | #if defined(EMBREE_RAY_MASK) |
| 102 | valid &= (ray.mask & accel->mask) != 0; |
| 103 | if (none(valid)) return false; |
| 104 | #endif |
| 105 | accel->occluded(valid,ray,prim.geomID(),prim.primID(),context); |
| 106 | return ray.tfar < 0.0f; |
| 107 | } |
| 108 | |
| 109 | static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { |
| 110 | intersect(vbool<K>(1<<int(k)),pre,ray,context,prim); |
| 111 | } |
| 112 | |
| 113 | static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, IntersectContext* context, const Primitive& prim) { |
| 114 | occluded(vbool<K>(1<<int(k)),pre,ray,context,prim); |
| 115 | return ray.tfar[k] < 0.0f; |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | typedef ObjectIntersectorK<4,false> ObjectIntersector4; |
| 120 | typedef ObjectIntersectorK<8,false> ObjectIntersector8; |
| 121 | typedef ObjectIntersectorK<16,false> ObjectIntersector16; |
| 122 | |
| 123 | typedef ObjectIntersectorK<4,true> ObjectIntersector4MB; |
| 124 | typedef ObjectIntersectorK<8,true> ObjectIntersector8MB; |
| 125 | typedef ObjectIntersectorK<16,true> ObjectIntersector16MB; |
| 126 | } |
| 127 | } |
| 128 | |