UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

76 lines (73 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.triNoise3D = void 0; var _LoopNode = require("../utils/LoopNode.js"); var _TSLBase = require("../tsl/TSLBase.js"); // https://github.com/cabbibo/glsl-tri-noise-3d const tri = /*@__PURE__*/(0, _TSLBase.Fn)(([x]) => { return x.fract().sub(.5).abs(); }).setLayout({ name: 'tri', type: 'float', inputs: [{ name: 'x', type: 'float' }] }); const tri3 = /*@__PURE__*/(0, _TSLBase.Fn)(([p]) => { return (0, _TSLBase.vec3)(tri(p.z.add(tri(p.y.mul(1.)))), tri(p.z.add(tri(p.x.mul(1.)))), tri(p.y.add(tri(p.x.mul(1.))))); }).setLayout({ name: 'tri3', type: 'vec3', inputs: [{ name: 'p', type: 'vec3' }] }); /** * Generates a noise value from the given position, speed and time parameters. * * @tsl * @function * @param {Node<vec3>} position - The position. * @param {Node<float>} speed - The speed. * @param {Node<float>} time - The time. * @return {Node<float>} The generated noise. */ const triNoise3D = exports.triNoise3D = /*@__PURE__*/(0, _TSLBase.Fn)(([position, speed, time]) => { const p = (0, _TSLBase.vec3)(position).toVar(); const z = (0, _TSLBase.float)(1.4).toVar(); const rz = (0, _TSLBase.float)(0.0).toVar(); const bp = (0, _TSLBase.vec3)(p).toVar(); (0, _LoopNode.Loop)({ start: (0, _TSLBase.float)(0.0), end: (0, _TSLBase.float)(3.0), type: 'float', condition: '<=' }, () => { const dg = (0, _TSLBase.vec3)(tri3(bp.mul(2.0))).toVar(); p.addAssign(dg.add(time.mul((0, _TSLBase.float)(0.1).mul(speed)))); bp.mulAssign(1.8); z.mulAssign(1.5); p.mulAssign(1.2); const t = (0, _TSLBase.float)(tri(p.z.add(tri(p.x.add(tri(p.y)))))).toVar(); rz.addAssign(t.div(z)); bp.addAssign(0.14); }); return rz; }).setLayout({ name: 'triNoise3D', type: 'float', inputs: [{ name: 'position', type: 'vec3' }, { name: 'speed', type: 'float' }, { name: 'time', type: 'float' }] });