Skip to content

Commit

Permalink
improve performance (cocos#16650)
Browse files Browse the repository at this point in the history
* improve performance

* fix typo
  • Loading branch information
star-e authored Jan 3, 2024
1 parent a55c0aa commit 6dc6fed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
37 changes: 29 additions & 8 deletions cocos/rendering/post-process/utils/pass-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export class PassContext {
forwardPass: any = undefined;
postProcess: PostProcess | undefined;

maxSpotLights = 0xFFFFFFFF;
maxSphereLights = 0xFFFFFFFF;
maxPointLights = 0xFFFFFFFF;
maxRangedDirLights = 0xFFFFFFFF;

setClearFlag (clearFlag: ClearFlagBit): PassContext {
this.clearFlag = clearFlag;
return this;
Expand Down Expand Up @@ -85,9 +90,25 @@ export class PassContext {
}

addSceneLights (queue: RenderQueueBuilder, camera: Camera, flags: SceneFlags = SceneFlags.BLEND): void {
if (this.maxPointLights === 0
&& this.maxSphereLights === 0
&& this.maxSpotLights === 0
&& this.maxRangedDirLights === 0) {
return;
}
const scene = camera.scene!;
for (let i = 0; i < scene.spotLights.length; i++) {
const light = scene.spotLights[i];
const spotLights = scene.spotLights;
const sphereLights = scene.sphereLights;
const pointLights = scene.pointLights;
const rangedDirLights = scene.rangedDirLights;

const numSpotLights = Math.min(spotLights.length, this.maxSpotLights);
const numSphereLights = Math.min(sphereLights.length, this.maxSphereLights);
const numPointLights = Math.min(pointLights.length, this.maxPointLights);
const numRangedDirLights = Math.min(rangedDirLights.length, this.maxRangedDirLights);

for (let i = 0; i < numSpotLights; i++) {
const light = spotLights[i];
if (light.baked) {
continue;
}
Expand All @@ -97,8 +118,8 @@ export class PassContext {
}
}
// sphere lights
for (let i = 0; i < scene.sphereLights.length; i++) {
const light = scene.sphereLights[i];
for (let i = 0; i < numSphereLights; i++) {
const light = sphereLights[i];
if (light.baked) {
continue;
}
Expand All @@ -108,8 +129,8 @@ export class PassContext {
}
}
// point lights
for (let i = 0; i < scene.pointLights.length; i++) {
const light = scene.pointLights[i];
for (let i = 0; i < numPointLights; i++) {
const light = pointLights[i];
if (light.baked) {
continue;
}
Expand All @@ -119,8 +140,8 @@ export class PassContext {
}
}
// ranged dir lights
for (let i = 0; i < scene.rangedDirLights.length; i++) {
const light = scene.rangedDirLights[i];
for (let i = 0; i < numRangedDirLights; i++) {
const light = rangedDirLights[i];
geometry.AABB.transform(boundingBox, rangedDirLightBoundingBox, light.node!.getWorldMatrix());
if (geometry.intersect.aabbFrustum(boundingBox, camera.frustum)) {
queue.addSceneOfCamera(camera, new LightInfo(light), flags);
Expand Down
8 changes: 4 additions & 4 deletions native/cocos/renderer/pipeline/custom/RenderGraphTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,10 @@ struct RenderData {
RenderData& operator=(RenderData&& rhs) = default;
RenderData& operator=(RenderData const& rhs) = delete;

PmrUnorderedMap<uint32_t, ccstd::pmr::vector<char>> constants;
PmrUnorderedMap<uint32_t, IntrusivePtr<gfx::Buffer>> buffers;
PmrUnorderedMap<uint32_t, IntrusivePtr<gfx::Texture>> textures;
PmrUnorderedMap<uint32_t, gfx::Sampler*> samplers;
PmrFlatMap<uint32_t, ccstd::pmr::vector<char>> constants;
PmrFlatMap<uint32_t, IntrusivePtr<gfx::Buffer>> buffers;
PmrFlatMap<uint32_t, IntrusivePtr<gfx::Texture>> textures;
PmrFlatMap<uint32_t, gfx::Sampler*> samplers;
ccstd::pmr::string custom;
};

Expand Down

0 comments on commit 6dc6fed

Please sign in to comment.