Skip to content

Commit

Permalink
feat: add transparent renderpass
Browse files Browse the repository at this point in the history
Render transparently after opaque pass.
  • Loading branch information
oscarlorentzon committed Feb 2, 2024
1 parent c1827c2 commit c627c57
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions declarations/mapillary.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -3113,6 +3113,7 @@ export type ViewerEventType =

declare var RenderPass: {|
+Opaque: 0, // 0
+Transparent: 1, // 1
|};

/**
Expand Down
6 changes: 6 additions & 0 deletions src/render/GLRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class GLRenderer {
private _subscriptions: SubscriptionHolder = new SubscriptionHolder();

private _opaqueRender$: Subject<void> = new Subject<void>();
private _transparentRender$: Subject<void> = new Subject<void>();

constructor(
canvas: HTMLCanvasElement,
Expand Down Expand Up @@ -245,6 +246,7 @@ export class GLRenderer {
renderer.resetState();

this._opaqueRender$.next();
this._transparentRender$.next();
});

subs.push(renderSubscription);
Expand Down Expand Up @@ -398,6 +400,10 @@ export class GLRenderer {
return this._opaqueRender$;
}

public get transparentRender$(): Observable<void> {
return this._transparentRender$;
}

public get webGLRenderer$(): Observable<THREE.WebGLRenderer> {
return this._webGLRenderer$;
}
Expand Down
7 changes: 6 additions & 1 deletion src/viewer/CustomRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { LngLatAlt } from "../api/interfaces/LngLatAlt";
import { WebGLRenderer } from "three";
import { RenderCamera } from "../render/RenderCamera";
import { IViewer } from "./interfaces/IViewer";
import { RenderPass } from "./enums/RenderPass";

export class CustomRenderer {
private _renderers: {
Expand Down Expand Up @@ -44,7 +45,11 @@ export class CustomRenderer {
renderer.onAdd(viewer, reference, gl.getContext());
}));

subs.push(this._container.glRenderer.opaqueRender$
const render$ = renderer.renderPass === RenderPass.Opaque ?
this._container.glRenderer.opaqueRender$ :
this._container.glRenderer.transparentRender$;

subs.push(render$
.pipe(
withLatestFrom(
this._container.renderService.renderCamera$,
Expand Down
5 changes: 5 additions & 0 deletions src/viewer/enums/RenderPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ export enum RenderPass {
* Occurs after the background render pass.
*/
Opaque,

/**
* Occurs last in the render sequence, after the opaque render pass.
*/
Transparent,
}

0 comments on commit c627c57

Please sign in to comment.