playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
42 lines (41 loc) • 2.04 kB
JavaScript
import { SEMANTIC_POSITION, SHADERLANGUAGE_GLSL, SHADERLANGUAGE_WGSL } from "../../platform/graphics/constants.js";
import { RenderPassShaderQuad } from "../../scene/graphics/render-pass-shader-quad.js";
import { ShaderUtils } from "../../scene/shader-lib/shader-utils.js";
import glslDepthAwareBlurPS from "../../scene/shader-lib/glsl/chunks/render-pass/frag/depthAwareBlur.js";
import wgslDepthAwareBlurPS from "../../scene/shader-lib/wgsl/chunks/render-pass/frag/depthAwareBlur.js";
import { ShaderChunks } from "../../scene/shader-lib/shader-chunks.js";
class RenderPassDepthAwareBlur extends RenderPassShaderQuad {
constructor(device, sourceTexture, cameraComponent, horizontal) {
super(device);
this.sourceTexture = sourceTexture;
ShaderChunks.get(device, SHADERLANGUAGE_GLSL).set("depthAwareBlurPS", glslDepthAwareBlurPS);
ShaderChunks.get(device, SHADERLANGUAGE_WGSL).set("depthAwareBlurPS", wgslDepthAwareBlurPS);
const defines = /* @__PURE__ */ new Map();
if (horizontal) defines.set("HORIZONTAL", "");
ShaderUtils.addScreenDepthChunkDefines(device, cameraComponent.shaderParams, defines);
this.shader = ShaderUtils.createShader(device, {
uniqueName: `DepthAware${horizontal ? "Horizontal" : "Vertical"}BlurShader`,
attributes: { aPosition: SEMANTIC_POSITION },
vertexChunk: "quadVS",
fragmentChunk: "depthAwareBlurPS",
fragmentDefines: defines
});
const scope = this.device.scope;
this.sourceTextureId = scope.resolve("sourceTexture");
this.sourceInvResolutionId = scope.resolve("sourceInvResolution");
this.sourceInvResolutionValue = new Float32Array(2);
this.filterSizeId = scope.resolve("filterSize");
}
execute() {
this.filterSizeId.setValue(4);
this.sourceTextureId.setValue(this.sourceTexture);
const { width, height } = this.sourceTexture;
this.sourceInvResolutionValue[0] = 1 / width;
this.sourceInvResolutionValue[1] = 1 / height;
this.sourceInvResolutionId.setValue(this.sourceInvResolutionValue);
super.execute();
}
}
export {
RenderPassDepthAwareBlur
};