All files / engine/Source/Shaders/Voxels IntersectLongitude.js

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                                                                                                                                                         
//This file is automatically rebuilt by the Cesium build process.
export default "// See IntersectionUtils.glsl for the definitions of Ray, NO_HIT, INF_HIT,\n\
// RayShapeIntersection\n\
\n\
vec4 transformNormalToEC(in vec4 intersection) {\n\
    return vec4(normalize(czm_normal * intersection.xyz), intersection.w);\n\
}\n\
\n\
RayShapeIntersection transformNormalsToEC(in RayShapeIntersection ix) {\n\
    return RayShapeIntersection(transformNormalToEC(ix.entry), transformNormalToEC(ix.exit));\n\
}\n\
\n\
vec4 intersectLongitude(in Ray ray, in float angle, in bool positiveNormal) {\n\
    float normalSign = positiveNormal ? 1.0 : -1.0;\n\
    vec2 planeNormal = vec2(-sin(angle), cos(angle)) * normalSign;\n\
\n\
    vec2 position = ray.pos.xy;\n\
    vec2 direction = ray.dir.xy;\n\
    float approachRate = dot(direction, planeNormal);\n\
    float distance = -dot(position, planeNormal);\n\
\n\
    float t = (approachRate == 0.0)\n\
        ? NO_HIT\n\
        : distance / approachRate;\n\
\n\
    return vec4(planeNormal, 0.0, t);\n\
}\n\
\n\
RayShapeIntersection intersectHalfSpace(in Ray ray, in float angle, in bool positiveNormal)\n\
{\n\
    vec4 intersection = intersectLongitude(ray, angle, positiveNormal);\n\
    vec4 farSide = vec4(normalize(ray.dir), INF_HIT);\n\
\n\
    bool hitFront = (intersection.w > 0.0) == (dot(ray.pos.xy, intersection.xy) > 0.0);\n\
    if (!hitFront) {\n\
        return RayShapeIntersection(intersection, farSide);\n\
    } else {\n\
        return RayShapeIntersection(-1.0 * farSide, intersection);\n\
    }\n\
}\n\
\n\
void intersectFlippedWedge(in Ray ray, in vec2 minMaxAngle, out RayShapeIntersection intersections[2])\n\
{\n\
    intersections[0] = transformNormalsToEC(intersectHalfSpace(ray, minMaxAngle.x, false));\n\
    intersections[1] = transformNormalsToEC(intersectHalfSpace(ray, minMaxAngle.y, true));\n\
}\n\
\n\
bool hitPositiveHalfPlane(in Ray ray, in vec4 intersection, in bool positiveNormal) {\n\
    float normalSign = positiveNormal ? 1.0 : -1.0;\n\
    vec2 planeDirection = vec2(intersection.y, -intersection.x) * normalSign;\n\
    vec2 hit = ray.pos.xy + intersection.w * ray.dir.xy;\n\
    return dot(hit, planeDirection) > 0.0;\n\
}\n\
\n\
void intersectHalfPlane(in Ray ray, in float angle, out RayShapeIntersection intersections[2]) {\n\
    vec4 intersection = intersectLongitude(ray, angle, true);\n\
    vec4 farSide = vec4(normalize(ray.dir), INF_HIT);\n\
    bool hitPositiveSide = hitPositiveHalfPlane(ray, intersection, true);\n\
\n\
    farSide = transformNormalToEC(farSide);\n\
\n\
    if (hitPositiveSide) {\n\
        intersection = transformNormalToEC(intersection);\n\
        intersections[0].entry = -1.0 * farSide;\n\
        intersections[0].exit = vec4(-1.0 * intersection.xyz, intersection.w);\n\
        intersections[1].entry = intersection;\n\
        intersections[1].exit = farSide;\n\
    } else {\n\
        vec4 miss = vec4(normalize(czm_normal * ray.dir), NO_HIT);\n\
        intersections[0].entry = -1.0 * farSide;\n\
        intersections[0].exit = farSide;\n\
        intersections[1].entry = miss;\n\
        intersections[1].exit = miss;\n\
    }\n\
}\n\
\n\
RayShapeIntersection intersectRegularWedge(in Ray ray, in vec2 minMaxAngle)\n\
{\n\
    // Note: works for maxAngle > minAngle + pi, where the \"regular wedge\"\n\
    // is actually a negative volume.\n\
    // Compute intersections with the two planes.\n\
    // Normals will point toward the \"outside\" (negative space)\n\
    vec4 intersect1 = intersectLongitude(ray, minMaxAngle.x, false);\n\
    vec4 intersect2 = intersectLongitude(ray, minMaxAngle.y, true);\n\
\n\
    // Choose intersection with smallest T as the \"first\", the other as \"last\"\n\
    // Note: first or last could be in the \"shadow\" wedge, beyond the tip\n\
    bool inOrder = intersect1.w <= intersect2.w;\n\
    vec4 first = inOrder ? intersect1 : intersect2;\n\
    vec4 last = inOrder ? intersect2 : intersect1;\n\
\n\
    bool firstIsAhead = first.w >= 0.0;\n\
    bool startedInsideFirst = dot(ray.pos.xy, first.xy) < 0.0;\n\
    bool exitFromInside = firstIsAhead == startedInsideFirst;\n\
    bool lastIsAhead = last.w > 0.0;\n\
    bool startedOutsideLast = dot(ray.pos.xy, last.xy) >= 0.0;\n\
    bool enterFromOutside = lastIsAhead == startedOutsideLast;\n\
\n\
    vec4 farSide = vec4(normalize(ray.dir), INF_HIT);\n\
    vec4 miss = vec4(normalize(ray.dir), NO_HIT);\n\
\n\
    if (exitFromInside && enterFromOutside) {\n\
        // Ray crosses both faces of negative wedge, exiting then entering the positive shape\n\
        return transformNormalsToEC(RayShapeIntersection(first, last));\n\
    } else if (!exitFromInside && enterFromOutside) {\n\
        // Ray starts inside wedge. last is in shadow wedge, and first is actually the entry\n\
        return transformNormalsToEC(RayShapeIntersection(-1.0 * farSide, first));\n\
    } else if (exitFromInside && !enterFromOutside) {\n\
        // First intersection was in the shadow wedge, so last is actually the exit\n\
        return transformNormalsToEC(RayShapeIntersection(last, farSide));\n\
    } else { // !exitFromInside && !enterFromOutside\n\
        // Both intersections were in the shadow wedge\n\
        return transformNormalsToEC(RayShapeIntersection(miss, miss));\n\
    }\n\
}\n\
";