@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.19.3 → 3.20.1

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.
Files changed (55) hide show
  1. package/dist/RenderingEngine.d.ts +5 -2
  2. package/dist/RenderingEngine.d.ts.map +1 -1
  3. package/dist/RenderingEngine.js +34 -15
  4. package/dist/RenderingEngine.js.map +1 -1
  5. package/dist/index.d.ts +2 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/interfaces/IRenderingEngine.d.ts +2 -1
  10. package/dist/interfaces/IRenderingEngine.d.ts.map +1 -1
  11. package/dist/loaders/EnvironmentMapLoader.d.ts.map +1 -1
  12. package/dist/loaders/EnvironmentMapLoader.js.map +1 -1
  13. package/dist/loaders/GeometryLoader.d.ts +7 -0
  14. package/dist/loaders/GeometryLoader.d.ts.map +1 -1
  15. package/dist/loaders/GeometryLoader.js +27 -6
  16. package/dist/loaders/GeometryLoader.js.map +1 -1
  17. package/dist/loaders/LightLoader.d.ts +1 -1
  18. package/dist/loaders/MaterialLoader.d.ts +5 -2
  19. package/dist/loaders/MaterialLoader.d.ts.map +1 -1
  20. package/dist/loaders/MaterialLoader.js +221 -8
  21. package/dist/loaders/MaterialLoader.js.map +1 -1
  22. package/dist/managers/RenderingManager.d.ts +5 -0
  23. package/dist/managers/RenderingManager.d.ts.map +1 -1
  24. package/dist/managers/RenderingManager.js +120 -11
  25. package/dist/managers/RenderingManager.js.map +1 -1
  26. package/dist/managers/SceneTreeManager.d.ts +1 -1
  27. package/dist/managers/SceneTreeManager.d.ts.map +1 -1
  28. package/dist/managers/SceneTreeManager.js +1 -0
  29. package/dist/managers/SceneTreeManager.js.map +1 -1
  30. package/dist/managers/postprocessing/ao/ao/AOPass.d.ts +2 -2
  31. package/dist/managers/postprocessing/ao/ao/AOPass.d.ts.map +1 -1
  32. package/dist/managers/postprocessing/ao/ao/AOPass.js +7 -4
  33. package/dist/managers/postprocessing/ao/ao/AOPass.js.map +1 -1
  34. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.d.ts +1 -1
  35. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.d.ts.map +1 -1
  36. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js +2 -1
  37. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js.map +1 -1
  38. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.d.ts +2 -2
  39. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.d.ts.map +1 -1
  40. package/dist/managers/postprocessing/utils/FullScreenQuad.d.ts +2 -2
  41. package/dist/managers/postprocessing/utils/FullScreenQuad.d.ts.map +1 -1
  42. package/dist/managers/postprocessing/utils/NormalPass.d.ts +2 -2
  43. package/dist/managers/postprocessing/utils/NormalPass.d.ts.map +1 -1
  44. package/dist/materials/SpecularGlossinessMaterial.d.ts.map +1 -1
  45. package/dist/materials/SpecularGlossinessMaterial.js +12 -3
  46. package/dist/materials/SpecularGlossinessMaterial.js.map +1 -1
  47. package/dist/shaders/PCSS.d.ts +2 -2
  48. package/dist/shaders/PCSS.d.ts.map +1 -1
  49. package/dist/shaders/PCSS.js +108 -87
  50. package/dist/shaders/PCSS.js.map +1 -1
  51. package/dist/shaders/gem.d.ts +2 -2
  52. package/dist/shaders/gem.d.ts.map +1 -1
  53. package/dist/shaders/gem.js +24 -20
  54. package/dist/shaders/gem.js.map +1 -1
  55. package/package.json +20 -20
@@ -1,127 +1,148 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.entry = exports.main = void 0;
3
+ exports.getShadow = exports.main = void 0;
4
4
  exports.main = `
5
5
 
6
+ // PCSS implementation
6
7
  uniform float lightSizeUV;
7
8
  uniform float blending;
8
9
 
9
- #ifdef SHADOWMAP_TYPE_PCF
10
+ #if defined( SHADOWMAP_TYPE_BASIC )
10
11
 
11
- #define NEAR_PLANE 0.1
12
- #define NUM_SAMPLES 20
13
- #define NUM_RINGS 11
12
+ #define PCSS_NEAR_PLANE 0.1
13
+ #define PCSS_NUM_SAMPLES 20
14
+ #define PCSS_NUM_RINGS 11
14
15
 
15
- vec2 poissonDisk[NUM_SAMPLES];
16
+ vec2 pcssPoissonDisk[PCSS_NUM_SAMPLES];
16
17
 
17
- void initPoissonSamples( const in vec2 randomSeed ) {
18
- float ANGLE_STEP = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES);
19
- float INV_NUM_SAMPLES = 1.0 / float(NUM_SAMPLES);
18
+ void initPCSSPoissonSamples( const in vec2 randomSeed ) {
19
+ float angleStep = PI2 * float( PCSS_NUM_RINGS ) / float( PCSS_NUM_SAMPLES );
20
+ float invNumSamples = 1.0 / float( PCSS_NUM_SAMPLES );
20
21
 
21
- // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
22
- float angle = rand(randomSeed) * PI2;
23
- float radius = INV_NUM_SAMPLES;
22
+ float angle = rand( randomSeed ) * PI2;
23
+ float radius = invNumSamples;
24
24
  float radiusStep = radius;
25
25
 
26
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
27
- poissonDisk[i] = vec2(cos(angle), sin(angle)) * pow(radius, 0.75);
26
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
27
+ pcssPoissonDisk[ i ] = vec2( cos( angle ), sin( angle ) ) * pow( radius, 0.75 );
28
28
  radius += radiusStep;
29
- angle += ANGLE_STEP;
29
+ angle += angleStep;
30
30
  }
31
31
  }
32
32
 
33
- float penumbraSize( const in float zReceiver, const in float zBlocker ) { // Parallel plane estimation
34
- return (zReceiver - zBlocker) / zBlocker;
33
+ float getPCSSDepth( sampler2D shadowMap, const in vec2 uv ) {
34
+ float depth = texture2D( shadowMap, uv ).r;
35
+
36
+ #ifdef USE_REVERSED_DEPTH_BUFFER
37
+ depth = 1.0 - depth;
38
+ #endif
39
+
40
+ return depth;
35
41
  }
36
42
 
37
- float findBlocker(sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {
38
- // This uses similar triangles to compute what
39
- // area of the shadow map we should search
40
- float searchRadius = lightSizeUV * (zReceiver - NEAR_PLANE) / zReceiver;
43
+ float getPCSSDepthCompare( sampler2D shadowMap, const in vec2 uv, const in float compare ) {
44
+ return step( compare, getPCSSDepth( shadowMap, uv ) );
45
+ }
46
+
47
+ float findPCSSBlocker( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {
48
+ float searchRadius = lightSizeUV * ( zReceiver - PCSS_NEAR_PLANE ) / max( zReceiver, 0.0001 );
41
49
  float blockerDepthSum = 0.0;
42
50
  int numBlockers = 0;
43
51
 
44
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
45
- float shadowMapDepth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * searchRadius));
46
- if (shadowMapDepth < zReceiver) {
52
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
53
+ float shadowMapDepth = getPCSSDepth( shadowMap, uv + pcssPoissonDisk[ i ] * searchRadius );
54
+ if ( shadowMapDepth < zReceiver ) {
47
55
  blockerDepthSum += shadowMapDepth;
48
- numBlockers++;
56
+ numBlockers ++;
49
57
  }
50
58
  }
51
59
 
52
- if (numBlockers == 0) return -1.0;
60
+ if ( numBlockers == 0 ) return -1.0;
53
61
 
54
- return blockerDepthSum / float(numBlockers);
62
+ return blockerDepthSum / float( numBlockers );
55
63
  }
56
64
 
57
- float PCF_Filter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRadius) {
58
- float sum = 0.0;
59
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
60
- float depth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * filterRadius));
61
- if (zReceiver <= depth) sum += 1.0;
65
+ float getPCSSFilteredShadow( sampler2D shadowMap, const in vec2 uv, const in float zReceiver, const in float filterRadius ) {
66
+ float shadow = 0.0;
67
+
68
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
69
+ shadow += getPCSSDepthCompare( shadowMap, uv + pcssPoissonDisk[ i ] * filterRadius, zReceiver );
62
70
  }
63
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
64
- float depth = unpackRGBAToDepth(texture2D(shadowMap, uv + -poissonDisk[i].yx * filterRadius));
65
- if (zReceiver <= depth) sum += 1.0;
71
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
72
+ shadow += getPCSSDepthCompare( shadowMap, uv - pcssPoissonDisk[ i ].yx * filterRadius, zReceiver );
66
73
  }
67
- return sum / (2.0 * float(NUM_SAMPLES));
68
- }
69
74
 
70
- float PCSS(sampler2D shadowMap, vec4 coords) {
71
- vec2 uv = coords.xy;
72
- float zReceiver = coords.z; // Assumed to be eye-space z in this code
75
+ return shadow / ( 2.0 * float( PCSS_NUM_SAMPLES ) );
76
+ }
73
77
 
74
- initPoissonSamples(uv);
75
- // STEP 1: blocker search
76
- float avgBlockerDepth = findBlocker(shadowMap, uv, zReceiver);
78
+ float getPCSSShadow( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {
79
+ initPCSSPoissonSamples( uv );
77
80
 
78
- //There are no occluders so early out (this saves filtering)
79
- if (avgBlockerDepth == -1.0) return 1.0;
81
+ float avgBlockerDepth = findPCSSBlocker( shadowMap, uv, zReceiver );
82
+ if ( avgBlockerDepth == -1.0 ) return 1.0;
80
83
 
81
- // STEP 2: penumbra size
82
- float penumbraRatio = penumbraSize(zReceiver, avgBlockerDepth);
83
- float filterRadius = penumbraRatio * lightSizeUV * NEAR_PLANE / zReceiver;
84
+ float penumbraRatio = ( zReceiver - avgBlockerDepth ) / max( avgBlockerDepth, 0.0001 );
85
+ float filterRadius = penumbraRatio * lightSizeUV * PCSS_NEAR_PLANE / max( zReceiver, 0.0001 );
84
86
 
85
- // STEP 3: filtering
86
- //return avgBlockerDepth;
87
- return PCF_Filter(shadowMap, uv, zReceiver, filterRadius);
87
+ return getPCSSFilteredShadow( shadowMap, uv, zReceiver, filterRadius );
88
88
  }
89
+
89
90
  #endif
90
91
  `;
91
- exports.entry = `
92
- // PCSS implementation
93
- vec2 texelSize = vec2( 1.0 / 1024.0 ); // Always use 1024 for consistency
94
- float dx = texelSize.x;
95
- float dy = texelSize.y;
96
- vec2 uv = shadowCoord.xy;
97
- vec2 f = fract( uv * shadowMapSize + 0.5 );
98
- uv -= f * texelSize;
99
- float shadow1 = (
100
- texture2DCompare( shadowMap, uv, shadowCoord.z ) +
101
- texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
102
- texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
103
- texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
104
- mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
105
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
106
- f.x ) +
107
- mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
108
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
109
- f.x ) +
110
- mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
111
- texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
112
- f.y ) +
113
- mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
114
- texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
115
- f.y ) +
116
- mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
117
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
118
- f.x ),
119
- mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
120
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
121
- f.x ),
122
- f.y )
123
- ) * ( 1.0 / 9.0 );
124
- float shadow2 = PCSS( shadowMap, shadowCoord );
125
- shadow = shadow1 * (1.0 - blending) + blending * shadow2;
126
- `;
92
+ exports.getShadow = `
93
+ float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
94
+ float shadow = 1.0;
95
+
96
+ shadowCoord.xyz /= shadowCoord.w;
97
+
98
+ #ifdef USE_REVERSED_DEPTH_BUFFER
99
+ shadowCoord.z -= shadowBias;
100
+ #else
101
+ shadowCoord.z += shadowBias;
102
+ #endif
103
+
104
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
105
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
106
+
107
+ if ( frustumTest ) {
108
+ vec2 texelSize = vec2( 1.0 / 1024.0 );
109
+ float dx = texelSize.x;
110
+ float dy = texelSize.y;
111
+ vec2 uv = shadowCoord.xy;
112
+ vec2 f = fract( uv * shadowMapSize + 0.5 );
113
+ uv -= f * texelSize;
114
+
115
+ float pcfShadow = (
116
+ getPCSSDepthCompare( shadowMap, uv, shadowCoord.z ) +
117
+ getPCSSDepthCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
118
+ getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
119
+ getPCSSDepthCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
120
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
121
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
122
+ f.x ) +
123
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
124
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
125
+ f.x ) +
126
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
127
+ getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
128
+ f.y ) +
129
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
130
+ getPCSSDepthCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
131
+ f.y ) +
132
+ mix( mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
133
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
134
+ f.x ),
135
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
136
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
137
+ f.x ),
138
+ f.y )
139
+ ) * ( 1.0 / 9.0 );
140
+
141
+ float pcssShadow = getPCSSShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
142
+ shadow = mix( pcfShadow, pcssShadow, blending );
143
+ }
144
+
145
+ return mix( 1.0, shadow, shadowIntensity );
146
+ }
147
+ `;
127
148
  //# sourceMappingURL=PCSS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PCSS.js","sourceRoot":"","sources":["../../src/shaders/PCSS.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFnB,CAAC;AAEW,QAAA,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAmCR,CAAC"}
1
+ {"version":3,"file":"PCSS.js","sourceRoot":"","sources":["../../src/shaders/PCSS.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFnB,CAAC;AAEW,QAAA,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDxB,CAAC"}
@@ -1,3 +1,3 @@
1
- export declare const vert = "\n#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\n// CUSTOM START\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n// CUSTOM END\n\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n #ifdef USE_TRANSMISSION\n vWorldPosition = worldPosition.xyz;\n #endif\n\n // CUSTOM START\n frag_position = position;\n frag_normal = objectNormal;\n // CUSTOM END\n}\n";
2
- export declare const frag = "\n#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define SPECULAR\n#endif\n\n// CUSTOM START\n#ifdef USE_IMPURITYMAP\n\tuniform sampler2D impurityMap;\n#endif\n// CUSTOM END\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULARINTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULARCOLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n\n\n// CUSTOM START\n\nvarying vec4 initialPosition;\nvarying vec3 initialNormal;\n\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n\nuniform vec3 center;\nuniform float radius;\nuniform samplerCube sphericalNormalMap;\nuniform mat3 normalMatrix;\nuniform mat4 modelMatrix;\n\nuniform float impurityScale;\nuniform vec3 colorTransferBegin;\nuniform vec3 colorTransferEnd;\nuniform float refractionIndex;\nuniform float gamma;\nuniform float contrast;\nuniform float brightness;\nuniform float dispersion;\nuniform float tracingOpacity;\n\n\nvec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.\n\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\treturn min(envMapColor.rgb * envMapIntensity, vec3(1.0));\n\t#else\n\t\treturn vec3( 0.0 );\n\t#endif\n}\n\nvec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {\n\t\n\tvec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;\n\n\tmat3 normalMatrix;\n\tnormalMatrix[0] = normalize(modelMatrix[0].xyz);\n\tnormalMatrix[1] = normalize(modelMatrix[1].xyz);\n\tnormalMatrix[2] = normalize(modelMatrix[2].xyz);\n\t\n\t// Calculate the normal vector in world space\n\tvec3 currentGeometryNormal = normalize(normalMatrix * normal);\n\t\n\t// Calculate the view direction vector in world space\n\tvec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);\n\n vec3 currentGeometryClearcoatNormal;\n\t\n\t#ifdef USE_CLEARCOAT\n currentGeometryClearcoatNormal = clearcoatNormal;\n #endif\n\n\tReflectedLight rLight;\n\tIncidentLight dLight;\n\n\tfloat temp = material.roughness;\n\tmaterial.roughness = 0.5;\n\n\t#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\t\tPointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n\t #pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\t\tpointLight = pointLights[ i ];\n getPointLightInfo( pointLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\t\t RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n\t\t}\n #pragma unroll_loop_end\n\t#endif\n\t#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n\t#endif\n\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n\tmaterial.roughness = temp;\n\t\n #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t\t\n\t\t#if defined( USE_LIGHT_PROBES )\n \tirradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );\n\t\t#endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );\n }\n #pragma unroll_loop_end\n #endif\n #endif\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n\n #if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vUv2 );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( currentGeometryNormal );\n #endif\n #endif\n #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );\n #endif\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n\n\tif(depth >= 0) {\n\t\tfloat frac = float(depth) / float(TRACING_DEPTH);\n\t\tvec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;\n\t\trLight.indirectSpecular *= colorTransfer;\n\t\trLight.directSpecular *= colorTransfer;\n\t}\n\n\tvec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;\n\n\t// gamma\n\tcolor = pow(color, vec3(1.0/gamma)); \n\n\t// contrast\n\tcolor.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5; \n\n\t// brightness\n\tcolor.r = min(max(color.r + brightness, 0.0), 1.0);\n\tcolor.g = min(max(color.g + brightness, 0.0), 1.0);\n\tcolor.b = min(max(color.b + brightness, 0.0), 1.0);\n\n\treturn color;\n}\n\nvec3 normalLookUp(vec3 dir) {\n\tvec4 s = textureCube(sphericalNormalMap, dir);\n\tif(s.a < 1.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, -s.z));\n\t} else if(s.a < 3.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, s.z));\n\t} else if(s.a < 5.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, -s.z));\n\t} else if(s.a < 7.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, -s.z));\n\t} else if(s.a < 9.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, s.z));\n\t} else if(s.a < 11.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, s.z));\n\t} else if(s.a < 13.0/256.0) {\n\t\treturn normalize(vec3(s.x, s.y, -s.z));\n\t} else {\n\t\treturn normalize(s.xyz);\n\t}\n}\n\n#ifdef USE_IMPURITYMAP\n\tfloat impurityLookUp(vec3 dir) {\n\t\tvec3 c = textureCube(impurityMap, dir.xy).rgb;\n\t\treturn (c.x + c.y + c.z) / 3.0;\n\t}\n#endif\n\nvec3 raySphereIntersection(vec3 o, vec3 d) {\n\n\tvec3 oc = o - center;\n float a = dot(d, d);\n float b = 2.0 * dot(oc, d);\n float c = dot(oc,oc) - radius*radius;\n float discriminant = b*b - 4.0*a*c;\n if(discriminant < 0.0){\n return vec3(0.0);\n }\n else{\n return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;\n }\n}\n\nvec3 hueToSaturatedColor(float hue) {\n float r,g,b;\n if (hue < 0.25){\n\t\tfloat t = 1.0 - (hue / 0.25);\n r = 1.0;\n g = 1.0;\n b = t; \n\t} else if (hue < 0.5){\n \tfloat t = 1.0 - (hue - 0.25 / 0.25);\n\t\tr = 1.0;\n g = t;\n b = 0.0;\n\t} else if (hue < 0.75){\n \tfloat t = 1.0 - (hue - 0.5 / 0.25);\n\t\tr = t;\n g = 0.0;\n b = 1.0 - t;\n } else {\n \tfloat t = hue - 0.75 / 0.25;\n r = t;\n g = t;\n b = 1.0;\n }\n return vec3(r, g, b) / 0.5 + 0.5;\n}\n// CUSTOM END\n\nvoid main() { \n // CUSTOM START\n vec3 frag_normal_normalized = frag_normal;\n // CUSTOM END\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\n // CUSTOM START\n\t\n // Extract the translation part of the model matrix\n\tvec3 translation = modelMatrix[3].xyz;\n\n\t// Extract the rotation part of the model matrix (3x3 upper-left submatrix)\n\tmat3 rotationMatrix = mat3(modelMatrix);\n\n\t// Calculate the inverse of the rotation matrix (transpose since it's orthogonal)\n\tmat3 inverseRotationMatrix;\n\tinverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);\n\tinverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);\n\tinverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);\n\n\t// Calculate the camera position in model space\n\tvec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);\n\n\t// Calculate the initial direction\n\tvec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);\n\n\tvec4 outgoingLight2;\n\tfloat r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);\n\tr_0 = r_0*r_0;\n\n\tfloat cos_theta_0 = -dot(initialDirection, frag_normal_normalized);\n\tfloat r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);\n\tr_0_outside = r_0_outside*r_0_outside;\n\tfloat initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);\n\n\toutgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);\n\t// gl_FragColor = outgoingLight2;\n\t// return;\n\tif(TRACING_DEPTH > 0) \n\t\toutgoingLight2 *= initialProbability;\n\t\t\n\tvec3 tempColor;\n\n\t#ifdef DISPERSION\n\t\tconst int loop = 3;\n\t\tvec3 dispersionColor;\n\t#else\n\t\tconst int loop = 1;\n\t#endif\n\t\t#pragma unroll_loop_start\n\t\tfor(int j = 0; j < loop; j++){\n\t\t\tvec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);\n\t\t\tvec3 newPosition = raySphereIntersection(frag_position, refractedDirection);\n\t\t\tvec3 lookUpVector = normalize(newPosition - center);\n\t\t\tvec3 newNormal = normalLookUp(lookUpVector);\n\t\t\tvec3 newDirection = reflect(refractedDirection, newNormal);\n\n\t\t\tfloat currentProbability = 1.0;\n\n\t\t\t#ifdef USE_IMPURITYMAP\n\t\t\t\tfloat impurityProbability = impurityLookUp(lookUpVector);\n\t\t\t\tcurrentProbability -= impurityProbability * impurityScale;\n\t\t\t\t// gl_FragColor = vec4(vec3(impurityProbability), 1.0);\n\t\t\t\t// return;\n\t\t\t#endif\n\t\t\t\n\t\t\t// if(0 == TRACING_DEPTH) {\n\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t// \treturn;\n\t\t\t// }\n\n\t\t\ttempColor = vec3(0.0);\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor(int i = 0; i < TRACING_DEPTH; i++) {\n\t\t\t\t// small position correction to avoid artefacts\n\t\t\t\tnewPosition = newPosition - lookUpVector * 1e-6;\n\t\t\t\tnewPosition = raySphereIntersection(newPosition, newDirection);\n\t\t\t\tlookUpVector = normalize(newPosition - center);\n\t\t\t\tnewNormal = normalLookUp(lookUpVector);\n\t\t\t\n\t\t\t\tfloat cos_theta = dot(newDirection, newNormal);\n\t\t\t\tfloat ratio;\n\t\t\t\tif(cos_theta > 0.0) {\n\t\t\t\t\tratio = refractionIndex;\n\t\t\t\t} else {\n\t\t\t\t\tcos_theta = -cos_theta;\n\t\t\t\t\tratio = 1.0 / refractionIndex;\n\t\t\t\t}\n\t\t\t\tfloat cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);\n\t\t\t\tfloat probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);\n\t\t\t\tif(cos_theta_2 < 0.0) probability = 0.0;\n\n\t\t\t\tvec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);\n\t\t\t\ttempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);\n\t\t\t\tif(i+1 == TRACING_DEPTH)\n\t\t\t\t\ttempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);\n\n\t\t\t\tnewDirection = reflect(newDirection, newNormal);\n\n\t\t\t\t// if(i+1 == TRACING_DEPTH) {\n\t\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t\t// \treturn;\n\t\t\t\t// }\n\n\t\t\t\tcurrentProbability *= (1.0 - probability);\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\n\t\t\t#ifdef DISPERSION\n\t\t\t\tif(j == 0) {\n\t\t\t\t\tdispersionColor.r = tempColor.r;\t\n\t\t\t\t} else if(j == 1) {\n\t\t\t\t\tdispersionColor.g = tempColor.g;\t\n\t\t\t\t} else if(j == 2) {\n\t\t\t\t\tdispersionColor.b = tempColor.b;\t\n\t\t\t\t}\n\t\t\t\ttempColor = dispersionColor;\n\t\t\t#endif\n\t\t}\t\n\t\t#pragma unroll_loop_end\n\n\tif(TRACING_DEPTH > 0)\n\t\toutgoingLight2.rgb += (1.0 - initialProbability) * tempColor;\n\n\tfloat alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;\n\tgl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);\n\n // CUSTOM END\n\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n\n";
1
+ export declare const vert = "\n#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\n// CUSTOM START\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n// CUSTOM END\n\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n #ifdef USE_TRANSMISSION\n vWorldPosition = worldPosition.xyz;\n #endif\n\n // CUSTOM START\n frag_position = position;\n frag_normal = objectNormal;\n // CUSTOM END\n}\n";
2
+ export declare const frag = "\n#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\n\n// CUSTOM START\n#ifdef USE_IMPURITYMAP\n\tuniform sampler2D impurityMap;\n#endif\n// CUSTOM END\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n\n\n// CUSTOM START\n\nvarying vec4 initialPosition;\nvarying vec3 initialNormal;\n\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n\nuniform vec3 center;\nuniform float radius;\nuniform samplerCube sphericalNormalMap;\nuniform mat3 normalMatrix;\nuniform mat4 modelMatrix;\n\nuniform float impurityScale;\nuniform vec3 colorTransferBegin;\nuniform vec3 colorTransferEnd;\nuniform float refractionIndex;\nuniform float gamma;\nuniform float contrast;\nuniform float brightness;\nuniform float dispersion;\nuniform float tracingOpacity;\n\n\nvec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.\n\t\treflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t#else\n\t\treturn vec3( 0.0 );\n\t#endif\n}\n\nvec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {\n\t\n\tvec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;\n\n\tmat3 normalMatrix;\n\tnormalMatrix[0] = normalize(modelMatrix[0].xyz);\n\tnormalMatrix[1] = normalize(modelMatrix[1].xyz);\n\tnormalMatrix[2] = normalize(modelMatrix[2].xyz);\n\t\n\t// Calculate the normal vector in world space\n\tvec3 currentGeometryNormal = normalize(normalMatrix * normal);\n\t\n\t// Calculate the view direction vector in world space\n\tvec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);\n\n vec3 currentGeometryClearcoatNormal = vec3( 0.0 );\n\t\n\t#ifdef USE_CLEARCOAT\n currentGeometryClearcoatNormal = clearcoatNormal;\n #endif\n\n\tReflectedLight rLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tIncidentLight dLight;\n\n\tfloat temp = material.roughness;\n\tmaterial.roughness = 0.5;\n\n\t#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\t\tPointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n\t #pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\t\tpointLight = pointLights[ i ];\n getPointLightInfo( pointLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n dLight.color *= ( dLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\t\t RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n\t\t}\n #pragma unroll_loop_end\n\t#endif\n\t#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n dLight.color *= ( dLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n\t#endif\n\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n dLight.color *= ( dLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n\tmaterial.roughness = temp;\n\t\n #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t\t\n\t\t#if defined( USE_LIGHT_PROBES )\n \tirradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );\n\t\t#endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );\n }\n #pragma unroll_loop_end\n #endif\n #endif\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n\n #if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( currentGeometryNormal );\n #endif\n #endif\n #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );\n #endif\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n\n\tif(depth >= 0) {\n\t\tfloat frac = float(depth) / float(TRACING_DEPTH);\n\t\tvec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;\n\t\trLight.indirectSpecular *= colorTransfer;\n\t\trLight.directSpecular *= colorTransfer;\n\t}\n\n\tvec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;\n\n\t// gamma\n\tcolor = pow(color, vec3(1.0/gamma)); \n\n\t// contrast\n\tcolor.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5; \n\n\t// brightness\n\tcolor.r = min(max(color.r + brightness, 0.0), 1.0);\n\tcolor.g = min(max(color.g + brightness, 0.0), 1.0);\n\tcolor.b = min(max(color.b + brightness, 0.0), 1.0);\n\n\treturn color;\n}\n\nvec3 normalLookUp(vec3 dir) {\n\tvec4 s = textureCube(sphericalNormalMap, dir);\n\tif(s.a < 1.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, -s.z));\n\t} else if(s.a < 3.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, s.z));\n\t} else if(s.a < 5.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, -s.z));\n\t} else if(s.a < 7.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, -s.z));\n\t} else if(s.a < 9.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, s.z));\n\t} else if(s.a < 11.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, s.z));\n\t} else if(s.a < 13.0/256.0) {\n\t\treturn normalize(vec3(s.x, s.y, -s.z));\n\t} else {\n\t\treturn normalize(s.xyz);\n\t}\n}\n\n#ifdef USE_IMPURITYMAP\n\tfloat impurityLookUp(vec3 dir) {\n\t\tvec3 c = texture2D(impurityMap, dir.xy * 0.5 + 0.5).rgb;\n\t\treturn (c.x + c.y + c.z) / 3.0;\n\t}\n#endif\n\nvec3 raySphereIntersection(vec3 o, vec3 d) {\n\n\tvec3 oc = o - center;\n float a = dot(d, d);\n float b = 2.0 * dot(oc, d);\n float c = dot(oc,oc) - radius*radius;\n float discriminant = b*b - 4.0*a*c;\n if(discriminant < 0.0){\n return vec3(0.0);\n }\n else{\n return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;\n }\n}\n\nvec3 hueToSaturatedColor(float hue) {\n float r,g,b;\n if (hue < 0.25){\n\t\tfloat t = 1.0 - (hue / 0.25);\n r = 1.0;\n g = 1.0;\n b = t; \n\t} else if (hue < 0.5){\n \tfloat t = 1.0 - (hue - 0.25 / 0.25);\n\t\tr = 1.0;\n g = t;\n b = 0.0;\n\t} else if (hue < 0.75){\n \tfloat t = 1.0 - (hue - 0.5 / 0.25);\n\t\tr = t;\n g = 0.0;\n b = 1.0 - t;\n } else {\n \tfloat t = hue - 0.75 / 0.25;\n r = t;\n g = t;\n b = 1.0;\n }\n return vec3(r, g, b) / 0.5 + 0.5;\n}\n// CUSTOM END\n\nvoid main() { \n // CUSTOM START\n vec3 frag_normal_normalized = frag_normal;\n // CUSTOM END\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\toutgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\n // CUSTOM START\n\t\n // Extract the translation part of the model matrix\n\tvec3 translation = modelMatrix[3].xyz;\n\n\t// Extract the rotation part of the model matrix (3x3 upper-left submatrix)\n\tmat3 rotationMatrix = mat3(modelMatrix);\n\n\t// Calculate the inverse of the rotation matrix (transpose since it's orthogonal)\n\tmat3 inverseRotationMatrix;\n\tinverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);\n\tinverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);\n\tinverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);\n\n\t// Calculate the camera position in model space\n\tvec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);\n\n\t// Calculate the initial direction\n\tvec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);\n\n\tvec4 outgoingLight2;\n\tfloat r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);\n\tr_0 = r_0*r_0;\n\n\tfloat cos_theta_0 = -dot(initialDirection, frag_normal_normalized);\n\tfloat r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);\n\tr_0_outside = r_0_outside*r_0_outside;\n\tfloat initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);\n\n\toutgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);\n\t// gl_FragColor = outgoingLight2;\n\t// return;\n\tif(TRACING_DEPTH > 0) \n\t\toutgoingLight2 *= initialProbability;\n\t\t\n\tvec3 tempColor;\n\n\t#ifdef DISPERSION\n\t\tconst int loop = 3;\n\t\tvec3 dispersionColor;\n\t#else\n\t\tconst int loop = 1;\n\t#endif\n\t\t#pragma unroll_loop_start\n\t\tfor(int j = 0; j < loop; j++){\n\t\t\tvec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);\n\t\t\tvec3 newPosition = raySphereIntersection(frag_position, refractedDirection);\n\t\t\tvec3 lookUpVector = normalize(newPosition - center);\n\t\t\tvec3 newNormal = normalLookUp(lookUpVector);\n\t\t\tvec3 newDirection = reflect(refractedDirection, newNormal);\n\n\t\t\tfloat currentProbability = 1.0;\n\n\t\t\t#ifdef USE_IMPURITYMAP\n\t\t\t\tfloat impurityProbability = impurityLookUp(lookUpVector);\n\t\t\t\tcurrentProbability -= impurityProbability * impurityScale;\n\t\t\t\t// gl_FragColor = vec4(vec3(impurityProbability), 1.0);\n\t\t\t\t// return;\n\t\t\t#endif\n\t\t\t\n\t\t\t// if(0 == TRACING_DEPTH) {\n\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t// \treturn;\n\t\t\t// }\n\n\t\t\ttempColor = vec3(0.0);\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor(int i = 0; i < TRACING_DEPTH; i++) {\n\t\t\t\t// small position correction to avoid artefacts\n\t\t\t\tnewPosition = newPosition - lookUpVector * 1e-6;\n\t\t\t\tnewPosition = raySphereIntersection(newPosition, newDirection);\n\t\t\t\tlookUpVector = normalize(newPosition - center);\n\t\t\t\tnewNormal = normalLookUp(lookUpVector);\n\t\t\t\n\t\t\t\tfloat cos_theta = dot(newDirection, newNormal);\n\t\t\t\tfloat ratio;\n\t\t\t\tif(cos_theta > 0.0) {\n\t\t\t\t\tratio = refractionIndex;\n\t\t\t\t} else {\n\t\t\t\t\tcos_theta = -cos_theta;\n\t\t\t\t\tratio = 1.0 / refractionIndex;\n\t\t\t\t}\n\t\t\t\tfloat cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);\n\t\t\t\tfloat probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);\n\t\t\t\tif(cos_theta_2 < 0.0) probability = 0.0;\n\n\t\t\t\tvec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);\n\t\t\t\ttempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);\n\t\t\t\tif(i+1 == TRACING_DEPTH)\n\t\t\t\t\ttempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);\n\n\t\t\t\tnewDirection = reflect(newDirection, newNormal);\n\n\t\t\t\t// if(i+1 == TRACING_DEPTH) {\n\t\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t\t// \treturn;\n\t\t\t\t// }\n\n\t\t\t\tcurrentProbability *= (1.0 - probability);\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\n\t\t\t#ifdef DISPERSION\n\t\t\t\tif(j == 0) {\n\t\t\t\t\tdispersionColor.r = tempColor.r;\t\n\t\t\t\t} else if(j == 1) {\n\t\t\t\t\tdispersionColor.g = tempColor.g;\t\n\t\t\t\t} else if(j == 2) {\n\t\t\t\t\tdispersionColor.b = tempColor.b;\t\n\t\t\t\t}\n\t\t\t\ttempColor = dispersionColor;\n\t\t\t#endif\n\t\t}\t\n\t\t#pragma unroll_loop_end\n\n\tif(TRACING_DEPTH > 0)\n\t\toutgoingLight2.rgb += (1.0 - initialProbability) * tempColor;\n\n\tfloat alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;\n\tgl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);\n\n // CUSTOM END\n\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n\n";
3
3
  //# sourceMappingURL=gem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gem.d.ts","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,s3CAqDhB,CAAC;AAEF,eAAO,MAAM,IAAI,q9lBA2gBhB,CAAC"}
1
+ {"version":3,"file":"gem.d.ts","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,w9CAwDhB,CAAC;AAEF,eAAO,MAAM,IAAI,8rmBA4gBhB,CAAC"}
@@ -8,6 +8,7 @@ varying vec3 vViewPosition;
8
8
  varying vec3 vWorldPosition;
9
9
  #endif
10
10
  #include <common>
11
+ #include <batching_pars_vertex>
11
12
  #include <uv_pars_vertex>
12
13
  #include <displacementmap_pars_vertex>
13
14
  #include <color_pars_vertex>
@@ -27,7 +28,9 @@ varying vec3 frag_normal;
27
28
  void main() {
28
29
  #include <uv_vertex>
29
30
  #include <color_vertex>
31
+ #include <morphinstance_vertex>
30
32
  #include <morphcolor_vertex>
33
+ #include <batching_vertex>
31
34
  #include <beginnormal_vertex>
32
35
  #include <morphnormal_vertex>
33
36
  #include <skinbase_vertex>
@@ -59,7 +62,7 @@ exports.frag = `
59
62
  #define STANDARD
60
63
  #ifdef PHYSICAL
61
64
  #define IOR
62
- #define SPECULAR
65
+ #define USE_SPECULAR
63
66
  #endif
64
67
 
65
68
  // CUSTOM START
@@ -76,13 +79,13 @@ uniform float opacity;
76
79
  #ifdef IOR
77
80
  uniform float ior;
78
81
  #endif
79
- #ifdef SPECULAR
82
+ #ifdef USE_SPECULAR
80
83
  uniform float specularIntensity;
81
84
  uniform vec3 specularColor;
82
- #ifdef USE_SPECULARINTENSITYMAP
85
+ #ifdef USE_SPECULAR_INTENSITYMAP
83
86
  uniform sampler2D specularIntensityMap;
84
87
  #endif
85
- #ifdef USE_SPECULARCOLORMAP
88
+ #ifdef USE_SPECULAR_COLORMAP
86
89
  uniform sampler2D specularColorMap;
87
90
  #endif
88
91
  #endif
@@ -99,10 +102,10 @@ uniform float opacity;
99
102
  #ifdef USE_SHEEN
100
103
  uniform vec3 sheenColor;
101
104
  uniform float sheenRoughness;
102
- #ifdef USE_SHEENCOLORMAP
105
+ #ifdef USE_SHEEN_COLORMAP
103
106
  uniform sampler2D sheenColorMap;
104
107
  #endif
105
- #ifdef USE_SHEENROUGHNESSMAP
108
+ #ifdef USE_SHEEN_ROUGHNESSMAP
106
109
  uniform sampler2D sheenRoughnessMap;
107
110
  #endif
108
111
  #endif
@@ -115,6 +118,7 @@ varying vec3 vViewPosition;
115
118
  #include <map_pars_fragment>
116
119
  #include <alphamap_pars_fragment>
117
120
  #include <alphatest_pars_fragment>
121
+ #include <alphahash_pars_fragment>
118
122
  #include <aomap_pars_fragment>
119
123
  #include <lightmap_pars_fragment>
120
124
  #include <emissivemap_pars_fragment>
@@ -169,10 +173,10 @@ vec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const
169
173
  #if defined( ENVMAP_TYPE_CUBE_UV )
170
174
  vec3 reflectVec = reflect( - viewDir, normal );
171
175
  // Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.
172
- reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
176
+ reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );
173
177
  reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
174
- vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
175
- return min(envMapColor.rgb * envMapIntensity, vec3(1.0));
178
+ vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
179
+ return envMapColor.rgb * envMapIntensity;
176
180
  #else
177
181
  return vec3( 0.0 );
178
182
  #endif
@@ -193,13 +197,13 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
193
197
  // Calculate the view direction vector in world space
194
198
  vec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);
195
199
 
196
- vec3 currentGeometryClearcoatNormal;
200
+ vec3 currentGeometryClearcoatNormal = vec3( 0.0 );
197
201
 
198
202
  #ifdef USE_CLEARCOAT
199
203
  currentGeometryClearcoatNormal = clearcoatNormal;
200
204
  #endif
201
205
 
202
- ReflectedLight rLight;
206
+ ReflectedLight rLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
203
207
  IncidentLight dLight;
204
208
 
205
209
  float temp = material.roughness;
@@ -218,7 +222,7 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
218
222
  getPointLightInfo( pointLight, currentGeometryPosition, dLight );
219
223
  #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
220
224
  pointLightShadow = pointLightShadows[ i ];
221
- dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
225
+ dLight.color *= ( dLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
222
226
  #endif
223
227
  RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
224
228
  }
@@ -235,7 +239,7 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
235
239
  getSpotLightInfo( spotLight, currentGeometryPosition, dLight );
236
240
  #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
237
241
  spotLightShadow = spotLightShadows[ i ];
238
- dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
242
+ dLight.color *= ( dLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
239
243
  #endif
240
244
  RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
241
245
  }
@@ -253,7 +257,7 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
253
257
  getDirectionalLightInfo( directionalLight, dLight );
254
258
  #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
255
259
  directionalLightShadow = directionalLightShadows[ i ];
256
- dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
260
+ dLight.color *= ( dLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
257
261
  #endif
258
262
  RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
259
263
  }
@@ -293,7 +297,7 @@ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalM
293
297
 
294
298
  #if defined( RE_IndirectDiffuse )
295
299
  #ifdef USE_LIGHTMAP
296
- vec4 lightMapTexel = texture2D( lightMap, vUv2 );
300
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
297
301
  vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
298
302
  irradiance += lightMapIrradiance;
299
303
  #endif
@@ -361,7 +365,7 @@ vec3 normalLookUp(vec3 dir) {
361
365
 
362
366
  #ifdef USE_IMPURITYMAP
363
367
  float impurityLookUp(vec3 dir) {
364
- vec3 c = textureCube(impurityMap, dir.xy).rgb;
368
+ vec3 c = texture2D(impurityMap, dir.xy * 0.5 + 0.5).rgb;
365
369
  return (c.x + c.y + c.z) / 3.0;
366
370
  }
367
371
  #endif
@@ -421,6 +425,7 @@ void main() {
421
425
  #include <color_fragment>
422
426
  #include <alphamap_fragment>
423
427
  #include <alphatest_fragment>
428
+ #include <alphahash_fragment>
424
429
  #include <roughnessmap_fragment>
425
430
  #include <metalnessmap_fragment>
426
431
  #include <normal_fragment_begin>
@@ -438,13 +443,12 @@ void main() {
438
443
  #include <transmission_fragment>
439
444
  vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
440
445
  #ifdef USE_SHEEN
441
- float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
442
- outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;
446
+ outgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;
443
447
  #endif
444
448
  #ifdef USE_CLEARCOAT
445
- float dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );
449
+ float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
446
450
  vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
447
- outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;
451
+ outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
448
452
  #endif
449
453
  #include <opaque_fragment>
450
454
 
@@ -1 +1 @@
1
- {"version":3,"file":"gem.js","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDnB,CAAC;AAEW,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2gBnB,CAAC"}
1
+ {"version":3,"file":"gem.js","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDnB,CAAC;AAEW,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4gBnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapediver/viewer.rendering-engine.rendering-engine-threejs",
3
- "version": "3.19.3",
3
+ "version": "3.20.1",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "Michael Oppitz <michael@shapediver.com>",
@@ -37,28 +37,28 @@
37
37
  "testEnvironment": "node"
38
38
  },
39
39
  "dependencies": {
40
- "@shapediver/viewer.data-engine.gltf-converter": "3.19.3",
41
- "@shapediver/viewer.data-engine.shared-types": "3.19.3",
42
- "@shapediver/viewer.data-engine.tag3d-engine": "3.19.3",
43
- "@shapediver/viewer.rendering-engine.animation-engine": "3.19.3",
44
- "@shapediver/viewer.rendering-engine.animation-frame-engine": "3.19.3",
45
- "@shapediver/viewer.rendering-engine.camera-engine": "3.19.3",
46
- "@shapediver/viewer.rendering-engine.canvas-engine": "3.19.3",
47
- "@shapediver/viewer.rendering-engine.intersection-engine": "3.19.3",
48
- "@shapediver/viewer.rendering-engine.light-engine": "3.19.3",
49
- "@shapediver/viewer.rendering-engine.rendering-engine": "3.19.3",
50
- "@shapediver/viewer.shared.global-access-objects": "3.19.3",
51
- "@shapediver/viewer.shared.math": "3.19.3",
52
- "@shapediver/viewer.shared.node-tree": "3.19.3",
53
- "@shapediver/viewer.shared.services": "3.19.3",
54
- "@shapediver/viewer.shared.types": "3.19.3",
40
+ "@shapediver/viewer.data-engine.gltf-converter": "3.20.1",
41
+ "@shapediver/viewer.data-engine.shared-types": "3.20.1",
42
+ "@shapediver/viewer.data-engine.tag3d-engine": "3.20.1",
43
+ "@shapediver/viewer.rendering-engine.animation-engine": "3.20.1",
44
+ "@shapediver/viewer.rendering-engine.animation-frame-engine": "3.20.1",
45
+ "@shapediver/viewer.rendering-engine.camera-engine": "3.20.1",
46
+ "@shapediver/viewer.rendering-engine.canvas-engine": "3.20.1",
47
+ "@shapediver/viewer.rendering-engine.intersection-engine": "3.20.1",
48
+ "@shapediver/viewer.rendering-engine.light-engine": "3.20.1",
49
+ "@shapediver/viewer.rendering-engine.rendering-engine": "3.20.1",
50
+ "@shapediver/viewer.shared.global-access-objects": "3.20.1",
51
+ "@shapediver/viewer.shared.math": "3.20.1",
52
+ "@shapediver/viewer.shared.node-tree": "3.20.1",
53
+ "@shapediver/viewer.shared.services": "3.20.1",
54
+ "@shapediver/viewer.shared.types": "3.20.1",
55
55
  "@tweenjs/tween.js": "25.0.0",
56
56
  "@types/stats.js": "0.17.4",
57
- "@types/three": "0.162.0",
57
+ "@types/three": "0.184.1",
58
58
  "gl-matrix": "3.4.4",
59
- "postprocessing": "6.35.3",
59
+ "postprocessing": "6.39.1",
60
60
  "stats.js": "0.17.0",
61
- "three": "0.162.0"
61
+ "three": "0.184.0"
62
62
  },
63
- "gitHead": "447c1056900cc0a6add0a5d363c705b703e95c11"
63
+ "gitHead": "1496133cb9d6973f9ee07de4d26decee7e7417fd"
64
64
  }