All files / engine/Source/Shaders/Voxels IntersectPlane.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                                                                                                                                                                     
//This file is automatically rebuilt by the Cesium build process.
export default "// See IntersectionUtils.glsl for the definitions of Ray, Intersections, INF_HIT,\n\
// NO_HIT, setShapeIntersection\n\
\n\
/* Clipping plane defines (set in Scene/VoxelRenderResources.js)\n\
#define CLIPPING_PLANES_UNION\n\
#define CLIPPING_PLANES_COUNT\n\
#define CLIPPING_PLANES_INTERSECTION_INDEX\n\
*/\n\
\n\
uniform sampler2D u_clippingPlanesTexture;\n\
uniform mat4 u_clippingPlanesMatrix;\n\
\n\
// Plane is in Hessian Normal Form\n\
vec4 intersectPlane(in Ray ray, in vec4 plane) {\n\
    vec3 n = plane.xyz; // normal\n\
    float w = plane.w; // -dot(pointOnPlane, normal)\n\
\n\
    float a = dot(ray.pos, n);\n\
    float b = dot(ray.dir, n);\n\
    float t = -(w + a) / b;\n\
\n\
    return vec4(n, t);\n\
}\n\
\n\
#ifdef CLIPPING_PLANES\n\
void intersectClippingPlanes(in Ray ray, inout Intersections ix) {\n\
    vec4 backSide = vec4(-ray.dir, -INF_HIT);\n\
    vec4 farSide = vec4(ray.dir, +INF_HIT);\n\
    RayShapeIntersection clippingVolume;\n\
\n\
    #if (CLIPPING_PLANES_COUNT == 1)\n\
        // Union and intersection are the same when there's one clipping plane, and the code\n\
        // is more simplified.\n\
        vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, 0);\n\
        vec4 intersection = intersectPlane(ray, planeUv);\n\
        bool reflects = dot(ray.dir, intersection.xyz) < 0.0;\n\
        clippingVolume.entry = reflects ? backSide : intersection;\n\
        clippingVolume.exit = reflects ? intersection : farSide;\n\
        setShapeIntersection(ix, CLIPPING_PLANES_INTERSECTION_INDEX, clippingVolume);\n\
    #elif defined(CLIPPING_PLANES_UNION)\n\
        vec4 firstTransmission = vec4(ray.dir, +INF_HIT);\n\
        vec4 lastReflection = vec4(-ray.dir, -INF_HIT);\n\
        for (int i = 0; i < CLIPPING_PLANES_COUNT; i++) {\n\
            vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, i);\n\
            vec4 intersection = intersectPlane(ray, planeUv);\n\
            if (dot(ray.dir, planeUv.xyz) > 0.0) {\n\
                firstTransmission = intersection.w <= firstTransmission.w ? intersection : firstTransmission;\n\
            } else {\n\
                lastReflection = intersection.w >= lastReflection.w ? intersection : lastReflection;\n\
            }\n\
        }\n\
        clippingVolume.entry = backSide;\n\
        clippingVolume.exit = lastReflection;\n\
        setShapeIntersection(ix, CLIPPING_PLANES_INTERSECTION_INDEX + 0, clippingVolume);\n\
        clippingVolume.entry = firstTransmission;\n\
        clippingVolume.exit = farSide;\n\
        setShapeIntersection(ix, CLIPPING_PLANES_INTERSECTION_INDEX + 1, clippingVolume);\n\
    #else // intersection\n\
        vec4 lastTransmission = vec4(ray.dir, -INF_HIT);\n\
        vec4 firstReflection = vec4(-ray.dir, +INF_HIT);\n\
        for (int i = 0; i < CLIPPING_PLANES_COUNT; i++) {\n\
            vec4 planeUv = getClippingPlane(u_clippingPlanesTexture, i);\n\
            vec4 intersection = intersectPlane(ray, planeUv);\n\
            if (dot(ray.dir, planeUv.xyz) > 0.0) {\n\
                lastTransmission = intersection.w > lastTransmission.w ? intersection : lastTransmission;\n\
            } else {\n\
                firstReflection = intersection.w < firstReflection.w ? intersection: firstReflection;\n\
            }\n\
        }\n\
        if (lastTransmission.w < firstReflection.w) {\n\
            clippingVolume.entry = lastTransmission;\n\
            clippingVolume.exit = firstReflection;\n\
        } else {\n\
            clippingVolume.entry = vec4(-ray.dir, NO_HIT);\n\
            clippingVolume.exit = vec4(ray.dir, NO_HIT);\n\
        }\n\
        setShapeIntersection(ix, CLIPPING_PLANES_INTERSECTION_INDEX, clippingVolume);\n\
    #endif\n\
}\n\
#endif\n\
";