UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

44 lines (43 loc) 1.84 kB
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 glslCocPS from "../../scene/shader-lib/glsl/chunks/render-pass/frag/coc.js"; import wgslCocPS from "../../scene/shader-lib/wgsl/chunks/render-pass/frag/coc.js"; import { ShaderChunks } from "../../scene/shader-lib/shader-chunks.js"; class RenderPassCoC extends RenderPassShaderQuad { focusDistance; focusRange; constructor(device, cameraComponent, nearBlur) { super(device); this.cameraComponent = cameraComponent; ShaderChunks.get(device, SHADERLANGUAGE_GLSL).set("cocPS", glslCocPS); ShaderChunks.get(device, SHADERLANGUAGE_WGSL).set("cocPS", wgslCocPS); const defines = /* @__PURE__ */ new Map(); if (nearBlur) defines.set("NEAR_BLUR", ""); ShaderUtils.addScreenDepthChunkDefines(device, cameraComponent.shaderParams, defines); this.shader = ShaderUtils.createShader(device, { uniqueName: `CocShader-${nearBlur}`, attributes: { aPosition: SEMANTIC_POSITION }, vertexChunk: "quadVS", fragmentChunk: "cocPS", fragmentDefines: defines }); this.paramsId = device.scope.resolve("params"); this.paramsValue = new Float32Array(3); this.cameraParams = new Float32Array(4); this.cameraParamsId = device.scope.resolve("camera_params"); } execute() { const { paramsValue, focusRange } = this; paramsValue[0] = this.focusDistance + 1e-3; paramsValue[1] = focusRange; paramsValue[2] = 1 / focusRange; this.paramsId.setValue(paramsValue); const camera = this.cameraComponent.camera; this.cameraParamsId.setValue(camera.fillShaderParams(this.cameraParams)); super.execute(); } } export { RenderPassCoC };