UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

79 lines (76 loc) 2.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _LightingModel = _interopRequireDefault(require("../core/LightingModel.js")); var _BRDF_Lambert = _interopRequireDefault(require("./BSDF/BRDF_Lambert.js")); var _PropertyNode = require("../core/PropertyNode.js"); var _Normal = require("../accessors/Normal.js"); var _TSLBase = require("../tsl/TSLBase.js"); var _MathNode = require("../math/MathNode.js"); var _MaterialReferenceNode = require("../accessors/MaterialReferenceNode.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const getGradientIrradiance = /*@__PURE__*/(0, _TSLBase.Fn)(({ normal, lightDirection, builder }) => { // dotNL will be from -1.0 to 1.0 const dotNL = normal.dot(lightDirection); const coord = (0, _TSLBase.vec2)(dotNL.mul(0.5).add(0.5), 0.0); if (builder.material.gradientMap) { const gradientMap = (0, _MaterialReferenceNode.materialReference)('gradientMap', 'texture').context({ getUV: () => coord }); return (0, _TSLBase.vec3)(gradientMap.r); } else { const fw = coord.fwidth().mul(0.5); return (0, _MathNode.mix)((0, _TSLBase.vec3)(0.7), (0, _TSLBase.vec3)(1.0), (0, _MathNode.smoothstep)((0, _TSLBase.float)(0.7).sub(fw.x), (0, _TSLBase.float)(0.7).add(fw.x), coord.x)); } }); /** * Represents the lighting model for a toon material. Used in {@link MeshToonNodeMaterial}. * * @augments LightingModel */ class ToonLightingModel extends _LightingModel.default { /** * Implements the direct lighting. Instead of using a conventional smooth irradiance, the irradiance is * reduced to a small number of discrete shades to create a comic-like, flat look. * * @param {Object} lightData - The light data. * @param {NodeBuilder} builder - The current node builder. */ direct({ lightDirection, lightColor, reflectedLight }, builder) { const irradiance = getGradientIrradiance({ normal: _Normal.normalGeometry, lightDirection, builder }).mul(lightColor); reflectedLight.directDiffuse.addAssign(irradiance.mul((0, _BRDF_Lambert.default)({ diffuseColor: _PropertyNode.diffuseColor.rgb }))); } /** * Implements the indirect lighting. * * @param {NodeBuilder} builder - The current node builder. */ indirect(builder) { const { ambientOcclusion, irradiance, reflectedLight } = builder.context; reflectedLight.indirectDiffuse.addAssign(irradiance.mul((0, _BRDF_Lambert.default)({ diffuseColor: _PropertyNode.diffuseColor }))); reflectedLight.indirectDiffuse.mulAssign(ambientOcclusion); } } var _default = exports.default = ToonLightingModel;