Cesium 自定义Material 系列 (十二)
- 对于墙纹理效果 我们先定义一下他的interface, 方便使用的人知道他的调用参数
-
export interface PMaterialBrick{
-
color?: any,
-
speed?: number,
-
brickColor?: any,
-
mortarColor?:any,
-
brickSize?: any,
-
brickPct?: any,
-
brickRoughness?: number,
-
mortarRoughness?: number
-
}
- 对于墙纹理我们叫 MaterialBrick
```javascript
import {MaterialProperty} from "./MaterialProperty";
const defaultOption: PMaterialBrick = {
brickColor: new Cesium.Color(0.6, 0.3, 0.1, 1.0),
mortarColor: new Cesium.Color(0.8, 0.8, 0.7, 1.0),
brickSize: new Cesium.Cartesian2(0.3, 0.15),
brickPct: new Cesium.Cartesian2(0.9, 0.85),
brickRoughness: 0.2,
mortarRoughness: 0.1
}
//墙效果
export class MaterialBrick extends MaterialProperty{
protected _getType(option: any): string {
return "MaterialBrick"
}
constructor(option=defaultOption) {
super(MaterialBrick.prototype, defaultOption, option);
}
-
protected _getTranslucent(material: any){
-
var uniforms = material.uniforms
-
return uniforms.brickColor.alpha < 1.0 || uniforms.mortarColor.alpha < 1.0
-
}
-
protected getSource(option: any): string {
-
return `
-
uniform vec4 brickColor;
-
uniform vec4 mortarColor;
-
uniform vec2 brickSize;
-
uniform vec2 brickPct;
-
uniform float brickRoughness;
-
uniform float mortarRoughness;
-
-
-
-
czm_material czm_getMaterial(czm_materialInput materialInput){
-
czm_material material = czm_getDefaultMaterial(materialInput);
-
-
// From OpenGL Shading Language (3rd edition) pg. 194, 501
-
vec2 st = materialInput.st;
-
vec2 position = st / brickSize;
-
if(fract(position.y * 0.5) > 0.5) {
-
position.x += 0.5;
-
}
更多参考 https://xiaozhuanlan.com/topic/8970156234
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律