Cesium 自定义Material 系列 (十)
- 对于沥青墙纹理效果 我们先定义一下他的interface, 方便使用的人知道他的调用参数
-
export interface PMaterialAsphalt{
-
asphaltColor: any,
-
bumpSize : 0.02,
-
roughness : 0.2
-
}
- 对于沥青墙纹理我们叫 MaterialAsphalt
-
import {MaterialProperty} from "../MaterialProperty";
-
const defaultOption: PMaterialAsphalt = {
-
asphaltColor: new Cesium.Color(1.0, 1.0, 1.0, 0.5),
-
bumpSize : 0.02,
-
roughness : 0.2
-
}
-
//沥青效果
-
export class MaterialAsphalt extends MaterialProperty{
-
protected _getType(option: any): string {
-
return "MaterialAsphalt"
-
}
-
constructor(option=defaultOption) {
-
super(MaterialAsphalt.prototype, defaultOption, option);
-
}
-
protected _getTranslucent(material: any){
-
return material.uniforms.asphaltColor.alpha < 1.0
-
}
-
protected getSource(option: any): string {
-
return `
-
uniform vec4 asphaltColor;
-
uniform float bumpSize;
-
uniform float roughness;
-
-
czm_material czm_getMaterial(czm_materialInput materialInput)
-
{
-
czm_material material = czm_getDefaultMaterial(materialInput);
-
-
// From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights
-
//Main cellular pattern
-
vec4 color = asphaltColor;
-
vec2 st = materialInput.st;
-
vec2 F = czm_cellular(st / bumpSize);
-
color.rgb -= (F.x / F.y) * 0.1;
-
-
//Extra bumps for roughness
-
float noise = czm_snoise(st / bumpSize);
-
noise = pow(noise, 5.0) * roughness;
-
color.rgb += noise;
-
-
material.diffuse = color.rgb;
-
material.alpha = color.a;
-
-
return material;
-
}
-
-
`;
-
}
-
}
-
对于调用方式
```javascript
let lon = 0, lat = 0, height = 250000, width = 3;
let material = new MaterialAsphalt({
asphaltColor: new Cesium.Color(1.0, 1.0, 1.0, 0.9),
bumpSize: 0.02,
roughness: 0.2,
});let entity = viewer.entities.add({
wall: {
maximumHeights: [height, height, height],
minimumHeights: [0, 0, 0],
positions: Cesium.Cartesian3.fromDegreesArrayHeights([
lon,
lat,
height,
lon + 3,
lat,
height,
lon + 3,
lat + 10,
height,
]),
更多参考 https://xiaozhuanlan.com/topic/8764139025
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律