@openhps/core
Version:
Open Hybrid Positioning System - Core component
28 lines (27 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.viewportSafeUV = void 0;
var _TSLBase = require("../tsl/TSLBase.js");
var _ScreenNode = require("../display/ScreenNode.js");
var _ViewportDepthTextureNode = require("../display/ViewportDepthTextureNode.js");
var _ViewportDepthNode = require("../display/ViewportDepthNode.js");
/**
* A special version of a screen uv function that involves a depth comparison
* when computing the final uvs. The function mitigates visual errors when
* using viewport texture nodes for refraction purposes. Without this function
* objects in front of a refractive surface might appear on the refractive surface
* which is incorrect.
*
* @tsl
* @function
* @param {?Node<vec2>} uv - Optional uv coordinates. By default `screenUV` is used.
* @return {Node<vec2>} The update uv coordinates.
*/
const viewportSafeUV = exports.viewportSafeUV = /*@__PURE__*/(0, _TSLBase.Fn)(([uv = null]) => {
const depth = (0, _ViewportDepthNode.linearDepth)();
const depthDiff = (0, _ViewportDepthNode.linearDepth)((0, _ViewportDepthTextureNode.viewportDepthTexture)(uv)).sub(depth);
const finalUV = depthDiff.lessThan(0).select(_ScreenNode.screenUV, uv);
return finalUV;
});