@zephyr3d/scene 0.9.6 → 0.9.8
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 +52 -55
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +92 -32
- package/dist/animation/joint_dynamics/controller.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/joint_dynamics/joint_dynamics_system.js +57 -19
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +71 -27
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics_modifier.js +4 -3
- package/dist/animation/joint_dynamics_modifier.js.map +1 -1
- package/dist/animation/skeleton.js +7 -10
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/app/engine.js +3 -9
- package/dist/app/engine.js.map +1 -1
- package/dist/app/scriptregistry.js +47 -16
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +3 -1
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +346 -7
- package/dist/asset/model.js.map +1 -1
- package/dist/avatar/wardrobe.js +7 -3
- package/dist/avatar/wardrobe.js.map +1 -1
- package/dist/camera/camera.js +240 -34
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1350 -622
- package/dist/index.js +6 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +1 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +23 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +178 -23
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +4 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +2 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +100 -27
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +1 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +276 -65
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +3 -3
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +2 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/mtoon.js +574 -0
- package/dist/material/mtoon.js.map +1 -0
- package/dist/material/pbrblueprint.js +494 -331
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +118 -100
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +45 -15
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/subsurfaceprofile.js +812 -0
- package/dist/material/subsurfaceprofile.js.map +1 -0
- package/dist/material/unlit.js +1 -1
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/compositor.js +46 -11
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/ssr.js +413 -87
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1053 -0
- package/dist/posteffect/sss.js.map +1 -0
- package/dist/posteffect/taa.js +61 -60
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +63 -12
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable.js +1 -5
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/drawable_mixin.js +2 -1
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +2 -1
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +2 -1
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +105 -18
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +51 -8
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +73 -59
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +8 -0
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +481 -95
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +55 -0
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +3 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +10 -4
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/sky.js +31 -1
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +23 -5
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +4 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +3 -1
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +11 -1
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +21 -3
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +29 -14
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/meshdrawable.js +6 -0
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +5 -2
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +5 -3
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +3 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +6 -5
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +4 -2
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +2 -1
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +4 -2
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +4 -2
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +26 -393
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +112 -12
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +2 -2
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +19 -10
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +58 -7
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js +6 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadow_region.js +229 -0
- package/dist/shadow/shadow_region.js.map +1 -0
- package/dist/shadow/shadowmapper.js +67 -59
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +45 -19
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +8 -8
- package/dist/utility/blueprint/common/constants.js.map +1 -1
- package/dist/utility/blueprint/material/pbr.js +31 -4
- package/dist/utility/blueprint/material/pbr.js.map +1 -1
- package/dist/utility/blueprint/material/texture.js +1 -17
- package/dist/utility/blueprint/material/texture.js.map +1 -1
- package/dist/utility/serialization/manager.js +66 -98
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +5 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +4 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +249 -54
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +37 -1
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +42 -3
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +1112 -646
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +7 -4
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +31 -12
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +4 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +3 -1
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +18 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -3
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +5 -2
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -1
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +4 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/textures/ltcdata.js +6 -0
- package/dist/utility/textures/ltcdata.js.map +1 -0
- package/dist/utility/textures/ltclut.js +61 -0
- package/dist/utility/textures/ltclut.js.map +1 -0
- package/dist/values.js +9 -1
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sources":["../../src/render/renderer.ts"],"sourcesContent":["import { CopyBlitter } from '../blitter';\r\nimport type { DrawContext } from './drawable';\r\nimport type { Scene } from '../scene';\r\nimport type { Camera } from '../camera';\r\nimport { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { getDevice } from '../app/api';\r\nimport { executeForwardPlusGraph } from './rendergraph/forward_plus_builder';\r\n\r\n/**\r\n * Forward render scheme\r\n * @internal\r\n */\r\nexport class SceneRenderer {\r\n /**\r\n * Renders a scene by given camera\r\n * @param scene - The scene to render\r\n * @param camera - The camera that will be used to render the scene\r\n */\r\n static renderScene(scene: Scene, camera: Camera): void {\r\n const device = getDevice();\r\n const colorFormat =\r\n camera.HDR && device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';\r\n const depthFormat = device.getDeviceCaps().framebufferCaps.supportDepth32floatStencil8\r\n ? 'd32fs8'\r\n : 'd24s8';\r\n const globalBindGroupAllocator = GlobalBindGroupAllocator.get();\r\n scene.frameUpdate();\r\n scene.frameUpdatePerCamera(camera);\r\n if (camera && !device.isContextLost()) {\r\n const defaultViewport = (!camera.TAA || device.type === 'webgl') && !camera.viewport && !camera.scissor;\r\n const renderX = camera.viewport ? device.screenXToDevice(camera.viewport[0]) : 0;\r\n const renderY = camera.viewport ? device.screenYToDevice(camera.viewport[1]) : 0;\r\n const renderWidth = camera.viewport\r\n ? device.screenXToDevice(camera.viewport[2])\r\n : device.getDrawingBufferWidth();\r\n const renderHeight = camera.viewport\r\n ? device.screenYToDevice(camera.viewport[3])\r\n : device.getDrawingBufferHeight();\r\n if (renderWidth <= 0 || renderHeight <= 0) {\r\n camera.getPickResultResolveFunc()?.(null);\r\n return;\r\n }\r\n const tmpFramebuffer = defaultViewport\r\n ? null\r\n : device.pool.fetchTemporalFramebuffer(false, renderWidth, renderHeight, colorFormat, depthFormat);\r\n const originFramebuffer = device.getFramebuffer();\r\n if (tmpFramebuffer) {\r\n device.pushDeviceStates();\r\n device.setFramebuffer(tmpFramebuffer);\r\n }\r\n device.clearFrameBuffer(camera.clearColor, camera.clearDepth, camera.clearStencil);\r\n const SSR = camera.SSR && scene.env.light.envLight && scene.env.light.envLight.hasRadiance();\r\n const ctx: DrawContext = {\r\n device,\r\n scene,\r\n renderWidth,\r\n renderHeight,\r\n oit: null,\r\n motionVectors: device.type !== 'webgl' && (camera.TAA || camera.motionBlur),\r\n HiZ: camera.HiZ && device.type !== 'webgl',\r\n HiZTexture: null,\r\n globalBindGroupAllocator,\r\n camera,\r\n compositor: camera.compositor,\r\n queue: 0,\r\n lightBlending: false,\r\n renderPass: null,\r\n renderPassHash: null,\r\n flip: false,\r\n depthFormat,\r\n colorFormat,\r\n drawEnvLight: false,\r\n env: null,\r\n materialFlags: 0,\r\n SSR,\r\n SSRCalcThickness: SSR && camera.ssrCalcThickness,\r\n SSRRoughnessTexture: device.pool.fetchTemporalTexture2D(\r\n true,\r\n 'rgba8unorm',\r\n renderWidth,\r\n renderHeight\r\n ),\r\n SSRNormalTexture: device.pool.fetchTemporalTexture2D(true, 'rgba8unorm', renderWidth, renderHeight),\r\n finalFramebuffer: device.getFramebuffer(),\r\n intermediateFramebuffer: null\r\n };\r\n this._renderScene(ctx);\r\n if (tmpFramebuffer) {\r\n device.popDeviceStates();\r\n const oversizedViewport =\r\n renderX < 0 ||\r\n renderY < 0 ||\r\n renderX + renderWidth > device.getDrawingBufferWidth() ||\r\n renderY + renderHeight > device.getDrawingBufferHeight();\r\n const blitter = new CopyBlitter();\r\n if (oversizedViewport) {\r\n blitter.destRect = [renderX, renderY, renderWidth, renderHeight];\r\n } else {\r\n blitter.viewport = camera.viewport ? camera.viewport.slice() : null;\r\n }\r\n blitter.scissor = camera.scissor ? camera.scissor.slice() : null;\r\n blitter.srgbOut = !originFramebuffer;\r\n blitter.blit(\r\n tmpFramebuffer.getColorAttachments()[0],\r\n originFramebuffer ?? null,\r\n fetchSampler('clamp_nearest_nomip')\r\n );\r\n device.pool.releaseFrameBuffer(tmpFramebuffer);\r\n }\r\n }\r\n GlobalBindGroupAllocator.release(globalBindGroupAllocator);\r\n }\r\n /** @internal */\r\n protected static _renderScene(ctx: DrawContext) {\r\n executeForwardPlusGraph(ctx);\r\n }\r\n}\r\n"],"names":["SceneRenderer","renderScene","scene","camera","device","getDevice","colorFormat","HDR","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","depthFormat","framebufferCaps","supportDepth32floatStencil8","globalBindGroupAllocator","GlobalBindGroupAllocator","get","frameUpdate","frameUpdatePerCamera","isContextLost","defaultViewport","TAA","type","viewport","scissor","renderX","screenXToDevice","renderY","screenYToDevice","renderWidth","getDrawingBufferWidth","renderHeight","getDrawingBufferHeight","getPickResultResolveFunc","tmpFramebuffer","pool","fetchTemporalFramebuffer","originFramebuffer","getFramebuffer","pushDeviceStates","setFramebuffer","clearFrameBuffer","clearColor","clearDepth","clearStencil","SSR","env","light","envLight","hasRadiance","ctx","oit","motionVectors","motionBlur","HiZ","HiZTexture","compositor","queue","lightBlending","renderPass","renderPassHash","flip","drawEnvLight","materialFlags","SSRCalcThickness","ssrCalcThickness","SSRRoughnessTexture","fetchTemporalTexture2D","SSRNormalTexture","finalFramebuffer","intermediateFramebuffer","_renderScene","popDeviceStates","oversizedViewport","blitter","CopyBlitter","destRect","slice","srgbOut","blit","getColorAttachments","fetchSampler","releaseFrameBuffer","release","executeForwardPlusGraph"],"mappings":";;;;;;;;;AASA;;;AAGC,IACM,MAAMA,aAAAA,CAAAA;AACX;;;;AAIC,MACD,OAAOC,WAAAA,CAAYC,KAAY,EAAEC,MAAc,EAAQ;AACrD,QAAA,MAAMC,MAASC,GAAAA,SAAAA,EAAAA;QACf,MAAMC,WAAAA,GACJH,MAAOI,CAAAA,GAAG,IAAIH,MAAAA,CAAOI,aAAa,EAAA,CAAGC,WAAW,CA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oBACL2C,OAAQnD,CAAAA,QAAQ,GAAGpB,MAAOoB,CAAAA,QAAQ,GAAGpB,MAAOoB,CAAAA,QAAQ,CAACsD,KAAK,EAAK,GAAA,IAAA;AACjE;gBACAH,OAAQlD,CAAAA,OAAO,GAAGrB,MAAOqB,CAAAA,OAAO,GAAGrB,MAAOqB,CAAAA,OAAO,CAACqD,KAAK,EAAK,GAAA,IAAA;gBAC5DH,OAAQI,CAAAA,OAAO,GAAG,CAACzC,iBAAAA;gBACnBqC,OAAQK,CAAAA,IAAI,CACV7C,cAAAA,CAAe8C,mBAAmB,EAAE,CAAC,CAAE,CAAA,EACvC3C,iBAAqB,IAAA,IAAA,EACrB4C,YAAa,CAAA,qBAAA,CAAA,CAAA;gBAEf7E,MAAO+B,CAAAA,IAAI,CAAC+C,kBAAkB,CAAChD,cAAAA,CAAAA;AACjC;AACF;AACAnB,QAAAA,wBAAAA,CAAyBoE,OAAO,CAACrE,wBAAAA,CAAAA;AACnC;AACA,qBACA,OAAiByD,YAAarB,CAAAA,GAAgB,EAAE;QAC9CkC,uBAAwBlC,CAAAA,GAAAA,CAAAA;AAC1B;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"renderer.js","sources":["../../src/render/renderer.ts"],"sourcesContent":["import type { TextureFormat } from '@zephyr3d/device';\r\nimport { CopyBlitter } from '../blitter';\r\nimport type { DrawContext } from './drawable';\r\nimport type { Scene } from '../scene';\r\nimport type { Camera } from '../camera';\r\nimport { GlobalBindGroupAllocator } from './globalbindgroup_allocator';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { getDevice } from '../app/api';\r\nimport { executeForwardPlusGraph } from './rendergraph/forward_plus_builder';\r\n\r\n/**\r\n * Forward render scheme\r\n * @internal\r\n */\r\nexport class SceneRenderer {\r\n /**\r\n * Renders a scene by given camera\r\n * @param scene - The scene to render\r\n * @param camera - The camera that will be used to render the scene\r\n */\r\n static renderScene(scene: Scene, camera: Camera): void {\r\n const device = getDevice();\r\n const halfFloatColorBuffer = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer;\r\n const colorFormat = camera.HDR && halfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';\r\n const depthFormat = device.getDeviceCaps().framebufferCaps.supportDepth32floatStencil8\r\n ? 'd32fs8'\r\n : 'd24s8';\r\n const globalBindGroupAllocator = GlobalBindGroupAllocator.get();\r\n scene.frameUpdate();\r\n scene.frameUpdatePerCamera(camera);\r\n if (camera && !device.isContextLost()) {\r\n const defaultViewport = (!camera.TAA || device.type === 'webgl') && !camera.viewport && !camera.scissor;\r\n const renderX = camera.viewport ? device.screenXToDevice(camera.viewport[0]) : 0;\r\n const renderY = camera.viewport ? device.screenYToDevice(camera.viewport[1]) : 0;\r\n const renderWidth = camera.viewport\r\n ? device.screenXToDevice(camera.viewport[2])\r\n : device.getDrawingBufferWidth();\r\n const renderHeight = camera.viewport\r\n ? device.screenYToDevice(camera.viewport[3])\r\n : device.getDrawingBufferHeight();\r\n if (renderWidth > 0 && renderHeight > 0) {\r\n const tmpFramebuffer = defaultViewport\r\n ? null\r\n : device.pool.fetchTemporalFramebuffer(false, renderWidth, renderHeight, colorFormat, depthFormat);\r\n const originFramebuffer = device.getFramebuffer();\r\n if (tmpFramebuffer) {\r\n device.pushDeviceStates();\r\n device.setFramebuffer(tmpFramebuffer);\r\n }\r\n device.clearFrameBuffer(camera.clearColor, camera.clearDepth, camera.clearStencil);\r\n const SSR = camera.SSR && scene.env.light.envLight && scene.env.light.envLight.hasRadiance();\r\n const SSS = camera.SSS;\r\n const glossySurfaceFormat: TextureFormat = halfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';\r\n const ctx: DrawContext = {\r\n device,\r\n scene,\r\n renderWidth,\r\n renderHeight,\r\n oit: null,\r\n motionVectors:\r\n device.type !== 'webgl' && (camera.TAA || camera.motionBlur || (SSR && camera.ssrTemporal)),\r\n HiZ: camera.HiZ && device.type !== 'webgl',\r\n HiZTexture: null,\r\n globalBindGroupAllocator,\r\n camera,\r\n compositor: camera.compositor,\r\n queue: 0,\r\n lightBlending: false,\r\n renderPass: null,\r\n renderPassHash: null,\r\n flip: false,\r\n depthFormat,\r\n colorFormat,\r\n drawEnvLight: false,\r\n env: null,\r\n sunLight: null,\r\n primaryDirectionalLight: null,\r\n primaryTransmissionLight: null,\r\n materialFlags: 0,\r\n SSR,\r\n SSS,\r\n SSRCalcThickness: SSR && camera.ssrCalcThickness,\r\n SSRRoughnessTexture: SSR\r\n ? device.pool.fetchTemporalTexture2D(true, glossySurfaceFormat, renderWidth, renderHeight)\r\n : null,\r\n SSRNormalTexture: SSR\r\n ? device.pool.fetchTemporalTexture2D(true, glossySurfaceFormat, renderWidth, renderHeight)\r\n : null,\r\n SSSProfileTexture: null,\r\n SSSParamTexture: null,\r\n SSSDiffuseTexture: null,\r\n SSSTransmissionTexture: null,\r\n ssrSDFBoxBuffer: null,\r\n ssrSDFBoxCount: 0,\r\n finalFramebuffer: device.getFramebuffer(),\r\n intermediateFramebuffer: null\r\n };\r\n this._renderScene(ctx);\r\n if (tmpFramebuffer) {\r\n device.popDeviceStates();\r\n const oversizedViewport =\r\n renderX < 0 ||\r\n renderY < 0 ||\r\n renderX + renderWidth > device.getDrawingBufferWidth() ||\r\n renderY + renderHeight > device.getDrawingBufferHeight();\r\n const blitter = new CopyBlitter();\r\n if (oversizedViewport) {\r\n blitter.destRect = [renderX, renderY, renderWidth, renderHeight];\r\n } else {\r\n blitter.viewport = camera.viewport ? camera.viewport.slice() : null;\r\n }\r\n blitter.scissor = camera.scissor ? camera.scissor.slice() : null;\r\n blitter.srgbOut = !originFramebuffer;\r\n blitter.blit(\r\n tmpFramebuffer.getColorAttachments()[0],\r\n originFramebuffer ?? null,\r\n fetchSampler('clamp_nearest_nomip')\r\n );\r\n device.pool.releaseFrameBuffer(tmpFramebuffer);\r\n }\r\n } else {\r\n camera.getPickResultResolveFunc()?.(null);\r\n return;\r\n }\r\n }\r\n GlobalBindGroupAllocator.release(globalBindGroupAllocator);\r\n }\r\n\r\n /** @internal */\r\n protected static _renderScene(ctx: DrawContext): void {\r\n executeForwardPlusGraph(ctx);\r\n }\r\n}\r\n"],"names":["SceneRenderer","renderScene","scene","camera","device","getDevice","halfFloatColorBuffer","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","colorFormat","HDR","depthFormat","framebufferCaps","supportDepth32floatStencil8","globalBindGroupAllocator","GlobalBindGroupAllocator","get","frameUpdate","frameUpdatePerCamera","isContextLost","defaultViewport","TAA","type","viewport","scissor","renderX","screenXToDevice","renderY","screenYToDevice","renderWidth","getDrawingBufferWidth","renderHeight","getDrawingBufferHeight","tmpFramebuffer","pool","fetchTemporalFramebuffer","originFramebuffer","getFramebuffer","pushDeviceStates","setFramebuffer","clearFrameBuffer","clearColor","clearDepth","clearStencil","SSR","env","light","envLight","hasRadiance","SSS","glossySurfaceFormat","ctx","oit","motionVectors","motionBlur","ssrTemporal","HiZ","HiZTexture","compositor","queue","lightBlending","renderPass","renderPassHash","flip","drawEnvLight","sunLight","primaryDirectionalLight","primaryTransmissionLight","materialFlags","SSRCalcThickness","ssrCalcThickness","SSRRoughnessTexture","fetchTemporalTexture2D","SSRNormalTexture","SSSProfileTexture","SSSParamTexture","SSSDiffuseTexture","SSSTransmissionTexture","ssrSDFBoxBuffer","ssrSDFBoxCount","finalFramebuffer","intermediateFramebuffer","_renderScene","popDeviceStates","oversizedViewport","blitter","CopyBlitter","destRect","slice","srgbOut","blit","getColorAttachments","fetchSampler","releaseFrameBuffer","getPickResultResolveFunc","release","executeForwardPlusGraph"],"mappings":";;;;;;;;;AAUA;;;AAGC,IACM,MAAMA,aAAAA,CAAAA;AACX;;;;AAIC,MACD,OAAOC,WAAAA,CAAYC,KAAY,EAAEC,MAAc,EAAQ;AACrD,QAAA,MAAMC,MAASC,GAAAA,SAAAA,EAAAA;AACf,QAAA,MAAMC,uBAAuBF,MAAOG,CAAAA,aAAa,EAAGC,CAAAA,WAAW,CAACC,2BAA2B;AAC3F,QAAA,MAAMC,WA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AwB7C,CAAAA,GAAAA,CAAAA;AAC1B;AACF;;;;"}
|
|
@@ -41,6 +41,14 @@ import { getDevice } from '../../app/api.js';
|
|
|
41
41
|
device.pool.releaseTexture(texture);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
+
* Retain a pooled texture so it can be owned outside the graph lifetime.
|
|
45
|
+
*
|
|
46
|
+
* @param texture - The texture to retain.
|
|
47
|
+
*/ retain(texture) {
|
|
48
|
+
const device = getDevice();
|
|
49
|
+
device.pool.retainTexture(texture);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
44
52
|
* Allocate a temporary framebuffer from the device pool.
|
|
45
53
|
*
|
|
46
54
|
* @param desc - Framebuffer descriptor from the render graph pass.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { FrameBuffer, Texture2D, TextureFormat } from '@zephyr3d/device';\r\nimport type { RGFramebufferDesc, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\n\r\n/**\r\n * Bridges the render graph's {@link RGTextureAllocator} interface to the\r\n * engine's device resource pool (`device.pool`).\r\n *\r\n * Transient textures are fetched from the pool on `allocate()` and\r\n * returned to the pool on `release()`, enabling automatic reuse\r\n * across frames without manual lifecycle management.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const allocator = new DevicePoolAllocator();\r\n * const executor = new RenderGraphExecutor(allocator, width, height);\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport class DevicePoolAllocator implements RGTextureAllocator<Texture2D, FrameBuffer> {\r\n /**\r\n * Allocate a transient texture from the device pool.\r\n *\r\n * @param desc - Texture descriptor from the render graph pass.\r\n * @param size - Resolved pixel dimensions.\r\n * @returns A pooled Texture2D instance.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): Texture2D {\r\n const device = getDevice();\r\n const mipmapping = (desc.mipLevels ?? 1) > 1;\r\n const texture = device.pool.fetchTemporalTexture2D(\r\n false,\r\n desc.format,\r\n size.width,\r\n size.height,\r\n mipmapping\r\n );\r\n if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {\r\n device.pool.releaseTexture(texture);\r\n throw new Error(\r\n `DevicePoolAllocator: texture \"${desc.label ?? '<unnamed>'}\" requested ${desc.mipLevels} ` +\r\n `mip levels, but only ${texture.mipLevelCount} were allocated.`\r\n );\r\n }\r\n return texture;\r\n }\r\n\r\n /**\r\n * Release a transient texture back to the device pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: Texture2D): void {\r\n const device = getDevice();\r\n device.pool.releaseTexture(texture);\r\n }\r\n\r\n /**\r\n * Allocate a temporary framebuffer from the device pool.\r\n *\r\n * @param desc - Framebuffer descriptor from the render graph pass.\r\n * @returns A pooled FrameBuffer instance.\r\n */\r\n allocateFramebuffer(desc: RGFramebufferDesc): FrameBuffer {\r\n const device = getDevice();\r\n const colors = Array.isArray(desc.colorAttachments)\r\n ? (desc.colorAttachments as Array<Texture2D | TextureFormat>)\r\n : desc.colorAttachments\r\n ? [desc.colorAttachments as Texture2D | TextureFormat]\r\n : [];\r\n const depthAttachment = (desc.depthAttachment ?? null) as Texture2D | TextureFormat | null;\r\n return device.pool.fetchTemporalFramebuffer(\r\n false,\r\n desc.width ?? 0,\r\n desc.height ?? 0,\r\n colors,\r\n depthAttachment,\r\n desc.mipmapping ?? false,\r\n desc.sampleCount ?? 1,\r\n desc.ignoreDepthStencil ?? true,\r\n desc.attachmentMipLevel ?? 0,\r\n desc.attachmentCubeface ?? 0,\r\n desc.attachmentLayer ?? 0\r\n );\r\n }\r\n\r\n /**\r\n * Release a temporary framebuffer back to the device pool.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer(framebuffer: FrameBuffer): void {\r\n const device = getDevice();\r\n device.pool.releaseFrameBuffer(framebuffer);\r\n }\r\n}\r\n"],"names":["DevicePoolAllocator","allocate","desc","size","device","getDevice","mipmapping","mipLevels","texture","pool","fetchTemporalTexture2D","format","width","height","mipLevelCount","releaseTexture","Error","label","release","allocateFramebuffer","colors","Array","isArray","colorAttachments","depthAttachment","fetchTemporalFramebuffer","sampleCount","ignoreDepthStencil","attachmentMipLevel","attachmentCubeface","attachmentLayer","releaseFramebuffer","framebuffer","releaseFrameBuffer"],"mappings":";;AAIA;;;;;;;;;;;;;;;AAeC,IACM,MAAMA,mBAAAA,CAAAA;AACX;;;;;;AAMC,MACDC,QAASC,CAAAA,IAAmB,EAAEC,IAAoB,EAAa;AAC7D,QAAA,MAAMC,MAASC,GAAAA,SAAAA,EAAAA;AACf,QAAA,MAAMC,aAAa,CAACJ,KAAKK,SAAS,IAAI,CAAA,IAAK,CAAA;AAC3C,QAAA,MAAMC,OAAUJ,GAAAA,MAAAA,CAAOK,IAAI,CAACC,sBAAsB,CAChD,KAAA,EACAR,IAAKS,CAAAA,MAAM,EACXR,IAAKS,CAAAA,KAAK,EACVT,IAAAA,CAAKU,MAAM,EACXP,UAAAA,CAAAA;QAEF,IAAIJ,IAAAA,CAAKK,SAAS,IAAIC,OAAAA,CAAQM,aAAa,GAAGZ,IAAAA,CAAKK,SAAS,EAAE;YAC5DH,MAAOK,CAAAA,IAAI,CAACM,cAAc,CAACP,OAAAA,CAAAA;YAC3B,MAAM,IAAIQ,KACR,CAAA,CAAC,8BAA8B,EAAEd,KAAKe,KAAK,IAAI,WAAY,CAAA,YAAY,EAAEf,IAAAA,CAAKK,SAAS,CAAC,CAAC,CAAC,GACxF,CAAC,qBAAqB,EAAEC,OAAQM,CAAAA,aAAa,CAAC,gBAAgB,CAAC,CAAA;AAErE;QACA,OAAON,OAAAA;AACT;AAEA;;;;MAKAU,OAAAA,CAAQV,OAAkB,EAAQ;AAChC,QAAA,MAAMJ,MAASC,GAAAA,SAAAA,EAAAA;QACfD,MAAOK,CAAAA,IAAI,CAACM,cAAc,CAACP,OAAAA,CAAAA;AAC7B;AAEA;;;;;
|
|
1
|
+
{"version":3,"file":"device_pool_allocator.js","sources":["../../../src/render/rendergraph/device_pool_allocator.ts"],"sourcesContent":["import type { FrameBuffer, Texture2D, TextureFormat } from '@zephyr3d/device';\r\nimport type { RGFramebufferDesc, RGTextureAllocator, RGTextureDesc, RGResolvedSize } from './types';\r\nimport { getDevice } from '../../app/api';\r\n\r\n/**\r\n * Bridges the render graph's {@link RGTextureAllocator} interface to the\r\n * engine's device resource pool (`device.pool`).\r\n *\r\n * Transient textures are fetched from the pool on `allocate()` and\r\n * returned to the pool on `release()`, enabling automatic reuse\r\n * across frames without manual lifecycle management.\r\n *\r\n * Usage:\r\n * ```ts\r\n * const allocator = new DevicePoolAllocator();\r\n * const executor = new RenderGraphExecutor(allocator, width, height);\r\n * ```\r\n *\r\n * @public\r\n */\r\nexport class DevicePoolAllocator implements RGTextureAllocator<Texture2D, FrameBuffer> {\r\n /**\r\n * Allocate a transient texture from the device pool.\r\n *\r\n * @param desc - Texture descriptor from the render graph pass.\r\n * @param size - Resolved pixel dimensions.\r\n * @returns A pooled Texture2D instance.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): Texture2D {\r\n const device = getDevice();\r\n const mipmapping = (desc.mipLevels ?? 1) > 1;\r\n const texture = device.pool.fetchTemporalTexture2D(\r\n false,\r\n desc.format,\r\n size.width,\r\n size.height,\r\n mipmapping\r\n );\r\n if (desc.mipLevels && texture.mipLevelCount < desc.mipLevels) {\r\n device.pool.releaseTexture(texture);\r\n throw new Error(\r\n `DevicePoolAllocator: texture \"${desc.label ?? '<unnamed>'}\" requested ${desc.mipLevels} ` +\r\n `mip levels, but only ${texture.mipLevelCount} were allocated.`\r\n );\r\n }\r\n return texture;\r\n }\r\n\r\n /**\r\n * Release a transient texture back to the device pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: Texture2D): void {\r\n const device = getDevice();\r\n device.pool.releaseTexture(texture);\r\n }\r\n\r\n /**\r\n * Retain a pooled texture so it can be owned outside the graph lifetime.\r\n *\r\n * @param texture - The texture to retain.\r\n */\r\n retain(texture: Texture2D): void {\r\n const device = getDevice();\r\n device.pool.retainTexture(texture);\r\n }\r\n\r\n /**\r\n * Allocate a temporary framebuffer from the device pool.\r\n *\r\n * @param desc - Framebuffer descriptor from the render graph pass.\r\n * @returns A pooled FrameBuffer instance.\r\n */\r\n allocateFramebuffer(desc: RGFramebufferDesc): FrameBuffer {\r\n const device = getDevice();\r\n const colors = Array.isArray(desc.colorAttachments)\r\n ? (desc.colorAttachments as Array<Texture2D | TextureFormat>)\r\n : desc.colorAttachments\r\n ? [desc.colorAttachments as Texture2D | TextureFormat]\r\n : [];\r\n const depthAttachment = (desc.depthAttachment ?? null) as Texture2D | TextureFormat | null;\r\n return device.pool.fetchTemporalFramebuffer(\r\n false,\r\n desc.width ?? 0,\r\n desc.height ?? 0,\r\n colors,\r\n depthAttachment,\r\n desc.mipmapping ?? false,\r\n desc.sampleCount ?? 1,\r\n desc.ignoreDepthStencil ?? true,\r\n desc.attachmentMipLevel ?? 0,\r\n desc.attachmentCubeface ?? 0,\r\n desc.attachmentLayer ?? 0\r\n );\r\n }\r\n\r\n /**\r\n * Release a temporary framebuffer back to the device pool.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer(framebuffer: FrameBuffer): void {\r\n const device = getDevice();\r\n device.pool.releaseFrameBuffer(framebuffer);\r\n }\r\n}\r\n"],"names":["DevicePoolAllocator","allocate","desc","size","device","getDevice","mipmapping","mipLevels","texture","pool","fetchTemporalTexture2D","format","width","height","mipLevelCount","releaseTexture","Error","label","release","retain","retainTexture","allocateFramebuffer","colors","Array","isArray","colorAttachments","depthAttachment","fetchTemporalFramebuffer","sampleCount","ignoreDepthStencil","attachmentMipLevel","attachmentCubeface","attachmentLayer","releaseFramebuffer","framebuffer","releaseFrameBuffer"],"mappings":";;AAIA;;;;;;;;;;;;;;;AAeC,IACM,MAAMA,mBAAAA,CAAAA;AACX;;;;;;AAMC,MACDC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