Skip to content

Commit 8d9cd59

Browse files
committed
WebGPURenderer: Added CubeRenderTarget support
1 parent 283aacc commit 8d9cd59

File tree

9 files changed

+106
-16
lines changed

9 files changed

+106
-16
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { WebGLCubeRenderTarget } from 'three';
2+
3+
// @TODO: Consider rename WebGLCubeRenderTarget to just CubeRenderTarget
4+
5+
class CubeRenderTarget extends WebGLCubeRenderTarget {
6+
7+
constructor( size = 1, options = {} ) {
8+
9+
super( size, options );
10+
11+
this.isCubeRenderTarget = true;
12+
13+
}
14+
15+
fromEquirectangularTexture( /*renderer, texture*/ ) {
16+
17+
console.warn( 'THREE.CubeRenderTarget.fromEquirectangularTexture(): Not implemented yet.' );
18+
19+
}
20+
21+
}
22+
23+
export default CubeRenderTarget;

examples/jsm/renderers/common/RenderContext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class RenderContext {
2828

2929
this.texture = null;
3030
this.depthTexture = null;
31+
this.activeCubeFace = 0;
3132

3233
}
3334

examples/jsm/renderers/common/Renderer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Renderer {
7979
this._clearStencil = 0;
8080

8181
this._renderTarget = null;
82+
this._currentActiveCubeFace = 0;
8283

8384
this._initialized = false;
8485
this._initPromise = null;
@@ -90,6 +91,10 @@ class Renderer {
9091
type: null
9192
};
9293

94+
this.xr = {
95+
enabled: false
96+
};
97+
9398
}
9499

95100
async init() {
@@ -154,7 +159,7 @@ class Renderer {
154159

155160
}
156161

157-
async compile( scene, camera ) {
162+
async compile( /*scene, camera*/ ) {
158163

159164
console.warn( 'THREE.Renderer: .compile() is not implemented yet.' );
160165

@@ -175,6 +180,7 @@ class Renderer {
175180

176181
const renderContext = this._renderContexts.get( scene, camera );
177182
const renderTarget = this._renderTarget;
183+
const activeCubeFace = this._activeCubeFace;
178184

179185
this._currentRenderContext = renderContext;
180186

@@ -269,6 +275,8 @@ class Renderer {
269275

270276
}
271277

278+
renderContext.activeCubeFace = activeCubeFace;
279+
272280
//
273281

274282
this._nodes.updateScene( scene );
@@ -560,9 +568,10 @@ class Renderer {
560568

561569
}
562570

563-
setRenderTarget( renderTarget ) {
571+
setRenderTarget( renderTarget, activeCubeFace = 0 ) {
564572

565573
this._renderTarget = renderTarget;
574+
this._activeCubeFace = activeCubeFace;
566575

567576
}
568577

examples/jsm/renderers/common/SampledTexture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SampledTexture extends Binding {
1111
this.id = id ++;
1212

1313
this.texture = texture;
14-
this.version = 0;
14+
this.version = texture.version;
1515

1616
this.isSampledTexture = true;
1717

examples/jsm/renderers/common/Sampler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Sampler extends Binding {
77
super( name );
88

99
this.texture = texture;
10-
this.version = 0;
10+
this.version = texture.version;
1111

1212
this.isSampler = true;
1313

examples/jsm/renderers/common/TextureRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class TextureRenderer {
88

99
this.renderTarget = new RenderTarget( 1, 1, options );
1010

11+
this.isTextureRenderer = true;
12+
1113
}
1214

1315
get texture() {

examples/jsm/renderers/common/Textures.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import DataMap from './DataMap.js';
2-
import { DepthTexture, DepthStencilFormat, UnsignedInt248Type } from 'three';
2+
import { Vector2, DepthTexture, DepthStencilFormat, UnsignedInt248Type } from 'three';
3+
4+
const _size = new Vector2();
35

46
class Textures extends DataMap {
57

@@ -17,6 +19,7 @@ class Textures extends DataMap {
1719
const renderTargetData = this.get( renderTarget );
1820

1921
const texture = renderTarget.texture;
22+
const size = this.getSize( texture );
2023

2124
let depthTexture = renderTarget.depthTexture || renderTargetData.depthTexture;
2225

@@ -25,23 +28,23 @@ class Textures extends DataMap {
2528
depthTexture = new DepthTexture();
2629
depthTexture.format = DepthStencilFormat;
2730
depthTexture.type = UnsignedInt248Type;
28-
depthTexture.image.width = texture.image.width;
29-
depthTexture.image.height = texture.image.height;
31+
depthTexture.image.width = size.width;
32+
depthTexture.image.height = size.height;
3033

3134
}
3235

33-
if ( renderTargetData.width !== texture.image.width || texture.image.height !== renderTargetData.height ) {
36+
if ( renderTargetData.width !== size.width || size.height !== renderTargetData.height ) {
3437

3538
texture.needsUpdate = true;
3639
depthTexture.needsUpdate = true;
3740

38-
depthTexture.image.width = texture.image.width;
39-
depthTexture.image.height = texture.image.height;
41+
depthTexture.image.width = size.width;
42+
depthTexture.image.height = size.height;
4043

4144
}
4245

43-
renderTargetData.width = texture.image.width;
44-
renderTargetData.height = texture.image.height;
46+
renderTargetData.width = size.width;
47+
renderTargetData.height = size.height;
4548
renderTargetData.texture = texture;
4649
renderTargetData.depthTexture = depthTexture;
4750

@@ -171,6 +174,24 @@ class Textures extends DataMap {
171174

172175
}
173176

177+
getSize( texture, target = _size ) {
178+
179+
if ( texture.isCubeTexture ) {
180+
181+
target.width = texture.image[ 0 ].width;
182+
target.height = texture.image[ 0 ].height;
183+
184+
} else {
185+
186+
target.width = texture.image.width;
187+
target.height = texture.image.height;
188+
189+
}
190+
191+
return target;
192+
193+
}
194+
174195
_destroyTexture( texture ) {
175196

176197
this.backend.destroySampler( texture );

examples/jsm/renderers/webgpu/WebGPUBackend.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat } from './utils/WebGPUConstants.js';
1+
import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
22

33
import WebGPUNodeBuilder from './nodes/WGSLNodeBuilder.js';
44
import Backend from '../common/Backend.js';
@@ -151,7 +151,13 @@ class WebGPUBackend extends Backend {
151151

152152
// @TODO: Support RenderTarget with antialiasing.
153153

154-
colorAttachment.view = textureData.texture.createView();
154+
colorAttachment.view = textureData.texture.createView( {
155+
baseMipLevel: 0,
156+
mipLevelCount: 1,
157+
baseArrayLayer: renderContext.activeCubeFace,
158+
dimension: GPUTextureViewDimension.TwoD
159+
} );
160+
155161
depthStencilAttachment.view = depthTextureData.texture.createView();
156162

157163
if ( renderContext.stencil && renderContext.depthTexture.format === DepthFormat ) {
@@ -264,6 +270,14 @@ class WebGPUBackend extends Backend {
264270

265271
this.device.queue.submit( [ renderContextData.encoder.finish() ] );
266272

273+
//
274+
275+
if ( renderContext.texture !== null && renderContext.texture.generateMipmaps === true ) {
276+
277+
this.textureUtils.generateMipmaps( renderContext.texture );
278+
279+
}
280+
267281
}
268282

269283
updateViewport( renderContext ) {

examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,26 @@ class WebGPUTextureUtils {
173173

174174
}
175175

176+
generateMipmaps( texture ) {
177+
178+
const textureData = this.backend.get( texture );
179+
180+
if ( texture.isCubeTexture ) {
181+
182+
for ( let i = 0; i < 6; i ++ ) {
183+
184+
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i );
185+
186+
}
187+
188+
} else {
189+
190+
this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU );
191+
192+
}
193+
194+
}
195+
176196
updateTexture( texture ) {
177197

178198
const textureData = this.backend.get( texture );
@@ -331,7 +351,7 @@ class WebGPUTextureUtils {
331351

332352
}
333353

334-
_generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer ) {
354+
_generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0 ) {
335355

336356
if ( this.mipmapUtils === null ) {
337357

@@ -529,7 +549,7 @@ class WebGPUTextureUtils {
529549

530550
_needsMipmaps( texture ) {
531551

532-
return ( texture.isCompressedTexture !== true ) && ( texture.generateMipmaps === true ) && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
552+
return ( texture.isCompressedTexture !== true ) /*&& ( texture.generateMipmaps === true )*/ && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
533553

534554
}
535555

0 commit comments

Comments
 (0)