@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.01 kB
JavaScript
import{LAYERID_DEPTH as e,SHADER_PREPASS_VELOCITY as t}from"../../scene/constants.js";import{PIXELFORMAT_RGBA32F as r,PIXELFORMAT_RGBA16F as s,FILTER_NEAREST as a,ADDRESS_CLAMP_TO_EDGE as i}from"../../platform/graphics/constants.js";import{Texture as n}from"../../platform/graphics/texture.js";import{RenderPass as o}from"../../platform/graphics/render-pass.js";import{RenderTarget as l}from"../../platform/graphics/render-target.js";const h=[];class d extends o{constructor(e,t,r,s,a,i){super(e),this.viewBindGroups=[],this.velocityTexture=void 0,this.scene=t,this.renderer=r,this.camera=s,this.setupRenderTarget(a,i)}destroy(){var e,t;super.destroy(),null==(e=this.renderTarget)||e.destroy(),this.renderTarget=null,null==(t=this.velocityTexture)||t.destroy(),this.velocityTexture=null,this.viewBindGroups.forEach((e=>{e.defaultUniformBuffer.destroy(),e.destroy()})),this.viewBindGroups.length=0}setupRenderTarget(e,t){const{device:o}=this,h=o.getRenderableHdrFormat([r,s]);this.velocityTexture=new n(o,{name:"VelocityTexture",width:4,height:4,format:h,mipmaps:!1,minFilter:a,magFilter:a,addressU:i,addressV:i});const d=new l({name:"PrepassRT",depthBuffer:e});this.init(d,t),this.depthStencilOps.storeDepth=!0}after(){this.device.scope.resolve("uSceneDepthMap").setValue(this.renderTarget.depthBuffer),this.device.scope.resolve("uSceneVelocityMap").setValue(this.velocityTexture)}execute(){const{renderer:r,scene:s,renderTarget:a}=this,i=this.camera.camera,n=s.layers.layerList,o=s.layers.subLayerEnabled,l=s.layers.subLayerList;for(let s=0;s<n.length;s++){const c=n[s];if(c.enabled&&o[s]&&c.camerasSet.has(i)){if(c.id===e)break;const n=c.getCulledInstances(i),o=l[s]?n.transparent:n.opaque;for(let e=0;e<o.length;e++){var d;const t=o[e];null!=(d=t.material)&&d.depthWrite&&h.push(t)}r.renderForwardLayer(i,a,null,void 0,t,this.viewBindGroups,{meshInstances:h}),h.length=0}}}frameUpdate(){super.frameUpdate();const{camera:e}=this;this.setClearDepth(e.clearDepthBuffer?1:void 0)}}export{d as RenderPassPrepass};