@gnsx/three 0.186.3 → 0.186.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -950,6 +950,11 @@ class RenderObject {
950
950
 
951
951
  cacheKey = hash( cacheKey, this.renderer.contextNode.id, this.renderer.contextNode.version );
952
952
 
953
+ // WITH_GENESYS
954
+ // hash() xors each argument as a number, so a view name has to be hashed first.
955
+ cacheKey = hash( cacheKey, hashString( this.renderer.debug.view ), this.renderer.debug.shaderComplexityBudget );
956
+ // !WITH_GENESYS
957
+
953
958
  return cacheKey;
954
959
 
955
960
  }
@@ -37,6 +37,7 @@ import { float, vec3, vec4, Fn } from '../../nodes/tsl/TSLCore.js';
37
37
  import { detachRendererReference } from '../../nodes/accessors/RendererReferenceNode.js';
38
38
  import { toneMappingExposure } from '../../nodes/display/ToneMappingNode.js';
39
39
  import { ProfilerService } from '../../profiler/ProfilerService.js';
40
+ import { DEBUG_VIEW_LIGHTING_COMPLEXITY, DEBUG_VIEW_NONE, DEBUG_VIEW_SHADER_COMPLEXITY, DEFAULT_SHADER_COMPLEXITY_BUDGET } from '../../nodes/display/ComplexityDebug.js';
40
41
  // !WITH_GENESYS
41
42
  import { reference } from '../../nodes/accessors/ReferenceNode.js';
42
43
  import { highpModelNormalViewMatrix, highpModelViewMatrix } from '../../nodes/accessors/ModelNode.js';
@@ -743,6 +744,8 @@ class Renderer {
743
744
  * @property {?Function} onNodeBuilderCreated - A callback function that is executed after a node builder has been created and before it is built.
744
745
  * @property {?Function} onShaderError - A callback function that is executed when a shader error happens. Only supported with WebGL 2 right now.
745
746
  * @property {Function} getShaderAsync - Allows the get the raw shader code for the given scene, camera and 3D object.
747
+ * @property {string} view - Debug view. `shaderComplexity` and `lightingComplexity` replace the shaded color with a heatmap.
748
+ * @property {number} shaderComplexityBudget - Proxy budget that fills the shader-complexity ramp.
746
749
  */
747
750
 
748
751
  /**
@@ -757,6 +760,10 @@ class Renderer {
757
760
  },
758
761
  onNodeBuilderCreated: null,
759
762
  onShaderError: null,
763
+ // WITH_GENESYS
764
+ view: DEBUG_VIEW_NONE,
765
+ shaderComplexityBudget: DEFAULT_SHADER_COMPLEXITY_BUDGET,
766
+ // !WITH_GENESYS
760
767
  getShaderAsync: async ( scene, camera, object ) => {
761
768
 
762
769
  await this.compileAsync( object, camera, scene );
@@ -2691,7 +2698,13 @@ class Renderer {
2691
2698
  const useToneMapping = this.currentToneMapping !== NoToneMapping;
2692
2699
  const useColorSpace = this.currentColorSpace !== ColorManagement.workingColorSpace;
2693
2700
 
2694
- return useToneMapping || useColorSpace;
2701
+ // WITH_GENESYS
2702
+ // Shader complexity writes a scalar into an intermediate target, then the output pass colorizes it.
2703
+ const shaderComplexity = this.debug.view === DEBUG_VIEW_SHADER_COMPLEXITY;
2704
+
2705
+ return useToneMapping || useColorSpace || shaderComplexity;
2706
+ // !WITH_GENESYS
2707
+ // return useToneMapping || useColorSpace;
2695
2708
 
2696
2709
  }
2697
2710
 
@@ -2742,6 +2755,16 @@ class Renderer {
2742
2755
  */
2743
2756
  get currentToneMapping() {
2744
2757
 
2758
+ // WITH_GENESYS
2759
+ const view = this.debug.view;
2760
+
2761
+ if ( view === DEBUG_VIEW_SHADER_COMPLEXITY || view === DEBUG_VIEW_LIGHTING_COMPLEXITY ) {
2762
+
2763
+ return NoToneMapping;
2764
+
2765
+ }
2766
+ // !WITH_GENESYS
2767
+
2745
2768
  return this.isOutputTarget ? this.toneMapping : NoToneMapping;
2746
2769
 
2747
2770
  }
@@ -7,7 +7,11 @@ import { NodeFrame, NodeUpdateType, StackTrace } from '../../../nodes/Nodes.js';
7
7
  import { renderGroup, cubeTexture, texture, fog, rangeFogFactor, densityFogFactor, reference, pmremTexture, screenUV, uniform } from '../../../nodes/TSL.js';
8
8
  import { builtin } from '../../../nodes/accessors/BuiltinNode.js';
9
9
 
10
- import { CubeUVReflectionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping } from '../../../constants.js';
10
+ import { CubeUVReflectionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, NoToneMapping } from '../../../constants.js';
11
+ // WITH_GENESYS
12
+ import { vec4 } from '../../../nodes/tsl/TSLCore.js';
13
+ import { colorizeShaderComplexity, DEBUG_VIEW_SHADER_COMPLEXITY } from '../../../nodes/display/ComplexityDebug.js';
14
+ // !WITH_GENESYS
11
15
  import { hashArray } from '../../../nodes/core/NodeUtils.js';
12
16
  import { error } from '../../../utils.js';
13
17
 
@@ -992,7 +996,10 @@ class NodeManager extends DataMap {
992
996
 
993
997
  const renderer = this.renderer;
994
998
 
995
- return renderer.toneMapping + ',' + renderer.currentColorSpace + ',' + renderer.xr.isPresenting;
999
+ // WITH_GENESYS
1000
+ return renderer.toneMapping + ',' + renderer.currentColorSpace + ',' + renderer.xr.isPresenting + ',' + renderer.debug.view;
1001
+ // !WITH_GENESYS
1002
+ // return renderer.toneMapping + ',' + renderer.currentColorSpace + ',' + renderer.xr.isPresenting;
996
1003
 
997
1004
  }
998
1005
 
@@ -1007,27 +1014,35 @@ class NodeManager extends DataMap {
1007
1014
 
1008
1015
  const renderer = this.renderer;
1009
1016
 
1010
- let output;
1017
+ let sampled;
1011
1018
 
1012
1019
  if ( outputTarget.isArrayTexture ) {
1013
1020
 
1014
1021
  if ( this.backend.isWebGLBackend ) {
1015
1022
 
1016
- output = texture( outputTarget, screenUV ).depth( builtin( 'gl_ViewID_OVR' ) ).renderOutput( renderer.toneMapping, renderer.currentColorSpace );
1023
+ sampled = texture( outputTarget, screenUV ).depth( builtin( 'gl_ViewID_OVR' ) );
1017
1024
 
1018
1025
  } else {
1019
1026
 
1020
- output = texture( outputTarget, screenUV ).depth( _outputLayerIndex ).renderOutput( renderer.toneMapping, renderer.currentColorSpace );
1027
+ sampled = texture( outputTarget, screenUV ).depth( _outputLayerIndex );
1021
1028
 
1022
1029
  }
1023
1030
 
1024
1031
  } else {
1025
1032
 
1026
- output = texture( outputTarget, screenUV ).renderOutput( renderer.toneMapping, renderer.currentColorSpace );
1033
+ sampled = texture( outputTarget, screenUV );
1027
1034
 
1028
1035
  }
1029
1036
 
1030
- return output;
1037
+ // WITH_GENESYS
1038
+ if ( renderer.debug.view === DEBUG_VIEW_SHADER_COMPLEXITY ) {
1039
+
1040
+ return vec4( colorizeShaderComplexity( sampled.r ), 1 ).renderOutput( NoToneMapping, renderer.currentColorSpace );
1041
+
1042
+ }
1043
+ // !WITH_GENESYS
1044
+
1045
+ return sampled.renderOutput( renderer.toneMapping, renderer.currentColorSpace );
1031
1046
 
1032
1047
  }
1033
1048
 
@@ -635,6 +635,10 @@ ${ flowData.code }
635
635
  */
636
636
  generateTexture( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet ) {
637
637
 
638
+ // WITH_GENESYS
639
+ this.recordFragmentTextureSample( texture, this.shaderStage, textureProperty + '|' + uvSnippet );
640
+ // !WITH_GENESYS
641
+
638
642
  if ( depthSnippet ) uvSnippet = `vec3( ${ uvSnippet }, ${ depthSnippet } )`;
639
643
 
640
644
  if ( texture.isDepthTexture ) {
@@ -678,6 +682,10 @@ ${ flowData.code }
678
682
  */
679
683
  generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
680
684
 
685
+ // WITH_GENESYS
686
+ this.recordFragmentTextureSample( texture, this.shaderStage, textureProperty + '|' + uvSnippet + '|' + levelSnippet );
687
+ // !WITH_GENESYS
688
+
681
689
  if ( depthSnippet ) uvSnippet = `vec3( ${ uvSnippet }, ${ depthSnippet } )`;
682
690
 
683
691
  if ( offsetSnippet ) {
@@ -934,9 +934,25 @@ class WebGLState {
934
934
 
935
935
  this.setFlipSided( flipSided );
936
936
 
937
- ( material.blending === NormalBlending && material.transparent === false )
938
- ? this.setBlending( NoBlending )
939
- : this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha );
937
+ // WITH_GENESYS
938
+ // WebGL has no cached render pipeline. One+One is applied on each draw instead.
939
+ if ( this.backend.renderer.debug.view === 'shaderComplexity' && material.isShadowPassMaterial !== true && this.backend.renderer.isOutputTarget !== true ) {
940
+
941
+ this.setBlending( AdditiveBlending, AddEquation, OneFactor, OneFactor, AddEquation, OneFactor, OneFactor, material.blendColor, material.blendAlpha, true );
942
+
943
+ } else if ( material.blending === NormalBlending && material.transparent === false ) {
944
+
945
+ this.setBlending( NoBlending );
946
+
947
+ } else {
948
+
949
+ this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha );
950
+
951
+ }
952
+ // !WITH_GENESYS
953
+ // ( material.blending === NormalBlending && material.transparent === false )
954
+ // ? this.setBlending( NoBlending )
955
+ // : this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha );
940
956
 
941
957
  this.setDepthFunc( material.depthFunc );
942
958
  this.setDepthTest( material.depthTest );
@@ -2389,6 +2389,9 @@ class WebGPUBackend extends Backend {
2389
2389
  const depthStencilFormat = utils.getCurrentDepthStencilFormat( renderObject.context );
2390
2390
  const primitiveTopology = utils.getPrimitiveTopology( object, material );
2391
2391
  const frontFaceCW = ( object.isMesh && object.matrixWorld.determinantAffine() < 0 );
2392
+ // WITH_GENESYS
2393
+ const debugView = renderObject.renderer.debug.view;
2394
+ // !WITH_GENESYS
2392
2395
 
2393
2396
  let needsUpdate = false;
2394
2397
 
@@ -2406,7 +2409,10 @@ class WebGPUBackend extends Backend {
2406
2409
  data.colorFormat !== colorFormat || data.depthStencilFormat !== depthStencilFormat ||
2407
2410
  data.primitiveTopology !== primitiveTopology ||
2408
2411
  data.frontFaceCW !== frontFaceCW ||
2409
- data.clippingContextCacheKey !== renderObject.clippingContextCacheKey
2412
+ data.clippingContextCacheKey !== renderObject.clippingContextCacheKey ||
2413
+ // WITH_GENESYS
2414
+ data.debugView !== debugView
2415
+ // !WITH_GENESYS
2410
2416
  ) {
2411
2417
 
2412
2418
  data.material = material; data.materialVersion = material.version;
@@ -2427,6 +2433,9 @@ class WebGPUBackend extends Backend {
2427
2433
  data.primitiveTopology = primitiveTopology;
2428
2434
  data.frontFaceCW = frontFaceCW;
2429
2435
  data.clippingContextCacheKey = renderObject.clippingContextCacheKey;
2436
+ // WITH_GENESYS
2437
+ data.debugView = debugView;
2438
+ // !WITH_GENESYS
2430
2439
 
2431
2440
  needsUpdate = true;
2432
2441
 
@@ -2470,7 +2479,10 @@ class WebGPUBackend extends Backend {
2470
2479
  utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ),
2471
2480
  utils.getPrimitiveTopology( object, material ),
2472
2481
  renderObject.getGeometryCacheKey(),
2473
- renderObject.clippingContextCacheKey
2482
+ renderObject.clippingContextCacheKey,
2483
+ // WITH_GENESYS
2484
+ renderObject.renderer.debug.view
2485
+ // !WITH_GENESYS
2474
2486
  ].join();
2475
2487
 
2476
2488
  }
@@ -376,6 +376,10 @@ class WGSLNodeBuilder extends NodeBuilder {
376
376
  */
377
377
  _generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
378
378
 
379
+ // WITH_GENESYS
380
+ if ( shaderStage === 'fragment' ) this.recordFragmentTextureSample( texture, shaderStage, textureProperty + '|' + uvSnippet );
381
+ // !WITH_GENESYS
382
+
379
383
  if ( shaderStage === 'fragment' ) {
380
384
 
381
385
  if ( depthSnippet ) {
@@ -656,6 +660,10 @@ class WGSLNodeBuilder extends NodeBuilder {
656
660
  */
657
661
  generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet = '0u', depthSnippet ) {
658
662
 
663
+ // WITH_GENESYS
664
+ this.recordFragmentTextureSample( texture, this.shaderStage, textureProperty + '|' + uvSnippet + '|' + levelSnippet );
665
+ // !WITH_GENESYS
666
+
659
667
  const wrapFunction = this.generateWrapFunction( texture );
660
668
  const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
661
669
 
@@ -693,6 +701,10 @@ class WGSLNodeBuilder extends NodeBuilder {
693
701
  */
694
702
  generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet = '0u' ) {
695
703
 
704
+ // WITH_GENESYS
705
+ this.recordFragmentTextureSample( texture, this.shaderStage, textureProperty + '|' + uvSnippet + '|' + levelSnippet );
706
+ // !WITH_GENESYS
707
+
696
708
  // Cube textures cannot use textureLoad in WGSL, must use textureSampleLevel
697
709
  if ( texture.isCubeTexture === true ) {
698
710
 
@@ -1071,6 +1083,10 @@ class WGSLNodeBuilder extends NodeBuilder {
1071
1083
 
1072
1084
  if ( this.isUnfilterable( texture ) === false ) {
1073
1085
 
1086
+ // WITH_GENESYS
1087
+ this.recordFragmentTextureSample( texture, this.shaderStage, textureProperty + '|' + uvSnippet + '|' + levelSnippet );
1088
+ // !WITH_GENESYS
1089
+
1074
1090
  if ( depthSnippet ) {
1075
1091
 
1076
1092
  if ( offsetSnippet ) {
@@ -106,6 +106,26 @@ class WebGPUPipelineUtils {
106
106
 
107
107
  }
108
108
 
109
+ // WITH_GENESYS
110
+ // Accumulate shader cost with One+One. Opaque materials normally disable blending.
111
+ if ( backend.renderer.debug.view === 'shaderComplexity' && material.isShadowPassMaterial !== true && backend.renderer.isOutputTarget !== true ) {
112
+
113
+ materialBlending = {
114
+ color: {
115
+ srcFactor: GPUBlendFactor.One,
116
+ dstFactor: GPUBlendFactor.One,
117
+ operation: GPUBlendOperation.Add
118
+ },
119
+ alpha: {
120
+ srcFactor: GPUBlendFactor.One,
121
+ dstFactor: GPUBlendFactor.One,
122
+ operation: GPUBlendOperation.Add
123
+ }
124
+ };
125
+
126
+ }
127
+ // !WITH_GENESYS
128
+
109
129
  // stencil
110
130
 
111
131
  let stencilFront = {};
package/build/three.cjs DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2010-2026 Three.js Authors
4
- * SPDX-License-Identifier: MIT
5
- *
6
- * The CommonJS build of three is deprecated. three is ESM-only going forward;
7
- * this entry now re-exports the ES module via require(esm) and will be removed
8
- * in a future release.
9
- *
10
- * Replace `require('three')` with `import * as THREE from 'three'`.
11
- */
12
- process.emitWarning(
13
- '`require("three")` is deprecated and will be removed.\n' +
14
- 'Replace `const THREE = require("three")` with `import * as THREE from "three"`.',
15
- { type: 'DeprecationWarning', code: 'THREE_CJS_DEPRECATED' }
16
- );
17
- module.exports = require( './three.module.js' );