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

Fix issue when using multi-views and scene clear color is transparent #9992

Merged
merged 2 commits into from Mar 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/preview release/what's new.md
Expand Up @@ -145,6 +145,7 @@
- Fix bones serialization to include their ids. This allows to retrieve bones (animation groups, etc.) once the scene has been re-serialized ([julien-moreau](https://github.com/julien-moreau))
- Fix an issue with hand-detachment when using hand tracking in WebXR ([#9882](https://github.com/BabylonJS/Babylon.js/issues/9882)) ([RaananW](https://github.com/RaananW))
- Fix issue with cursor and 'doNotHandleCursors' on GUI ([msDestiny14](https://github.com/msDestiny14))
- Fix issue with multi-views when using a transparent scene clear color ([Popov72](https://github.com/Popov72))
- Fix thin instances + animated bones not rendered in the depth renderer ([Popov72](https://github.com/Popov72))

## Breaking changes
Expand Down
12 changes: 9 additions & 3 deletions src/Engines/Extensions/engine.views.ts
Expand Up @@ -12,6 +12,8 @@ export class EngineView {
target: HTMLCanvasElement;
/** Defines an optional camera used to render the view (will use active camera else) */
camera?: Camera;
/** Indicates if the destination view canvas should be cleared before copying the parent canvas. Can help if the scene clear color has alpha < 1 */
clearBeforeCopy?: boolean;
}

declare module "../../Engines/engine" {
Expand All @@ -35,9 +37,10 @@ declare module "../../Engines/engine" {
* Register a new child canvas
* @param canvas defines the canvas to register
* @param camera defines an optional camera to use with this canvas (it will overwrite the scene.camera for this view)
* @param clearBeforeCopy Indicates if the destination view canvas should be cleared before copying the parent canvas. Can help if the scene clear color has alpha < 1
* @returns the associated view
*/
registerView(canvas: HTMLCanvasElement, camera?: Camera): EngineView;
registerView(canvas: HTMLCanvasElement, camera?: Camera, clearBeforeCopy?: boolean): EngineView;

/**
* Remove a registered child canvas
Expand All @@ -52,7 +55,7 @@ Engine.prototype.getInputElement = function(): Nullable<HTMLElement> {
return this.inputElement || this.getRenderingCanvas();
};

Engine.prototype.registerView = function(canvas: HTMLCanvasElement, camera?: Camera): EngineView {
Engine.prototype.registerView = function(canvas: HTMLCanvasElement, camera?: Camera, clearBeforeCopy?: boolean): EngineView {
if (!this.views) {
this.views = [];
}
Expand All @@ -69,7 +72,7 @@ Engine.prototype.registerView = function(canvas: HTMLCanvasElement, camera?: Cam
canvas.height = masterCanvas.height;
}

let newView = {target: canvas, camera: camera};
let newView = {target: canvas, camera, clearBeforeCopy};
this.views.push(newView);

if (camera) {
Expand Down Expand Up @@ -153,6 +156,9 @@ Engine.prototype._renderViews = function() {
this._renderFrame();

// Copy to target
if (view.clearBeforeCopy) {
context.clearRect(0, 0, parent.width, parent.height);
}
context.drawImage(parent, 0, 0);

// Restore
Expand Down