pixi.js
Version:
PixiJS — The HTML5 Creation Engine =============
1 lines • 3.42 kB
Source Map (JSON)
{"version":3,"file":"generateBlurProgram.mjs","sources":["../../../../../src/filters/defaults/blur/gpu/generateBlurProgram.ts"],"sourcesContent":["import { GpuProgram } from '../../../../rendering/renderers/gpu/shader/GpuProgram';\nimport { GAUSSIAN_VALUES } from '../const';\nimport source from './blur-template.wgsl';\n\nexport function generateBlurProgram(horizontal: boolean, kernelSize: number)\n{\n const kernel = GAUSSIAN_VALUES[kernelSize];\n const halfLength = kernel.length;\n\n const blurStructSource: string[] = [];\n const blurOutSource: string[] = [];\n const blurSamplingSource: string[] = [];\n\n for (let i = 0; i < kernelSize; i++)\n {\n blurStructSource[i] = `@location(${i}) offset${i}: vec2<f32>,`;\n\n if (horizontal)\n {\n blurOutSource[i] = `filteredCord + vec2(${i - halfLength + 1} * strength, 0.0),`;\n }\n else\n {\n blurOutSource[i] = `filteredCord + vec2(0.0, ${i - halfLength + 1} * strength),`;\n }\n\n const kernelIndex = i < halfLength ? i : (kernelSize - i - 1);\n const kernelValue = kernel[kernelIndex].toString();\n\n blurSamplingSource[i] = `finalColor += textureSample(uTexture, uSampler, offset${i}) * ${kernelValue};`;\n }\n\n const blurStruct = blurStructSource.join('\\n');\n const blurOut = blurOutSource.join('\\n');\n const blurSampling = blurSamplingSource.join('\\n');\n\n const finalSource = source\n .replace('%blur-struct%', blurStruct)\n .replace('%blur-vertex-out%', blurOut)\n .replace('%blur-fragment-in%', blurStruct)\n .replace('%blur-sampling%', blurSampling);\n\n return GpuProgram.from({\n vertex: {\n source: finalSource,\n entryPoint: 'mainVertex',\n },\n fragment: {\n source: finalSource,\n entryPoint: 'mainFragment',\n },\n });\n}\n\n"],"names":[],"mappings":";;;;;AAIgB,SAAA,mBAAA,CAAoB,YAAqB,UACzD,EAAA;AACI,EAAM,MAAA,MAAA,GAAS,gBAAgB,UAAU,CAAA,CAAA;AACzC,EAAA,MAAM,aAAa,MAAO,CAAA,MAAA,CAAA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