@openhps/core
Version:
Open Hybrid Positioning System - Core component
457 lines (415 loc) • 17.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _PropertyNode = require("../../nodes/core/PropertyNode.js");
var _MaterialNode = require("../../nodes/accessors/MaterialNode.js");
var _TSLBase = require("../../nodes/tsl/TSLBase.js");
var _getRoughness = _interopRequireDefault(require("../../nodes/functions/material/getRoughness.js"));
var _AccessorsUtils = require("../../nodes/accessors/AccessorsUtils.js");
var _PhysicalLightingModel = _interopRequireDefault(require("../../nodes/functions/PhysicalLightingModel.js"));
var _MeshStandardNodeMaterial = _interopRequireDefault(require("./MeshStandardNodeMaterial.js"));
var _MathNode = require("../../nodes/math/MathNode.js");
var _MeshPhysicalMaterial = require("../MeshPhysicalMaterial.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const _defaultValues = /*@__PURE__*/new _MeshPhysicalMaterial.MeshPhysicalMaterial();
/**
* Node material version of {@link MeshPhysicalMaterial}.
*
* @augments MeshStandardNodeMaterial
*/
class MeshPhysicalNodeMaterial extends _MeshStandardNodeMaterial.default {
static get type() {
return 'MeshPhysicalNodeMaterial';
}
/**
* Constructs a new mesh physical node material.
*
* @param {Object} [parameters] - The configuration parameter.
*/
constructor(parameters) {
super();
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isMeshPhysicalNodeMaterial = true;
/**
* The clearcoat of physical materials is by default inferred from the `clearcoat`
* and `clearcoatMap` properties. This node property allows to overwrite the default
* and define the clearcoat with a node instead.
*
* If you don't want to overwrite the clearcoat but modify the existing
* value instead, use {@link materialClearcoat}.
*
* @type {?Node<float>}
* @default null
*/
this.clearcoatNode = null;
/**
* The clearcoat roughness of physical materials is by default inferred from the `clearcoatRoughness`
* and `clearcoatRoughnessMap` properties. This node property allows to overwrite the default
* and define the clearcoat roughness with a node instead.
*
* If you don't want to overwrite the clearcoat roughness but modify the existing
* value instead, use {@link materialClearcoatRoughness}.
*
* @type {?Node<float>}
* @default null
*/
this.clearcoatRoughnessNode = null;
/**
* The clearcoat normal of physical materials is by default inferred from the `clearcoatNormalMap`
* property. This node property allows to overwrite the default
* and define the clearcoat normal with a node instead.
*
* If you don't want to overwrite the clearcoat normal but modify the existing
* value instead, use {@link materialClearcoatNormal}.
*
* @type {?Node<vec3>}
* @default null
*/
this.clearcoatNormalNode = null;
/**
* The sheen of physical materials is by default inferred from the `sheen`, `sheenColor`
* and `sheenColorMap` properties. This node property allows to overwrite the default
* and define the sheen with a node instead.
*
* If you don't want to overwrite the sheen but modify the existing
* value instead, use {@link materialSheen}.
*
* @type {?Node<vec3>}
* @default null
*/
this.sheenNode = null;
/**
* The sheen roughness of physical materials is by default inferred from the `sheenRoughness` and
* `sheenRoughnessMap` properties. This node property allows to overwrite the default
* and define the sheen roughness with a node instead.
*
* If you don't want to overwrite the sheen roughness but modify the existing
* value instead, use {@link materialSheenRoughness}.
*
* @type {?Node<float>}
* @default null
*/
this.sheenRoughnessNode = null;
/**
* The iridescence of physical materials is by default inferred from the `iridescence`
* property. This node property allows to overwrite the default
* and define the iridescence with a node instead.
*
* If you don't want to overwrite the iridescence but modify the existing
* value instead, use {@link materialIridescence}.
*
* @type {?Node<float>}
* @default null
*/
this.iridescenceNode = null;
/**
* The iridescence IOR of physical materials is by default inferred from the `iridescenceIOR`
* property. This node property allows to overwrite the default
* and define the iridescence IOR with a node instead.
*
* If you don't want to overwrite the iridescence IOR but modify the existing
* value instead, use {@link materialIridescenceIOR}.
*
* @type {?Node<float>}
* @default null
*/
this.iridescenceIORNode = null;
/**
* The iridescence thickness of physical materials is by default inferred from the `iridescenceThicknessRange`
* and `iridescenceThicknessMap` properties. This node property allows to overwrite the default
* and define the iridescence thickness with a node instead.
*
* If you don't want to overwrite the iridescence thickness but modify the existing
* value instead, use {@link materialIridescenceThickness}.
*
* @type {?Node<float>}
* @default null
*/
this.iridescenceThicknessNode = null;
/**
* The specular intensity of physical materials is by default inferred from the `specularIntensity`
* and `specularIntensityMap` properties. This node property allows to overwrite the default
* and define the specular intensity with a node instead.
*
* If you don't want to overwrite the specular intensity but modify the existing
* value instead, use {@link materialSpecularIntensity}.
*
* @type {?Node<float>}
* @default null
*/
this.specularIntensityNode = null;
/**
* The specular color of physical materials is by default inferred from the `specularColor`
* and `specularColorMap` properties. This node property allows to overwrite the default
* and define the specular color with a node instead.
*
* If you don't want to overwrite the specular color but modify the existing
* value instead, use {@link materialSpecularColor}.
*
* @type {?Node<vec3>}
* @default null
*/
this.specularColorNode = null;
/**
* The ior of physical materials is by default inferred from the `ior`
* property. This node property allows to overwrite the default
* and define the ior with a node instead.
*
* If you don't want to overwrite the ior but modify the existing
* value instead, use {@link materialIOR}.
*
* @type {?Node<float>}
* @default null
*/
this.iorNode = null;
/**
* The transmission of physical materials is by default inferred from the `transmission` and
* `transmissionMap` properties. This node property allows to overwrite the default
* and define the transmission with a node instead.
*
* If you don't want to overwrite the transmission but modify the existing
* value instead, use {@link materialTransmission}.
*
* @type {?Node<float>}
* @default null
*/
this.transmissionNode = null;
/**
* The thickness of physical materials is by default inferred from the `thickness` and
* `thicknessMap` properties. This node property allows to overwrite the default
* and define the thickness with a node instead.
*
* If you don't want to overwrite the thickness but modify the existing
* value instead, use {@link materialThickness}.
*
* @type {?Node<float>}
* @default null
*/
this.thicknessNode = null;
/**
* The attenuation distance of physical materials is by default inferred from the
* `attenuationDistance` property. This node property allows to overwrite the default
* and define the attenuation distance with a node instead.
*
* If you don't want to overwrite the attenuation distance but modify the existing
* value instead, use {@link materialAttenuationDistance}.
*
* @type {?Node<float>}
* @default null
*/
this.attenuationDistanceNode = null;
/**
* The attenuation color of physical materials is by default inferred from the
* `attenuationColor` property. This node property allows to overwrite the default
* and define the attenuation color with a node instead.
*
* If you don't want to overwrite the attenuation color but modify the existing
* value instead, use {@link materialAttenuationColor}.
*
* @type {?Node<vec3>}
* @default null
*/
this.attenuationColorNode = null;
/**
* The dispersion of physical materials is by default inferred from the
* `dispersion` property. This node property allows to overwrite the default
* and define the dispersion with a node instead.
*
* If you don't want to overwrite the dispersion but modify the existing
* value instead, use {@link materialDispersion}.
*
* @type {?Node<float>}
* @default null
*/
this.dispersionNode = null;
/**
* The anisotropy of physical materials is by default inferred from the
* `anisotropy` property. This node property allows to overwrite the default
* and define the anisotropy with a node instead.
*
* If you don't want to overwrite the anisotropy but modify the existing
* value instead, use {@link materialAnisotropy}.
*
* @type {?Node<float>}
* @default null
*/
this.anisotropyNode = null;
this.setDefaultValues(_defaultValues);
this.setValues(parameters);
}
/**
* Whether the lighting model should use clearcoat or not.
*
* @type {boolean}
* @default true
*/
get useClearcoat() {
return this.clearcoat > 0 || this.clearcoatNode !== null;
}
/**
* Whether the lighting model should use iridescence or not.
*
* @type {boolean}
* @default true
*/
get useIridescence() {
return this.iridescence > 0 || this.iridescenceNode !== null;
}
/**
* Whether the lighting model should use sheen or not.
*
* @type {boolean}
* @default true
*/
get useSheen() {
return this.sheen > 0 || this.sheenNode !== null;
}
/**
* Whether the lighting model should use anisotropy or not.
*
* @type {boolean}
* @default true
*/
get useAnisotropy() {
return this.anisotropy > 0 || this.anisotropyNode !== null;
}
/**
* Whether the lighting model should use transmission or not.
*
* @type {boolean}
* @default true
*/
get useTransmission() {
return this.transmission > 0 || this.transmissionNode !== null;
}
/**
* Whether the lighting model should use dispersion or not.
*
* @type {boolean}
* @default true
*/
get useDispersion() {
return this.dispersion > 0 || this.dispersionNode !== null;
}
/**
* Setups the specular related node variables.
*/
setupSpecular() {
const iorNode = this.iorNode ? (0, _TSLBase.float)(this.iorNode) : _MaterialNode.materialIOR;
_PropertyNode.ior.assign(iorNode);
_PropertyNode.specularColor.assign((0, _MathNode.mix)((0, _MathNode.min)((0, _MathNode.pow2)(_PropertyNode.ior.sub(1.0).div(_PropertyNode.ior.add(1.0))).mul(_MaterialNode.materialSpecularColor), (0, _TSLBase.vec3)(1.0)).mul(_MaterialNode.materialSpecularIntensity), _PropertyNode.diffuseColor.rgb, _PropertyNode.metalness));
_PropertyNode.specularF90.assign((0, _MathNode.mix)(_MaterialNode.materialSpecularIntensity, 1.0, _PropertyNode.metalness));
}
/**
* Setups the lighting model.
*
* @return {PhysicalLightingModel} The lighting model.
*/
setupLightingModel( /*builder*/
) {
return new _PhysicalLightingModel.default(this.useClearcoat, this.useSheen, this.useIridescence, this.useAnisotropy, this.useTransmission, this.useDispersion);
}
/**
* Setups the physical specific node variables.
*
* @param {NodeBuilder} builder - The current node builder.
*/
setupVariants(builder) {
super.setupVariants(builder);
// CLEARCOAT
if (this.useClearcoat) {
const clearcoatNode = this.clearcoatNode ? (0, _TSLBase.float)(this.clearcoatNode) : _MaterialNode.materialClearcoat;
const clearcoatRoughnessNode = this.clearcoatRoughnessNode ? (0, _TSLBase.float)(this.clearcoatRoughnessNode) : _MaterialNode.materialClearcoatRoughness;
_PropertyNode.clearcoat.assign(clearcoatNode);
_PropertyNode.clearcoatRoughness.assign((0, _getRoughness.default)({
roughness: clearcoatRoughnessNode
}));
}
// SHEEN
if (this.useSheen) {
const sheenNode = this.sheenNode ? (0, _TSLBase.vec3)(this.sheenNode) : _MaterialNode.materialSheen;
const sheenRoughnessNode = this.sheenRoughnessNode ? (0, _TSLBase.float)(this.sheenRoughnessNode) : _MaterialNode.materialSheenRoughness;
_PropertyNode.sheen.assign(sheenNode);
_PropertyNode.sheenRoughness.assign(sheenRoughnessNode);
}
// IRIDESCENCE
if (this.useIridescence) {
const iridescenceNode = this.iridescenceNode ? (0, _TSLBase.float)(this.iridescenceNode) : _MaterialNode.materialIridescence;
const iridescenceIORNode = this.iridescenceIORNode ? (0, _TSLBase.float)(this.iridescenceIORNode) : _MaterialNode.materialIridescenceIOR;
const iridescenceThicknessNode = this.iridescenceThicknessNode ? (0, _TSLBase.float)(this.iridescenceThicknessNode) : _MaterialNode.materialIridescenceThickness;
_PropertyNode.iridescence.assign(iridescenceNode);
_PropertyNode.iridescenceIOR.assign(iridescenceIORNode);
_PropertyNode.iridescenceThickness.assign(iridescenceThicknessNode);
}
// ANISOTROPY
if (this.useAnisotropy) {
const anisotropyV = (this.anisotropyNode ? (0, _TSLBase.vec2)(this.anisotropyNode) : _MaterialNode.materialAnisotropy).toVar();
_PropertyNode.anisotropy.assign(anisotropyV.length());
(0, _TSLBase.If)(_PropertyNode.anisotropy.equal(0.0), () => {
anisotropyV.assign((0, _TSLBase.vec2)(1.0, 0.0));
}).Else(() => {
anisotropyV.divAssign((0, _TSLBase.vec2)(_PropertyNode.anisotropy));
_PropertyNode.anisotropy.assign(_PropertyNode.anisotropy.saturate());
});
// Roughness along the anisotropy bitangent is the material roughness, while the tangent roughness increases with anisotropy.
_PropertyNode.alphaT.assign(_PropertyNode.anisotropy.pow2().mix(_PropertyNode.roughness.pow2(), 1.0));
_PropertyNode.anisotropyT.assign(_AccessorsUtils.TBNViewMatrix[0].mul(anisotropyV.x).add(_AccessorsUtils.TBNViewMatrix[1].mul(anisotropyV.y)));
_PropertyNode.anisotropyB.assign(_AccessorsUtils.TBNViewMatrix[1].mul(anisotropyV.x).sub(_AccessorsUtils.TBNViewMatrix[0].mul(anisotropyV.y)));
}
// TRANSMISSION
if (this.useTransmission) {
const transmissionNode = this.transmissionNode ? (0, _TSLBase.float)(this.transmissionNode) : _MaterialNode.materialTransmission;
const thicknessNode = this.thicknessNode ? (0, _TSLBase.float)(this.thicknessNode) : _MaterialNode.materialThickness;
const attenuationDistanceNode = this.attenuationDistanceNode ? (0, _TSLBase.float)(this.attenuationDistanceNode) : _MaterialNode.materialAttenuationDistance;
const attenuationColorNode = this.attenuationColorNode ? (0, _TSLBase.vec3)(this.attenuationColorNode) : _MaterialNode.materialAttenuationColor;
_PropertyNode.transmission.assign(transmissionNode);
_PropertyNode.thickness.assign(thicknessNode);
_PropertyNode.attenuationDistance.assign(attenuationDistanceNode);
_PropertyNode.attenuationColor.assign(attenuationColorNode);
if (this.useDispersion) {
const dispersionNode = this.dispersionNode ? (0, _TSLBase.float)(this.dispersionNode) : _MaterialNode.materialDispersion;
_PropertyNode.dispersion.assign(dispersionNode);
}
}
}
/**
* Setups the clearcoat normal node.
*
* @return {Node<vec3>} The clearcoat normal.
*/
setupClearcoatNormal() {
return this.clearcoatNormalNode ? (0, _TSLBase.vec3)(this.clearcoatNormalNode) : _MaterialNode.materialClearcoatNormal;
}
setup(builder) {
builder.context.setupClearcoatNormal = () => this.setupClearcoatNormal(builder);
super.setup(builder);
}
copy(source) {
this.clearcoatNode = source.clearcoatNode;
this.clearcoatRoughnessNode = source.clearcoatRoughnessNode;
this.clearcoatNormalNode = source.clearcoatNormalNode;
this.sheenNode = source.sheenNode;
this.sheenRoughnessNode = source.sheenRoughnessNode;
this.iridescenceNode = source.iridescenceNode;
this.iridescenceIORNode = source.iridescenceIORNode;
this.iridescenceThicknessNode = source.iridescenceThicknessNode;
this.specularIntensityNode = source.specularIntensityNode;
this.specularColorNode = source.specularColorNode;
this.transmissionNode = source.transmissionNode;
this.thicknessNode = source.thicknessNode;
this.attenuationDistanceNode = source.attenuationDistanceNode;
this.attenuationColorNode = source.attenuationColorNode;
this.dispersionNode = source.dispersionNode;
this.anisotropyNode = source.anisotropyNode;
return super.copy(source);
}
}
var _default = exports.default = MeshPhysicalNodeMaterial;