@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 3 kB
JavaScript
import{ShaderUtils as e}from"../../../platform/graphics/shader-utils.js";import{BLEND_NORMAL as a,BLEND_ADDITIVE as n,BLEND_MULTIPLICATIVE as r}from"../../constants.js";import{shaderChunks as t}from"../chunks/chunks.js";import{ShaderGenerator as l}from"./shader-generator.js";const i=new class extends l{generateKey(e){let a="particle";for(const n in e)e.hasOwnProperty(n)&&(a+=e[n]);return a}_animTex(e){let a="";return a+=e.animTexLoop?t.particleAnimFrameLoopVS:t.particleAnimFrameClampVS,a+=t.particleAnimTexVS,a}createShaderDefinition(i,o){const c=`#define PARTICLE_${o.useCpu?"CPU":"GPU"}\n`;let m=`#define PARTICLE\n${c}`,p=`#define VERTEXSHADER\n${c}`;o.mesh&&(p+="#define USE_MESH\n"),o.localSpace&&(p+="#define LOCAL_SPACE\n"),o.screenSpace&&(p+="#define SCREEN_SPACE\n"),o.animTex&&(p+="\nuniform vec2 animTexTilesParams;\n"),o.animTex&&(p+="\nuniform vec4 animTexParams;\n"),o.animTex&&(p+="\nuniform vec2 animTexIndexParams;\n"),2===o.normal&&(p+="\nvarying mat3 ParticleMat;\n"),1===o.normal&&(p+="\nvarying vec3 Normal;\n"),o.soft&&(p+="\nvarying float vDepth;\n");const S=o.customFace?t.particle_customFaceVS:t.particle_billboardVS;return o.useCpu?(o.soft>0&&(p+=t.screenDepthPS),p+=t.particle_cpuVS,o.localSpace&&(p+=t.particle_localShiftVS),o.animTex&&(p+=this._animTex(o)),o.alignToMotion&&(p+=t.particle_pointAlongVS),p+=o.mesh?t.particle_meshVS:S,1===o.normal&&(p+=t.particle_normalVS),2===o.normal&&(p+=t.particle_TBNVS),o.stretch>0&&(p+=t.particle_stretchVS),p+=t.particle_cpu_endVS,o.soft>0&&(p+=t.particle_softVS)):(p+=t.particle_initVS,p+=o.pack8?t.particleInputRgba8PS:t.particleInputFloatPS,o.soft>0&&(p+=t.screenDepthPS),p+=t.particleVS,o.localSpace&&(p+=t.particle_localShiftVS),o.animTex&&(p+=this._animTex(o)),o.wrap&&(p+=t.particle_wrapVS),o.alignToMotion&&(p+=t.particle_pointAlongVS),p+=o.mesh?t.particle_meshVS:S,1===o.normal&&(p+=t.particle_normalVS),2===o.normal&&(p+=t.particle_TBNVS),o.stretch>0&&(p+=t.particle_stretchVS),p+=t.particle_endVS,o.soft>0&&(p+=t.particle_softVS)),p+="}\n",o.normal>0&&(1===o.normal?m+="\nvarying vec3 Normal;\n":2===o.normal&&(m+="\nvarying mat3 ParticleMat;\n"),m+="\nuniform vec3 lightCube[6];\n"),o.soft&&(m+="\nvarying float vDepth;\n"),0===o.normal&&"none"===o.fog&&(o.srgb=!1),m+=t.decodePS,m+=l.gammaCode(o.gamma),m+=l.tonemapCode(o.toneMap),"linear"===o.fog?m+=t.fogLinearPS:"exp"===o.fog?m+=t.fogExpPS:"exp2"===o.fog?m+=t.fogExp2PS:m+=t.fogNonePS,2===o.normal&&(m+="\nuniform sampler2D normalMap;\n"),o.soft>0&&(m+=t.screenDepthPS),m+=t.particlePS,o.soft>0&&(m+=t.particle_softPS),1===o.normal&&(m+="\nvec3 normal = Normal;\n"),2===o.normal&&(m+=t.particle_normalMapPS),o.normal>0&&(m+=o.halflambert?t.particle_halflambertPS:t.particle_lambertPS),o.normal>0&&(m+=t.particle_lightingPS),o.blend===a?m+=t.particle_blendNormalPS:o.blend===n?m+=t.particle_blendAddPS:o.blend===r&&(m+=t.particle_blendMultiplyPS),m+=t.particle_endPS,e.createDefinition(i,{name:"ParticleShader",vertexCode:p,fragmentCode:m})}};export{i as particle};