UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

47 lines (44 loc) 2.14 kB
import { ShaderProcessorOptions } from '../../platform/graphics/shader-processor-options.js'; import { PARTICLEORIENTATION_SCREEN, TONEMAP_LINEAR, GAMMA_NONE, SHADER_FORWARD, SHADERDEF_UV0 } from '../constants.js'; import { getProgramLibrary } from '../shader-lib/get-program-library.js'; import { Material } from '../materials/material.js'; import { particle } from '../shader-lib/programs/particle.js'; import { ShaderUtils } from '../shader-lib/shader-utils.js'; class ParticleMaterial extends Material { constructor(emitter){ super(), this.emitter = null; this.emitter = emitter; } getShaderVariant(params) { const { device, scene, cameraShaderParams, objDefs } = params; const { emitter } = this; const options = { defines: ShaderUtils.getCoreDefines(this, params), pass: SHADER_FORWARD, useCpu: this.emitter.useCpu, normal: emitter.lighting ? emitter.normalMap !== null ? 2 : 1 : 0, halflambert: this.emitter.halfLambert, stretch: this.emitter.stretch, alignToMotion: this.emitter.alignToMotion, soft: this.emitter.depthSoftening, mesh: this.emitter.useMesh, meshUv: objDefs & SHADERDEF_UV0, gamma: cameraShaderParams?.shaderOutputGamma ?? GAMMA_NONE, toneMap: cameraShaderParams?.toneMapping ?? TONEMAP_LINEAR, fog: scene && !this.emitter.noFog ? scene.fog.type : 'none', wrap: this.emitter.wrap && this.emitter.wrapBounds, localSpace: this.emitter.localSpace, screenSpace: emitter.inTools ? false : this.emitter.screenSpace, blend: this.emitter.blendType, animTex: this.emitter._isAnimated(), animTexLoop: this.emitter.animLoop, pack8: this.emitter.pack8, customFace: this.emitter.orientation !== PARTICLEORIENTATION_SCREEN }; const processingOptions = new ShaderProcessorOptions(params.viewUniformFormat, params.viewBindGroupFormat, params.vertexFormat); const library = getProgramLibrary(device); library.register('particle', particle); return library.getProgram('particle', options, processingOptions, this.userId); } } export { ParticleMaterial };