UNPKG

@itwin/core-frontend

Version:
30 lines 1.6 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module WebGL */ Object.defineProperty(exports, "__esModule", { value: true }); exports.addLogDepth = addLogDepth; const core_bentley_1 = require("@itwin/core-bentley"); const System_1 = require("../System"); const Common_1 = require("./Common"); // Based on http://tulrich.com/geekstuff/log_depth_buffer.txt // Previously attempted to adjust z in vertex shader along the lines of https://outerra.blogspot.com/2013/07/logarithmic-depth-buffer-optimizations.html // - but interpolation along triangles intersecting the near plane was far too wonky. const finalizeDepth = "return 0.0 == u_logZ.x ? -v_eyeSpace.z / u_logZ.y : log(-v_eyeSpace.z * u_logZ.x) / u_logZ.y;"; /** @internal */ function addLogDepth(builder) { (0, core_bentley_1.assert)(System_1.System.instance.supportsLogZBuffer); (0, Common_1.addEyeSpace)(builder); const frag = builder.frag; frag.addUniform("u_logZ", 3 /* VariableType.Vec2 */, (prog) => { prog.addProgramUniform("u_logZ", (uniform, params) => { uniform.setUniform2fv(params.target.uniforms.frustum.logZ); }); }); frag.set(20 /* FragmentShaderComponent.FinalizeDepth */, finalizeDepth); } //# sourceMappingURL=LogarithmicDepthBuffer.js.map