开源

Cesium绘制一实一虚线

2023-02-16  本文已影响0人  周五蛋碎一地

双实线做完了发现还有个一实一虚线要做,正好那就把双实线改一下得了,让一侧显示虚线就可以了,相当于把polyline与polylineDash结合到一块

mat2 rotate(float rad) {
    float c = cos(rad);
    float s = sin(rad);
    return mat2(c, s, -s, c);
}

czm_material czm_getMaterial(czm_materialInput materialInput) {
    czm_material material = czm_getDefaultMaterial(materialInput);
    float minIntervalRatio = min(intervalRatio, 0.9);
    vec2 st = materialInput.st;
    vec2 pos = rotate(v_polylineAngle) * gl_FragCoord.xy;
    float dashPosition = fract(pos.x / (dashLength * czm_pixelRatio));
    float maskIndex = floor(dashPosition * maskLength);
    float maskTest = floor(dashPattern / pow(2.0, maskIndex));
    vec4 fragColor = (mod(maskTest, 2.0) < 1.0) ? vec4(0.0) : color;
    if(sideWise) {
        if(st.t < 0.5 && fragColor.a < 0.005) {
            discard;
        }
    } else {
        if(st.t > 0.5 && fragColor.a < 0.005) {
            discard;
        }
    }

    fragColor = color;
    if(st.t < 0.5 + minIntervalRatio * 0.5 && st.t > 0.5 - minIntervalRatio * 0.5) {
        fragColor.a = 0.0;
    } else {
        fragColor.a = color.a;
    }

    fragColor = czm_gammaCorrect(fragColor);

    material.emission = fragColor.rgb;
    material.alpha = fragColor.a;

    return material;
}

效果如下:


让这里能掉头,怎么样?
上一篇 下一篇

猜你喜欢

热点阅读