Skip to content

Instantly share code, notes, and snippets.

@ShopifyEng
Last active December 4, 2020 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShopifyEng/5e8bfa0de5630779ad7350c7a73cb650 to your computer and use it in GitHub Desktop.
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
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