mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
The base version of sorting priority add (#11599)
* sorting Priority add * fix CI * name change * binding add * name change to priority * bind remove Co-authored-by: ChiaNing <sun.clooud.mo@gmail.com>
This commit is contained in:
@@ -367,6 +367,7 @@ export class MeshRenderer extends ModelRenderer {
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
super.onEnable();
|
||||
if (!this._model) {
|
||||
this._updateModels();
|
||||
}
|
||||
|
||||
@@ -49,9 +49,23 @@ export class ModelRenderer extends Renderer {
|
||||
this._onVisibilityChange(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The priority which will be applied to the committed models.(Valid only in transparent queues)
|
||||
* @zh 应用于所有提交渲染的 Model 的排序优先级(只在半透明渲染队列中起效)
|
||||
*/
|
||||
get priority () {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
set priority (val) {
|
||||
if (val === this._priority) return;
|
||||
this._updatePriority();
|
||||
}
|
||||
|
||||
@serializable
|
||||
protected _visFlags = Layers.Enum.NONE;
|
||||
protected _models: scene.Model[] = [];
|
||||
protected _priority = 0;
|
||||
|
||||
/**
|
||||
* @zh 收集组件中的 models
|
||||
@@ -62,6 +76,10 @@ export class ModelRenderer extends Renderer {
|
||||
return this._models;
|
||||
}
|
||||
|
||||
protected onEnable () {
|
||||
this._updatePriority();
|
||||
}
|
||||
|
||||
protected _attachToScene () {
|
||||
}
|
||||
|
||||
@@ -70,4 +88,12 @@ export class ModelRenderer extends Renderer {
|
||||
|
||||
protected _onVisibilityChange (val) {
|
||||
}
|
||||
|
||||
protected _updatePriority () {
|
||||
if (this._models.length > 0) {
|
||||
for (let i = 0; i < this._models.length; i++) {
|
||||
this._models[i].priority = this._priority;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,6 +414,7 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
}
|
||||
const hash = (0 << 30) | pass.priority << 16 | subModel.priority << 8 | passIdx;
|
||||
const rp = new RenderInfo();
|
||||
rp.priority = ro.model.priority;
|
||||
rp.hash = hash;
|
||||
rp.depth = ro.depth || 0;
|
||||
rp.shaderId = shader.typedID;
|
||||
@@ -435,7 +436,7 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
* @zh 比较排序函数。半透明对象按优先级 -> 深度由后向前 -> Shader ID 顺序排序。
|
||||
*/
|
||||
protected _transparentCompareFn (a: RenderInfo, b: RenderInfo) {
|
||||
return (a.hash - b.hash) || (b.depth - a.depth) || (a.shaderId - b.shaderId);
|
||||
return (a.priority - b.priority) || (a.hash - b.hash) || (b.depth - a.depth) || (a.shaderId - b.shaderId);
|
||||
}
|
||||
|
||||
private _uploadInstanceBuffers () {
|
||||
|
||||
@@ -43,6 +43,7 @@ export class RenderObject implements IRenderObject {
|
||||
}
|
||||
}
|
||||
export class RenderInfo implements IRenderPass {
|
||||
public priority = 0;
|
||||
public hash = -1;
|
||||
public depth = -1;
|
||||
public shaderId = -1;
|
||||
|
||||
@@ -72,6 +72,7 @@ export interface IRenderObject {
|
||||
* @zh 渲染过程接口。
|
||||
*/
|
||||
export interface IRenderPass {
|
||||
priority: number;
|
||||
hash: number;
|
||||
depth: number;
|
||||
shaderId: number;
|
||||
|
||||
@@ -44,7 +44,7 @@ export function opaqueCompareFn (a: IRenderPass, b: IRenderPass) {
|
||||
* @zh 比较排序函数。半透明对象按优先级 -> 深度由后向前 -> Shader ID 顺序排序。
|
||||
*/
|
||||
export function transparentCompareFn (a: IRenderPass, b: IRenderPass) {
|
||||
return (a.hash - b.hash) || (b.depth - a.depth) || (a.shaderId - b.shaderId);
|
||||
return (a.priority - b.priority) || (a.hash - b.hash) || (b.depth - a.depth) || (a.shaderId - b.shaderId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,6 +69,7 @@ export class RenderQueue {
|
||||
constructor (desc: IRenderQueueDesc) {
|
||||
this._passDesc = desc;
|
||||
this._passPool = new RecyclePool<IRenderPass>(() => ({
|
||||
priority: 0,
|
||||
hash: 0,
|
||||
depth: 0,
|
||||
shaderId: 0,
|
||||
@@ -105,6 +106,7 @@ export class RenderQueue {
|
||||
}
|
||||
const hash = (0 << 30) | pass.priority << 16 | subModel.priority << 8 | passIdx;
|
||||
const rp = this._passPool.add();
|
||||
rp.priority = renderObj.model.priority;
|
||||
rp.hash = hash;
|
||||
rp.depth = renderObj.depth || 0;
|
||||
rp.shaderId = shader.typedID;
|
||||
|
||||
@@ -266,6 +266,18 @@ export class Model {
|
||||
this._enabled = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Rendering priority in the transparent queue of model.
|
||||
* @zh Model 在透明队列中的渲染排序优先级
|
||||
*/
|
||||
get priority () : number {
|
||||
return this._priority;
|
||||
}
|
||||
|
||||
set priority (val: number) {
|
||||
this._priority = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The type of the model
|
||||
* @zh 模型类型
|
||||
@@ -412,6 +424,8 @@ export class Model {
|
||||
*/
|
||||
protected _visFlags = Layers.Enum.NONE;
|
||||
|
||||
protected _priority = 0;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @en native object
|
||||
|
||||
@@ -961,6 +961,7 @@ export class ParticleSystem extends ModelRenderer {
|
||||
}
|
||||
|
||||
protected onEnable () {
|
||||
super.onEnable();
|
||||
legacyCC.director.on(legacyCC.Director.EVENT_BEFORE_COMMIT, this.beforeRender, this);
|
||||
if (this.playOnAwake && (!EDITOR || legacyCC.GAME_VIEW)) {
|
||||
this.play();
|
||||
|
||||
@@ -65,6 +65,7 @@ struct CC_DLL RenderTargetInfo {
|
||||
};
|
||||
|
||||
struct CC_DLL RenderPass {
|
||||
uint32_t priority = 0;
|
||||
uint32_t hash = 0;
|
||||
float depth = 0.0F;
|
||||
uint32_t shaderID = 0;
|
||||
@@ -175,6 +176,10 @@ inline bool opaqueCompareFn(const RenderPass &a, const RenderPass &b) {
|
||||
}
|
||||
|
||||
inline bool transparentCompareFn(const RenderPass &a, const RenderPass &b) {
|
||||
if (a.priority != b.priority) {
|
||||
return a.priority < b.priority;
|
||||
}
|
||||
|
||||
if (a.hash != b.hash) {
|
||||
return a.hash < b.hash;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,8 @@ bool RenderQueue::insertRenderPass(const RenderObject &renderObj, uint32_t subMo
|
||||
auto modelPriority = static_cast<uint32_t>(subModel->getPriority());
|
||||
auto shaderId = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(subModel->getShader(passIdx)));
|
||||
const auto hash = (0 << 30) | (passPriority << 16) | (modelPriority << 8) | passIdx;
|
||||
RenderPass renderPass = {hash, renderObj.depth, shaderId, passIdx, subModel};
|
||||
const auto priority = renderObj.model->getPriority();
|
||||
RenderPass renderPass = {priority, hash, renderObj.depth, shaderId, passIdx, subModel};
|
||||
_queue.emplace_back(renderPass);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -164,6 +164,8 @@ public:
|
||||
inline bool isDynamicBatching() const { return _isDynamicBatching; }
|
||||
inline float getShadowBias() const { return _shadowBias; }
|
||||
inline float getShadowNormalBias() const { return _shadowNormalBias; }
|
||||
inline uint32_t getPriority() const { return _priority; }
|
||||
inline void setPriority(uint32_t value) { _priority = value; }
|
||||
|
||||
void initLocalDescriptors(index_t subModelIndex);
|
||||
void initWorldBoundDescriptors(index_t subModelIndex);
|
||||
@@ -227,6 +229,8 @@ protected:
|
||||
IntrusivePtr<Texture2D> _lightmap;
|
||||
Vec4 _lightmapUVParam;
|
||||
|
||||
uint32_t _priority{0};
|
||||
|
||||
// For JS
|
||||
CallbacksInvoker _eventProcessor;
|
||||
bool _isCalledFromJS{false};
|
||||
|
||||
@@ -106,7 +106,7 @@ getter_setter = Root::[device:_device mainWindow curWindow tempWindow windows sc
|
||||
RenderScene::[name cameras? mainLight? sphereLights? spotLights? models],
|
||||
Skybox::[model enabled/isEnabled/setEnabled useHDR/isUseHDR/setUseHDR useIBL/isUseIBL/setUseIBL useDiffuseMap/isUseDiffuseMap/setUseDiffuseMap isRGBE/isRGBE/setRGBE envmap diffuseMap],
|
||||
Fog::[enabled/isEnabled/setEnabled accurate/isAccurate/setAccurate fogColor type fogDensity fogStart fogEnd fogAtten fogTop fogRange fogRange colorArray],
|
||||
Model::[scene _subModels:subModels/getSubModels inited/isInited _localDataUpdated/isLocalDataUpdated/setLocalDataUpdated _worldBounds:worldBounds/getWorldBounds/setWorldBounds _modelBounds:modelBounds/getModelBounds/setModelBounds worldBoundBuffer localBuffer updateStamp isInstancingEnabled/isInstancingEnabled receiveShadow/isReceiveShadow/setReceiveShadow castShadow/isCastShadow/setCastShadow node transform visFlags enabled/isEnabled/setEnabled type instancedAttributes/getInstancedAttributeBlock/setInstancedAttributeBlock isDynamicBatching/isDynamicBatching/setDynamicBatching],
|
||||
Model::[scene _subModels:subModels/getSubModels inited/isInited _localDataUpdated/isLocalDataUpdated/setLocalDataUpdated _worldBounds:worldBounds/getWorldBounds/setWorldBounds _modelBounds:modelBounds/getModelBounds/setModelBounds worldBoundBuffer localBuffer updateStamp isInstancingEnabled/isInstancingEnabled receiveShadow/isReceiveShadow/setReceiveShadow castShadow/isCastShadow/setCastShadow node transform visFlags enabled/isEnabled/setEnabled type instancedAttributes/getInstancedAttributeBlock/setInstancedAttributeBlock isDynamicBatching/isDynamicBatching/setDynamicBatching priority],
|
||||
SubModel::[passes shaders subMesh priority inputAssembler descriptorSet patches planarInstanceShader planarShader],
|
||||
ShadowsInfo::[enabled/isEnabled/setEnabled type planeDirection planeHeight shadowColor maxReceived shadowMapSize],
|
||||
Shadows::[enabled/isEnabled/setEnabled type normal distance shadowColor maxReceived size shadowMapDirty/isShadowMapDirty/setShadowMapDirty matLight material instancingMaterial],
|
||||
|
||||
Reference in New Issue
Block a user