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

WebGPURenderer: Add HDR Support #29573

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions examples/webgpu_tsl_vfx_linkedparticles.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<script type="importmap">
{
"imports": {
"three": "../build/three.webgpu.js",
"three/tsl": "../build/three.webgpu.js",
"three": "../src/Three.WebGPU.js",
"three/tsl": "../src/Three.WebGPU.js",
"three/addons/": "./jsm/"
}
}
Expand Down Expand Up @@ -88,7 +88,7 @@

// renderer

renderer = new THREE.WebGPURenderer( { antialias: true } );
renderer = new THREE.WebGPURenderer( { antialias: true, hdr: true } );
renderer.setClearColor( 0x14171a );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
Expand Down Expand Up @@ -369,7 +369,7 @@
const gui = new GUI();

gui.add( controls, 'autoRotate' ).name( 'Auto Rotate' );
gui.add( controls, 'autoRotateSpeed', - 10.0, 10.0, 0.01 ).name( 'Auto Rotate Speed' );
gui.add( controls, 'autoRotateSpeed', - 10.0, 10.0, 0.01 ).name( 'Auto Rotate Speed' );

const partFolder = gui.addFolder( 'Particles' );
partFolder.add( timeScale, 'value', 0.0, 4.0, 0.01 ).name( 'timeScale' );
Expand Down
7 changes: 6 additions & 1 deletion src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class WebGPUBackend extends Backend {
this.parameters.alpha = ( parameters.alpha === undefined ) ? true : parameters.alpha;

this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;
this.parameters.hdr = ( parameters.hdr === true );

this.trackTimestamp = ( parameters.trackTimestamp === true );

Expand Down Expand Up @@ -107,14 +108,18 @@ class WebGPUBackend extends Backend {
this.context = context;

const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
const hdr = parameters.hdr ? 'extended' : 'standard';

this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );

this.context.configure( {
device: this.device,
format: this.utils.getPreferredCanvasFormat(),
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
alphaMode: alphaMode
alphaMode: alphaMode,
toneMapping: {
mode: hdr
}
} );

this.updateSize();
Expand Down
10 changes: 7 additions & 3 deletions src/renderers/webgpu/utils/WebGPUUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,15 @@ class WebGPUUtils {

getPreferredCanvasFormat() {

// TODO: Remove this check when Quest 34.5 is out
// https://github.com/mrdoob/three.js/pull/29221/files#r1731833949

if ( navigator.userAgent.includes( 'Quest' ) ) {
if ( this.backend.parameters.hdr === true ) {

return GPUTextureFormat.RGBA16Float;
Comment on lines +115 to +117
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we expose RGBA16 drawing buffers independently of the HDR parameter? Perhaps something like drawingBufferType or canvasType, with possible values of HalfFloatType or UnsignedByteType?

There will certainly be interest in using high-precision output without HDR, and I believe it's also good to make HDR usage explicit about the drawing buffer configuration.


} else if ( navigator.userAgent.includes( 'Quest' ) ) {

// TODO: Remove this check when Quest 34.5 is out
// https://github.com/mrdoob/three.js/pull/29221/files#r1731833949
return GPUTextureFormat.BGRA8Unorm;

} else {
Expand Down