mirror of
https://github.com/jiawanlong/Cesium-Examples.git
synced 2025-07-04 15:17:36 +00:00
67 lines
2.9 KiB
HTML
67 lines
2.9 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">
|
||
Cesium.Ion.defaultAccessToken =
|
||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3ZjQ5ZGUzNC1jNWYwLTQ1ZTMtYmNjYS05YTY4ZTVmN2I2MDkiLCJpZCI6MTE3MTM4LCJpYXQiOjE2NzY0NDUyODB9.ZaNSBIfc1sGLhQd_xqhiSsc0yr8oS0wt1hAo9gbke6M";
|
||
const viewer = new Cesium.Viewer("map", {});
|
||
viewer.scene.debugShowFramesPerSecond = true;
|
||
|
||
/*
|
||
1. 顶点着色器(Vertex Shader)坐标变换、传递数据给片段着色器、动态变形
|
||
2. 片段着色器(Fragment Shader)计算颜色、应用光照、后处理效果
|
||
*/
|
||
|
||
const customShader = new Cesium.CustomShader({
|
||
lightingModel: Cesium.LightingModel.UNLIT,
|
||
fragmentShaderText: `
|
||
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
|
||
|
||
float _baseHeight = 0.0; // 物体的基础高度,需要修改成一个合适的建筑基础高度
|
||
float _heightRange = 60.0; // 高亮的范围(_baseHeight ~ _baseHeight + _heightRange) 默认是 0-60米
|
||
float _glowRange = 300.0; // 光环的移动范围(高度)
|
||
float vtxf_height = fsInput.attributes.positionMC.y-_baseHeight;
|
||
float vtxf_a11 = fract(czm_frameNumber / 120.0) * 3.14159265 * 2.0;
|
||
float vtxf_a12 = vtxf_height / _heightRange + sin(vtxf_a11) * 0.1;
|
||
material.diffuse*= vec3(vtxf_a12, vtxf_a12, vtxf_a12);
|
||
float vtxf_a13 = fract(czm_frameNumber / 360.0);
|
||
float vtxf_h = clamp(vtxf_height / _glowRange, 0.0, 1.0);
|
||
vtxf_a13 = abs(vtxf_a13 - 0.5) * 2.0;
|
||
float vtxf_diff = step(0.005, abs(vtxf_h - vtxf_a13));
|
||
material.diffuse += material.diffuse * (1.0 - vtxf_diff);
|
||
}
|
||
`,
|
||
});
|
||
|
||
const tileset = new Cesium.Cesium3DTileset({
|
||
url: "./data/tileset.json",
|
||
customShader: customShader
|
||
});
|
||
|
||
tileset.readyPromise.then(function (tileset) {
|
||
viewer.scene.primitives.add(tileset);
|
||
viewer.zoomTo(tileset)
|
||
})
|
||
</script>
|
||
</body>
|
||
|
||
</html> |