Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred Cheung committed Sep 22, 2023
1 parent dc9e90e commit a276618
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/graph/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Object.freeze(kEvents);

export type GraphEventsMap = { [K in keyof typeof kEvents]: ReturnType<() => { readonly 0: unique symbol }[0]> };

// Configuration constants for Post Processing
const DOWNSAMPLED_RATIO = 1/7; // determines the fraction of the full size texture dimensions to downsample to
const MAX_BLUR_PASSES = 20; // determines the maximum number of blurring passes used when glow is most diffuse

export class Graph extends EventEmitter.mixin(GraphPoints) implements Renderable {
public static get events(): GraphEventsMap {
return kEvents as GraphEventsMap;
Expand Down Expand Up @@ -76,7 +80,7 @@ export class Graph extends EventEmitter.mixin(GraphPoints) implements Renderable
public render(context:App, mode: RenderMode, uniforms: RenderUniforms): void {
this.emit(kEvents.preRender, this, mode, uniforms);

const isPicking = mode === RenderMode.PICKING && this.picking && this.picking.enabled;
const isPicking = mode === RenderMode.PICKING && this.picking?.enabled;
if (isPicking) {
this.picking.offscreenBuffer.prepareContext(context);
}
Expand All @@ -103,11 +107,9 @@ export class Graph extends EventEmitter.mixin(GraphPoints) implements Renderable
const renderFrameTexture = this._renderBuffer.colorTarget;
context.disable(PicoGL.BLEND);

const downsampledRatio = 1/7; // magic number
const maxBlurPasses = 20;
const downsampledSize: [number, number] = [
Math.round(context.width * downsampledRatio),
Math.round(context.height * downsampledRatio),
Math.round(context.width * DOWNSAMPLED_RATIO),
Math.round(context.height * DOWNSAMPLED_RATIO),
];
outputTexture1.resize(...downsampledSize);
outputBuffer1.colorTarget(0, outputTexture1);
Expand All @@ -117,7 +119,7 @@ export class Graph extends EventEmitter.mixin(GraphPoints) implements Renderable
this.context.drawFramebuffer(outputBuffer1);
this._postProcess.resample(downsampledSize, renderFrameTexture);

for(let i = 0; i < Math.round(glow * maxBlurPasses) + 1; i++) {
for(let i = 0; i <= Math.round(glow * MAX_BLUR_PASSES); i++) {
this.context.drawFramebuffer(outputBuffer2);
this._postProcess.blur(outputTexture1, true);
this.context.drawFramebuffer(outputBuffer1);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/OffscreenBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class OffscreenBuffer {
}

private context: App;
public colorTarget: Texture;
readonly colorTarget: Texture;
private depthTarget: Renderbuffer;
private frameBuffer: Framebuffer;

Expand Down

0 comments on commit a276618

Please sign in to comment.