UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 2.05 kB
import{PIXELFORMAT_RGBA32F as t,PIXELFORMAT_RGBA16F as e,PIXELFORMAT_DEPTH as r,PIXELFORMAT_R32F as a,PIXELFORMAT_RGBA8 as s,FILTER_NEAREST as o,FILTER_LINEAR as i,ADDRESS_CLAMP_TO_EDGE as h,FUNC_LESS as n}from"../../platform/graphics/constants.js";import{RenderTarget as p}from"../../platform/graphics/render-target.js";import{Texture as d}from"../../platform/graphics/texture.js";import{SHADOW_VSM32 as c,SHADOW_VSM16 as l,SHADOW_PCF5 as u,SHADOW_PCF1 as m,SHADOW_PCF3 as w,SHADOW_PCSS as f,LIGHTTYPE_OMNI as g}from"../constants.js";class F{constructor(t,e){this.texture=t,this.cached=!1,this.renderTargets=e}destroy(){this.texture&&(this.texture.destroy(),this.texture=null);const t=this.renderTargets;for(let e=0;e<t.length;e++)t[e].destroy();this.renderTargets.length=0}static getShadowFormat(o,i){return i===c?t:i===l?e:i===u?r:i!==m&&i!==w||!o.supportsDepthShadow?i!==f||o.isWebGL1?s:a:r}static getShadowFiltering(t,e){return e!==m&&e!==w&&e!==f||t.supportsDepthShadow?e===c?t.extTextureFloatLinear?i:o:e===l?t.extTextureHalfFloatLinear?i:o:i:o}static create(t,e){let r=null;return r=e._type===g?this.createCubemap(t,e._shadowResolution,e._shadowType):this.create2dMap(t,e._shadowResolution,e._shadowType),r}static createAtlas(t,e,r){const a=this.create2dMap(t,e,r),s=a.renderTargets,o=s[0];for(let t=0;t<5;t++)s.push(o);return a}static create2dMap(t,e,r){const a=this.getShadowFormat(t,r),s=this.getShadowFiltering(t,r),o=new d(t,{format:a,width:e,height:e,mipmaps:!1,minFilter:s,magFilter:s,addressU:h,addressV:h,name:"ShadowMap2D"});let i=null;return r===u||(r===m||r===w)&&t.supportsDepthShadow?(o.compareOnRead=!0,o.compareFunc=n,i=new p({depthBuffer:o})):i=new p({colorBuffer:o,depth:!0}),t.isWebGPU&&(i.flipY=!0),new F(o,[i])}static createCubemap(t,e,r){const i=r!==f||t.isWebGL1?s:a,n=new d(t,{format:i,width:e,height:e,cubemap:!0,mipmaps:!1,minFilter:o,magFilter:o,addressU:h,addressV:h,name:"ShadowMapCube"}),c=[];for(let t=0;t<6;t++){const e=new p({colorBuffer:n,face:t,depth:!0});c.push(e)}return new F(n,c)}}export{F as ShadowMap};