UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

46 lines (43 loc) 1.59 kB
import { Vec3 } from '../../core/math/vec3.js'; import { random } from '../../core/math/random.js'; import { Color } from '../../core/math/color.js'; import { Entity } from '../entity.js'; import { SHADOW_PCF3_32F } from '../../scene/constants.js'; import { BakeLight } from './bake-light.js'; var _tempPoint = new Vec3(); class BakeLightAmbient extends BakeLight { get numVirtualLights() { return this.light.bakeNumSamples; } prepareVirtualLight(index, numVirtualLights) { random.spherePointDeterministic(_tempPoint, index, numVirtualLights, 0, this.scene.ambientBakeSpherePart); this.light._node.lookAt(_tempPoint.mulScalar(-1)); this.light._node.rotateLocal(90, 0, 0); var gamma = 2.2; var fullIntensity = 2 * Math.PI * this.scene.ambientBakeSpherePart; var linearIntensity = Math.pow(fullIntensity, gamma); this.light.intensity = Math.pow(linearIntensity / numVirtualLights, 1 / gamma); } constructor(lightmapper){ var scene = lightmapper.scene; var lightEntity = new Entity('AmbientLight'); lightEntity.addComponent('light', { type: 'directional', affectDynamic: true, affectLightmapped: false, bake: true, bakeNumSamples: scene.ambientBakeNumSamples, castShadows: true, normalOffsetBias: 0.05, shadowBias: 0.2, shadowDistance: 1, shadowResolution: 2048, shadowType: SHADOW_PCF3_32F, color: Color.WHITE, intensity: 1, bakeDir: false }); super(scene, lightEntity.light.light, lightmapper.lightingParams); } } export { BakeLightAmbient };