@@ -16,7 +16,7 @@ import { NodeAccess } from '../../../nodes/core/constants.js';
16
16
import VarNode from '../../../nodes/core/VarNode.js' ;
17
17
import ExpressionNode from '../../../nodes/code/ExpressionNode.js' ;
18
18
19
- import { NoColorSpace , FloatType , RepeatWrapping , ClampToEdgeWrapping , MirroredRepeatWrapping , NearestFilter } from '../../../constants.js' ;
19
+ import { NoColorSpace , FloatType , RepeatWrapping , ClampToEdgeWrapping , MirroredRepeatWrapping , NearestFilter , SRGBColorSpace } from '../../../constants.js' ;
20
20
21
21
// GPUShaderStage is not defined in browsers not supporting WebGPU
22
22
const GPUShaderStage = ( typeof self !== 'undefined' ) ? self . GPUShaderStage : { VERTEX : 1 , FRAGMENT : 2 , COMPUTE : 4 } ;
@@ -219,7 +219,14 @@ class WGSLNodeBuilder extends NodeBuilder {
219
219
*/
220
220
needsToWorkingColorSpace ( texture ) {
221
221
222
- return texture . isVideoTexture === true && texture . colorSpace !== NoColorSpace ;
222
+ if ( texture . isVideoTexture && texture . colorSpace === SRGBColorSpace ) {
223
+
224
+ // Video textures are always in sRGB color space, so no conversion is needed
225
+ return false ;
226
+
227
+ }
228
+
229
+ return texture . colorSpace !== NoColorSpace ;
223
230
224
231
}
225
232
@@ -250,30 +257,7 @@ class WGSLNodeBuilder extends NodeBuilder {
250
257
251
258
} else {
252
259
253
- return this . _generateTextureSampleLevel ( texture , textureProperty , uvSnippet , '0' , depthSnippet ) ;
254
-
255
- }
256
-
257
- }
258
-
259
- /**
260
- * Generates the WGSL snippet when sampling video textures.
261
- *
262
- * @private
263
- * @param {string } textureProperty - The name of the video texture uniform in the shader.
264
- * @param {string } uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
265
- * @param {string } [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
266
- * @return {string } The WGSL snippet.
267
- */
268
- _generateVideoSample ( textureProperty , uvSnippet , shaderStage = this . shaderStage ) {
269
-
270
- if ( shaderStage === 'fragment' ) {
271
-
272
- return `textureSampleBaseClampToEdge( ${ textureProperty } , ${ textureProperty } _sampler, vec2<f32>( ${ uvSnippet } .x, 1.0 - ${ uvSnippet } .y ) )` ;
273
-
274
- } else {
275
-
276
- console . error ( `WebGPURenderer: THREE.VideoTexture does not support ${ shaderStage } shader.` ) ;
260
+ return this . generateTextureSampleLevel ( texture , textureProperty , uvSnippet , '0' , depthSnippet ) ;
277
261
278
262
}
279
263
@@ -290,7 +274,7 @@ class WGSLNodeBuilder extends NodeBuilder {
290
274
* @param {string } depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
291
275
* @return {string } The WGSL snippet.
292
276
*/
293
- _generateTextureSampleLevel ( texture , textureProperty , uvSnippet , levelSnippet , depthSnippet ) {
277
+ generateTextureSampleLevel ( texture , textureProperty , uvSnippet , levelSnippet , depthSnippet ) {
294
278
295
279
if ( this . isUnfilterable ( texture ) === false ) {
296
280
@@ -434,7 +418,7 @@ class WGSLNodeBuilder extends NodeBuilder {
434
418
}
435
419
436
420
// Build parameters string based on texture type and multisampling
437
- if ( isMultisampled || texture . isVideoTexture || texture . isStorageTexture ) {
421
+ if ( isMultisampled || texture . isStorageTexture ) {
438
422
439
423
textureDimensionsParams = textureProperty ;
440
424
@@ -531,11 +515,7 @@ class WGSLNodeBuilder extends NodeBuilder {
531
515
532
516
let snippet ;
533
517
534
- if ( texture . isVideoTexture === true ) {
535
-
536
- snippet = `textureLoad( ${ textureProperty } , ${ uvIndexSnippet } )` ;
537
-
538
- } else if ( depthSnippet ) {
518
+ if ( depthSnippet ) {
539
519
540
520
snippet = `textureLoad( ${ textureProperty } , ${ uvIndexSnippet } , ${ depthSnippet } , u32( ${ levelSnippet } ) )` ;
541
521
@@ -624,11 +604,7 @@ class WGSLNodeBuilder extends NodeBuilder {
624
604
625
605
let snippet = null ;
626
606
627
- if ( texture . isVideoTexture === true ) {
628
-
629
- snippet = this . _generateVideoSample ( textureProperty , uvSnippet , shaderStage ) ;
630
-
631
- } else if ( this . isUnfilterable ( texture ) ) {
607
+ if ( this . isUnfilterable ( texture ) ) {
632
608
633
609
snippet = this . generateTextureLod ( texture , textureProperty , uvSnippet , depthSnippet , '0' , shaderStage ) ;
634
610
@@ -711,22 +687,22 @@ class WGSLNodeBuilder extends NodeBuilder {
711
687
* @param {string } [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
712
688
* @return {string } The WGSL snippet.
713
689
*/
714
- generateTextureLevel ( texture , textureProperty , uvSnippet , levelSnippet , depthSnippet , shaderStage = this . shaderStage ) {
690
+ generateTextureLevel ( texture , textureProperty , uvSnippet , levelSnippet , depthSnippet ) {
715
691
716
- let snippet = null ;
692
+ if ( this . isUnfilterable ( texture ) === false ) {
717
693
718
- if ( texture . isVideoTexture === true ) {
694
+ return `textureSampleLevel( ${ textureProperty } , ${ textureProperty } _sampler, ${ uvSnippet } , ${ levelSnippet } )` ;
719
695
720
- snippet = this . _generateVideoSample ( textureProperty , uvSnippet , shaderStage ) ;
696
+ } else if ( this . isFilteredTexture ( texture ) ) {
697
+
698
+ return this . generateFilteredTexture ( texture , textureProperty , uvSnippet , levelSnippet ) ;
721
699
722
700
} else {
723
701
724
- snippet = this . _generateTextureSampleLevel ( texture , textureProperty , uvSnippet , levelSnippet , depthSnippet ) ;
702
+ return this . generateTextureLod ( texture , textureProperty , uvSnippet , depthSnippet , levelSnippet ) ;
725
703
726
704
}
727
705
728
- return snippet ;
729
-
730
706
}
731
707
732
708
/**
@@ -1729,10 +1705,6 @@ ${ flowData.code }
1729
1705
1730
1706
textureType = 'texture_3d<f32>' ;
1731
1707
1732
- } else if ( texture . isVideoTexture === true ) {
1733
-
1734
- textureType = 'texture_external' ;
1735
-
1736
1708
} else {
1737
1709
1738
1710
const componentPrefix = this . getComponentTypeFromTexture ( texture ) . charAt ( 0 ) ;
0 commit comments