From 8f06bf8d5205ec83be4f704eb444eeb157b6e62c Mon Sep 17 00:00:00 2001 From: Michael Herzog Date: Wed, 3 Jul 2024 20:39:02 +0200 Subject: [PATCH] MeshBasicNodeMaterial: Add `envMap` support. (#28795) --- src/nodes/materials/MeshBasicNodeMaterial.js | 36 +++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/nodes/materials/MeshBasicNodeMaterial.js b/src/nodes/materials/MeshBasicNodeMaterial.js index 1c3e3aba8e5ffb..e218fcd1c5956a 100644 --- a/src/nodes/materials/MeshBasicNodeMaterial.js +++ b/src/nodes/materials/MeshBasicNodeMaterial.js @@ -1,6 +1,9 @@ import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js'; - +import { diffuseColor } from '../core/PropertyNode.js'; +import { materialSpecularStrength, materialReflectivity } from '../accessors/MaterialNode.js'; import { MeshBasicMaterial } from '../../materials/MeshBasicMaterial.js'; +import { MultiplyOperation, MixOperation, AddOperation } from '../../constants.js'; +import { mix } from '../math/MathNode.js'; const defaultValues = new MeshBasicMaterial(); @@ -21,6 +24,37 @@ class MeshBasicNodeMaterial extends NodeMaterial { } + setupVariants( builder ) { + + const envNode = this.getEnvNode( builder ); + + if ( envNode !== null ) { + + switch ( this.combine ) { + + case MultiplyOperation: + diffuseColor.assign( mix( diffuseColor.rgb, diffuseColor.rgb.mul( envNode.rgb ), materialSpecularStrength.mul( materialReflectivity ) ) ); + break; + + case MixOperation: + diffuseColor.assign( mix( diffuseColor.rgb, envNode.rgb, materialSpecularStrength.mul( materialReflectivity ) ) ); + break; + + case AddOperation: + diffuseColor.addAssign( envNode.rgb.mul( materialSpecularStrength.mul( materialReflectivity ) ) ); + break; + + default: + console.warn( 'THREE.MeshBasicNodeMaterial: Unsupported .combine value:', this.combine ); + break; + + } + + } + + + } + } export default MeshBasicNodeMaterial;