Cesium 自定义Material 系列 (十七)

  • 对于木制墙纹理效果 我们先定义一下他的interface, 方便使用的人知道他的调用参数
  • export interface PMaterialBrick{
  • color?: any,
  • speed?: number,
  • brickColor?: any,
  • mortarColor?:any,
  • brickSize?: any,
  • brickPct?: any,
  • brickRoughness?: number,
  • mortarRoughness?: number
  • }
  • 对于木制墙纹理我们叫 MaterialTWood

``javascript import { MaterialProperty } from "./MaterialProperty"; const defaultOption: PMaterialTWood = { lightWoodColor: new Cesium.Color(0.6, 0.3, 0.1, 1.0), darkWoodColor: new Cesium.Color(0.4, 0.2, 0.07, 1.0), ringFrequency: 3.0, noiseScale: new Cesium.Cartesian2(0.7, 0.5), grainFrequency: 27.0 } //木质效果 export class MaterialTWood extends MaterialProperty { protected _getType(option: any): string { return "MaterialTWood" } constructor(option = defaultOption) { super(MaterialTWood.prototype, defaultOption, option); } protected _getTranslucent(material: any) { var uniforms = material.uniforms return uniforms.lightWoodColor.alpha < 1.0 || uniforms.darkWoodColor.alpha < 1.0; } protected getSource(option: any): string { return
uniform vec4 lightWoodColor;
uniform vec4 darkWoodColor;
uniform float ringFrequency;
uniform vec2 noiseScale;
uniform float grainFrequency;

  • czm_material czm_getMaterial(czm_materialInput materialInput){
  • czm_material material = czm_getDefaultMaterial(materialInput);
  •  
  • //Based on wood shader from OpenGL Shading Language (3rd edition) pg. 455
  • vec2 st = materialInput.st;
  •  
  • vec2 noisevec;
  • noisevec.x = czm_snoise(st * noiseScale.x);
  • noisevec.y = czm_snoise(st * noiseScale.y);
  •  
  • vec2 location = st + noisevec;
  • float dist = sqrt(location.x * location.x + location.y * location.y);
posted @ 2022-01-20 17:12  haibalai  阅读(65)  评论(0编辑  收藏  举报