Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export class FrameGraphGeometryRendererTask extends FrameGraphTask {
this._renderer.renderParticles = false;
this._renderer.enableBoundingBoxRendering = false;
this._renderer.enableOutlineRendering = false;
this._renderer.disableDepthPrePass = true;

this._renderer.customIsReadyFunction = (mesh: AbstractMesh, refreshRate: number, preWarm?: boolean) => {
if (this.dontRenderWhenMaterialDepthWriteIsDisabled && mesh.material && mesh.material.disableDepthWrite) {
Expand Down
13 changes: 13 additions & 0 deletions packages/dev/core/src/Rendering/objectRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ export class ObjectRenderer {
*/
public dontSetTransformationMatrix = false;

private _disableDepthPrePass = false;
/**
* Specifies to disable depth pre-pass if true (default: false)
*/
public get disableDepthPrePass() {
return this._disableDepthPrePass;
}

public set disableDepthPrePass(value: boolean) {
this._disableDepthPrePass = value;
this._renderingManager.disableDepthPrePass = value;
}

/**
* Override the mesh isReady function with your own one.
*/
Expand Down
18 changes: 11 additions & 7 deletions packages/dev/core/src/Rendering/renderingGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class RenderingGroup {

public onBeforeTransparentRendering: () => void;

public disableDepthPrePass = false;

/**
* Set the opaque sort comparison function.
* If null the sub meshes will be render in the order they were created
Expand Down Expand Up @@ -201,23 +203,23 @@ export class RenderingGroup {
* @param subMeshes The submeshes to render
*/
private _renderOpaqueSorted(subMeshes: SmartArray<SubMesh>): void {
RenderingGroup._RenderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera, false);
RenderingGroup._RenderSorted(subMeshes, this._opaqueSortCompareFn, this._scene.activeCamera, false, this.disableDepthPrePass);
}

/**
* Renders the opaque submeshes in the order from the alphatestSortCompareFn.
* @param subMeshes The submeshes to render
*/
private _renderAlphaTestSorted(subMeshes: SmartArray<SubMesh>): void {
RenderingGroup._RenderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera, false);
RenderingGroup._RenderSorted(subMeshes, this._alphaTestSortCompareFn, this._scene.activeCamera, false, this.disableDepthPrePass);
}

/**
* Renders the opaque submeshes in the order from the transparentSortCompareFn.
* @param subMeshes The submeshes to render
*/
private _renderTransparentSorted(subMeshes: SmartArray<SubMesh>): void {
RenderingGroup._RenderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera, true);
RenderingGroup._RenderSorted(subMeshes, this._transparentSortCompareFn, this._scene.activeCamera, true, this.disableDepthPrePass);
}

/**
Expand All @@ -226,12 +228,14 @@ export class RenderingGroup {
* @param sortCompareFn The comparison function use to sort
* @param camera The camera position use to preprocess the submeshes to help sorting
* @param transparent Specifies to activate blending if true
* @param disableDepthPrePass Specifies to disable depth pre-pass if true (default: false)
*/
private static _RenderSorted(
subMeshes: SmartArray<SubMesh>,
sortCompareFn: Nullable<(a: SubMesh, b: SubMesh) => number>,
camera: Nullable<Camera>,
transparent: boolean
transparent: boolean,
disableDepthPrePass?: boolean
): void {
let subIndex = 0;
let subMesh: SubMesh;
Expand Down Expand Up @@ -262,7 +266,7 @@ export class RenderingGroup {
if (transparent) {
const material = subMesh.getMaterial();

if (material && material.needDepthPrePass) {
if (material && material.needDepthPrePass && !disableDepthPrePass) {
const engine = material.getScene().getEngine();
engine.setColorWrite(false);
engine.setAlphaMode(Constants.ALPHA_DISABLE);
Expand Down Expand Up @@ -413,13 +417,13 @@ export class RenderingGroup {
this._transparentSubMeshes.push(subMesh);
} else if (material.needAlphaTestingForMesh(mesh)) {
// Alpha test
if (material.needDepthPrePass) {
if (material.needDepthPrePass && !this.disableDepthPrePass) {
this._depthOnlySubMeshes.push(subMesh);
}

this._alphaTestSubMeshes.push(subMesh);
} else {
if (material.needDepthPrePass) {
if (material.needDepthPrePass && !this.disableDepthPrePass) {
this._depthOnlySubMeshes.push(subMesh);
}

Expand Down
16 changes: 16 additions & 0 deletions packages/dev/core/src/Rendering/renderingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ export class RenderingManager {
*/
public _useSceneAutoClearSetup = false;

private _disableDepthPrePass = false;
/**
* Specifies to disable depth pre-pass if true (default: false)
*/
public get disableDepthPrePass() {
return this._disableDepthPrePass;
}

public set disableDepthPrePass(value: boolean) {
this._disableDepthPrePass = value;
for (const group of this._renderingGroups) {
group.disableDepthPrePass = value;
}
}

private _scene: Scene;
private _renderingGroups = new Array<RenderingGroup>();
private _depthStencilBufferAlreadyCleaned: boolean;
Expand Down Expand Up @@ -301,6 +316,7 @@ export class RenderingManager {
this._customAlphaTestSortCompareFn[renderingGroupId],
this._customTransparentSortCompareFn[renderingGroupId]
);
this._renderingGroups[renderingGroupId].disableDepthPrePass = this._disableDepthPrePass;
}
}

Expand Down