UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 1.77 kB
import{Color as e}from"../../core/math/color.js";import{PIXELFORMAT_RGBA8 as r,FILTER_NEAREST as t,ADDRESS_CLAMP_TO_EDGE as s}from"../../platform/graphics/constants.js";import{Texture as a}from"../../platform/graphics/texture.js";import{RenderPass as o}from"../../platform/graphics/render-pass.js";import{BlendState as n}from"../../platform/graphics/blend-state.js";import{RenderTarget as i}from"../../platform/graphics/render-target.js";import{LAYERID_DEPTH as l,SHADER_DEPTH as p}from"../constants.js";const d=new e(254/255,254/255,254/255,254/255),c=[],h=[[],[],[]],m=["uSceneDepthMap","uDepthMap"];class f extends o{constructor(e,r,t){super(e),this.renderer=r,this.camera=t,this.setupRenderTarget()}destroy(){super.destroy(),this.renderTarget&&(this.renderTarget.destroyTextureBuffers(),this.renderTarget.destroy(),this.renderTarget=null)}update(e){this.scene=e}setupRenderTarget(){const e=new a(this.device,{name:m[0],format:r,width:4,height:4,mipmaps:!1,minFilter:t,magFilter:t,addressU:s,addressV:s}),o=new i({name:`${m[0]}RT}`,colorBuffer:e,depth:!0,stencil:!1});this.init(o,{}),this.setClearColor(d),this.setClearDepth(1)}before(){const e=this.device,r=this.renderTarget.colorBuffer;m.forEach((t=>e.scope.resolve(t).setValue(r)))}execute(){const{device:e,renderer:r,camera:t,scene:s,renderTarget:a}=this,o=s.layers.layerList,i=s.layers.subLayerEnabled,d=s.layers.subLayerList;for(let s=0;s<o.length;s++){const f=o[s];if(f.enabled&&i[s]&&f.camerasSet.has(t)){if(f.id===l)break;const o=f.getCulledInstances(t),i=d[s]?o.transparent:o.opaque;for(let e=0;e<i.length;e++){var m;const r=i[e];null!=(m=r.material)&&m.depthWrite&&c.push(r)}r.setCameraUniforms(t,a),r.renderForward(t,c,h,p,(r=>{e.setBlendState(n.NOBLEND)}),f),c.length=0}}}}export{f as RenderPassDepth};