|
|
@@ -6,11 +6,20 @@ import { nodeImmutable, float, vec2, vec3, mat2 } from '../tsl/TSLBase.js';
|
|
|
import { uniform } from '../core/UniformNode.js';
|
|
|
import { normalMap } from '../display/NormalMapNode.js';
|
|
|
import { bumpMap } from '../display/BumpMapNode.js';
|
|
|
-
|
|
|
import { Vector2 } from '../../math/Vector2.js';
|
|
|
|
|
|
+/** @module MaterialNode **/
|
|
|
+
|
|
|
const _propertyCache = new Map();
|
|
|
|
|
|
+/**
|
|
|
+ * This class should simplify the node access to material properties.
|
|
|
+ * It internal uses reference nodes to make sure changes to material
|
|
|
+ * properties are automatically reflected to prefdefined TSL objects
|
|
|
+ * like e.g. `materialColor`.
|
|
|
+ *
|
|
|
+ * @augments Node
|
|
|
+ */
|
|
|
class MaterialNode extends Node {
|
|
|
|
|
|
static get type() {
|
|
|
@@ -19,14 +28,31 @@ class MaterialNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new material node.
|
|
|
+ *
|
|
|
+ * @param {String} scope - The scope defines what kind of material property is referred by the node.
|
|
|
+ */
|
|
|
constructor( scope ) {
|
|
|
|
|
|
super();
|
|
|
|
|
|
+ /**
|
|
|
+ * The scope defines what material property is referred by the node.
|
|
|
+ *
|
|
|
+ * @type {String}
|
|
|
+ */
|
|
|
this.scope = scope;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a cached reference node for the given property and type.
|
|
|
+ *
|
|
|
+ * @param {String} property - The name of the material property.
|
|
|
+ * @param {String} type - The uniform type of the property.
|
|
|
+ * @return {MaterialReferenceNode} A material reference node representing the property access.
|
|
|
+ */
|
|
|
getCache( property, type ) {
|
|
|
|
|
|
let node = _propertyCache.get( property );
|
|
|
@@ -43,24 +69,49 @@ class MaterialNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a float-typed material reference node for the given property name.
|
|
|
+ *
|
|
|
+ * @param {String} property - The name of the material property.
|
|
|
+ * @return {MaterialReferenceNode<float>} A material reference node representing the property access.
|
|
|
+ */
|
|
|
getFloat( property ) {
|
|
|
|
|
|
return this.getCache( property, 'float' );
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a color-typed material reference node for the given property name.
|
|
|
+ *
|
|
|
+ * @param {String} property - The name of the material property.
|
|
|
+ * @return {MaterialReferenceNode<color>} A material reference node representing the property access.
|
|
|
+ */
|
|
|
getColor( property ) {
|
|
|
|
|
|
return this.getCache( property, 'color' );
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a texture-typed material reference node for the given property name.
|
|
|
+ *
|
|
|
+ * @param {String} property - The name of the material property.
|
|
|
+ * @return {MaterialReferenceNode} A material reference node representing the property access.
|
|
|
+ */
|
|
|
getTexture( property ) {
|
|
|
|
|
|
return this.getCache( property === 'map' ? 'map' : property + 'Map', 'texture' );
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * The node setup is done depending on the selected scope. Multiple material properties
|
|
|
+ * might be grouped into a single node composition if they logically belong together.
|
|
|
+ *
|
|
|
+ * @param {NodeBuilder} builder - The current node builder.
|
|
|
+ * @return {Node} The node representing the selected scope.
|
|
|
+ */
|
|
|
setup( builder ) {
|
|
|
|
|
|
const material = builder.context.material;
|
|
|
@@ -391,45 +442,288 @@ MaterialNode.AO_MAP = 'ao';
|
|
|
|
|
|
export default MaterialNode;
|
|
|
|
|
|
+/**
|
|
|
+ * TSL object that represents alpha test of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialAlphaTest = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ALPHA_TEST );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the diffuse color of the current material.
|
|
|
+ * The value is composed via `color` * `map`.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialColor = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.COLOR );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the shininess of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialShininess = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SHININESS );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the emissive color of the current material.
|
|
|
+ * The value is composed via `emissive` * `emissiveIntensity` * `emissiveMap`.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialEmissive = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.EMISSIVE );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the opacity of the current material.
|
|
|
+ * The value is composed via `opacity` * `alphaMap`.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialOpacity = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.OPACITY );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the specular of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialSpecular = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR );
|
|
|
|
|
|
+/**
|
|
|
+ * TSL object that represents the specular intensity of the current material.
|
|
|
+ * The value is composed via `specularIntensity` * `specularMap.a`.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialSpecularIntensity = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR_INTENSITY );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the specular color of the current material.
|
|
|
+ * The value is composed via `specularColor` * `specularMap.rgb`.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialSpecularColor = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR_COLOR );
|
|
|
|
|
|
+/**
|
|
|
+ * TSL object that represents the specular strength of the current material.
|
|
|
+ * The value is composed via `specularMap.r`.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialSpecularStrength = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SPECULAR_STRENGTH );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the reflectivity of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialReflectivity = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.REFLECTIVITY );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the roughness of the current material.
|
|
|
+ * The value is composed via `roughness` * `roughnessMap.g`
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialRoughness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ROUGHNESS );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the metalness of the current material.
|
|
|
+ * The value is composed via `metalness` * `metalnessMap.b`
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialMetalness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.METALNESS );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the normal of the current material.
|
|
|
+ * The value will be either `normalMap`, `bumpMap` or `normalView`.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.NORMAL ).context( { getUV: null } );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the clearcoat of the current material.
|
|
|
+ * The value is composed via `clearcoat` * `clearcoat.r`
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialClearcoat = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the clearcoat roughness of the current material.
|
|
|
+ * The value is composed via `clearcoatRoughness` * `clearcoatRoughnessMap.r`
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialClearcoatRoughness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_ROUGHNESS );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the clearcoat normal of the current material.
|
|
|
+ * The value will be either `clearcoatNormalMap` or `normalView`.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialClearcoatNormal = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.CLEARCOAT_NORMAL ).context( { getUV: null } );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the rotation of the current sprite material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialRotation = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ROTATION );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the sheen color of the current material.
|
|
|
+ * The value is composed via `sheen` * `sheenColor` * `sheenColorMap`.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialSheen = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SHEEN );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the sheen roughness of the current material.
|
|
|
+ * The value is composed via `sheenRoughness` * `sheenRoughnessMap.a` .
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialSheenRoughness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.SHEEN_ROUGHNESS );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the anisotriopy of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<vec2>}
|
|
|
+ */
|
|
|
export const materialAnisotropy = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ANISOTROPY );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the iridescence of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialIridescence = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the iridescence IOR of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialIridescenceIOR = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_IOR );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the iridescence thickness of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialIridescenceThickness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_THICKNESS );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the transmission of the current material.
|
|
|
+ * The value is composed via `transmission` * `transmissionMap.r`.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialTransmission = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.TRANSMISSION );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the thickness of the current material.
|
|
|
+ * The value is composed via `thickness` * `thicknessMap.g`.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialThickness = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.THICKNESS );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the IOR of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialIOR = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.IOR );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the attenuation distance of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialAttenuationDistance = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_DISTANCE );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the attenuation color of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialAttenuationColor = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_COLOR );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the scale of the current dashed line material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialLineScale = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_SCALE );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the dash size of the current dashed line material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialLineDashSize = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_SIZE );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the gap size of the current dashed line material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialLineGapSize = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_GAP_SIZE );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the line width of the current line material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialLineWidth = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_WIDTH );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the dash offset of the current line material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialLineDashOffset = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_OFFSET );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the point width of the current points material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialPointWidth = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.POINT_WIDTH );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the dispersion of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialDispersion = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.DISPERSION );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the light map of the current material.
|
|
|
+ * The value is composed via `lightMapIntensity` * `lightMap.rgb`.
|
|
|
+ *
|
|
|
+ * @type {Node<vec3>}
|
|
|
+ */
|
|
|
export const materialLightMap = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.LIGHT_MAP );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the ambient occlusion map of the current material.
|
|
|
+ * The value is composed via `aoMap.r` - 1 * `aoMapIntensity` + 1.
|
|
|
+ *
|
|
|
+ * @type {Node<float>}
|
|
|
+ */
|
|
|
export const materialAOMap = /*@__PURE__*/ nodeImmutable( MaterialNode, MaterialNode.AO_MAP );
|
|
|
+
|
|
|
+/**
|
|
|
+ * TSL object that represents the anisotriopy vector of the current material.
|
|
|
+ *
|
|
|
+ * @type {Node<vec2>}
|
|
|
+ */
|
|
|
export const materialAnisotropyVector = /*@__PURE__*/ uniform( new Vector2() ).onReference( function ( frame ) {
|
|
|
|
|
|
return frame.material;
|