Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine particle-simulator-2d.ts: Remove ZERO_VEC2 & misc #17591

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cocos/input/types/event-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ export enum InputEventType {
* trigger this event.
* @zh 当鼠标离开窗口或者 canvas 时发出该消息。只有 Windows、macOS 或者 PC web 会触发该事件。
*/
MOUSE_LEAVE = 'mouse-leave',
MOUSE_LEAVE = 'mouse-leave-window',

/**
* @en The event type indicates mouse enters the window or canvas. Only Windows, macOS or web PC can
* trigger this event.
* @zh 当鼠标进入窗口或者 canvas 时发出该消息。只有 Windows、macOS 或者 PC web 会触发该事件。
*/
MOUSE_ENTER = 'mouse-enter',
MOUSE_ENTER = 'mouse-enter-window',

/**
* @en
Expand Down
27 changes: 13 additions & 14 deletions cocos/particle-2d/particle-simulator-2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
THE SOFTWARE.
*/

import { Vec2, Color, js, misc, random, IColorLike, Vec4 } from '../core';
import { Vec2, Color, js, misc, random, IColorLike, Vec4, clamp } from '../core';
import { vfmtPosUvColor, getComponentPerVertex } from '../2d/renderer/vertex-format';
import { PositionType, EmitterMode, START_SIZE_EQUAL_TO_END_SIZE, START_RADIUS_EQUAL_TO_END_RADIUS } from './define';
import { ParticleSystem2D } from './particle-system-2d';
import { MeshRenderData } from '../2d/renderer/render-data';

const ZERO_VEC2 = new Vec2(0, 0);
const _pos = new Vec2();
const _tpa = new Vec2();
const _tpb = new Vec2();
Expand Down Expand Up @@ -78,8 +77,8 @@ class ParticlePool extends js.Pool<Particle> {
}

const pool = new ParticlePool((par: Particle): void => {
par.pos.set(ZERO_VEC2);
par.startPos.set(ZERO_VEC2);
par.pos.set(Vec2.ZERO);
par.startPos.set(Vec2.ZERO);
par.color.set(0, 0, 0, 255);
par.deltaColor.r = par.deltaColor.g = par.deltaColor.b = 0;
par.deltaColor.a = 255;
Expand All @@ -88,10 +87,10 @@ const pool = new ParticlePool((par: Particle): void => {
par.rotation = 0;
par.deltaRotation = 0;
par.timeToLive = 0;
par.drawPos.set(ZERO_VEC2);
par.drawPos.set(Vec2.ZERO);
par.aspectRatio = 1;
// Mode A
par.dir.set(ZERO_VEC2);
par.dir.set(Vec2.ZERO);
par.radialAccel = 0;
par.tangentialAccel = 0;
// Mode B
Expand Down Expand Up @@ -169,14 +168,14 @@ export class Simulator {
const endColor = psys.endColor;
const endColorVar = psys.endColorVar;

particle.color.r = sr = misc.clampf(startColor.r + startColorVar.r * (random() - 0.5) * 2, 0, 255);
particle.color.g = sg = misc.clampf(startColor.g + startColorVar.g * (random() - 0.5) * 2, 0, 255);
particle.color.b = sb = misc.clampf(startColor.b + startColorVar.b * (random() - 0.5) * 2, 0, 255);
particle.color.a = sa = misc.clampf(startColor.a + startColorVar.a * (random() - 0.5) * 2, 0, 255);
particle.deltaColor.r = (misc.clampf(endColor.r + endColorVar.r * (random() - 0.5) * 2, 0, 255) - sr) / timeToLive;
particle.deltaColor.g = (misc.clampf(endColor.g + endColorVar.g * (random() - 0.5) * 2, 0, 255) - sg) / timeToLive;
particle.deltaColor.b = (misc.clampf(endColor.b + endColorVar.b * (random() - 0.5) * 2, 0, 255) - sb) / timeToLive;
particle.deltaColor.a = (misc.clampf(endColor.a + endColorVar.a * (random() - 0.5) * 2, 0, 255) - sa) / timeToLive;
particle.color.r = sr = clamp(startColor.r + startColorVar.r * (random() - 0.5) * 2, 0, 255);
particle.color.g = sg = clamp(startColor.g + startColorVar.g * (random() - 0.5) * 2, 0, 255);
particle.color.b = sb = clamp(startColor.b + startColorVar.b * (random() - 0.5) * 2, 0, 255);
particle.color.a = sa = clamp(startColor.a + startColorVar.a * (random() - 0.5) * 2, 0, 255);
particle.deltaColor.r = (clamp(endColor.r + endColorVar.r * (random() - 0.5) * 2, 0, 255) - sr) / timeToLive;
particle.deltaColor.g = (clamp(endColor.g + endColorVar.g * (random() - 0.5) * 2, 0, 255) - sg) / timeToLive;
particle.deltaColor.b = (clamp(endColor.b + endColorVar.b * (random() - 0.5) * 2, 0, 255) - sb) / timeToLive;
particle.deltaColor.a = (clamp(endColor.a + endColorVar.a * (random() - 0.5) * 2, 0, 255) - sa) / timeToLive;

// size
let startS = psys.startSize + psys.startSizeVar * (random() - 0.5) * 2;
Expand Down
27 changes: 6 additions & 21 deletions cocos/rendering/custom/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,7 @@ export function getDescBindingFromName (bindingName: string): number {
return -1;
}

const uniformMap: Map<string, Float32Array> = new Map();
const buffHashMap: Map<Buffer, number> = new Map();
function numsHash (arr: number[]): number {
let hash = 0;
for (let i = 0; i < arr.length; i++) {
hash = hashCombineNum(arr[i], hash);
}
return hash;
}

const uniformMap: Map<Buffer, Float32Array> = new Map();
class DescBuffManager {
private buffers: Buffer[] = [];
private currBuffIdx: number = 0;
Expand All @@ -484,20 +475,14 @@ class DescBuffManager {
updateBuffer (bindId: number, vals: number[], layout: string, setData: DescriptorSetData): void {
const descriptorSet = setData.descriptorSet!;
const buffer = this.getCurrentBuffer();
const uniformKey = `${layout}${bindId}${this.currBuffIdx}`;
let currUniform = uniformMap.get(uniformKey);
const currHash = numsHash(vals);
let currUniform = uniformMap.get(buffer);
if (!currUniform) {
currUniform = new Float32Array(vals);
uniformMap.set(uniformKey, currUniform);
}
const destHash = buffHashMap.get(buffer);
if (destHash !== currHash) {
currUniform.set(vals);
buffer.update(currUniform);
bindGlobalDesc(descriptorSet, bindId, buffer);
buffHashMap.set(buffer, currHash);
uniformMap.set(buffer, currUniform);
}
currUniform.set(vals);
buffer.update(currUniform);
bindGlobalDesc(descriptorSet, bindId, buffer);
}
}

Expand Down
3 changes: 2 additions & 1 deletion cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ class DeviceRenderScene implements RecordingInterface {
const renderQueueDesc = sceneCulling.renderQueueIndex.get(this.graphScene.sceneID)!;
const renderQueue = sceneCulling.renderQueues[renderQueueDesc.renderQueueTarget];
const graphSceneData = this.graphScene.scene!;
if (bool(graphSceneData.flags & SceneFlags.REFLECTION_PROBE)) renderQueue.probeQueue.applyMacro();
renderQueue.recordCommands(context.commandBuffer, this._renderPass);
if (bool(graphSceneData.flags & SceneFlags.REFLECTION_PROBE)) renderQueue.probeQueue.removeMacro();
if (graphSceneData.flags & SceneFlags.GEOMETRY) {
Expand Down Expand Up @@ -1995,7 +1996,7 @@ class PreRenderVisitor extends BaseRenderVisitor implements RenderGraphVisitor {
if (!this.rg.getValid(this.sceneID)) return;
const renderQueue = this.currQueue as DeviceRenderQueue;
const graphScene = context.pools.addGraphScene();
graphScene.init(null, value, -1);
graphScene.init(null, value, this.sceneID);
const renderScene = renderQueue.addScene(graphScene);
renderScene.preRecord();
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/rendering/custom/scene-culling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function addRenderObject (
): void {
const probeQueue = queue.probeQueue;
if (isDrawProbe) {
probeQueue.applyMacro(model, phaseLayoutId);
probeQueue.addToProbeQueue(model, phaseLayoutId);
}
const subModels = model.subModels;
const subModelCount = subModels.length;
Expand Down
20 changes: 12 additions & 8 deletions cocos/rendering/custom/web-pipeline-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ export class ProbeHelperQueue {
this.probeMap.length = 0;
}

applyMacro (): void {
for (const subModel of this.probeMap) {
let patches: IMacroPatch[] = [
{ name: CC_USE_RGBE_OUTPUT, value: true },
];
if (subModel.patches) {
patches = patches.concat(subModel.patches);
}
subModel.onMacroPatchesStateChanged(patches);
}
}
removeMacro (): void {
for (const subModel of this.probeMap) {
if (!subModel.patches) continue;
Expand All @@ -238,7 +249,7 @@ export class ProbeHelperQueue {
}
}
}
applyMacro (model: Model, probeLayoutId: number): void {
addToProbeQueue (model: Model, probeLayoutId: number): void {
const subModels = model.subModels;
for (let j = 0; j < subModels.length; j++) {
const subModel: SubModel = subModels[j];
Expand All @@ -258,13 +269,6 @@ export class ProbeHelperQueue {
}
if (passIdx < 0) { continue; }
if (!bUseReflectPass) {
let patches: IMacroPatch[] = [];
patches = patches.concat(subModel.patches!);
const useRGBEPatchs: IMacroPatch[] = [
{ name: CC_USE_RGBE_OUTPUT, value: true },
];
patches = patches.concat(useRGBEPatchs);
subModel.onMacroPatchesStateChanged(patches);
this.probeMap.push(subModel);
}
}
Expand Down
14 changes: 11 additions & 3 deletions cocos/spine/skeleton-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ class SkeletonCache {
}
}

const skeletonInfo = this._skeletonCache[assetUuid];
if (!skeletonInfo) return;

const sharedOperate = (aniKey: string, animationCache: AnimationCache): void => {
this._animationPool[`${assetUuid}#${aniKey}`] = animationCache;
animationCache.clear();
Expand All @@ -366,9 +369,6 @@ class SkeletonCache {
animationCache.destroy();
};
const operate = this._privateMode ? privateOperate : sharedOperate;

const skeletonInfo = this._skeletonCache[assetUuid];
if (!skeletonInfo) return;
const animationsCache = skeletonInfo.animationsCache;
for (const aniKey in animationsCache) {
// Clear cache texture, and put cache into pool.
Expand Down Expand Up @@ -466,6 +466,14 @@ class SkeletonCache {
delete animationPool[key];
}
}
let skeletonInfo = this._skeletonCache[uuid];
const skeleton = skeletonInfo && skeletonInfo.skeleton;
if (skeleton) {
spine.wasmUtil.destroySpineSkeleton(skeleton);
}
if (skeletonInfo) {
delete this._skeletonCache[uuid];
}
} else {
const animationPool = this._animationPool;
for (const key in animationPool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,6 @@ export class BuiltinPipelineSettings extends Component {
return this._settings.bloom.threshold;
}

@property({
tooltip: 'i18n:bloom.intensity',
group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
type: CCFloat,
min: 0,
})
set bloomIntensity(value: number) {
this._settings.bloom.intensity = value;
}
Expand Down
6 changes: 6 additions & 0 deletions editor/assets/default_renderpipeline/builtin-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class CameraConfigs {
enableFXAA = false;
enableFSR = false;
enableHDR = false;
enablePlanarReflectionProbe = false;
useFullPipeline = false;
singleForwardRadiancePass = false;
radianceFormat = gfx.Format.RGBA8;
Expand Down Expand Up @@ -212,6 +213,8 @@ function setupCameraConfigs(
&& !!camera.scene.mainLight
&& camera.scene.mainLight.shadowEnabled;

cameraConfigs.enablePlanarReflectionProbe = isMainGameWindow || camera.cameraUsage === CameraUsage.SCENE_VIEW;

cameraConfigs.enableProfiler = DEBUG && isMainGameWindow;

cameraConfigs.settings = camera.pipelineSettings
Expand Down Expand Up @@ -1506,6 +1509,9 @@ if (rendering) {
const height = Math.max(Math.floor(area.y), 1);

if (probe.probeType === renderer.scene.ProbeType.PLANAR) {
if (!this._cameraConfigs.enablePlanarReflectionProbe) {
continue;
}
const window: renderer.RenderWindow = probe.realtimePlanarTexture!.window!;
const colorName = `PlanarProbeRT${probeID}`;
const depthStencilName = `PlanarProbeDS${probeID}`;
Expand Down
Loading