diff --git a/src/nodes/Nodes.js b/src/nodes/Nodes.js index 681858b1805421..106b56a61197e1 100644 --- a/src/nodes/Nodes.js +++ b/src/nodes/Nodes.js @@ -86,7 +86,7 @@ export { default as VertexColorNode, vertexColor } from './accessors/VertexColor export { default as CubeTextureNode, cubeTexture } from './accessors/CubeTextureNode.js'; export { default as InstanceNode, instance } from './accessors/InstanceNode.js'; export { default as BatchNode, batch } from './accessors/BatchNode.js'; -export { default as MaterialNode, materialAlphaTest, materialColor, materialShininess, materialEmissive, materialOpacity, materialSpecular, materialSpecularStrength, materialReflectivity, materialRoughness, materialMetalness, materialNormal, materialClearcoat, materialClearcoatRoughness, materialClearcoatNormal, materialRotation, materialSheen, materialSheenRoughness, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineWidth, materialLineDashOffset, materialPointWidth, materialAnisotropy, materialAnisotropyVector, materialDispersion, materialLightMap } from './accessors/MaterialNode.js'; +export { default as MaterialNode, materialAlphaTest, materialColor, materialShininess, materialEmissive, materialOpacity, materialSpecular, materialSpecularStrength, materialReflectivity, materialRoughness, materialMetalness, materialNormal, materialClearcoat, materialClearcoatRoughness, materialClearcoatNormal, materialRotation, materialSheen, materialSheenRoughness, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineWidth, materialLineDashOffset, materialPointWidth, materialAnisotropy, materialAnisotropyVector, materialDispersion, materialLightMap, materialAOMap } from './accessors/MaterialNode.js'; export { default as MaterialReferenceNode, materialReference } from './accessors/MaterialReferenceNode.js'; export { default as RendererReferenceNode, rendererReference } from './accessors/RendererReferenceNode.js'; export { default as MorphNode, morphReference } from './accessors/MorphNode.js'; diff --git a/src/nodes/accessors/MaterialNode.js b/src/nodes/accessors/MaterialNode.js index 36b719b624258f..92cb27bfe0701a 100644 --- a/src/nodes/accessors/MaterialNode.js +++ b/src/nodes/accessors/MaterialNode.js @@ -323,6 +323,10 @@ class MaterialNode extends Node { node = this.getTexture( scope ).rgb.mul( this.getFloat( 'lightMapIntensity' ) ); + } else if ( scope === MaterialNode.AO_MAP ) { + + node = this.getTexture( scope ).r.sub( 1.0 ).mul( this.getFloat( 'aoMapIntensity' ) ).add( 1.0 ); + } else { const outputType = this.getNodeType( builder ); @@ -373,6 +377,7 @@ MaterialNode.LINE_DASH_OFFSET = 'dashOffset'; MaterialNode.POINT_WIDTH = 'pointWidth'; MaterialNode.DISPERSION = 'dispersion'; MaterialNode.LIGHT_MAP = 'light'; +MaterialNode.AO_MAP = 'ao'; export default MaterialNode; @@ -414,6 +419,7 @@ export const materialLineDashOffset = nodeImmutable( MaterialNode, MaterialNode. export const materialPointWidth = nodeImmutable( MaterialNode, MaterialNode.POINT_WIDTH ); export const materialDispersion = nodeImmutable( MaterialNode, MaterialNode.DISPERSION ); export const materialLightMap = nodeImmutable( MaterialNode, MaterialNode.LIGHT_MAP ); +export const materialAOMap = nodeImmutable( MaterialNode, MaterialNode.AO_MAP ); export const materialAnisotropyVector = uniform( new Vector2() ).onReference( function ( frame ) { return frame.material; diff --git a/src/nodes/lighting/AONode.js b/src/nodes/lighting/AONode.js index 84c539ef325d8e..92030103824817 100644 --- a/src/nodes/lighting/AONode.js +++ b/src/nodes/lighting/AONode.js @@ -13,10 +13,7 @@ class AONode extends LightingNode { setup( builder ) { - const aoIntensity = 1; - const aoNode = this.aoNode.x.sub( 1.0 ).mul( aoIntensity ).add( 1.0 ); - - builder.context.ambientOcclusion.mulAssign( aoNode ); + builder.context.ambientOcclusion.mulAssign( this.aoNode ); } diff --git a/src/nodes/materials/NodeMaterial.js b/src/nodes/materials/NodeMaterial.js index f9c8d3e38e34fc..26c256c43d8fea 100644 --- a/src/nodes/materials/NodeMaterial.js +++ b/src/nodes/materials/NodeMaterial.js @@ -4,7 +4,7 @@ import { NormalBlending } from '../../constants.js'; import { getNodeChildren, getCacheKey } from '../core/NodeUtils.js'; import { attribute } from '../core/AttributeNode.js'; import { output, diffuseColor, varyingProperty } from '../core/PropertyNode.js'; -import { materialAlphaTest, materialColor, materialOpacity, materialEmissive, materialNormal, materialLightMap } from '../accessors/MaterialNode.js'; +import { materialAlphaTest, materialColor, materialOpacity, materialEmissive, materialNormal, materialLightMap, materialAOMap } from '../accessors/MaterialNode.js'; import { modelViewProjection } from '../accessors/ModelViewProjectionNode.js'; import { transformedNormalView, normalLocal } from '../accessors/NormalNode.js'; import { instance } from '../accessors/InstanceNode.js'; @@ -373,7 +373,7 @@ class NodeMaterial extends Material { if ( this.aoNode !== null || builder.material.aoMap ) { - const aoNode = this.aoNode !== null ? this.aoNode : texture( builder.material.aoMap ); + const aoNode = this.aoNode !== null ? this.aoNode : materialAOMap; materialLightsNode.push( new AONode( aoNode ) );