@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 3.99 kB
JavaScript
import{SHADER_FORWARDHDR as e,GAMMA_SRGBHDR as t,TONEMAP_LINEAR as n,SHADERDEF_SCREENSPACE as a,SHADERDEF_SKIN as i,SHADERDEF_INSTANCING as s,SHADERDEF_MORPH_POSITION as o,SHADERDEF_MORPH_NORMAL as l,SHADERDEF_MORPH_TEXTURE_BASED as c,SHADERDEF_TANGENTS as r,SPRITE_RENDERMODE_SIMPLE as d,CUBEPROJ_NONE as g,SPECULAR_BLINN as u,GAMMA_NONE as h,MASK_AFFECT_DYNAMIC as p,LIGHTTYPE_DIRECTIONAL as b,LIGHTTYPE_OMNI as S,LIGHTTYPE_SPOT as m,SHADERDEF_NOSHADOW as f}from"../constants.js";class M{static update(a,i,s,o,l,c){M.updateSharedOptions(a,i,s,o,l),M.updateMaterialOptions(a,i),M.updateEnvOptions(a,i,s),M.updateLightingOptions(a,i,o,c),l===e&&(a.gamma=t,a.toneMap=n)}static updateSharedOptions(e,t,n,g,u){e.chunks=t.chunks,e.pass=u,e.alphaTest=t.alphaTest>0,e.blendType=t.blendType,e.screenSpace=g&&!!(g&a),e.skin=g&&!!(g&i),e.useInstancing=g&&!!(g&s),e.useMorphPosition=g&&!!(g&o),e.useMorphNormal=g&&!!(g&l),e.useMorphTextureBased=g&&!!(g&c),e.hasTangents=g&&!!(g&r),e.nineSlicedMode=t.nineSlicedMode||d,t.useLighting&&n.clusteredLightingEnabled?(e.clusteredLightingEnabled=!0,e.clusteredLightingCookiesEnabled=n.lighting.cookiesEnabled,e.clusteredLightingShadowsEnabled=n.lighting.shadowsEnabled,e.clusteredLightingShadowType=n.lighting.shadowType,e.clusteredLightingAreaLightsEnabled=n.lighting.areaLightsEnabled):(e.clusteredLightingEnabled=!1,e.clusteredLightingCookiesEnabled=!1,e.clusteredLightingShadowsEnabled=!1,e.clusteredLightingAreaLightsEnabled=!1)}static updateMaterialOptions(e,t){e.useAmbientTint=!1,e.separateAmbient=!1,e.customFragmentShader=null,e.pixelSnap=t.pixelSnap,e.shadingModel=t.shadingModel,e.ambientSH=t.ambientSH,e.fastTbn=t.fastTbn,e.twoSidedLighting=t.twoSidedLighting,e.occludeDirect=t.occludeDirect,e.occludeSpecular=t.occludeSpecular,e.occludeSpecularFloat=1!==t.occludeSpecularIntensity,e.useMsdf=!1,e.msdfTextAttribute=!1,e.alphaToCoverage=t.alphaToCoverage,e.opacityFadesSpecular=t.opacityFadesSpecular,e.opacityDither=t.opacityDither,e.cubeMapProjection=g,e.conserveEnergy=t.conserveEnergy&&t.shadingModel===u,e.useSpecular=t.hasSpecular,e.useSpecularityFactor=t.hasSpecularityFactor,e.enableGGXSpecular=t.ggxSpecular,e.fresnelModel=t.fresnelModel,e.useRefraction=t.hasRefraction,e.useClearCoat=t.hasClearCoat,e.useSheen=t.hasSheen,e.useIridescence=t.hasIrridescence,e.useMetalness=t.hasMetalness,e.useDynamicRefraction=t.dynamicRefraction,e.dispersion=t.dispersion>0,e.vertexColors=!1,e.lightMapEnabled=t.hasLighting,e.dirLightMapEnabled=t.dirLightMap,e.useHeights=t.hasHeights,e.useNormals=t.hasNormals,e.useClearCoatNormals=t.hasClearCoatNormals,e.useAo=t.hasAo,e.diffuseMapEnabled=t.hasDiffuseMap}static updateEnvOptions(e,t,n){e.fog=t.useFog?n.fog:"none",e.gamma=t.useGammaTonemap?n.gammaCorrection:h,e.toneMap=t.useGammaTonemap?n.toneMapping:-1,e.fixSeams=!1,t.useSkybox&&n.envAtlas&&n.skybox?(e.reflectionSource="envAtlasHQ",e.reflectionEncoding=n.envAtlas.encoding,e.reflectionCubemapEncoding=n.skybox.encoding):t.useSkybox&&n.envAtlas?(e.reflectionSource="envAtlas",e.reflectionEncoding=n.envAtlas.encoding):t.useSkybox&&n.skybox?(e.reflectionSource="cubeMap",e.reflectionEncoding=n.skybox.encoding):(e.reflectionSource=null,e.reflectionEncoding=null),t.ambientSH?(e.ambientSource="ambientSH",e.ambientEncoding=null):e.reflectionSource&&n.envAtlas?(e.ambientSource="envAtlas",e.ambientEncoding=n.envAtlas.encoding):(e.ambientSource="constant",e.ambientEncoding=null);const a=!!e.reflectionSource;e.skyboxIntensity=a,e.useCubeMapRotation=a&&n._skyboxRotationShaderInclude}static updateLightingOptions(e,t,n,a){if(e.lightMapWithoutAmbient=!1,t.useLighting){const t=[],i=n?n>>16:p;e.lightMaskDynamic=!!(i&p),e.lightMapWithoutAmbient=!1,a&&(M.collectLights(b,a[b],t,i),M.collectLights(S,a[S],t,i),M.collectLights(m,a[m],t,i)),e.lights=t}else e.lights=[];(0===e.lights.length||n&f)&&(e.noShadow=!0)}static collectLights(e,t,n,a){for(let e=0;e<t.length;e++){const i=t[e];i.enabled&&i.mask&a&&n.push(i)}}}export{M as LitMaterialOptionsBuilder};