Skip to content

Commit

Permalink
Fix resolution updates for subpasses
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruesc committed Aug 9, 2024
1 parent c127651 commit 8e90b7a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
49 changes: 47 additions & 2 deletions src/core/Pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ export abstract class Pass<TMaterial extends Material | null = null>
this.disposables = new Set<Disposable>();

this.resolution = new Resolution();
this.resolution.addEventListener(Resolution.EVENT_CHANGE, () => this.updateOutputBufferSize());
this.resolution.addEventListener(Resolution.EVENT_CHANGE, () => this.onResolutionChange(this.resolution));
this.resolution.addEventListener(Resolution.EVENT_CHANGE, (e) => this.handleResolutionEvent(e));

this.input = new Input();
this.output = new Output();
Expand Down Expand Up @@ -275,6 +274,7 @@ export abstract class Pass<TMaterial extends Material | null = null>

this.input.setChanged();
this.output.setChanged();
this.resolution.setChanged();

for(const pass of this.subpasses) {

Expand All @@ -288,6 +288,7 @@ export abstract class Pass<TMaterial extends Material | null = null>
* A list of subpasses.
*
* Subpasses are included in automatic resource optimizations and will be disposed when the parent pass is disposed.
* The resolution of the subpasses is also kept in sync with the base resolution of the parent pass.
*
* They also gain access to the following data:
* - {@link timer}
Expand All @@ -308,6 +309,8 @@ export abstract class Pass<TMaterial extends Material | null = null>
this._subpasses = value;
Object.freeze(this._subpasses);

this.updateSubpassResolution();

for(const pass of this.subpasses) {

pass.timer = this.timer;
Expand Down Expand Up @@ -458,6 +461,22 @@ export abstract class Pass<TMaterial extends Material | null = null>

}

/**
* Updates the resolution of all subpasses.
*/

private updateSubpassResolution(): void {

const { baseWidth, baseHeight } = this.resolution;

for(const pass of this.subpasses) {

pass.resolution.setBaseSize(baseWidth, baseHeight);

}

}

/**
* Updates the size of the default output buffer, if it exists.
*/
Expand Down Expand Up @@ -643,6 +662,32 @@ export abstract class Pass<TMaterial extends Material | null = null>

}

/**
* Handles {@link resolution} events.
*
* @param event - A resolution event.
*/

private handleResolutionEvent(event: Event): void {

if(!this.attached) {

return;

}

switch(event.type) {

case "change":
this.onResolutionChange();
this.updateOutputBufferSize();
this.updateSubpassResolution();
break;

}

}

/**
* Handles {@link input} events.
*
Expand Down
2 changes: 1 addition & 1 deletion src/passes/EffectPass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export class EffectPass extends Pass<EffectMaterial> {

for(const effect of this.effects) {

effect.resolution.copy(resolution);
effect.resolution.setBaseSize(resolution.baseWidth, resolution.baseHeight);

}

Expand Down

0 comments on commit 8e90b7a

Please sign in to comment.