|
@@ -1,6 +1,7 @@
|
|
|
import Node, { addNodeClass } from '../core/Node.js';
|
|
|
import { reference } from './ReferenceNode.js';
|
|
|
import { materialReference } from './MaterialReferenceNode.js';
|
|
|
+import { normalView } from './NormalNode.js';
|
|
|
import { nodeImmutable, float } from '../shadernode/ShaderNode.js';
|
|
|
|
|
|
const _propertyCache = new Map();
|
|
@@ -45,7 +46,7 @@ class MaterialNode extends Node {
|
|
|
|
|
|
getTexture( property ) {
|
|
|
|
|
|
- return this.getCache( property, 'texture' );
|
|
|
+ return this.getCache( property === 'map' ? 'map' : property + 'Map', 'texture' );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -56,17 +57,9 @@ class MaterialNode extends Node {
|
|
|
|
|
|
let node = null;
|
|
|
|
|
|
- if ( scope === MaterialNode.ALPHA_TEST || scope === MaterialNode.SHININESS || scope === MaterialNode.REFLECTIVITY || scope === MaterialNode.ROTATION || scope === MaterialNode.IRIDESCENCE || scope === MaterialNode.IRIDESCENCE_IOR ) {
|
|
|
+ if ( scope === MaterialNode.COLOR ) {
|
|
|
|
|
|
- node = this.getFloat( scope );
|
|
|
-
|
|
|
- } else if ( scope === MaterialNode.SPECULAR_COLOR ) {
|
|
|
-
|
|
|
- node = this.getColor( 'specular' );
|
|
|
-
|
|
|
- } else if ( scope === MaterialNode.COLOR ) {
|
|
|
-
|
|
|
- const colorNode = this.getColor( 'color' );
|
|
|
+ const colorNode = this.getColor( scope );
|
|
|
|
|
|
if ( material.map && material.map.isTexture === true ) {
|
|
|
|
|
@@ -80,11 +73,11 @@ class MaterialNode extends Node {
|
|
|
|
|
|
} else if ( scope === MaterialNode.OPACITY ) {
|
|
|
|
|
|
- const opacityNode = this.getFloat( 'opacity' );
|
|
|
+ const opacityNode = this.getFloat( scope );
|
|
|
|
|
|
if ( material.alphaMap && material.alphaMap.isTexture === true ) {
|
|
|
|
|
|
- node = opacityNode.mul( this.getTexture( 'alphaMap' ) );
|
|
|
+ node = opacityNode.mul( this.getTexture( 'alpha' ) );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -96,7 +89,7 @@ class MaterialNode extends Node {
|
|
|
|
|
|
if ( material.specularMap && material.specularMap.isTexture === true ) {
|
|
|
|
|
|
- node = this.getTexture( 'specularMap' ).r;
|
|
|
+ node = this.getTexture( scope ).r;
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -104,13 +97,13 @@ class MaterialNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
- } else if ( scope === MaterialNode.ROUGHNESS ) {
|
|
|
+ } else if ( scope === MaterialNode.ROUGHNESS ) { // TODO: cleanup similar branches
|
|
|
|
|
|
- const roughnessNode = this.getFloat( 'roughness' );
|
|
|
+ const roughnessNode = this.getFloat( scope );
|
|
|
|
|
|
if ( material.roughnessMap && material.roughnessMap.isTexture === true ) {
|
|
|
|
|
|
- node = roughnessNode.mul( this.getTexture( 'roughnessMap' ).g );
|
|
|
+ node = roughnessNode.mul( this.getTexture( scope ).g );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -120,11 +113,11 @@ class MaterialNode extends Node {
|
|
|
|
|
|
} else if ( scope === MaterialNode.METALNESS ) {
|
|
|
|
|
|
- const metalnessNode = this.getFloat( 'metalness' );
|
|
|
+ const metalnessNode = this.getFloat( scope );
|
|
|
|
|
|
if ( material.metalnessMap && material.metalnessMap.isTexture === true ) {
|
|
|
|
|
|
- node = metalnessNode.mul( this.getTexture( 'metalnessMap' ).b );
|
|
|
+ node = metalnessNode.mul( this.getTexture( scope ).b );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -134,11 +127,11 @@ class MaterialNode extends Node {
|
|
|
|
|
|
} else if ( scope === MaterialNode.EMISSIVE ) {
|
|
|
|
|
|
- const emissiveNode = this.getColor( 'emissive' );
|
|
|
+ const emissiveNode = this.getColor( scope );
|
|
|
|
|
|
if ( material.emissiveMap && material.emissiveMap.isTexture === true ) {
|
|
|
|
|
|
- node = emissiveNode.mul( this.getTexture( 'emissiveMap' ) );
|
|
|
+ node = emissiveNode.mul( this.getTexture( scope ) );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -146,13 +139,29 @@ class MaterialNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ } else if ( scope === MaterialNode.NORMAL ) {
|
|
|
+
|
|
|
+ if ( material.normalMap ) {
|
|
|
+
|
|
|
+ node = this.getTexture( 'normal' ).normalMap( this.getCache( 'normalScale', 'vec2' ) );
|
|
|
+
|
|
|
+ } else if ( material.bumpMap ) {
|
|
|
+
|
|
|
+ node = this.getTexture( 'bump' ).r.bumpMap( this.getFloat( 'bumpScale' ) );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ node = normalView;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
} else if ( scope === MaterialNode.CLEARCOAT ) {
|
|
|
|
|
|
- const clearcoatNode = this.getFloat( 'clearcoat' );
|
|
|
+ const clearcoatNode = this.getFloat( scope );
|
|
|
|
|
|
if ( material.clearcoatMap && material.clearcoatMap.isTexture === true ) {
|
|
|
|
|
|
- node = clearcoatNode.mul( this.getTexture( 'clearcoatMap' ).r );
|
|
|
+ node = clearcoatNode.mul( this.getTexture( scope ).r );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -162,11 +171,11 @@ class MaterialNode extends Node {
|
|
|
|
|
|
} else if ( scope === MaterialNode.CLEARCOAT_ROUGHNESS ) {
|
|
|
|
|
|
- const clearcoatRoughnessNode = this.getFloat( 'clearcoatRoughness' );
|
|
|
+ const clearcoatRoughnessNode = this.getFloat( scope );
|
|
|
|
|
|
if ( material.clearcoatRoughnessMap && material.clearcoatRoughnessMap.isTexture === true ) {
|
|
|
|
|
|
- node = clearcoatRoughnessNode.mul( this.getTexture( 'clearcoatRoughnessMap' ).r );
|
|
|
+ node = clearcoatRoughnessNode.mul( this.getTexture( scope ).r );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -174,13 +183,25 @@ class MaterialNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ } else if ( scope === MaterialNode.CLEARCOAT_NORMAL ) {
|
|
|
+
|
|
|
+ if ( material.clearcoatNormalMap ) {
|
|
|
+
|
|
|
+ node = this.getTexture( scope ).normalMap( this.getCache( scope + 'Scale', 'vec2' ) );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ node = normalView;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
} else if ( scope === MaterialNode.SHEEN ) {
|
|
|
|
|
|
const sheenNode = this.getColor( 'sheenColor' ).mul( this.getFloat( 'sheen' ) ); // Move this mul() to CPU
|
|
|
|
|
|
if ( material.sheenColorMap && material.sheenColorMap.isTexture === true ) {
|
|
|
|
|
|
- node = sheenNode.mul( this.getTexture( 'sheenColorMap' ).rgb );
|
|
|
+ node = sheenNode.mul( this.getTexture( 'sheenColor' ).rgb );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -190,11 +211,11 @@ class MaterialNode extends Node {
|
|
|
|
|
|
} else if ( scope === MaterialNode.SHEEN_ROUGHNESS ) {
|
|
|
|
|
|
- const sheenRoughnessNode = this.getFloat( 'sheenRoughness' );
|
|
|
+ const sheenRoughnessNode = this.getFloat( scope );
|
|
|
|
|
|
if ( material.sheenRoughnessMap && material.sheenRoughnessMap.isTexture === true ) {
|
|
|
|
|
|
- node = sheenRoughnessNode.mul( this.getTexture( 'sheenRoughnessMap' ).a );
|
|
|
+ node = sheenRoughnessNode.mul( this.getTexture( scope ).a );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -212,7 +233,7 @@ class MaterialNode extends Node {
|
|
|
|
|
|
const iridescenceThicknessMinimum = reference( 0, 'float', material.iridescenceThicknessRange );
|
|
|
|
|
|
- node = iridescenceThicknessMaximum.sub( iridescenceThicknessMinimum ).mul( this.getTexture( 'iridescenceThicknessMap' ).g ).add( iridescenceThicknessMinimum );
|
|
|
+ node = iridescenceThicknessMaximum.sub( iridescenceThicknessMinimum ).mul( this.getTexture( scope ).g ).add( iridescenceThicknessMinimum );
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -224,7 +245,7 @@ class MaterialNode extends Node {
|
|
|
|
|
|
const outputType = this.getNodeType( builder );
|
|
|
|
|
|
- node = materialReference( scope, outputType );
|
|
|
+ node = this.getCache( scope, outputType );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -238,13 +259,15 @@ MaterialNode.ALPHA_TEST = 'alphaTest';
|
|
|
MaterialNode.COLOR = 'color';
|
|
|
MaterialNode.OPACITY = 'opacity';
|
|
|
MaterialNode.SHININESS = 'shininess';
|
|
|
-MaterialNode.SPECULAR = 'specular';
|
|
|
+MaterialNode.SPECULAR_COLOR = 'specular';
|
|
|
MaterialNode.SPECULAR_STRENGTH = 'specularStrength';
|
|
|
MaterialNode.REFLECTIVITY = 'reflectivity';
|
|
|
MaterialNode.ROUGHNESS = 'roughness';
|
|
|
MaterialNode.METALNESS = 'metalness';
|
|
|
+MaterialNode.NORMAL = 'normal';
|
|
|
MaterialNode.CLEARCOAT = 'clearcoat';
|
|
|
MaterialNode.CLEARCOAT_ROUGHNESS = 'clearcoatRoughness';
|
|
|
+MaterialNode.CLEARCOAT_NORMAL = 'clearcoatNormal';
|
|
|
MaterialNode.EMISSIVE = 'emissive';
|
|
|
MaterialNode.ROTATION = 'rotation';
|
|
|
MaterialNode.SHEEN = 'sheen';
|
|
@@ -252,6 +275,12 @@ MaterialNode.SHEEN_ROUGHNESS = 'sheenRoughness';
|
|
|
MaterialNode.IRIDESCENCE = 'iridescence';
|
|
|
MaterialNode.IRIDESCENCE_IOR = 'iridescenceIOR';
|
|
|
MaterialNode.IRIDESCENCE_THICKNESS = 'iridescenceThickness';
|
|
|
+MaterialNode.LINE_SCALE = 'scale';
|
|
|
+MaterialNode.LINE_DASH_SIZE = 'dashSize';
|
|
|
+MaterialNode.LINE_GAP_SIZE = 'gapSize';
|
|
|
+MaterialNode.LINE_WIDTH = 'linewidth';
|
|
|
+MaterialNode.LINE_DASH_OFFSET = 'dashOffset';
|
|
|
+MaterialNode.POINT_WIDTH = 'pointWidth';
|
|
|
|
|
|
export default MaterialNode;
|
|
|
|
|
@@ -265,13 +294,21 @@ export const materialSpecularStrength = nodeImmutable( MaterialNode, MaterialNod
|
|
|
export const materialReflectivity = nodeImmutable( MaterialNode, MaterialNode.REFLECTIVITY );
|
|
|
export const materialRoughness = nodeImmutable( MaterialNode, MaterialNode.ROUGHNESS );
|
|
|
export const materialMetalness = nodeImmutable( MaterialNode, MaterialNode.METALNESS );
|
|
|
+export const materialNormal = nodeImmutable( MaterialNode, MaterialNode.NORMAL );
|
|
|
export const materialClearcoat = nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT );
|
|
|
export const materialClearcoatRoughness = nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_ROUGHNESS );
|
|
|
+export const materialClearcoatNormal = nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_NORMAL );
|
|
|
export const materialRotation = nodeImmutable( MaterialNode, MaterialNode.ROTATION );
|
|
|
export const materialSheen = nodeImmutable( MaterialNode, MaterialNode.SHEEN );
|
|
|
export const materialSheenRoughness = nodeImmutable( MaterialNode, MaterialNode.SHEEN_ROUGHNESS );
|
|
|
export const materialIridescence = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE );
|
|
|
export const materialIridescenceIOR = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_IOR );
|
|
|
export const materialIridescenceThickness = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_THICKNESS );
|
|
|
+export const materialLineScale = nodeImmutable( MaterialNode, MaterialNode.LINE_SCALE );
|
|
|
+export const materialLineDashSize = nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_SIZE );
|
|
|
+export const materialLineGapSize = nodeImmutable( MaterialNode, MaterialNode.LINE_GAP_SIZE );
|
|
|
+export const materialLineWidth = nodeImmutable( MaterialNode, MaterialNode.LINE_WIDTH );
|
|
|
+export const materialLineDashOffset = nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_OFFSET );
|
|
|
+export const materialPointWidth = nodeImmutable( MaterialNode, MaterialNode.POINT_WIDTH );
|
|
|
|
|
|
addNodeClass( 'MaterialNode', MaterialNode );
|