@openhps/core
Version:
Open Hybrid Positioning System - Core component
106 lines (97 loc) • 3.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.densityFog = densityFog;
exports.fog = exports.densityFogFactor = void 0;
exports.rangeFog = rangeFog;
exports.rangeFogFactor = void 0;
var _Position = require("../accessors/Position.js");
var _MathNode = require("../math/MathNode.js");
var _TSLBase = require("../tsl/TSLBase.js");
/**
* Returns a node that represents the `z` coordinate in view space
* for the current fragment. It's a different representation of the
* default depth value.
*
* This value can be part of a computation that defines how the fog
* density increases when moving away from the camera.
*
* @param {NodeBuilder} builder - The current node builder.
* @return {Node} The viewZ node.
*/
function getViewZNode(builder) {
let viewZ;
const getViewZ = builder.context.getViewZ;
if (getViewZ !== undefined) {
viewZ = getViewZ(this);
}
return (viewZ || _Position.positionView.z).negate();
}
/**
* Constructs a new range factor node.
*
* @tsl
* @function
* @param {Node} near - Defines the near value.
* @param {Node} far - Defines the far value.
*/
const rangeFogFactor = exports.rangeFogFactor = (0, _TSLBase.Fn)(([near, far], builder) => {
const viewZ = getViewZNode(builder);
return (0, _MathNode.smoothstep)(near, far, viewZ);
});
/**
* Represents an exponential squared fog. This type of fog gives
* a clear view near the camera and a faster than exponentially
* densening fog farther from the camera.
*
* @tsl
* @function
* @param {Node} density - Defines the fog density.
*/
const densityFogFactor = exports.densityFogFactor = (0, _TSLBase.Fn)(([density], builder) => {
const viewZ = getViewZNode(builder);
return density.mul(density, viewZ, viewZ).negate().exp().oneMinus();
});
/**
* This class can be used to configure a fog for the scene.
* Nodes of this type are assigned to `Scene.fogNode`.
*
* @tsl
* @function
* @param {Node} color - Defines the color of the fog.
* @param {Node} factor - Defines how the fog is factored in the scene.
*/
const fog = exports.fog = (0, _TSLBase.Fn)(([color, factor]) => {
return (0, _TSLBase.vec4)(factor.toFloat().mix(_TSLBase.output.rgb, color.toVec3()), _TSLBase.output.a);
});
// Deprecated
/**
* @tsl
* @function
* @deprecated since r171. Use `fog( color, rangeFogFactor( near, far ) )` instead.
*
* @param {Node} color
* @param {Node} near
* @param {Node} far
* @returns {Function}
*/
function rangeFog(color, near, far) {
// @deprecated, r171
console.warn('THREE.TSL: "rangeFog( color, near, far )" is deprecated. Use "fog( color, rangeFogFactor( near, far ) )" instead.');
return fog(color, rangeFogFactor(near, far));
}
/**
* @tsl
* @function
* @deprecated since r171. Use `fog( color, densityFogFactor( density ) )` instead.
*
* @param {Node} color
* @param {Node} density
* @returns {Function}
*/
function densityFog(color, density) {
// @deprecated, r171
console.warn('THREE.TSL: "densityFog( color, density )" is deprecated. Use "fog( color, densityFogFactor( density ) )" instead.');
return fog(color, densityFogFactor(density));
}