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

RenderPassCameraFrame exposes HDR formats #6969

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/extras/render-passes/render-pass-camera-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const SSAOTYPE_LIGHTING = 'lighting';
export const SSAOTYPE_COMBINE = 'combine';

class CameraFrameOptions {
formats;

samples = 1;

sceneColorMap = true;
Expand Down Expand Up @@ -120,7 +122,7 @@ class RenderPassCameraFrame extends RenderPass {
sanitizeOptions(options) {
options = Object.assign({}, _defaultOptions, options);

// automatically enabled prepass when required internally
// automatically enable prepass when required internally
if (options.taaEnabled || options.ssaoType !== SSAOTYPE_NONE) {
options.prepassEnabled = true;
}
Expand All @@ -142,11 +144,19 @@ class RenderPassCameraFrame extends RenderPass {

needsReset(options) {
const currentOptions = this.options;

// helper to compare arrays
const arraysNotEqual = (arr1, arr2) => arr1 !== arr2 &&
(!(Array.isArray(arr1) && Array.isArray(arr2)) ||
arr1.length !== arr2.length ||
!arr1.every((value, index) => value === arr2[index]));
Comment on lines +149 to +152
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent few minutes looking for this and didn't find it .. I though I removed it in 2.0 :)
Will adjust, thanks!


return options.ssaoType !== currentOptions.ssaoType ||
options.ssaoBlurEnabled !== currentOptions.ssaoBlurEnabled ||
options.taaEnabled !== currentOptions.taaEnabled ||
options.bloomEnabled !== currentOptions.bloomEnabled ||
options.prepassEnabled !== currentOptions.prepassEnabled;
options.prepassEnabled !== currentOptions.prepassEnabled ||
arraysNotEqual(options.formats, currentOptions.formats);
}

// manually called, applies changes
Expand Down Expand Up @@ -174,7 +184,7 @@ class RenderPassCameraFrame extends RenderPass {
const cameraComponent = this.cameraComponent;
const targetRenderTarget = cameraComponent.renderTarget;

this.hdrFormat = device.getRenderableHdrFormat() || PIXELFORMAT_RGBA8;
this.hdrFormat = device.getRenderableHdrFormat(options.formats) || PIXELFORMAT_RGBA8;

// camera renders in HDR mode (linear output, no tonemapping)
if (!cameraComponent.rendering) {
Expand Down Expand Up @@ -342,7 +352,8 @@ class RenderPassCameraFrame extends RenderPass {
}

setupBloomPass(options, inputTexture) {
if (options.bloomEnabled) {
// HDR bloom is not supported on RGBA8 format
if (options.bloomEnabled && this.hdrFormat !== PIXELFORMAT_RGBA8) {
// create a bloom pass, which generates bloom texture based on the provided texture
this.bloomPass = new RenderPassBloom(this.device, inputTexture, this.hdrFormat);
}
Expand Down Expand Up @@ -399,7 +410,7 @@ class RenderPassCameraFrame extends RenderPass {

// TAA history buffer is double buffered, assign the current one to the follow up passes.
this.composePass.sceneTexture = sceneTexture;
if (this.options.bloomEnabled) {
if (this.options.bloomEnabled && this.bloomPass) {
this.bloomPass.sourceTexture = sceneTexture;
}
}
Expand Down