@zephyr3d/scene 0.9.26 → 0.9.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animationset.js +92 -30
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/joint_dynamics/convex_collider.js +320 -0
- package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
- package/dist/animation/skeleton.js +21 -1
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/asset/model.js +6 -2
- package/dist/asset/model.js.map +1 -1
- package/dist/camera/camera.js +75 -23
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +4764 -3600
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/material/hairstrand.js +235 -235
- package/dist/material/hairstrand.js.map +1 -1
- package/dist/material/material.js +296 -296
- package/dist/material/material.js.map +1 -1
- package/dist/material/mixins/lit.js +33 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/shader/helper.js +404 -3
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/water.js +2057 -72
- package/dist/material/water.js.map +1 -1
- package/dist/posteffect/motionblur.js +663 -58
- package/dist/posteffect/motionblur.js.map +1 -1
- package/dist/posteffect/posteffect.js +12 -1
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +46 -44
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/sss.js +30 -2
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/render/abuffer_oit.js +37 -37
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/clipmap.js +156 -5
- package/dist/render/clipmap.js.map +1 -1
- package/dist/render/cull_visitor.js +1 -0
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/dualdepthpeeling_oit.js +49 -49
- package/dist/render/dualdepthpeeling_oit.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +3 -3
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/fft_wavegenerator.js +57 -15
- package/dist/render/fft_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +127 -20
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/hzb.js +80 -22
- package/dist/render/hzb.js.map +1 -1
- package/dist/render/lightpass.js +6 -3
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/oit.js +11 -11
- package/dist/render/oit.js.map +1 -1
- package/dist/render/render_queue.js +36 -0
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +4 -0
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/blackboard.js +1 -0
- package/dist/render/rendergraph/blackboard.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +318 -9
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/frame_resource_requirements.js +1 -0
- package/dist/render/rendergraph/frame_resource_requirements.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +8 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/underwater.js +624 -0
- package/dist/render/underwater.js.map +1 -0
- package/dist/render/water_caustics.js +1380 -0
- package/dist/render/water_caustics.js.map +1 -0
- package/dist/render/weightedblended_oit.js +33 -33
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/water.js +540 -4
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/water.js +22 -19
- package/dist/shaders/water.js.map +1 -1
- package/dist/shaders/water_medium.js +56 -0
- package/dist/shaders/water_medium.js.map +1 -0
- package/dist/shadow/shadow_region.js +49 -49
- package/dist/shadow/shadow_region.js.map +1 -1
- package/dist/utility/serialization/manager.js +3 -1
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +31 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +53 -25
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +1101 -21
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/shprojector.js +87 -87
- package/dist/utility/shprojector.js.map +1 -1
- package/package.json +1 -1
- package/dist/render/rendergraph/frame_graph_context.js +0 -41
- package/dist/render/rendergraph/frame_graph_context.js.map +0 -1
- package/dist/shaders/ssgi.js +0 -63
- package/dist/shaders/ssgi.js.map +0 -1
- package/dist/shaders/ssgi_reprojection.js +0 -118
- package/dist/shaders/ssgi_reprojection.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shprojector.js","sources":["../../src/utility/shprojector.ts"],"sourcesContent":["import type {\n AbstractDevice,\n BindGroup,\n FrameBuffer,\n GPUDataBuffer,\n GPUProgram,\n RenderStateSet,\n TextureCube\n} from '@zephyr3d/device';\nimport { Primitive } from '../render/primitive';\nimport type { Nullable } from '@zephyr3d/base';\nimport { Disposable, DRef, Vector4 } from '@zephyr3d/base';\nimport { fetchSampler } from './misc';\nimport { getDevice } from '../app/api';\n\n/**\n * CubemapSHProjector is responsible for projecting a cubemap texture into spherical harmonics (SH) coefficients.\n * This is commonly used for efficient environment lighting approximation in real-time rendering.\n *\n * The class uses Monte Carlo sampling to compute the first 9 spherical harmonics coefficients (up to order 2)\n * from a cubemap texture, which can then be used for ambient lighting calculations.\n *\n * @example\n * ```typescript\n * const projector = new CubemapSHProjector(10000);\n * const shBuffer = device.createBuffer(4 * 4 * 9, { usage: 'uniform' });\n * projector.projectCubemap(environmentCubemap, shBuffer);\n * // shBuffer now contains the 9 SH coefficients as RGB values\n * projector.dispose();\n * ```\n *\n * @public\n */\nexport class CubemapSHProjector extends Disposable {\n private static _programInst: Nullable<GPUProgram> = null;\n private static _bindGroupInst: Nullable<BindGroup> = null;\n private static _renderStats: Nullable<RenderStateSet> = null;\n private readonly _primitive: DRef<Primitive>;\n private readonly _renderTarget: DRef<FrameBuffer>;\n private readonly _numSamples: number;\n /**\n * Creates a new CubemapSHProjector instance.\n *\n * @param numSamples - Number of Monte Carlo samples to use for SH projection.\n * Higher values provide better accuracy but slower computation.\n * Default is 10000.\n */\n constructor(numSamples = 10000) {\n super();\n this._numSamples = numSamples;\n this._primitive = new DRef();\n this._renderTarget = new DRef();\n }\n /**\n * Projects a cubemap texture into spherical harmonics coefficients and stores them in a GPUBuffer.\n *\n * The method performs Monte Carlo integration over the sphere to compute the first 9 SH coefficients.\n * The results are written to a 3x3 render target where each pixel contains RGB values for one SH coefficient.\n * The layout is:\n * - (0,0): Y₀₀ (0,1): Y₁₋₁ (0,2): Y₁₀\n * - (1,0): Y₁₁ (1,1): Y₂₋₂ (1,2): Y₂₋₁\n * - (2,0): Y₂₀ (2,1): Y₂₁ (2,2): Y₂₂\n *\n * @param cubemap - The input cubemap texture to project\n * @param outBuffer - GPU data buffer to receive the computed SH coefficients.\n * Must be large enough to hold 9 RGB values (36 floats for RGBA32F format).\n *\n * @example\n * ```typescript\n * const shBuffer = device.createDataBuffer(9 * 4 * 4); // 9 coefficients * 4 components * 4 bytes\n * projector.projectCubemap(environmentMap, shBuffer);\n * ```\n */\n projectCubemap(cubemap: TextureCube, outBuffer: GPUDataBuffer, radianceSource = true) {\n const device = getDevice();\n if (!this._renderTarget.get()) {\n const texture = device.createTexture2D('rgba32f', 3, 3, {\n mipmapping: false\n })!;\n this._renderTarget.set(device.createFrameBuffer([texture], null));\n }\n this.projectCubemapToTexture(cubemap, this._renderTarget.get()!, radianceSource);\n this._renderTarget.get()!.getColorAttachments()[0].readPixelsToBuffer(0, 0, 3, 3, 0, 0, outBuffer);\n }\n /**\n * Projects a cubemap texture into spherical harmonics coefficients and stores them in a 3x3 texture.\n *\n * The method performs Monte Carlo integration over the sphere to compute the first 9 SH coefficients.\n * The results are written to a 3x3 render target where each pixel contains RGB values for one SH coefficient.\n * The layout is:\n * - (0,0): Y₀₀ (0,1): Y₁₋₁ (0,2): Y₁₀\n * - (1,0): Y₁₁ (1,1): Y₂₋₂ (1,2): Y₂₋₁\n * - (2,0): Y₂₀ (2,1): Y₂₁ (2,2): Y₂₂\n *\n * @param cubemap - The input cubemap texture to project\n * @param outFramebuffer - Framebuffer that contains the 3x3 texture to receive the computed SH coefficients in color attachment slot 0.\n *\n * @example\n * ```typescript\n * const shTexture = device.createTexture2D('rgba32f', 3, 3); // 9 coefficients * 4 components * 4 bytes\n * const shFramebuffer = device.createFrameBuffer([shTexture], null);\n * projector.projectCubemapToTexture(environmentMap, shFramebuffer);\n * ```\n */\n projectCubemapToTexture(cubemap: TextureCube, framebuffer: FrameBuffer, radianceSource = true) {\n const device = getDevice();\n const clearColor = new Vector4(0, 0, 0, 1);\n this.init(device);\n device.pushDeviceStates();\n device.setRenderStates(CubemapSHProjector._renderStats);\n device.setProgram(CubemapSHProjector._programInst);\n device.setFramebuffer(framebuffer);\n device.clearFrameBuffer(clearColor, null, null);\n const bindGroup = CubemapSHProjector._bindGroupInst!;\n bindGroup.setTexture('cubemap', cubemap, fetchSampler('clamp_linear_nomip'));\n bindGroup.setValue('scale', radianceSource ? 1.0 : Math.PI);\n device.setBindGroup(0, bindGroup);\n this._primitive.get()!.drawInstanced(9);\n device.popDeviceStates();\n }\n /**\n * Disposes of all resources allocated by this projector instance.\n * Should be called when the projector is no longer needed to prevent memory leaks.\n */\n protected onDispose() {\n super.onDispose();\n this._primitive.dispose();\n if (this._renderTarget.get()) {\n this._renderTarget.get()!.getColorAttachments()[0].dispose();\n this._renderTarget.dispose();\n }\n }\n /**\n * Initializes the GPU resources needed for SH projection.\n * This method is called automatically by projectCubemap() and sets up:\n * - Sample directions primitive (Monte Carlo samples on unit sphere)\n * - Render target (3x3 RGBA32F texture)\n * - Render states (additive blending, no depth test)\n * - GPU program for SH evaluation\n *\n * @param device - The graphics device to create resources with\n * @internal\n */\n private init(device: AbstractDevice) {\n if (!this._primitive.get()) {\n const samples = new Float32Array(this._numSamples * 4);\n for (let i = 0; i < this._numSamples; i++) {\n let x1: number, x2: number, s: number;\n do {\n x1 = Math.random() * 2 - 1;\n x2 = Math.random() * 2 - 1;\n s = x1 * x1 + x2 * x2;\n } while (s >= 1);\n const sqrtS = Math.sqrt(1 - s);\n samples[i * 4 + 0] = 2 * x1 * sqrtS;\n samples[i * 4 + 1] = 2 * x2 * sqrtS;\n samples[i * 4 + 2] = 1 - 2 * s;\n samples[i * 4 + 3] = (4 * Math.PI) / this._numSamples;\n }\n const primitive = new Primitive();\n primitive.createAndSetVertexBuffer('position_f32x4', samples);\n if (device.type === 'webgl') {\n primitive.createAndSetVertexBuffer(\n 'tex0_f32',\n new Float32Array([0, 1, 2, 3, 4, 5, 6, 7, 8]),\n 'instance'\n );\n }\n primitive.indexCount = this._numSamples;\n primitive.indexStart = 0;\n primitive.primitiveType = 'point-list';\n this._primitive.set(primitive);\n }\n\n if (!CubemapSHProjector._renderStats) {\n CubemapSHProjector._renderStats = device.createRenderStateSet();\n CubemapSHProjector._renderStats.useDepthState().enableTest(false).enableWrite(false);\n CubemapSHProjector._renderStats\n .useBlendingState()\n .enable(true)\n .setBlendEquation('add', 'add')\n .setBlendFuncRGB('one', 'one')\n .setBlendFuncAlpha('zero', 'one');\n CubemapSHProjector._renderStats.useRasterizerState().setCullMode('none');\n }\n\n if (!CubemapSHProjector._programInst) {\n CubemapSHProjector._programInst = CubemapSHProjector._createProgram(device)!;\n CubemapSHProjector._bindGroupInst = device.createBindGroup(\n CubemapSHProjector._programInst.bindGroupLayouts[0]\n );\n }\n }\n /**\n * Creates the GPU program for spherical harmonics evaluation.\n *\n * The vertex shader uses instanced rendering to generate 9 instances (one per SH coefficient).\n * Each instance renders all sample points, but the vertex shader maps them to different\n * pixels in the 3x3 output texture based on the instance ID.\n *\n * The fragment shader evaluates the appropriate SH basis function based on the pixel location,\n * samples the cubemap in the sample direction, and multiplies by the integration weight.\n *\n * @param device - The graphics device to create the program with\n * @returns The compiled GPU program\n * @internal\n */\n private static _createProgram(device: AbstractDevice) {\n const program = device.buildRenderProgram({\n vertex(pb) {\n this.$inputs.directionWeight = pb.vec4().attrib('position');\n if (device.type === 'webgl') {\n this.$inputs.instanceId = pb.float().attrib('texCoord0');\n }\n pb.main(function () {\n this.$outputs.direction = this.$inputs.directionWeight.xyz;\n this.$outputs.weight = this.$inputs.directionWeight.w;\n if (pb.getDevice().type !== 'webgpu') {\n this.$builtins.pointSize = 1;\n }\n this.$outputs.shIndex =\n device.type === 'webgl' ? this.$inputs.instanceId : pb.int(this.$builtins.instanceIndex);\n this.$l.x = pb.mod(this.$outputs.shIndex, 3);\n this.$l.y = pb.div(this.$outputs.shIndex, 3);\n this.$l.ndcX = pb.sub(pb.div(pb.add(pb.float(this.x), 0.5), 1.5), 1);\n this.$l.ndcY = pb.sub(pb.div(pb.add(pb.float(this.y), 0.5), 1.5), 1);\n this.$l.$builtins.position = pb.vec4(this.ndcX, this.ndcY, 0, 1);\n if (pb.getDevice().type === 'webgpu') {\n this.$builtins.position = pb.mul(this.$builtins.position, pb.vec4(1, -1, 1, 1));\n }\n });\n },\n fragment(pb) {\n this.$outputs.color = pb.vec4();\n this.cubemap = pb.texCube().uniform(0);\n this.scale = pb.float().uniform(0);\n pb.func('cosineLobeBandFactor', [pb.int('l')], function () {\n this.$if(pb.equal(this.l, 0), function () {\n this.$return(pb.float(1));\n });\n this.$if(pb.lessThanEqual(this.l, 3), function () {\n this.$return(2 / 3);\n });\n this.$return(1 / 4);\n });\n pb.func('Y0', [pb.vec3('v')], function () {\n this.$return(0.282094791773878);\n });\n pb.func('Y1', [pb.vec3('v')], function () {\n this.$return(pb.mul(this.v.y, -0.4886025119));\n });\n pb.func('Y2', [pb.vec3('v')], function () {\n this.$return(pb.mul(this.v.z, 0.4886025119));\n });\n pb.func('Y3', [pb.vec3('v')], function () {\n this.$return(pb.mul(this.v.x, -0.4886025119));\n });\n pb.func('Y4', [pb.vec3('v')], function () {\n this.$return(pb.mul(this.v.x, this.v.y, 1.0925484306));\n });\n pb.func('Y5', [pb.vec3('v')], function () {\n this.$return(pb.mul(this.v.y, this.v.z, -1.0925484306));\n });\n pb.func('Y6', [pb.vec3('v')], function () {\n this.$return(pb.mul(pb.sub(pb.mul(this.v.z, this.v.z, 3), 1), 0.3153915652));\n });\n pb.func('Y7', [pb.vec3('v')], function () {\n this.$return(pb.mul(this.v.x, this.v.z, -1.0925484306));\n });\n pb.func('Y8', [pb.vec3('v')], function () {\n this.$return(pb.mul(pb.sub(pb.mul(this.v.x, this.v.x), pb.mul(this.v.y, this.v.y)), 0.5462742153));\n });\n pb.func('evalBasis', [pb.vec3('dir'), pb.int('c')], function () {\n this.$if(pb.equal(this.c, 0), function () {\n this.$return(this.Y0(this.dir));\n })\n .$elseif(pb.equal(this.c, 1), function () {\n this.$return(this.Y1(this.dir));\n })\n .$elseif(pb.equal(this.c, 2), function () {\n this.$return(this.Y2(this.dir));\n })\n .$elseif(pb.equal(this.c, 3), function () {\n this.$return(this.Y3(this.dir));\n })\n .$elseif(pb.equal(this.c, 4), function () {\n this.$return(this.Y4(this.dir));\n })\n .$elseif(pb.equal(this.c, 5), function () {\n this.$return(this.Y5(this.dir));\n })\n .$elseif(pb.equal(this.c, 6), function () {\n this.$return(this.Y6(this.dir));\n })\n .$elseif(pb.equal(this.c, 7), function () {\n this.$return(this.Y7(this.dir));\n })\n .$elseif(pb.equal(this.c, 8), function () {\n this.$return(this.Y8(this.dir));\n })\n .$else(function () {\n this.$return(0);\n });\n });\n pb.main(function () {\n this.$l.radiance = pb.textureSampleLevel(this.cubemap, this.$inputs.direction, 0).rgb;\n this.$l.bandFactor = this.cosineLobeBandFactor(\n pb.getDevice().type === 'webgl' ? pb.int(this.$inputs.shIndex) : this.$inputs.shIndex\n );\n this.$l.sh = this.evalBasis(\n this.$inputs.direction,\n pb.getDevice().type === 'webgl' ? pb.int(this.$inputs.shIndex) : this.$inputs.shIndex\n );\n this.$outputs.color = pb.vec4(\n pb.mul(this.radiance, this.sh, this.$inputs.weight, this.bandFactor, this.scale),\n 1\n );\n });\n }\n })!;\n program.name = '@CubemapSHProjector_SHProject';\n return program;\n }\n}\n"],"names":["CubemapSHProjector","Disposable","_programInst","_bindGroupInst","_renderStats","_primitive","_renderTarget","_numSamples","numSamples","DRef","projectCubemap","cubemap","outBuffer","radianceSource","device","getDevice","get","texture","createTexture2D","mipmapping","set","createFrameBuffer","projectCubemapToTexture","getColorAttachments","readPixelsToBuffer","framebuffer","clearColor","Vector4","init","pushDeviceStates","setRenderStates","setProgram","setFramebuffer","clearFrameBuffer","bindGroup","setTexture","fetchSampler","setValue","Math","PI","setBindGroup","drawInstanced","popDeviceStates","onDispose","dispose","samples","Float32Array","i","x1","x2","s","random","sqrtS","sqrt","primitive","Primitive","createAndSetVertexBuffer","type","indexCount","indexStart","primitiveType","createRenderStateSet","useDepthState","enableTest","enableWrite","useBlendingState","enable","setBlendEquation","setBlendFuncRGB","setBlendFuncAlpha","useRasterizerState","setCullMode","_createProgram","createBindGroup","bindGroupLayouts","program","buildRenderProgram","vertex","pb","$inputs","directionWeight","vec4","attrib","instanceId","float","main","$outputs","direction","xyz","weight","w","$builtins","pointSize","shIndex","int","instanceIndex","$l","x","mod","y","div","ndcX","sub","add","ndcY","position","mul","fragment","color","texCube","uniform","scale","func","$if","equal","l","$return","lessThanEqual","vec3","v","z","c","Y0","dir","$elseif","Y1","Y2","Y3","Y4","Y5","Y6","Y7","Y8","$else","radiance","textureSampleLevel","rgb","bandFactor","cosineLobeBandFactor","sh","evalBasis","name"],"mappings":";;;;;AAeA;;;;;;;;;;;;;;;;;IAkBO,MAAMA,kBAA2BC,SAAAA,UAAAA,CAAAA;AACtC,IAAA,OAAeC,eAAqC,IAAK;AACzD,IAAA,OAAeC,iBAAsC,IAAK;AAC1D,IAAA,OAAeC,eAAyC,IAAK;IAC5CC,UAA4B;IAC5BC,aAAiC;IACjCC,WAAoB;AACrC;;;;;;MAOA,WAAA,CAAYC,UAAa,GAAA,KAAK,CAAE;QAC9B,KAAK,EAAA;QACL,IAAI,CAACD,WAAW,GAAGC,UAAAA;QACnB,IAAI,CAACH,UAAU,GA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A,IAAI,CAC3BH,EAAAA,CAAG4B,GAAG,CAAC,IAAI,CAAC4B,QAAQ,EAAE,IAAI,CAACK,EAAE,EAAE,IAAI,CAAC5D,OAAO,CAACU,MAAM,EAAE,IAAI,CAACgD,UAAU,EAAE,IAAI,CAAC1B,KAAK,CAC/E,EAAA,CAAA,CAAA;AAEJ,iBAAA,CAAA;AACF;AACF,SAAA,CAAA;AACApC,QAAAA,OAAAA,CAAQkE,IAAI,GAAG,+BAAA;QACf,OAAOlE,OAAAA;AACT;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"shprojector.js","sources":["../../src/utility/shprojector.ts"],"sourcesContent":["import type {\r\n AbstractDevice,\r\n BindGroup,\r\n FrameBuffer,\r\n GPUDataBuffer,\r\n GPUProgram,\r\n RenderStateSet,\r\n TextureCube\r\n} from '@zephyr3d/device';\r\nimport { Primitive } from '../render/primitive';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport { Disposable, DRef, Vector4 } from '@zephyr3d/base';\r\nimport { fetchSampler } from './misc';\r\nimport { getDevice } from '../app/api';\r\n\r\n/**\r\n * CubemapSHProjector is responsible for projecting a cubemap texture into spherical harmonics (SH) coefficients.\r\n * This is commonly used for efficient environment lighting approximation in real-time rendering.\r\n *\r\n * The class uses Monte Carlo sampling to compute the first 9 spherical harmonics coefficients (up to order 2)\r\n * from a cubemap texture, which can then be used for ambient lighting calculations.\r\n *\r\n * @example\r\n * ```typescript\r\n * const projector = new CubemapSHProjector(10000);\r\n * const shBuffer = device.createBuffer(4 * 4 * 9, { usage: 'uniform' });\r\n * projector.projectCubemap(environmentCubemap, shBuffer);\r\n * // shBuffer now contains the 9 SH coefficients as RGB values\r\n * projector.dispose();\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport class CubemapSHProjector extends Disposable {\r\n private static _programInst: Nullable<GPUProgram> = null;\r\n private static _bindGroupInst: Nullable<BindGroup> = null;\r\n private static _renderStats: Nullable<RenderStateSet> = null;\r\n private readonly _primitive: DRef<Primitive>;\r\n private readonly _renderTarget: DRef<FrameBuffer>;\r\n private readonly _numSamples: number;\r\n /**\r\n * Creates a new CubemapSHProjector instance.\r\n *\r\n * @param numSamples - Number of Monte Carlo samples to use for SH projection.\r\n * Higher values provide better accuracy but slower computation.\r\n * Default is 10000.\r\n */\r\n constructor(numSamples = 10000) {\r\n super();\r\n this._numSamples = numSamples;\r\n this._primitive = new DRef();\r\n this._renderTarget = new DRef();\r\n }\r\n /**\r\n * Projects a cubemap texture into spherical harmonics coefficients and stores them in a GPUBuffer.\r\n *\r\n * The method performs Monte Carlo integration over the sphere to compute the first 9 SH coefficients.\r\n * The results are written to a 3x3 render target where each pixel contains RGB values for one SH coefficient.\r\n * The layout is:\r\n * - (0,0): Y₀₀ (0,1): Y₁₋₁ (0,2): Y₁₀\r\n * - (1,0): Y₁₁ (1,1): Y₂₋₂ (1,2): Y₂₋₁\r\n * - (2,0): Y₂₀ (2,1): Y₂₁ (2,2): Y₂₂\r\n *\r\n * @param cubemap - The input cubemap texture to project\r\n * @param outBuffer - GPU data buffer to receive the computed SH coefficients.\r\n * Must be large enough to hold 9 RGB values (36 floats for RGBA32F format).\r\n *\r\n * @example\r\n * ```typescript\r\n * const shBuffer = device.createDataBuffer(9 * 4 * 4); // 9 coefficients * 4 components * 4 bytes\r\n * projector.projectCubemap(environmentMap, shBuffer);\r\n * ```\r\n */\r\n projectCubemap(cubemap: TextureCube, outBuffer: GPUDataBuffer, radianceSource = true) {\r\n const device = getDevice();\r\n if (!this._renderTarget.get()) {\r\n const texture = device.createTexture2D('rgba32f', 3, 3, {\r\n mipmapping: false\r\n })!;\r\n this._renderTarget.set(device.createFrameBuffer([texture], null));\r\n }\r\n this.projectCubemapToTexture(cubemap, this._renderTarget.get()!, radianceSource);\r\n this._renderTarget.get()!.getColorAttachments()[0].readPixelsToBuffer(0, 0, 3, 3, 0, 0, outBuffer);\r\n }\r\n /**\r\n * Projects a cubemap texture into spherical harmonics coefficients and stores them in a 3x3 texture.\r\n *\r\n * The method performs Monte Carlo integration over the sphere to compute the first 9 SH coefficients.\r\n * The results are written to a 3x3 render target where each pixel contains RGB values for one SH coefficient.\r\n * The layout is:\r\n * - (0,0): Y₀₀ (0,1): Y₁₋₁ (0,2): Y₁₀\r\n * - (1,0): Y₁₁ (1,1): Y₂₋₂ (1,2): Y₂₋₁\r\n * - (2,0): Y₂₀ (2,1): Y₂₁ (2,2): Y₂₂\r\n *\r\n * @param cubemap - The input cubemap texture to project\r\n * @param outFramebuffer - Framebuffer that contains the 3x3 texture to receive the computed SH coefficients in color attachment slot 0.\r\n *\r\n * @example\r\n * ```typescript\r\n * const shTexture = device.createTexture2D('rgba32f', 3, 3); // 9 coefficients * 4 components * 4 bytes\r\n * const shFramebuffer = device.createFrameBuffer([shTexture], null);\r\n * projector.projectCubemapToTexture(environmentMap, shFramebuffer);\r\n * ```\r\n */\r\n projectCubemapToTexture(cubemap: TextureCube, framebuffer: FrameBuffer, radianceSource = true) {\r\n const device = getDevice();\r\n const clearColor = new Vector4(0, 0, 0, 1);\r\n this.init(device);\r\n device.pushDeviceStates();\r\n device.setRenderStates(CubemapSHProjector._renderStats);\r\n device.setProgram(CubemapSHProjector._programInst);\r\n device.setFramebuffer(framebuffer);\r\n device.clearFrameBuffer(clearColor, null, null);\r\n const bindGroup = CubemapSHProjector._bindGroupInst!;\r\n bindGroup.setTexture('cubemap', cubemap, fetchSampler('clamp_linear_nomip'));\r\n bindGroup.setValue('scale', radianceSource ? 1.0 : Math.PI);\r\n device.setBindGroup(0, bindGroup);\r\n this._primitive.get()!.drawInstanced(9);\r\n device.popDeviceStates();\r\n }\r\n /**\r\n * Disposes of all resources allocated by this projector instance.\r\n * Should be called when the projector is no longer needed to prevent memory leaks.\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._primitive.dispose();\r\n if (this._renderTarget.get()) {\r\n this._renderTarget.get()!.getColorAttachments()[0].dispose();\r\n this._renderTarget.dispose();\r\n }\r\n }\r\n /**\r\n * Initializes the GPU resources needed for SH projection.\r\n * This method is called automatically by projectCubemap() and sets up:\r\n * - Sample directions primitive (Monte Carlo samples on unit sphere)\r\n * - Render target (3x3 RGBA32F texture)\r\n * - Render states (additive blending, no depth test)\r\n * - GPU program for SH evaluation\r\n *\r\n * @param device - The graphics device to create resources with\r\n * @internal\r\n */\r\n private init(device: AbstractDevice) {\r\n if (!this._primitive.get()) {\r\n const samples = new Float32Array(this._numSamples * 4);\r\n for (let i = 0; i < this._numSamples; i++) {\r\n let x1: number, x2: number, s: number;\r\n do {\r\n x1 = Math.random() * 2 - 1;\r\n x2 = Math.random() * 2 - 1;\r\n s = x1 * x1 + x2 * x2;\r\n } while (s >= 1);\r\n const sqrtS = Math.sqrt(1 - s);\r\n samples[i * 4 + 0] = 2 * x1 * sqrtS;\r\n samples[i * 4 + 1] = 2 * x2 * sqrtS;\r\n samples[i * 4 + 2] = 1 - 2 * s;\r\n samples[i * 4 + 3] = (4 * Math.PI) / this._numSamples;\r\n }\r\n const primitive = new Primitive();\r\n primitive.createAndSetVertexBuffer('position_f32x4', samples);\r\n if (device.type === 'webgl') {\r\n primitive.createAndSetVertexBuffer(\r\n 'tex0_f32',\r\n new Float32Array([0, 1, 2, 3, 4, 5, 6, 7, 8]),\r\n 'instance'\r\n );\r\n }\r\n primitive.indexCount = this._numSamples;\r\n primitive.indexStart = 0;\r\n primitive.primitiveType = 'point-list';\r\n this._primitive.set(primitive);\r\n }\r\n\r\n if (!CubemapSHProjector._renderStats) {\r\n CubemapSHProjector._renderStats = device.createRenderStateSet();\r\n CubemapSHProjector._renderStats.useDepthState().enableTest(false).enableWrite(false);\r\n CubemapSHProjector._renderStats\r\n .useBlendingState()\r\n .enable(true)\r\n .setBlendEquation('add', 'add')\r\n .setBlendFuncRGB('one', 'one')\r\n .setBlendFuncAlpha('zero', 'one');\r\n CubemapSHProjector._renderStats.useRasterizerState().setCullMode('none');\r\n }\r\n\r\n if (!CubemapSHProjector._programInst) {\r\n CubemapSHProjector._programInst = CubemapSHProjector._createProgram(device)!;\r\n CubemapSHProjector._bindGroupInst = device.createBindGroup(\r\n CubemapSHProjector._programInst.bindGroupLayouts[0]\r\n );\r\n }\r\n }\r\n /**\r\n * Creates the GPU program for spherical harmonics evaluation.\r\n *\r\n * The vertex shader uses instanced rendering to generate 9 instances (one per SH coefficient).\r\n * Each instance renders all sample points, but the vertex shader maps them to different\r\n * pixels in the 3x3 output texture based on the instance ID.\r\n *\r\n * The fragment shader evaluates the appropriate SH basis function based on the pixel location,\r\n * samples the cubemap in the sample direction, and multiplies by the integration weight.\r\n *\r\n * @param device - The graphics device to create the program with\r\n * @returns The compiled GPU program\r\n * @internal\r\n */\r\n private static _createProgram(device: AbstractDevice) {\r\n const program = device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.directionWeight = pb.vec4().attrib('position');\r\n if (device.type === 'webgl') {\r\n this.$inputs.instanceId = pb.float().attrib('texCoord0');\r\n }\r\n pb.main(function () {\r\n this.$outputs.direction = this.$inputs.directionWeight.xyz;\r\n this.$outputs.weight = this.$inputs.directionWeight.w;\r\n if (pb.getDevice().type !== 'webgpu') {\r\n this.$builtins.pointSize = 1;\r\n }\r\n this.$outputs.shIndex =\r\n device.type === 'webgl' ? this.$inputs.instanceId : pb.int(this.$builtins.instanceIndex);\r\n this.$l.x = pb.mod(this.$outputs.shIndex, 3);\r\n this.$l.y = pb.div(this.$outputs.shIndex, 3);\r\n this.$l.ndcX = pb.sub(pb.div(pb.add(pb.float(this.x), 0.5), 1.5), 1);\r\n this.$l.ndcY = pb.sub(pb.div(pb.add(pb.float(this.y), 0.5), 1.5), 1);\r\n this.$l.$builtins.position = pb.vec4(this.ndcX, this.ndcY, 0, 1);\r\n if (pb.getDevice().type === 'webgpu') {\r\n this.$builtins.position = pb.mul(this.$builtins.position, pb.vec4(1, -1, 1, 1));\r\n }\r\n });\r\n },\r\n fragment(pb) {\r\n this.$outputs.color = pb.vec4();\r\n this.cubemap = pb.texCube().uniform(0);\r\n this.scale = pb.float().uniform(0);\r\n pb.func('cosineLobeBandFactor', [pb.int('l')], function () {\r\n this.$if(pb.equal(this.l, 0), function () {\r\n this.$return(pb.float(1));\r\n });\r\n this.$if(pb.lessThanEqual(this.l, 3), function () {\r\n this.$return(2 / 3);\r\n });\r\n this.$return(1 / 4);\r\n });\r\n pb.func('Y0', [pb.vec3('v')], function () {\r\n this.$return(0.282094791773878);\r\n });\r\n pb.func('Y1', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(this.v.y, -0.4886025119));\r\n });\r\n pb.func('Y2', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(this.v.z, 0.4886025119));\r\n });\r\n pb.func('Y3', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(this.v.x, -0.4886025119));\r\n });\r\n pb.func('Y4', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(this.v.x, this.v.y, 1.0925484306));\r\n });\r\n pb.func('Y5', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(this.v.y, this.v.z, -1.0925484306));\r\n });\r\n pb.func('Y6', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(pb.sub(pb.mul(this.v.z, this.v.z, 3), 1), 0.3153915652));\r\n });\r\n pb.func('Y7', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(this.v.x, this.v.z, -1.0925484306));\r\n });\r\n pb.func('Y8', [pb.vec3('v')], function () {\r\n this.$return(pb.mul(pb.sub(pb.mul(this.v.x, this.v.x), pb.mul(this.v.y, this.v.y)), 0.5462742153));\r\n });\r\n pb.func('evalBasis', [pb.vec3('dir'), pb.int('c')], function () {\r\n this.$if(pb.equal(this.c, 0), function () {\r\n this.$return(this.Y0(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 1), function () {\r\n this.$return(this.Y1(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 2), function () {\r\n this.$return(this.Y2(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 3), function () {\r\n this.$return(this.Y3(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 4), function () {\r\n this.$return(this.Y4(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 5), function () {\r\n this.$return(this.Y5(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 6), function () {\r\n this.$return(this.Y6(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 7), function () {\r\n this.$return(this.Y7(this.dir));\r\n })\r\n .$elseif(pb.equal(this.c, 8), function () {\r\n this.$return(this.Y8(this.dir));\r\n })\r\n .$else(function () {\r\n this.$return(0);\r\n });\r\n });\r\n pb.main(function () {\r\n this.$l.radiance = pb.textureSampleLevel(this.cubemap, this.$inputs.direction, 0).rgb;\r\n this.$l.bandFactor = this.cosineLobeBandFactor(\r\n pb.getDevice().type === 'webgl' ? pb.int(this.$inputs.shIndex) : this.$inputs.shIndex\r\n );\r\n this.$l.sh = this.evalBasis(\r\n this.$inputs.direction,\r\n pb.getDevice().type === 'webgl' ? pb.int(this.$inputs.shIndex) : this.$inputs.shIndex\r\n );\r\n this.$outputs.color = pb.vec4(\r\n pb.mul(this.radiance, this.sh, this.$inputs.weight, this.bandFactor, this.scale),\r\n 1\r\n );\r\n });\r\n }\r\n })!;\r\n program.name = '@CubemapSHProjector_SHProject';\r\n return program;\r\n }\r\n}\r\n"],"names":["CubemapSHProjector","Disposable","_programInst","_bindGroupInst","_renderStats","_primitive","_renderTarget","_numSamples","numSamples","DRef","projectCubemap","cubemap","outBuffer","radianceSource","device","getDevice","get","texture","createTexture2D","mipmapping","set","createFrameBuffer","projectCubemapToTexture","getColorAttachments","readPixelsToBuffer","framebuffer","clearColor","Vector4","init","pushDeviceStates","setRenderStates","setProgram","setFramebuffer","clearFrameBuffer","bindGroup","setTexture","fetchSampler","setValue","Math","PI","setBindGroup","drawInstanced","popDeviceStates","onDispose","dispose","samples","Float32Array","i","x1","x2","s","random","sqrtS","sqrt","primitive","Primitive","createAndSetVertexBuffer","type","indexCount","indexStart","primitiveType","createRenderStateSet","useDepthState","enableTest","enableWrite","useBlendingState","enable","setBlendEquation","setBlendFuncRGB","setBlendFuncAlpha","useRasterizerState","setCullMode","_createProgram","createBindGroup","bindGroupLayouts","program","buildRenderProgram","vertex","pb","$inputs","directionWeight","vec4","attrib","instanceId","float","main","$outputs","direction","xyz","weight","w","$builtins","pointSize","shIndex","int","instanceIndex","$l","x","mod","y","div","ndcX","sub","add","ndcY","position","mul","fragment","color","texCube","uniform","scale","func","$if","equal","l","$return","lessThanEqual","vec3","v","z","c","Y0","dir","$elseif","Y1","Y2","Y3","Y4","Y5","Y6","Y7","Y8","$else","radiance","textureSampleLevel","rgb","bandFactor","cosineLobeBandFactor","sh","evalBasis","name"],"mappings":";;;;;AAeA;;;;;;;;;;;;;;;;;IAkBO,MAAMA,kBAA2BC,SAAAA,UAAAA,CAAAA;AACtC,IAAA,OAAeC,eAAqC,IAAK;AACzD,IAAA,OAAeC,iBAAsC,IAAK;AAC1D,IAAA,OAAeC,eAAyC,IAAK;IAC5CC,UAA4B;IAC5BC,aAAiC;IACjCC,WAAoB;AACrC;;;;;;MAOA,WAAA,CAAYC,UAAa,GAAA,KAAK,CAAE;QAC9B,KAAK,EAAA;QACL,IAAI,CAACD,WAAW,GAAGC,UAAAA;QACnB,IAAI,CAACH,UAAU,GAAG,IAAII,IAAAA,EAAAA;QACtB,IAAI,CAACH,aAAa,GAAG,IAAIG,IAAAA,EAAAA;AAC3B;AACA;;;;;;;;;;;;;;;;;;;AAmBC,MACDC,eAAeC,OAAoB,EAAEC,SAAwB,EAAEC,cAAAA,GAAiB,IAAI,EAAE;AACpF,QAAA,MAAMC,MAASC,GAAAA,SAAAA,EAAAA;AACf,QAAA,IAAI,CAAC,IAAI,CAACT,aAAa,CAACU,GAAG,EAAI,EAAA;AAC7B,YAAA,MAAMC,UAAUH,MAAOI,CAAAA,eAAe,CAAC,SAAA,EAAW,GAAG,CAAG,EAAA;gBACtDC,UAAY,EAAA;AACd,aAAA,CAAA;AACA,YAAA,IAAI,CAACb,aAAa,CAACc,GAAG,C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Side-effect passes (SkyUpdate, ClusterLights, ...) carry no data product, so
|
|
5
|
-
* they are ordered relative to one another through logical tokens rather than
|
|
6
|
-
* texture reads/writes. This scope tracks the most recently emitted token so a
|
|
7
|
-
* pass can chain after the previous one and (optionally) emit its own, without
|
|
8
|
-
* the builder threading a mutable `orderToken` local between blocks.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/ class OrderingScope {
|
|
12
|
-
/** @internal */ _last = null;
|
|
13
|
-
/**
|
|
14
|
-
* Declare a read on the most recently emitted ordering token, if any, to
|
|
15
|
-
* order the current pass after the previous side-effect pass.
|
|
16
|
-
*
|
|
17
|
-
* @param builder - The pass builder of the current pass.
|
|
18
|
-
*/ chainInto(builder) {
|
|
19
|
-
if (this._last) {
|
|
20
|
-
builder.read(this._last);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Emit a new ordering token from the current pass and record it as the latest
|
|
25
|
-
* link in the chain.
|
|
26
|
-
*
|
|
27
|
-
* @param builder - The pass builder of the current pass.
|
|
28
|
-
* @param name - Debug label for the token.
|
|
29
|
-
* @returns The newly created token handle.
|
|
30
|
-
*/ emit(builder, name) {
|
|
31
|
-
const token = builder.createToken(name);
|
|
32
|
-
this._last = token;
|
|
33
|
-
return token;
|
|
34
|
-
}
|
|
35
|
-
/** The most recently emitted ordering token, or null. */ get last() {
|
|
36
|
-
return this._last;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { OrderingScope };
|
|
41
|
-
//# sourceMappingURL=frame_graph_context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"frame_graph_context.js","sources":["../../../src/render/rendergraph/frame_graph_context.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\nimport type { RGHandle, RGPassBuilder } from './types';\nimport type { RenderGraph } from './rendergraph';\nimport type { RGBlackboard } from './blackboard';\nimport type { HistoryResourceManager } from './history_resource_manager';\nimport type { DrawContext } from '../drawable';\nimport type { RenderQueue } from '../render_queue';\nimport type { Texture2D, FrameBuffer } from '@zephyr3d/device';\nimport type { ForwardPlusOptions, FrameState, ForwardPlusBuildState } from './forward_plus_builder';\n\n/**\n * Ordering helper that encapsulates the side-effect \"order token\" chain.\n *\n * Side-effect passes (SkyUpdate, ClusterLights, ...) carry no data product, so\n * they are ordered relative to one another through logical tokens rather than\n * texture reads/writes. This scope tracks the most recently emitted token so a\n * pass can chain after the previous one and (optionally) emit its own, without\n * the builder threading a mutable `orderToken` local between blocks.\n *\n * @public\n */\nexport class OrderingScope {\n /** @internal */\n private _last: Nullable<RGHandle> = null;\n\n /**\n * Declare a read on the most recently emitted ordering token, if any, to\n * order the current pass after the previous side-effect pass.\n *\n * @param builder - The pass builder of the current pass.\n */\n chainInto(builder: RGPassBuilder): void {\n if (this._last) {\n builder.read(this._last);\n }\n }\n\n /**\n * Emit a new ordering token from the current pass and record it as the latest\n * link in the chain.\n *\n * @param builder - The pass builder of the current pass.\n * @param name - Debug label for the token.\n * @returns The newly created token handle.\n */\n emit(builder: RGPassBuilder, name: string): RGHandle {\n const token = builder.createToken(name);\n this._last = token;\n return token;\n }\n\n /** The most recently emitted ordering token, or null. */\n get last(): Nullable<RGHandle> {\n return this._last;\n }\n}\n\n/**\n * Build-time context threaded through the Forward+ graph assembly.\n *\n * This aggregates everything the individual pass-build blocks previously reached\n * through enclosing function locals (`orderToken`, the mutable `depthHandle`,\n * result bundles, ...). Collecting them here is the seam that lets each pass be\n * expressed as an independent unit reading its inputs from a shared context\n * rather than from closure-captured variables.\n *\n * Handles for well-known frame resources (linear depth, scene color, ...) flow\n * through {@link RenderModuleContext.blackboard} keyed by\n * {@link ./blackboard#FrameResources}; the mutable execute-time state that is\n * not a render-graph resource stays on {@link FrameGraphContext.frame}.\n *\n * @public\n */\nexport interface RenderModuleContext {\n /** The render graph being populated for this frame. */\n readonly graph: RenderGraph;\n /** Frame draw context. */\n readonly ctx: DrawContext;\n /** The culled render queue for this frame. */\n readonly renderQueue: RenderQueue;\n /** Named registry of shared frame-resource handles (see {@link ./blackboard#FrameResources}). */\n readonly blackboard: RGBlackboard;\n /** Cross-frame history resource manager, or null when unavailable. */\n readonly history: Nullable<HistoryResourceManager<Texture2D>>;\n /** Pipeline feature toggles derived from scene/camera state. */\n readonly options: ForwardPlusOptions;\n /** Ordering-token chain for side-effect passes. */\n readonly ordering: OrderingScope;\n /** The imported backbuffer handle (graph sink). */\n readonly backbuffer: RGHandle;\n}\n\n/**\n * Full build-time context threaded through the Forward+ pipeline. Extends the\n * public {@link RenderModuleContext} with the Forward+ pipeline's internal\n * mutable state, which built-in modules read/write but custom modules should\n * not depend on.\n *\n * @internal\n */\nexport interface FrameGraphContext extends RenderModuleContext {\n /** Mutable execute-time state shared between pass callbacks. */\n readonly frame: FrameState;\n /** Mutable build-state shared between modules for non-resource intermediates. */\n readonly state: ForwardPlusBuildState;\n}\n\n/** Backend framebuffer type used by the Forward+ allocator. */\nexport type ForwardPlusFramebuffer = FrameBuffer;\n"],"names":["OrderingScope","_last","chainInto","builder","read","emit","name","token","createToken","last"],"mappings":"AAUA;;;;;;;;;;AAUC,IACM,MAAMA,aAAAA,CAAAA;qBAEX,KAAQC,GAA4B,IAAK;AAEzC;;;;;MAMAC,SAAAA,CAAUC,OAAsB,EAAQ;QACtC,IAAI,IAAI,CAACF,KAAK,EAAE;AACdE,YAAAA,OAAAA,CAAQC,IAAI,CAAC,IAAI,CAACH,KAAK,CAAA;AACzB;AACF;AAEA;;;;;;;AAOC,MACDI,IAAKF,CAAAA,OAAsB,EAAEG,IAAY,EAAY;QACnD,MAAMC,KAAAA,GAAQJ,OAAQK,CAAAA,WAAW,CAACF,IAAAA,CAAAA;QAClC,IAAI,CAACL,KAAK,GAAGM,KAAAA;QACb,OAAOA,KAAAA;AACT;8DAGA,IAAIE,IAA2B,GAAA;QAC7B,OAAO,IAAI,CAACR,KAAK;AACnB;AACF;;;;"}
|
package/dist/shaders/ssgi.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Animated interleaved-gradient-noise pair used to decorrelate SSGI rays.
|
|
3
|
-
*
|
|
4
|
-
* Produces two low-discrepancy random numbers in [0, 1) for a given fragment,
|
|
5
|
-
* advanced per sample/frame through golden-ratio sequences so the temporal
|
|
6
|
-
* resolve pass converges the Monte-Carlo estimate.
|
|
7
|
-
*
|
|
8
|
-
* @param scope - The shader scope
|
|
9
|
-
* @param fragCoord - Fragment coordinate in pixels
|
|
10
|
-
* @param seed - Sequence index (frameIndex * sampleCount + sampleIndex)
|
|
11
|
-
* @returns A vec2 of pseudo random numbers in [0, 1)
|
|
12
|
-
*
|
|
13
|
-
* @internal
|
|
14
|
-
*/ function SSGI_rand2(scope, fragCoord, seed) {
|
|
15
|
-
const pb = scope.$builder;
|
|
16
|
-
pb.func('SSGI_ign', [
|
|
17
|
-
pb.vec2('p')
|
|
18
|
-
], function() {
|
|
19
|
-
this.$return(pb.fract(pb.mul(52.9829189, pb.fract(pb.add(pb.mul(0.06711056, this.p.x), pb.mul(0.00583715, this.p.y))))));
|
|
20
|
-
});
|
|
21
|
-
pb.func('SSGI_rand2', [
|
|
22
|
-
pb.vec2('fragCoord'),
|
|
23
|
-
pb.float('seed')
|
|
24
|
-
], function() {
|
|
25
|
-
this.$l.n1 = this.SSGI_ign(this.fragCoord);
|
|
26
|
-
this.$l.n2 = this.SSGI_ign(pb.add(this.fragCoord, pb.vec2(5.588238, 5.588238)));
|
|
27
|
-
// Golden-ratio (and its square) sequences advance the pair every sample
|
|
28
|
-
this.$return(pb.fract(pb.add(pb.vec2(this.n1, this.n2), pb.mul(pb.vec2(0.61803398875, 0.38196601125), this.seed))));
|
|
29
|
-
});
|
|
30
|
-
return scope.SSGI_rand2(fragCoord, seed);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Cosine-weighted hemisphere sampling around a normal.
|
|
34
|
-
*
|
|
35
|
-
* With cosine-weighted sampling the Monte-Carlo estimator of the rendering
|
|
36
|
-
* equation's diffuse term reduces to the plain average of the sampled
|
|
37
|
-
* radiances, so the SSGI trace pass can simply accumulate hit colors.
|
|
38
|
-
*
|
|
39
|
-
* @param scope - The shader scope
|
|
40
|
-
* @param normal - Unit normal the hemisphere is oriented around
|
|
41
|
-
* @param rand - Two random numbers in [0, 1)
|
|
42
|
-
* @returns A unit direction inside the hemisphere
|
|
43
|
-
*
|
|
44
|
-
* @internal
|
|
45
|
-
*/ function SSGI_cosineSampleHemisphere(scope, normal, rand) {
|
|
46
|
-
const pb = scope.$builder;
|
|
47
|
-
pb.func('SSGI_cosineSampleHemisphere', [
|
|
48
|
-
pb.vec3('n'),
|
|
49
|
-
pb.vec2('u')
|
|
50
|
-
], function() {
|
|
51
|
-
this.$l.up = this.$choice(pb.lessThan(pb.abs(this.n.z), 0.999), pb.vec3(0, 0, 1), pb.vec3(1, 0, 0));
|
|
52
|
-
this.$l.tangent = pb.normalize(pb.cross(this.up, this.n));
|
|
53
|
-
this.$l.bitangent = pb.cross(this.n, this.tangent);
|
|
54
|
-
this.$l.r = pb.sqrt(this.u.x);
|
|
55
|
-
this.$l.phi = pb.mul(this.u.y, Math.PI * 2);
|
|
56
|
-
this.$l.dir = pb.add(pb.mul(this.tangent, pb.mul(this.r, pb.cos(this.phi))), pb.mul(this.bitangent, pb.mul(this.r, pb.sin(this.phi))), pb.mul(this.n, pb.sqrt(pb.max(0, pb.sub(1, this.u.x)))));
|
|
57
|
-
this.$return(pb.normalize(this.dir));
|
|
58
|
-
});
|
|
59
|
-
return scope.SSGI_cosineSampleHemisphere(normal, rand);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { SSGI_cosineSampleHemisphere, SSGI_rand2 };
|
|
63
|
-
//# sourceMappingURL=ssgi.js.map
|
package/dist/shaders/ssgi.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssgi.js","sources":["../../src/shaders/ssgi.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\n\n/**\n * Animated interleaved-gradient-noise pair used to decorrelate SSGI rays.\n *\n * Produces two low-discrepancy random numbers in [0, 1) for a given fragment,\n * advanced per sample/frame through golden-ratio sequences so the temporal\n * resolve pass converges the Monte-Carlo estimate.\n *\n * @param scope - The shader scope\n * @param fragCoord - Fragment coordinate in pixels\n * @param seed - Sequence index (frameIndex * sampleCount + sampleIndex)\n * @returns A vec2 of pseudo random numbers in [0, 1)\n *\n * @internal\n */\nexport function SSGI_rand2(scope: PBInsideFunctionScope, fragCoord: PBShaderExp, seed: PBShaderExp) {\n const pb = scope.$builder;\n pb.func('SSGI_ign', [pb.vec2('p')], function () {\n this.$return(\n pb.fract(\n pb.mul(52.9829189, pb.fract(pb.add(pb.mul(0.06711056, this.p.x), pb.mul(0.00583715, this.p.y))))\n )\n );\n });\n pb.func('SSGI_rand2', [pb.vec2('fragCoord'), pb.float('seed')], function () {\n this.$l.n1 = this.SSGI_ign(this.fragCoord);\n this.$l.n2 = this.SSGI_ign(pb.add(this.fragCoord, pb.vec2(5.588238, 5.588238)));\n // Golden-ratio (and its square) sequences advance the pair every sample\n this.$return(\n pb.fract(pb.add(pb.vec2(this.n1, this.n2), pb.mul(pb.vec2(0.61803398875, 0.38196601125), this.seed)))\n );\n });\n return scope.SSGI_rand2(fragCoord, seed);\n}\n\n/**\n * Cosine-weighted hemisphere sampling around a normal.\n *\n * With cosine-weighted sampling the Monte-Carlo estimator of the rendering\n * equation's diffuse term reduces to the plain average of the sampled\n * radiances, so the SSGI trace pass can simply accumulate hit colors.\n *\n * @param scope - The shader scope\n * @param normal - Unit normal the hemisphere is oriented around\n * @param rand - Two random numbers in [0, 1)\n * @returns A unit direction inside the hemisphere\n *\n * @internal\n */\nexport function SSGI_cosineSampleHemisphere(\n scope: PBInsideFunctionScope,\n normal: PBShaderExp,\n rand: PBShaderExp\n) {\n const pb = scope.$builder;\n pb.func('SSGI_cosineSampleHemisphere', [pb.vec3('n'), pb.vec2('u')], function () {\n this.$l.up = this.$choice(pb.lessThan(pb.abs(this.n.z), 0.999), pb.vec3(0, 0, 1), pb.vec3(1, 0, 0));\n this.$l.tangent = pb.normalize(pb.cross(this.up, this.n));\n this.$l.bitangent = pb.cross(this.n, this.tangent);\n this.$l.r = pb.sqrt(this.u.x);\n this.$l.phi = pb.mul(this.u.y, Math.PI * 2);\n this.$l.dir = pb.add(\n pb.mul(this.tangent, pb.mul(this.r, pb.cos(this.phi))),\n pb.mul(this.bitangent, pb.mul(this.r, pb.sin(this.phi))),\n pb.mul(this.n, pb.sqrt(pb.max(0, pb.sub(1, this.u.x))))\n );\n this.$return(pb.normalize(this.dir));\n });\n return scope.SSGI_cosineSampleHemisphere(normal, rand);\n}\n"],"names":["SSGI_rand2","scope","fragCoord","seed","pb","$builder","func","vec2","$return","fract","mul","add","p","x","y","float","$l","n1","SSGI_ign","n2","SSGI_cosineSampleHemisphere","normal","rand","vec3","up","$choice","lessThan","abs","n","z","tangent","normalize","cross","bitangent","r","sqrt","u","phi","Math","PI","dir","cos","sin","max","sub"],"mappings":"AAEA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,KAA4B,EAAEC,SAAsB,EAAEC,IAAiB,EAAA;IAChG,MAAMC,EAAAA,GAAKH,MAAMI,QAAQ;IACzBD,EAAGE,CAAAA,IAAI,CAAC,UAAY,EAAA;AAACF,QAAAA,EAAAA,CAAGG,IAAI,CAAC,GAAA;KAAK,EAAE,WAAA;AAClC,QAAA,IAAI,CAACC,OAAO,CACVJ,EAAAA,CAAGK,KAAK,CACNL,EAAAA,CAAGM,GAAG,CAAC,YAAYN,EAAGK,CAAAA,KAAK,CAACL,EAAAA,CAAGO,GAAG,CAACP,EAAAA,CAAGM,GAAG,CAAC,UAAY,EAAA,IAAI,CAACE,CAAC,CAACC,CAAC,CAAA,EAAGT,EAAGM,CAAAA,GAAG,CAAC,UAAY,EAAA,IAAI,CAACE,CAAC,CAACE,CAAC,C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AACL,GAAG,CAAA,CAAA,CAAA,EACrDjC,EAAGM,CAAAA,GAAG,CAAC,IAAI,CAACkB,CAAC,EAAExB,EAAG+B,CAAAA,IAAI,CAAC/B,EAAAA,CAAGuC,GAAG,CAAC,CAAA,EAAGvC,EAAGwC,CAAAA,GAAG,CAAC,CAAG,EAAA,IAAI,CAACR,CAAC,CAACvB,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA;QAErD,IAAI,CAACL,OAAO,CAACJ,EAAAA,CAAG2B,SAAS,CAAC,IAAI,CAACS,GAAG,CAAA,CAAA;AACpC,KAAA,CAAA;IACA,OAAOvC,KAAAA,CAAMmB,2BAA2B,CAACC,MAAQC,EAAAA,IAAAA,CAAAA;AACnD;;;;"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Matrix4x4 } from '@zephyr3d/base';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Shared helpers for validating SSGI temporal history across frames.
|
|
5
|
-
*
|
|
6
|
-
* SSGI stores the surface depth of a frame as that frame's view-space Z (the
|
|
7
|
-
* distance along the camera forward axis, in world units). Comparing such a
|
|
8
|
-
* value against the *current* frame's view-space Z is only meaningful while the
|
|
9
|
-
* camera is still: rotating the camera turns the forward axis, so a static world
|
|
10
|
-
* point changes its view-space Z by roughly
|
|
11
|
-
*
|
|
12
|
-
* dz ~ dTheta * viewZ * tan(halfFovX) * |ndc.x|
|
|
13
|
-
*
|
|
14
|
-
* which is zero at the screen center and grows with both depth and screen
|
|
15
|
-
* eccentricity. At a plain mouse-look rate that already exceeds any reasonable
|
|
16
|
-
* absolute tolerance for distant off-center pixels, so history gets rejected in
|
|
17
|
-
* screen-edge bands even though it is perfectly valid. Every consumer therefore
|
|
18
|
-
* has to convert the current depth into the *previous* frame's view space before
|
|
19
|
-
* comparing.
|
|
20
|
-
*
|
|
21
|
-
* @internal
|
|
22
|
-
*/ /**
|
|
23
|
-
* Relative share of the compared depth added to the absolute tolerance. 2% keeps
|
|
24
|
-
* a 10m surface within 0.2m, comfortably above rgba16f depth quantization while
|
|
25
|
-
* still separating surfaces that a bounce should not share.
|
|
26
|
-
* @internal
|
|
27
|
-
*/ const SSGI_DEPTH_TOLERANCE_SLOPE = 0.02;
|
|
28
|
-
/**
|
|
29
|
-
* `prevVP * inverse(currentVP)`: maps a current-frame clip position onto the
|
|
30
|
-
* previous frame's clip space, where `w` is the previous view-space Z.
|
|
31
|
-
*
|
|
32
|
-
* The current half uses the jittered inverse VP because every consumer
|
|
33
|
-
* reconstructs from a depth buffer that was rasterized with jitter applied.
|
|
34
|
-
* Jitter only shifts clip x/y, so pairing it with the unjittered `prevVPMatrix`
|
|
35
|
-
* still produces the correct `w`.
|
|
36
|
-
*
|
|
37
|
-
* Falls back to the current VP before any previous transform exists, which
|
|
38
|
-
* degenerates into comparing the current depth against itself - harmless,
|
|
39
|
-
* because the history textures are empty on that frame anyway.
|
|
40
|
-
*
|
|
41
|
-
* @param ctx - Current draw context
|
|
42
|
-
* @returns The reprojection matrix
|
|
43
|
-
* @internal
|
|
44
|
-
*/ function ssgiCurrentToPrevClipMatrix(ctx) {
|
|
45
|
-
const camera = ctx.camera;
|
|
46
|
-
const prevVP = camera.prevVPMatrix ?? camera.viewProjectionMatrix;
|
|
47
|
-
return Matrix4x4.multiply(prevVP, camera.jitteredInvVPMatrix);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Converts the current frame's linear depth at `uv` into the view-space Z it
|
|
51
|
-
* would have had in the previous frame, so it can be compared against the depth
|
|
52
|
-
* stored in the SSGI surface history.
|
|
53
|
-
*
|
|
54
|
-
* `currentToPrevClipMatrix` must be `prevViewProjection * inverse(currentViewProjection)`,
|
|
55
|
-
* mapping a current-frame clip position onto the previous frame's clip space. In
|
|
56
|
-
* a perspective projection the resulting `w` is exactly the previous view-space
|
|
57
|
-
* Z in world units, which is the quantity the surface pass wrote.
|
|
58
|
-
*
|
|
59
|
-
* @param scope - Current shader scope
|
|
60
|
-
* @param currentToPrevClipMatrix - `prevVP * invCurrentVP`, as a mat4
|
|
61
|
-
* @param uv - Screen uv of the pixel being validated
|
|
62
|
-
* @param linearDepth - Normalized linear depth (viewZ / far) at `uv`
|
|
63
|
-
* @param nearFar - Camera near and far planes
|
|
64
|
-
* @returns Previous-frame view-space Z, in world units
|
|
65
|
-
* @internal
|
|
66
|
-
*/ function ssgiPreviousViewDepth(scope, currentToPrevClipMatrix, uv, linearDepth, nearFar) {
|
|
67
|
-
const pb = scope.$builder;
|
|
68
|
-
const funcName = 'Z_ssgiPreviousViewDepth';
|
|
69
|
-
pb.func(funcName, [
|
|
70
|
-
pb.mat4('toPrevClip'),
|
|
71
|
-
pb.vec2('uv'),
|
|
72
|
-
pb.float('linearDepth'),
|
|
73
|
-
pb.vec2('nearFar')
|
|
74
|
-
], function() {
|
|
75
|
-
// Invert the perspective depth mapping. `linearDepth` is the normalized
|
|
76
|
-
// viewZ / far that the depth prepass stored, so the non-linear depth is
|
|
77
|
-
// (near / linearDepth - far) / (near - far) - identical to the
|
|
78
|
-
// reconstruction in SSGI_getPosition. Operating on the normalized value
|
|
79
|
-
// directly matters: converting to world-unit viewZ first and reusing the
|
|
80
|
-
// same expression silently drops a factor of `far`, which pins every
|
|
81
|
-
// pixel at the far plane and rejects all history.
|
|
82
|
-
this.$l.safeLinearDepth = pb.max(this.linearDepth, 1e-6);
|
|
83
|
-
this.$l.ndcZ = pb.div(pb.sub(pb.div(this.nearFar.x, this.safeLinearDepth), this.nearFar.y), pb.sub(this.nearFar.x, this.nearFar.y));
|
|
84
|
-
this.$l.clipPos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.ndcZ, 0, 1), 2), 1), 1);
|
|
85
|
-
// clipPos is already normalized (w = 1 after the NDC divide), so the
|
|
86
|
-
// reprojected w is directly the previous view-space Z.
|
|
87
|
-
this.$return(pb.mul(this.toPrevClip, this.clipPos).w);
|
|
88
|
-
});
|
|
89
|
-
return scope[funcName](currentToPrevClipMatrix, uv, linearDepth, nearFar);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Depth tolerance for a history comparison at a given depth.
|
|
93
|
-
*
|
|
94
|
-
* A single absolute tolerance cannot serve the whole depth range: it is far too
|
|
95
|
-
* loose next to the camera, where a few centimetres separate distinct surfaces,
|
|
96
|
-
* and too tight in the distance, where depth precision and residual reprojection
|
|
97
|
-
* error both scale with viewZ. Scaling the floor by depth keeps the test at a
|
|
98
|
-
* roughly constant relative strictness.
|
|
99
|
-
*
|
|
100
|
-
* @param scope - Current shader scope
|
|
101
|
-
* @param baseTolerance - Configured absolute tolerance, in world units
|
|
102
|
-
* @param viewDepth - View-space Z the comparison happens at, in world units
|
|
103
|
-
* @returns Effective tolerance, in world units
|
|
104
|
-
* @internal
|
|
105
|
-
*/ function ssgiDepthTolerance(scope, baseTolerance, viewDepth) {
|
|
106
|
-
const pb = scope.$builder;
|
|
107
|
-
const funcName = 'Z_ssgiDepthTolerance';
|
|
108
|
-
pb.func(funcName, [
|
|
109
|
-
pb.float('baseTolerance'),
|
|
110
|
-
pb.float('viewDepth')
|
|
111
|
-
], function() {
|
|
112
|
-
this.$return(pb.max(pb.max(this.baseTolerance, 1e-4), pb.mul(pb.abs(this.viewDepth), SSGI_DEPTH_TOLERANCE_SLOPE)));
|
|
113
|
-
});
|
|
114
|
-
return scope[funcName](baseTolerance, viewDepth);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export { SSGI_DEPTH_TOLERANCE_SLOPE, ssgiCurrentToPrevClipMatrix, ssgiDepthTolerance, ssgiPreviousViewDepth };
|
|
118
|
-
//# sourceMappingURL=ssgi_reprojection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssgi_reprojection.js","sources":["../../src/shaders/ssgi_reprojection.ts"],"sourcesContent":["import { Matrix4x4 } from '@zephyr3d/base';\nimport type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\nimport type { DrawContext } from '../render/drawable';\n\n/**\n * Shared helpers for validating SSGI temporal history across frames.\n *\n * SSGI stores the surface depth of a frame as that frame's view-space Z (the\n * distance along the camera forward axis, in world units). Comparing such a\n * value against the *current* frame's view-space Z is only meaningful while the\n * camera is still: rotating the camera turns the forward axis, so a static world\n * point changes its view-space Z by roughly\n *\n * dz ~ dTheta * viewZ * tan(halfFovX) * |ndc.x|\n *\n * which is zero at the screen center and grows with both depth and screen\n * eccentricity. At a plain mouse-look rate that already exceeds any reasonable\n * absolute tolerance for distant off-center pixels, so history gets rejected in\n * screen-edge bands even though it is perfectly valid. Every consumer therefore\n * has to convert the current depth into the *previous* frame's view space before\n * comparing.\n *\n * @internal\n */\n\n/**\n * Relative share of the compared depth added to the absolute tolerance. 2% keeps\n * a 10m surface within 0.2m, comfortably above rgba16f depth quantization while\n * still separating surfaces that a bounce should not share.\n * @internal\n */\nexport const SSGI_DEPTH_TOLERANCE_SLOPE = 0.02;\n\n/**\n * `prevVP * inverse(currentVP)`: maps a current-frame clip position onto the\n * previous frame's clip space, where `w` is the previous view-space Z.\n *\n * The current half uses the jittered inverse VP because every consumer\n * reconstructs from a depth buffer that was rasterized with jitter applied.\n * Jitter only shifts clip x/y, so pairing it with the unjittered `prevVPMatrix`\n * still produces the correct `w`.\n *\n * Falls back to the current VP before any previous transform exists, which\n * degenerates into comparing the current depth against itself - harmless,\n * because the history textures are empty on that frame anyway.\n *\n * @param ctx - Current draw context\n * @returns The reprojection matrix\n * @internal\n */\nexport function ssgiCurrentToPrevClipMatrix(ctx: DrawContext): Matrix4x4 {\n const camera = ctx.camera;\n const prevVP = camera.prevVPMatrix ?? camera.viewProjectionMatrix;\n return Matrix4x4.multiply(prevVP, camera.jitteredInvVPMatrix);\n}\n\n/**\n * Converts the current frame's linear depth at `uv` into the view-space Z it\n * would have had in the previous frame, so it can be compared against the depth\n * stored in the SSGI surface history.\n *\n * `currentToPrevClipMatrix` must be `prevViewProjection * inverse(currentViewProjection)`,\n * mapping a current-frame clip position onto the previous frame's clip space. In\n * a perspective projection the resulting `w` is exactly the previous view-space\n * Z in world units, which is the quantity the surface pass wrote.\n *\n * @param scope - Current shader scope\n * @param currentToPrevClipMatrix - `prevVP * invCurrentVP`, as a mat4\n * @param uv - Screen uv of the pixel being validated\n * @param linearDepth - Normalized linear depth (viewZ / far) at `uv`\n * @param nearFar - Camera near and far planes\n * @returns Previous-frame view-space Z, in world units\n * @internal\n */\nexport function ssgiPreviousViewDepth(\n scope: PBInsideFunctionScope,\n currentToPrevClipMatrix: PBShaderExp,\n uv: PBShaderExp,\n linearDepth: PBShaderExp,\n nearFar: PBShaderExp\n): PBShaderExp {\n const pb = scope.$builder;\n const funcName = 'Z_ssgiPreviousViewDepth';\n pb.func(\n funcName,\n [pb.mat4('toPrevClip'), pb.vec2('uv'), pb.float('linearDepth'), pb.vec2('nearFar')],\n function () {\n // Invert the perspective depth mapping. `linearDepth` is the normalized\n // viewZ / far that the depth prepass stored, so the non-linear depth is\n // (near / linearDepth - far) / (near - far) - identical to the\n // reconstruction in SSGI_getPosition. Operating on the normalized value\n // directly matters: converting to world-unit viewZ first and reusing the\n // same expression silently drops a factor of `far`, which pins every\n // pixel at the far plane and rejects all history.\n this.$l.safeLinearDepth = pb.max(this.linearDepth, 1e-6);\n this.$l.ndcZ = pb.div(\n pb.sub(pb.div(this.nearFar.x, this.safeLinearDepth), this.nearFar.y),\n pb.sub(this.nearFar.x, this.nearFar.y)\n );\n this.$l.clipPos = pb.vec4(\n pb.sub(pb.mul(this.uv, 2), pb.vec2(1)),\n pb.sub(pb.mul(pb.clamp(this.ndcZ, 0, 1), 2), 1),\n 1\n );\n // clipPos is already normalized (w = 1 after the NDC divide), so the\n // reprojected w is directly the previous view-space Z.\n this.$return(pb.mul(this.toPrevClip, this.clipPos).w);\n }\n );\n return scope[funcName](currentToPrevClipMatrix, uv, linearDepth, nearFar) as PBShaderExp;\n}\n\n/**\n * Depth tolerance for a history comparison at a given depth.\n *\n * A single absolute tolerance cannot serve the whole depth range: it is far too\n * loose next to the camera, where a few centimetres separate distinct surfaces,\n * and too tight in the distance, where depth precision and residual reprojection\n * error both scale with viewZ. Scaling the floor by depth keeps the test at a\n * roughly constant relative strictness.\n *\n * @param scope - Current shader scope\n * @param baseTolerance - Configured absolute tolerance, in world units\n * @param viewDepth - View-space Z the comparison happens at, in world units\n * @returns Effective tolerance, in world units\n * @internal\n */\nexport function ssgiDepthTolerance(\n scope: PBInsideFunctionScope,\n baseTolerance: PBShaderExp,\n viewDepth: PBShaderExp\n): PBShaderExp {\n const pb = scope.$builder;\n const funcName = 'Z_ssgiDepthTolerance';\n pb.func(funcName, [pb.float('baseTolerance'), pb.float('viewDepth')], function () {\n this.$return(\n pb.max(pb.max(this.baseTolerance, 1e-4), pb.mul(pb.abs(this.viewDepth), SSGI_DEPTH_TOLERANCE_SLOPE))\n );\n });\n return scope[funcName](baseTolerance, viewDepth) as PBShaderExp;\n}\n"],"names":["SSGI_DEPTH_TOLERANCE_SLOPE","ssgiCurrentToPrevClipMatrix","ctx","camera","prevVP","prevVPMatrix","viewProjectionMatrix","Matrix4x4","multiply","jitteredInvVPMatrix","ssgiPreviousViewDepth","scope","currentToPrevClipMatrix","uv","linearDepth","nearFar","pb","$builder","funcName","func","mat4","vec2","float","$l","safeLinearDepth","max","ndcZ","div","sub","x","y","clipPos","vec4","mul","clamp","$return","toPrevClip","w","ssgiDepthTolerance","baseTolerance","viewDepth","abs"],"mappings":";;AAIA;;;;;;;;;;;;;;;;;;;;;;;;IA2BaA,MAAAA,0BAAAA,GAA6B;AAE1C;;;;;;;;;;;;;;;;IAiBO,SAASC,2BAAAA,CAA4BC,GAAgB,EAAA;IAC1D,MAAMC,MAAAA,GAASD,IAAIC,MAAM;AACzB,IAAA,MAAMC,MAASD,GAAAA,MAAAA,CAAOE,YAAY,IAAIF,OAAOG,oBAAoB;AACjE,IAAA,OAAOC,SAAUC,CAAAA,QAAQ,CAACJ,MAAAA,EAAQD,OAAOM,mBAAmB,CAAA;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