All files / engine/Source/Shaders/Materials ElevationBandMaterial.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                                                                                                                                                         
//This file is automatically rebuilt by the Cesium build process.
export default "uniform sampler2D heights;\n\
uniform sampler2D colors;\n\
\n\
// This material expects heights to be sorted from lowest to highest.\n\
\n\
float getHeight(int idx, float invTexSize)\n\
{\n\
    vec2 uv = vec2((float(idx) + 0.5) * invTexSize, 0.5);\n\
#ifdef OES_texture_float\n\
    return texture(heights, uv).x;\n\
#else\n\
    return czm_unpackFloat(texture(heights, uv));\n\
#endif\n\
}\n\
\n\
czm_material czm_getMaterial(czm_materialInput materialInput)\n\
{\n\
    czm_material material = czm_getDefaultMaterial(materialInput);\n\
\n\
    float height = materialInput.height;\n\
    float invTexSize = 1.0 / float(heightsDimensions.x);\n\
\n\
    float minHeight = getHeight(0, invTexSize);\n\
    float maxHeight = getHeight(heightsDimensions.x - 1, invTexSize);\n\
\n\
    // early-out when outside the height range\n\
    if (height < minHeight || height > maxHeight) {\n\
        material.diffuse = vec3(0.0);\n\
        material.alpha = 0.0;\n\
        return material;\n\
    }\n\
\n\
    // Binary search to find heights above and below.\n\
    int idxBelow = 0;\n\
    int idxAbove = heightsDimensions.x;\n\
    float heightBelow = minHeight;\n\
    float heightAbove = maxHeight;\n\
\n\
    // while loop not allowed, so use for loop with max iterations.\n\
    // maxIterations of 16 supports a texture size up to 65536 (2^16).\n\
    const int maxIterations = 16;\n\
    for (int i = 0; i < maxIterations; i++) {\n\
        if (idxBelow >= idxAbove - 1) {\n\
            break;\n\
        }\n\
\n\
        int idxMid = (idxBelow + idxAbove) / 2;\n\
        float heightTex = getHeight(idxMid, invTexSize);\n\
\n\
        if (height > heightTex) {\n\
            idxBelow = idxMid;\n\
            heightBelow = heightTex;\n\
        } else {\n\
            idxAbove = idxMid;\n\
            heightAbove = heightTex;\n\
        }\n\
    }\n\
\n\
    float lerper = heightBelow == heightAbove ? 1.0 : (height - heightBelow) / (heightAbove - heightBelow);\n\
    vec2 colorUv = vec2(invTexSize * (float(idxBelow) + 0.5 + lerper), 0.5);\n\
    vec4 color = texture(colors, colorUv);\n\
\n\
    // undo preumultiplied alpha\n\
    if (color.a > 0.0) \n\
    {\n\
        color.rgb /= color.a;\n\
    }\n\
    \n\
    color.rgb = czm_gammaCorrect(color.rgb);\n\
\n\
    material.diffuse = color.rgb;\n\
    material.alpha = color.a;\n\
    return material;\n\
}\n\
";