Skip to content

Commit

Permalink
Adding explicit render to CDF generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Bond committed Dec 20, 2024
1 parent 878d9cf commit 259bd1f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class _IblShadowsVoxelTracingPass {
uniforms: ["sizeParams"],
samplers: ["debugSampler"],
engine: this._engine,
reusable: false,
reusable: true,
shaderLanguage: isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,
extraInitializations: (useWebGPU: boolean, list: Promise<any>[]) => {
if (useWebGPU) {
Expand Down
33 changes: 32 additions & 1 deletion packages/dev/core/src/Rendering/iblCdfGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class IblCdfGenerator {
/** Enable the debug view for this pass */
public debugEnabled: boolean = false;
private _debugPass: PostProcess;
private _debugSizeParams: Vector4 = new Vector4(0.0, 0.0, 0.0, 0.0);
private _debugSizeParams: Vector4 = new Vector4(0.0, 0.0, 1.0, 1.0);

/**
* Sets params that control the position and scaling of the debug display on the screen.
Expand Down Expand Up @@ -337,6 +337,37 @@ export class IblCdfGenerator {
);
}

/**
* Explicitly trigger generation of CDF maps when they are ready to render.
* @returns Promise that resolves when the CDF maps are rendered.
*/
public renderWhenReady(): Promise<void> {
// Once the textures are generated, notify that they are ready to use.
this._icdfPT.onGeneratedObservable.addOnce(() => {
this.onGeneratedObservable.notifyObservers();
});
const promises: Array<Promise<void>> = [];
const renderTargets: Array<ProceduralTexture> = [this._cdfyPT, this._cdfxPT, this._scaledLuminancePT, this._icdfPT];
renderTargets.forEach((target) => {
promises.push(
new Promise((resolve) => {
if (target.isReady()) {
resolve();
} else {
target.getEffect().executeWhenCompiled(() => {
resolve();
});
}
})
);
});
return Promise.all(promises).then(() => {
renderTargets.forEach((target) => {
target.render();
});
});
}

/**
* Disposes the CDF renderer and associated resources
*/
Expand Down

0 comments on commit 259bd1f

Please sign in to comment.