
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({
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)