Skip to content

Commit

Permalink
light Add bake dirty for render filter (cocos#8146)
Browse files Browse the repository at this point in the history
* light Add bake dirty for render filter

* light component add bake dirty

Co-authored-by: Myway3D1 <[email protected]>
  • Loading branch information
MSoft1115 and Myway3D authored Jan 18, 2021
1 parent b3f6bb9 commit 5f53b78
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cocos/3d/lights/light-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const _color_tmp = new Vec3();
*/
@ccclass('cc.StaticLightSettings')
class StaticLightSettings {
@serializable
protected _baked = false;
@serializable
protected _editorOnly = false;
@serializable
Expand All @@ -67,6 +69,17 @@ class StaticLightSettings {
this._editorOnly = val;
}

/**
* bake state
*/
get baked () {
return this._baked;
}

set baked (val) {
this._baked = val;
}

/**
* @en bakeable.
* @zh 是否可烘培。
Expand Down Expand Up @@ -195,6 +208,20 @@ export class Light extends Component {
return this._type;
}

/**
* bake state
*/
get baked () {
return this.staticSettings.baked;
}

set baked (val) {
this.staticSettings.baked = val;
if (this._light !== null) {
this._light.baked = val;
}
}

constructor () {
super();
this._lightType = scene.Light;
Expand Down Expand Up @@ -224,6 +251,7 @@ export class Light extends Component {
this.useColorTemperature = this._useColorTemperature;
this.colorTemperature = this._colorTemperature;
this._light.node = this.node;
this._light.baked = this.baked;
}

protected _destroyLight () {
Expand Down
8 changes: 8 additions & 0 deletions cocos/core/pipeline/render-additive-light-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ export class RenderAdditiveLightQueue {

for (let i = 0; i < sphereLights.length; i++) {
const light = sphereLights[i];
if (light.baked) {
continue;
}

Sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range);
if (intersect.sphereFrustum(_sphere, camera.frustum)) {
validLights.push(light);
Expand All @@ -230,6 +234,10 @@ export class RenderAdditiveLightQueue {
const { spotLights } = camera.scene!;
for (let i = 0; i < spotLights.length; i++) {
const light = spotLights[i];
if (light.baked) {
continue;
}

Sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range);
if (intersect.sphereFrustum(_sphere, camera.frustum)) {
validLights.push(light);
Expand Down
10 changes: 10 additions & 0 deletions cocos/core/renderer/scene/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ export enum LightType {
export const nt2lm = (size: number) => 4 * Math.PI * Math.PI * size * size;

export class Light {
get baked () {
return this._baked;
}

set baked (val) {
this._baked = val;
}

set color (color: Vec3) {
this._color.set(color);
LightPool.setVec3(this._handle, LightView.COLOR, color);
Expand Down Expand Up @@ -131,6 +139,8 @@ export class Light {
return this._handle;
}

protected _baked = false;

protected _color: Vec3 = new Vec3(1, 1, 1);

protected _colorTemp = 6550.0;
Expand Down

0 comments on commit 5f53b78

Please sign in to comment.