1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "../builders/primref.h"
namespace embree
{
namespace isa
{
template<size_t N>
__forceinline void splitPolygon(const BBox3fa& bounds,
const size_t dim,
const float pos,
const Vec3fa (&v)[N+1],
BBox3fa& left_o,
BBox3fa& right_o)
{
BBox3fa left = empty, right = empty;
/* clip triangle to left and right box by processing all edges */
for (size_t i=0; i<N; i++)
{
const Vec3fa &v0 = v[i];
const Vec3fa &v1 = v[i+1];
const float v0d = v0[dim];
const float v1d = v1[dim];
if (v0d <= pos) left. extend(v0); // this point is on left side
if (v0d >= pos) right.extend(v0); // this point is on right side
if ((v0d < pos && pos < v1d) || (v1d < pos && pos < v0d)) // the edge crosses the splitting location
{
assert((v1d-v0d) != 0.0f);
const float inv_length = 1.0f/(v1d-v0d);
const Vec3fa c = madd(Vec3fa((pos-v0d)*inv_length),v1-v0,v0);
left.extend(c);
right.extend(c);
}
}
/* clip against current bounds */
left_o = intersect(left,bounds);
right_o = intersect(right,bounds);
}
template<size_t N>
__forceinline void splitPolygon(const BBox3fa& bounds,
const size_t dim,
const float pos,
const Vec3fa (&v)[N+1],
const Vec3fa (&inv_length)[N],
BBox3fa& left_o,
BBox3fa& right_o)
{
BBox3fa left = empty, right = empty;
/* clip triangle to left and right box by processing all edges */
for (size_t i=0; i<N; i++)
{
const Vec3fa &v0 = v[i];
const Vec3fa &v1 = v[i+1];
const float v0d = v0[dim];
const float v1d = v1[dim];
if (v0d <= pos) left. extend(v0); // this point is on left side
if (v0d >= pos) right.extend(v0); // this point is on right side
if ((v0d < pos && pos < v1d) || (v1d < pos && pos < v0d)) // the edge crosses the splitting location
{
assert((v1d-v0d) != 0.0f);
const Vec3fa c = madd(Vec3fa((pos-v0d)*inv_length[i][dim]),v1-v0,v0);
left.extend(c);
right.extend(c);
}
}
/* clip against current bounds */
left_o = intersect(left,bounds);
right_o = intersect(right,bounds);
}
template<size_t N>
__forceinline void splitPolygon(const PrimRef& prim,
const size_t dim,
const float pos,
const Vec3fa (&v)[N+1],
PrimRef& left_o,
PrimRef& right_o)
{
BBox3fa left = empty, right = empty;
for (size_t i=0; i<N; i++)
{
const Vec3fa &v0 = v[i];
const Vec3fa &v1 = v[i+1];
const float v0d = v0[dim];
const float v1d = v1[dim];
if (v0d <= pos) left. extend(v0); // this point is on left side
if (v0d >= pos) right.extend(v0); // this point is on right side
if ((v0d < pos && pos < v1d) || (v1d < pos && pos < v0d)) // the edge crosses the splitting location
{
assert((v1d-v0d) != 0.0f);
const float inv_length = 1.0f/(v1d-v0d);
const Vec3fa c = madd(Vec3fa((pos-v0d)*inv_length),v1-v0,v0);
left.extend(c);
right.extend(c);
}
}
/* clip against current bounds */
new (&left_o ) PrimRef(intersect(left ,prim.bounds()),prim.geomID(), prim.primID());
new (&right_o) PrimRef(intersect(right,prim.bounds()),prim.geomID(), prim.primID());
}
}
}
|