-
-
Save ShopifyEng/5e8bfa0de5630779ad7350c7a73cb650 to your computer and use it in GitHub Desktop.
A World Rendered Beautifully: The Making of the BFCM 3D Data Visualization - ShieldMaterial.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {MeshStandardMaterialParameters, IUniform} from 'three'; | |
import {CustomMeshStandardMaterial} from '../CustomMeshStandardMaterial'; | |
import fragmentShader from './shield.frag'; | |
interface OptionalShieldMaterialParams { | |
maxOpacity?: number; | |
} | |
interface CustomUniforms { | |
maxOpacity: IUniform; | |
} | |
interface ShieldMaterialParams | |
extends MeshStandardMaterialParameters, | |
OptionalShieldMaterialParams {} | |
const DEFAULT_PARAMS: ShieldMaterialParams = { | |
maxOpacity: 0.9, | |
}; | |
const DEFAULT_UNIFORMS: CustomUniforms = { | |
maxOpacity: {value: 0.9}, | |
}; | |
class ShieldMaterial extends CustomMeshStandardMaterial { | |
get maxOpacity(): number { | |
return this.getCustomUniform('maxOpacity'); | |
} | |
set maxOpacity(value: number) { | |
this.setCustomUniform('maxOpacity', value); | |
} | |
constructor(params: ShieldMaterialParams) { | |
super(params, { | |
fragmentShader, | |
uniforms: { | |
maxOpacity: {value: params.maxOpacity || 0}, | |
}, | |
}); | |
} | |
} | |
export {ShieldMaterial}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment