UNPKG

playcanvas

Version:

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

47 lines (46 loc) 2.26 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); 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 { constructor(device, cameraComponent, nearBlur) { super(device); __publicField(this, "focusDistance"); __publicField(this, "focusRange"); 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 };