@openhps/core
Version:
Open Hybrid Positioning System - Core component
82 lines (80 loc) • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _F_Schlick = _interopRequireDefault(require("./F_Schlick.js"));
var _V_GGX_SmithCorrelated = _interopRequireDefault(require("./V_GGX_SmithCorrelated.js"));
var _V_GGX_SmithCorrelated_Anisotropic = _interopRequireDefault(require("./V_GGX_SmithCorrelated_Anisotropic.js"));
var _D_GGX = _interopRequireDefault(require("./D_GGX.js"));
var _D_GGX_Anisotropic = _interopRequireDefault(require("./D_GGX_Anisotropic.js"));
var _Normal = require("../../accessors/Normal.js");
var _Position = require("../../accessors/Position.js");
var _PropertyNode = require("../../core/PropertyNode.js");
var _TSLBase = require("../../tsl/TSLBase.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
const BRDF_GGX = /*@__PURE__*/(0, _TSLBase.Fn)(inputs => {
const {
lightDirection,
f0,
f90,
roughness,
f,
USE_IRIDESCENCE,
USE_ANISOTROPY
} = inputs;
const normalView = inputs.normalView || _Normal.transformedNormalView;
const alpha = roughness.pow2(); // UE4's roughness
const halfDir = lightDirection.add(_Position.positionViewDirection).normalize();
const dotNL = normalView.dot(lightDirection).clamp();
const dotNV = normalView.dot(_Position.positionViewDirection).clamp(); // @ TODO: Move to core dotNV
const dotNH = normalView.dot(halfDir).clamp();
const dotVH = _Position.positionViewDirection.dot(halfDir).clamp();
let F = (0, _F_Schlick.default)({
f0,
f90,
dotVH
});
let V, D;
if ((0, _TSLBase.defined)(USE_IRIDESCENCE)) {
F = _PropertyNode.iridescence.mix(F, f);
}
if ((0, _TSLBase.defined)(USE_ANISOTROPY)) {
const dotTL = _PropertyNode.anisotropyT.dot(lightDirection);
const dotTV = _PropertyNode.anisotropyT.dot(_Position.positionViewDirection);
const dotTH = _PropertyNode.anisotropyT.dot(halfDir);
const dotBL = _PropertyNode.anisotropyB.dot(lightDirection);
const dotBV = _PropertyNode.anisotropyB.dot(_Position.positionViewDirection);
const dotBH = _PropertyNode.anisotropyB.dot(halfDir);
V = (0, _V_GGX_SmithCorrelated_Anisotropic.default)({
alphaT: _PropertyNode.alphaT,
alphaB: alpha,
dotTV,
dotBV,
dotTL,
dotBL,
dotNV,
dotNL
});
D = (0, _D_GGX_Anisotropic.default)({
alphaT: _PropertyNode.alphaT,
alphaB: alpha,
dotNH,
dotTH,
dotBH
});
} else {
V = (0, _V_GGX_SmithCorrelated.default)({
alpha,
dotNL,
dotNV
});
D = (0, _D_GGX.default)({
alpha,
dotNH
});
}
return F.mul(V).mul(D);
}); // validated
var _default = exports.default = BRDF_GGX;