@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.95 kB
JavaScript
import{Vec4 as e}from"../../core/math/vec4.js";import{Texture as t}from"../../platform/graphics/texture.js";import{reprojectTexture as a}from"./reproject-texture.js";import{PIXELFORMAT_RGBA8 as r,TEXTURETYPE_RGBP as s,TEXTURETYPE_DEFAULT as l,ADDRESS_CLAMP_TO_EDGE as i,TEXTUREPROJECTION_EQUIRECT as m,PIXELFORMAT_RGBA16F as o,PIXELFORMAT_RGBA32F as n}from"../../platform/graphics/constants.js";const d=(e,t=0)=>1+Math.floor(Math.log2(Math.max(e,t)));class u{static generateSkyboxCubemap(e,l){const m=((e,a,r,l)=>new t(e,{name:`lighting-${a}`,cubemap:!0,width:a,height:a,format:r,type:s,addressU:i,addressV:i,fixCubemapSeams:!0,mipmaps:!!l}))(e.device,l||(e.cubemap?e.width:e.width/4),r,!1);return a(e,m,{numSamples:1024}),m}static generateLightingSource(e,m){const d=e.device,u=(e=>(e=>e.extTextureHalfFloat&&e.textureHalfFloatRenderable)(e)?o:(e=>e.extTextureFloat&&e.textureFloatRenderable)(e)?n:r)(d),p=(null==m?void 0:m.target)||new t(d,{name:"lighting-source",cubemap:!0,width:(null==m?void 0:m.size)||128,height:(null==m?void 0:m.size)||128,format:u,type:u===r?s:l,addressU:i,addressV:i,fixCubemapSeams:!1,mipmaps:!0});return a(e,p,{numSamples:e.mipmaps?1:1024}),p}static generateAtlas(l,o){const n=l.device,u=r,p=(null==o?void 0:o.target)||new t(n,{name:"envAtlas",width:(null==o?void 0:o.size)||512,height:(null==o?void 0:o.size)||512,format:u,type:s,projection:m,addressU:i,addressV:i,mipmaps:!1}),h=p.width/512,c=new e(0,0,512*h,256*h),x=d(256)-d(4);for(let e=0;e<x;++e)a(l,p,{numSamples:1,rect:c,seamPixels:h}),c.x+=c.w,c.y+=c.w,c.z=Math.max(1,Math.floor(.5*c.z)),c.w=Math.max(1,Math.floor(.5*c.w));c.set(0,256*h,256*h,128*h);for(let e=1;e<7;++e)a(l,p,{numSamples:(null==o?void 0:o.numReflectionSamples)||1024,distribution:(null==o?void 0:o.distribution)||"ggx",specularPower:Math.max(1,2048>>2*e),rect:c,seamPixels:h}),c.y+=c.w,c.z=Math.max(1,Math.floor(.5*c.z)),c.w=Math.max(1,Math.floor(.5*c.w));return c.set(128*h,384*h,64*h,32*h),a(l,p,{numSamples:(null==o?void 0:o.numAmbientSamples)||2048,distribution:"lambert",rect:c,seamPixels:h}),p}static generatePrefilteredAtlas(r,s){const l=r[0].device,o=r[0].format,n=r[0].type,u=(null==s?void 0:s.target)||new t(l,{name:"envPrefilteredAtlas",width:(null==s?void 0:s.size)||512,height:(null==s?void 0:s.size)||512,format:o,type:n,projection:m,addressU:i,addressV:i,mipmaps:!1}),p=u.width/512,h=new e(0,0,512*p,256*p),c=d(512);for(let e=0;e<c;++e)a(r[0],u,{numSamples:1,rect:h,seamPixels:p}),h.x+=h.w,h.y+=h.w,h.z=Math.max(1,Math.floor(.5*h.z)),h.w=Math.max(1,Math.floor(.5*h.w));h.set(0,256*p,256*p,128*p);for(let e=1;e<r.length;++e)a(r[e],u,{numSamples:1,rect:h,seamPixels:p}),h.y+=h.w,h.z=Math.max(1,Math.floor(.5*h.z)),h.w=Math.max(1,Math.floor(.5*h.w));return h.set(128*p,384*p,64*p,32*p),null!=s&&s.legacyAmbient?a(r[5],u,{numSamples:1,rect:h,seamPixels:p}):a(r[0],u,{numSamples:(null==s?void 0:s.numSamples)||2048,distribution:"lambert",rect:h,seamPixels:p}),u}}export{u as EnvLighting};