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

Add priority property for Renderer #803

Merged
merged 9 commits into from
May 24, 2022
18 changes: 10 additions & 8 deletions packages/core/src/RenderPipeline/BasicRenderPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,16 @@ export class BasicRenderPipeline {
* @param element - Render element
*/
pushPrimitive(element: RenderElement | SpriteElement) {
const renderQueueType = element.material.renderQueueType;

if (renderQueueType > (RenderQueueType.Transparent + RenderQueueType.AlphaTest) >> 1) {
this._transparentQueue.pushPrimitive(element);
} else if (renderQueueType > (RenderQueueType.AlphaTest + RenderQueueType.Opaque) >> 1) {
this._alphaTestQueue.pushPrimitive(element);
} else {
this._opaqueQueue.pushPrimitive(element);
switch (element.material.renderQueueType) {
case RenderQueueType.Transparent:
this._transparentQueue.pushPrimitive(element);
break;
case RenderQueueType.AlphaTest:
this._alphaTestQueue.pushPrimitive(element);
break;
default:
this._opaqueQueue.pushPrimitive(element);
break;
}
}

Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/RenderPipeline/RenderQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ export class RenderQueue {
*/
static _compareFromNearToFar(a: Item, b: Item): number {
return (
a.material.renderQueueType - b.material.renderQueueType ||
a.component._distanceForSort - b.component._distanceForSort ||
b.component._renderSortId - a.component._renderSortId
a.component.sortingLayer - b.component.sortingLayer ||
a.component._distanceForSort - b.component._distanceForSort
);
}

Expand All @@ -30,9 +29,8 @@ export class RenderQueue {
*/
static _compareFromFarToNear(a: Item, b: Item): number {
return (
a.material.renderQueueType - b.material.renderQueueType ||
b.component._distanceForSort - a.component._distanceForSort ||
b.component._renderSortId - a.component._renderSortId
a.component.sortingLayer - b.component.sortingLayer ||
b.component._distanceForSort - a.component._distanceForSort
);
}

Expand Down
17 changes: 13 additions & 4 deletions packages/core/src/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export abstract class Renderer extends Component {
@ignoreClone
_globalShaderMacro: ShaderMacroCollection = new ShaderMacroCollection();

/** @internal temp solution. */
@ignoreClone
_renderSortId: number = 0;

@ignoreClone
protected _overrideUpdate: boolean = false;
@shallowClone
Expand All @@ -66,6 +62,8 @@ export abstract class Renderer extends Component {
private _normalMatrix: Matrix = new Matrix();
@ignoreClone
private _materialsInstanced: boolean[] = [];
@ignoreClone
private _sortingLayer: number = 0;

/**
* Material count.
Expand Down Expand Up @@ -94,6 +92,17 @@ export abstract class Renderer extends Component {
return this._bounds;
}

/**
* The render order of the renderer.
*/
get sortingLayer(): number {
return this._sortingLayer;
}

set sortingLayer(value: number) {
this._sortingLayer = value;
}

/**
* @internal
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/material/enums/RenderQueueType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/
export enum RenderQueueType {
/** Opaque queue. */
Opaque = 1000,
Opaque = "Opaque",
/** Opaque queue, alpha cutoff. */
AlphaTest = 2000,
AlphaTest = "AlphaTest",
/** Transparent queue, rendering from back to front to ensure correct rendering of transparent objects. */
Transparent = 3000
Transparent = "Transparent"
}