mirror of
https://github.com/jiawanlong/Cesium-Examples.git
synced 2025-12-17 07:18:51 +00:00
84 lines
2.7 KiB
HTML
84 lines
2.7 KiB
HTML
<!--********************************************************************
|
||
* by jiawanlong
|
||
*********************************************************************-->
|
||
<!DOCTYPE html>
|
||
<html>
|
||
|
||
<head>
|
||
<meta charset="UTF-8" />
|
||
<link rel="stylesheet" href="./../../libs/cesium/Cesium1.98/Widgets/widgets.css" />
|
||
<script type="text/javascript" src="./../../libs/cesium/Cesium1.98/Cesium.js"></script>
|
||
</head>
|
||
|
||
<body style="
|
||
margin: 0;
|
||
overflow: hidden;
|
||
background: #fff;
|
||
width: 100%;
|
||
height: 100%;
|
||
position: absolute; top: 0;
|
||
">
|
||
<div id="map" style="margin: 0 auto; width: 100%; height: 100%"></div>
|
||
|
||
<script type="text/javascript">
|
||
const viewer = new Cesium.Viewer('map', {
|
||
imageryProvider: false,
|
||
baseLayerPicker: false,
|
||
});
|
||
|
||
var xyz = new Cesium.UrlTemplateImageryProvider({
|
||
"url": '//data.mars3d.cn/tile/img/{z}/{x}/{y}.jpg'
|
||
})
|
||
viewer.imageryLayers.addImageryProvider(xyz)
|
||
viewer.scene.debugShowFramesPerSecond = true;
|
||
|
||
/*
|
||
1. 顶点着色器(Vertex Shader)坐标变换、传递数据给片段着色器、动态变形
|
||
2. 片段着色器(Fragment Shader)计算颜色、应用光照、后处理效果
|
||
*/
|
||
|
||
const customShader = new Cesium.CustomShader({
|
||
vertexShaderText: `
|
||
void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
|
||
// vec3 position = vsInput.attributes.positionMC;
|
||
// position.y = position.y + 10.5;
|
||
// vsOutput.positionMC = position;
|
||
}
|
||
`,
|
||
fragmentShaderText: `
|
||
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
|
||
float height = fsInput.attributes.positionMC.y;
|
||
|
||
vec3 lowColor = vec3(0.0, 0.0, 1.0); // 蓝色
|
||
vec3 highColor = vec3(1.0, 0.0, 0.0); // 红色
|
||
|
||
// material.diffuse = mix(lowColor, highColor, smoothstep(0.0, 200.0, height));
|
||
|
||
if(height > 30.0){
|
||
material.diffuse = lowColor;
|
||
}else{
|
||
material.diffuse = highColor;
|
||
}
|
||
|
||
}
|
||
`,
|
||
});
|
||
|
||
const tileset = new Cesium.Cesium3DTileset({
|
||
url: "./data/tileset.json",
|
||
customShader: customShader
|
||
});
|
||
|
||
tileset.readyPromise
|
||
.then(function (tileset) {
|
||
viewer.scene.primitives.add(tileset);
|
||
viewer.zoomTo(tileset)
|
||
})
|
||
.catch(function (error) {
|
||
console.log(error);
|
||
});
|
||
|
||
</script>
|
||
</body>
|
||
|
||
</html> |