cesium白膜条纹着色器

289 阅读1分钟

Snipaste_2023-11-01_15-54-20.png

const modelCenter = CESIUM.Cartesian3.fromDegrees(x, x, x)
const modelMatrix = CESIUM.Transforms.eastNorthUpToFixedFrame(modelCenter)
const gltfModel = CESIUM.Model.fromGltfAsync({
  url: xxx,
  modelMatrix,
  customShader: new CESIUM.CustomShader({
    // translucencyMode: CESIUM.CustomShaderTranslucencyMode.TRANSLUCENT, //透明
    mode: CESIUM.CustomShaderMode.REPLACE_MATERIAL, //替换本来的材质
    varyings: {
      v_position: CESIUM.VaryingType.VEC3,
      v_normalMC: CESIUM.VaryingType.VEC3,
    },
    uniforms: {
      color1: {
        value: CESIUM.Color.fromCssColorString('#ffffff'),
        type: CESIUM.UniformType.VEC3,
      },
      color2: {
        value: CESIUM.Color.fromCssColorString('#3BABFF'),
        type: CESIUM.UniformType.VEC3,
      },
    },
    vertexShaderText: `
      void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
        v_position = vsOutput.positionMC;
        v_normalMC = vsInput.attributes.normalMC;
      }
    `,
    fragmentShaderText: `
      void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
      {
          float tau = 6.283185;
          float spaceSize = 4.;
          float depth = v_position.y / spaceSize;
          vec3 color = vec3(0.0);
          color += color1 * (0.5 * cos(tau * depth)) + color2 * (1. - 0.5 * cos(tau * depth));
          material.diffuse = color;
      }
    `,
  }),
})
viewer.scene.primitives.add(gltfModel)