1 |
- {"ast":null,"code":"import { FrameGraphBloomMergeTask } from \"./bloomMergeTask.js\";\nimport { FrameGraphTask } from \"../../frameGraphTask.js\";\nimport { ThinBloomEffect } from \"../../../PostProcesses/thinBloomEffect.js\";\nimport { FrameGraphExtractHighlightsTask } from \"./extractHighlightsTask.js\";\nimport { FrameGraphBlurTask } from \"./blurTask.js\";\n/**\n * Task which applies a bloom render effect.\n */\nexport class FrameGraphBloomTask extends FrameGraphTask {\n /**\n * The name of the task.\n */\n get name() {\n return this._name;\n }\n set name(name) {\n this._name = name;\n if (this._downscale) {\n this._downscale.name = `${name} Downscale`;\n }\n if (this._blurX) {\n this._blurX.name = `${name} Blur X`;\n }\n if (this._blurY) {\n this._blurY.name = `${name} Blur Y`;\n }\n if (this._merge) {\n this._merge.name = `${name} Merge`;\n }\n }\n /**\n * Constructs a new bloom task.\n * @param name Name of the task.\n * @param frameGraph The frame graph this task is associated with.\n * @param engine The engine to use for the bloom effect.\n * @param weight Weight of the bloom effect.\n * @param kernel Kernel size of the bloom effect.\n * @param threshold Threshold of the bloom effect.\n * @param hdr Whether the bloom effect is HDR.\n * @param bloomScale The scale of the bloom effect. This value is multiplied by the source texture size to determine the bloom texture size.\n */\n constructor(name, frameGraph, engine, weight, kernel, threshold, hdr = false, bloomScale = 0.5) {\n super(name, frameGraph);\n /**\n * The sampling mode to use for the source texture.\n */\n this.sourceSamplingMode = 2;\n this.hdr = hdr;\n this._defaultPipelineTextureType = 0;\n if (hdr) {\n const caps = engine.getCaps();\n if (caps.textureHalfFloatRender) {\n this._defaultPipelineTextureType = 2;\n } else if (caps.textureFloatRender) {\n this._defaultPipelineTextureType = 1;\n }\n }\n this.bloom = new ThinBloomEffect(name, engine, bloomScale);\n this.bloom.threshold = threshold;\n this.bloom.kernel = kernel;\n this.bloom.weight = weight;\n this._downscale = new FrameGraphExtractHighlightsTask(`${name} Downscale`, this._frameGraph, this.bloom._downscale);\n this._blurX = new FrameGraphBlurTask(`${name} Blur X`, this._frameGraph, this.bloom._blurX);\n this._blurY = new FrameGraphBlurTask(`${name} Blur Y`, this._frameGraph, this.bloom._blurY);\n this._merge = new FrameGraphBloomMergeTask(`${name} Merge`, this._frameGraph, this.bloom._merge);\n this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();\n }\n isReady() {\n return this.bloom.isReady();\n }\n record() {\n if (this.sourceTexture === undefined) {\n throw new Error(\"FrameGraphBloomTask: sourceTexture is required\");\n }\n const sourceTextureDescription = this._frameGraph.textureManager.getTextureDescription(this.sourceTexture);\n const textureCreationOptions = {\n size: {\n width: Math.floor(sourceTextureDescription.size.width * this.bloom.scale),\n height: Math.floor(sourceTextureDescription.size.height * this.bloom.scale)\n },\n options: {\n createMipMaps: false,\n types: [this._defaultPipelineTextureType],\n formats: [5],\n samples: 1,\n useSRGBBuffers: [false],\n labels: [\"\"]\n },\n sizeIsPercentage: false\n };\n const downscaleTextureHandle = this._frameGraph.textureManager.createRenderTargetTexture(this._downscale.name, textureCreationOptions);\n this._downscale.sourceTexture = this.sourceTexture;\n this._downscale.sourceSamplingMode = 2;\n this._downscale.destinationTexture = downscaleTextureHandle;\n this._downscale.record(true);\n const blurXTextureHandle = this._frameGraph.textureManager.createRenderTargetTexture(this._blurX.name, textureCreationOptions);\n this._blurX.sourceTexture = downscaleTextureHandle;\n this._blurX.sourceSamplingMode = 2;\n this._blurX.destinationTexture = blurXTextureHandle;\n this._blurX.record(true);\n const blurYTextureHandle = this._frameGraph.textureManager.createRenderTargetTexture(this._blurY.name, textureCreationOptions);\n this._blurY.sourceTexture = blurXTextureHandle;\n this._blurY.sourceSamplingMode = 2;\n this._blurY.destinationTexture = blurYTextureHandle;\n this._blurY.record(true);\n const sourceTextureCreationOptions = this._frameGraph.textureManager.getTextureCreationOptions(this.sourceTexture);\n this._frameGraph.textureManager.resolveDanglingHandle(this.outputTexture, this.destinationTexture, this._merge.name, sourceTextureCreationOptions);\n this._merge.sourceTexture = this.sourceTexture;\n this._merge.sourceSamplingMode = this.sourceSamplingMode;\n this._merge.blurTexture = blurYTextureHandle;\n this._merge.destinationTexture = this.outputTexture;\n this._merge.record(true);\n const passDisabled = this._frameGraph.addRenderPass(this.name + \"_disabled\", true);\n passDisabled.setRenderTarget(this.outputTexture);\n passDisabled.setExecuteFunc(context => {\n context.copyTexture(this.sourceTexture);\n });\n }\n dispose() {\n this._downscale.dispose();\n this._blurX.dispose();\n this._blurY.dispose();\n this._merge.dispose();\n super.dispose();\n }\n}","map":{"version":3,"names":["FrameGraphBloomMergeTask","FrameGraphTask","ThinBloomEffect","FrameGraphExtractHighlightsTask","FrameGraphBlurTask","FrameGraphBloomTask","name","_name","_downscale","_blurX","_blurY","_merge","constructor","frameGraph","engine","weight","kernel","threshold","hdr","bloomScale","sourceSamplingMode","_defaultPipelineTextureType","caps","getCaps","textureHalfFloatRender","textureFloatRender","bloom","_frameGraph","outputTexture","textureManager","createDanglingHandle","isReady","record","sourceTexture","undefined","Error","sourceTextureDescription","getTextureDescription","textureCreationOptions","size","width","Math","floor","scale","height","options","createMipMaps","types","formats","samples","useSRGBBuffers","labels","sizeIsPercentage","downscaleTextureHandle","createRenderTargetTexture","destinationTexture","blurXTextureHandle","blurYTextureHandle","sourceTextureCreationOptions","getTextureCreationOptions","resolveDanglingHandle","blurTexture","passDisabled","addRenderPass","setRenderTarget","setExecuteFunc","context","copyTexture","dispose"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/FrameGraph/Tasks/PostProcesses/bloomTask.js"],"sourcesContent":["\nimport { FrameGraphBloomMergeTask } from \"./bloomMergeTask.js\";\nimport { FrameGraphTask } from \"../../frameGraphTask.js\";\nimport { ThinBloomEffect } from \"../../../PostProcesses/thinBloomEffect.js\";\nimport { FrameGraphExtractHighlightsTask } from \"./extractHighlightsTask.js\";\nimport { FrameGraphBlurTask } from \"./blurTask.js\";\n/**\n * Task which applies a bloom render effect.\n */\nexport class FrameGraphBloomTask extends FrameGraphTask {\n /**\n * The name of the task.\n */\n get name() {\n return this._name;\n }\n set name(name) {\n this._name = name;\n if (this._downscale) {\n this._downscale.name = `${name} Downscale`;\n }\n if (this._blurX) {\n this._blurX.name = `${name} Blur X`;\n }\n if (this._blurY) {\n this._blurY.name = `${name} Blur Y`;\n }\n if (this._merge) {\n this._merge.name = `${name} Merge`;\n }\n }\n /**\n * Constructs a new bloom task.\n * @param name Name of the task.\n * @param frameGraph The frame graph this task is associated with.\n * @param engine The engine to use for the bloom effect.\n * @param weight Weight of the bloom effect.\n * @param kernel Kernel size of the bloom effect.\n * @param threshold Threshold of the bloom effect.\n * @param hdr Whether the bloom effect is HDR.\n * @param bloomScale The scale of the bloom effect. This value is multiplied by the source texture size to determine the bloom texture size.\n */\n constructor(name, frameGraph, engine, weight, kernel, threshold, hdr = false, bloomScale = 0.5) {\n super(name, frameGraph);\n /**\n * The sampling mode to use for the source texture.\n */\n this.sourceSamplingMode = 2;\n this.hdr = hdr;\n this._defaultPipelineTextureType = 0;\n if (hdr) {\n const caps = engine.getCaps();\n if (caps.textureHalfFloatRender) {\n this._defaultPipelineTextureType = 2;\n }\n else if (caps.textureFloatRender) {\n this._defaultPipelineTextureType = 1;\n }\n }\n this.bloom = new ThinBloomEffect(name, engine, bloomScale);\n this.bloom.threshold = threshold;\n this.bloom.kernel = kernel;\n this.bloom.weight = weight;\n this._downscale = new FrameGraphExtractHighlightsTask(`${name} Downscale`, this._frameGraph, this.bloom._downscale);\n this._blurX = new FrameGraphBlurTask(`${name} Blur X`, this._frameGraph, this.bloom._blurX);\n this._blurY = new FrameGraphBlurTask(`${name} Blur Y`, this._frameGraph, this.bloom._blurY);\n this._merge = new FrameGraphBloomMergeTask(`${name} Merge`, this._frameGraph, this.bloom._merge);\n this.outputTexture = this._frameGraph.textureManager.createDanglingHandle();\n }\n isReady() {\n return this.bloom.isReady();\n }\n record() {\n if (this.sourceTexture === undefined) {\n throw new Error(\"FrameGraphBloomTask: sourceTexture is required\");\n }\n const sourceTextureDescription = this._frameGraph.textureManager.getTextureDescription(this.sourceTexture);\n const textureCreationOptions = {\n size: {\n width: Math.floor(sourceTextureDescription.size.width * this.bloom.scale),\n height: Math.floor(sourceTextureDescription.size.height * this.bloom.scale),\n },\n options: {\n createMipMaps: false,\n types: [this._defaultPipelineTextureType],\n formats: [5],\n samples: 1,\n useSRGBBuffers: [false],\n labels: [\"\"],\n },\n sizeIsPercentage: false,\n };\n const downscaleTextureHandle = this._frameGraph.textureManager.createRenderTargetTexture(this._downscale.name, textureCreationOptions);\n this._downscale.sourceTexture = this.sourceTexture;\n this._downscale.sourceSamplingMode = 2;\n this._downscale.destinationTexture = downscaleTextureHandle;\n this._downscale.record(true);\n const blurXTextureHandle = this._frameGraph.textureManager.createRenderTargetTexture(this._blurX.name, textureCreationOptions);\n this._blurX.sourceTexture = downscaleTextureHandle;\n this._blurX.sourceSamplingMode = 2;\n this._blurX.destinationTexture = blurXTextureHandle;\n this._blurX.record(true);\n const blurYTextureHandle = this._frameGraph.textureManager.createRenderTargetTexture(this._blurY.name, textureCreationOptions);\n this._blurY.sourceTexture = blurXTextureHandle;\n this._blurY.sourceSamplingMode = 2;\n this._blurY.destinationTexture = blurYTextureHandle;\n this._blurY.record(true);\n const sourceTextureCreationOptions = this._frameGraph.textureManager.getTextureCreationOptions(this.sourceTexture);\n this._frameGraph.textureManager.resolveDanglingHandle(this.outputTexture, this.destinationTexture, this._merge.name, sourceTextureCreationOptions);\n this._merge.sourceTexture = this.sourceTexture;\n this._merge.sourceSamplingMode = this.sourceSamplingMode;\n this._merge.blurTexture = blurYTextureHandle;\n this._merge.destinationTexture = this.outputTexture;\n this._merge.record(true);\n const passDisabled = this._frameGraph.addRenderPass(this.name + \"_disabled\", true);\n passDisabled.setRenderTarget(this.outputTexture);\n passDisabled.setExecuteFunc((context) => {\n context.copyTexture(this.sourceTexture);\n });\n }\n dispose() {\n this._downscale.dispose();\n this._blurX.dispose();\n this._blurY.dispose();\n this._merge.dispose();\n super.dispose();\n }\n}\n"],"mappings":"AACA,SAASA,wB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