@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.18.2 → 3.19.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 (103) hide show
  1. package/LICENSE +73 -73
  2. package/README.md +3 -3
  3. package/dist/RenderingEngine.d.ts +5 -5
  4. package/dist/RenderingEngine.d.ts.map +1 -1
  5. package/dist/RenderingEngine.js.map +1 -1
  6. package/dist/index.d.ts +3 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/injectors/TextureUnifierInjector.js +57 -57
  10. package/dist/interfaces/IRenderingEngine.d.ts +2 -2
  11. package/dist/interfaces/IRenderingEngine.d.ts.map +1 -1
  12. package/dist/loaders/EnvironmentMapLoader.d.ts +1 -1
  13. package/dist/loaders/EnvironmentMapLoader.d.ts.map +1 -1
  14. package/dist/loaders/EnvironmentMapLoader.js.map +1 -1
  15. package/dist/loaders/GeometryLoader.d.ts +2 -2
  16. package/dist/loaders/GeometryLoader.d.ts.map +1 -1
  17. package/dist/loaders/GeometryLoader.js +43 -43
  18. package/dist/loaders/GeometryLoader.js.map +1 -1
  19. package/dist/loaders/HTMLElementAnchorLoader.d.ts +2 -2
  20. package/dist/loaders/HTMLElementAnchorLoader.d.ts.map +1 -1
  21. package/dist/loaders/HTMLElementAnchorLoader.js.map +1 -1
  22. package/dist/loaders/LightLoader.d.ts +2 -2
  23. package/dist/loaders/LightLoader.d.ts.map +1 -1
  24. package/dist/loaders/LightLoader.js.map +1 -1
  25. package/dist/loaders/MaterialLoader.d.ts +7 -7
  26. package/dist/loaders/MaterialLoader.d.ts.map +1 -1
  27. package/dist/loaders/MaterialLoader.js +42 -42
  28. package/dist/loaders/MaterialLoader.js.map +1 -1
  29. package/dist/managers/ARManager.d.ts +1 -1
  30. package/dist/managers/ARManager.d.ts.map +1 -1
  31. package/dist/managers/ARManager.js.map +1 -1
  32. package/dist/managers/CameraManager.d.ts +1 -1
  33. package/dist/managers/CameraManager.d.ts.map +1 -1
  34. package/dist/managers/CameraManager.js.map +1 -1
  35. package/dist/managers/EnvironmentGeometryManager.d.ts +2 -2
  36. package/dist/managers/EnvironmentGeometryManager.d.ts.map +1 -1
  37. package/dist/managers/EnvironmentGeometryManager.js.map +1 -1
  38. package/dist/managers/FlagManager.d.ts +1 -1
  39. package/dist/managers/FlagManager.d.ts.map +1 -1
  40. package/dist/managers/FlagManager.js.map +1 -1
  41. package/dist/managers/PostProcessingManager.d.ts +2 -2
  42. package/dist/managers/PostProcessingManager.d.ts.map +1 -1
  43. package/dist/managers/PostProcessingManager.js.map +1 -1
  44. package/dist/managers/RenderingManager.d.ts +2 -1
  45. package/dist/managers/RenderingManager.d.ts.map +1 -1
  46. package/dist/managers/RenderingManager.js +12 -0
  47. package/dist/managers/RenderingManager.js.map +1 -1
  48. package/dist/managers/SceneTracingManager.d.ts +3 -3
  49. package/dist/managers/SceneTracingManager.d.ts.map +1 -1
  50. package/dist/managers/SceneTracingManager.js.map +1 -1
  51. package/dist/managers/SceneTreeManager.d.ts +3 -3
  52. package/dist/managers/SceneTreeManager.d.ts.map +1 -1
  53. package/dist/managers/SceneTreeManager.js.map +1 -1
  54. package/dist/managers/SettingsManager.d.ts +2 -2
  55. package/dist/managers/SettingsManager.d.ts.map +1 -1
  56. package/dist/managers/SettingsManager.js.map +1 -1
  57. package/dist/managers/environmentGeometry/ContactShadow.d.ts +1 -1
  58. package/dist/managers/environmentGeometry/ContactShadow.d.ts.map +1 -1
  59. package/dist/managers/environmentGeometry/ContactShadow.js +3 -3
  60. package/dist/managers/environmentGeometry/Grid.d.ts +2 -2
  61. package/dist/managers/environmentGeometry/Grid.d.ts.map +1 -1
  62. package/dist/managers/environmentGeometry/GroundPlane.d.ts +2 -2
  63. package/dist/managers/environmentGeometry/GroundPlane.d.ts.map +1 -1
  64. package/dist/managers/environmentGeometry/GroundPlane.js.map +1 -1
  65. package/dist/managers/environmentGeometry/GroundPlaneShadow.d.ts +2 -2
  66. package/dist/managers/environmentGeometry/GroundPlaneShadow.d.ts.map +1 -1
  67. package/dist/managers/environmentGeometry/IEnvironmentGeometry.d.ts +1 -1
  68. package/dist/managers/environmentGeometry/IEnvironmentGeometry.d.ts.map +1 -1
  69. package/dist/managers/postprocessing/GodRaysManager.d.ts +1 -1
  70. package/dist/managers/postprocessing/GodRaysManager.d.ts.map +1 -1
  71. package/dist/managers/postprocessing/OutlineManager.d.ts +1 -1
  72. package/dist/managers/postprocessing/OutlineManager.d.ts.map +1 -1
  73. package/dist/managers/postprocessing/SelectiveBloomManager.d.ts +1 -1
  74. package/dist/managers/postprocessing/SelectiveBloomManager.d.ts.map +1 -1
  75. package/dist/managers/postprocessing/ao/ao/shader/ao_compose.js +18 -18
  76. package/dist/managers/postprocessing/ao/ao/shader/ao_utils.js +81 -81
  77. package/dist/managers/postprocessing/ao/hbao/shader/hbao.js +154 -154
  78. package/dist/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.js +152 -152
  79. package/dist/managers/postprocessing/ao/ssao/shader/ssao.js +115 -115
  80. package/dist/managers/postprocessing/ao/utils/shader/basic.js +10 -10
  81. package/dist/managers/postprocessing/ao/utils/shader/sampleBlueNoise.js +37 -37
  82. package/dist/managers/postprocessing/effects/tone-mapping/tone-mapping.js +92 -92
  83. package/dist/managers/postprocessing/utils/CopyMaterial.js +36 -36
  84. package/dist/managers/postprocessing/utils/CopyShader.js +23 -23
  85. package/dist/managers/sceneTree/SDTFUtils.d.ts +2 -2
  86. package/dist/managers/sceneTree/SDTFUtils.d.ts.map +1 -1
  87. package/dist/managers/sceneTree/SDTFUtils.js.map +1 -1
  88. package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts +1 -1
  89. package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts.map +1 -1
  90. package/dist/managers/sceneTree/SceenTreeManagerUtils.js.map +1 -1
  91. package/dist/objects/SDColor.d.ts +1 -1
  92. package/dist/objects/SDColor.d.ts.map +1 -1
  93. package/dist/objects/SDObject.d.ts +1 -1
  94. package/dist/objects/SDObject.d.ts.map +1 -1
  95. package/dist/shaders/PCSS.js +121 -121
  96. package/dist/shaders/gem.js +576 -576
  97. package/dist/shaders/multi_points.js +288 -288
  98. package/dist/styling/viewport-css.js +112 -112
  99. package/dist/types/IThreejsData.d.ts +1 -1
  100. package/dist/types/IThreejsData.d.ts.map +1 -1
  101. package/dist/types/ThreejsData.d.ts +1 -1
  102. package/dist/types/ThreejsData.d.ts.map +1 -1
  103. package/package.json +17 -17
@@ -1,582 +1,582 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.frag = exports.vert = void 0;
4
- exports.vert = `
5
- #define STANDARD
6
- varying vec3 vViewPosition;
7
- #ifdef USE_TRANSMISSION
8
- varying vec3 vWorldPosition;
9
- #endif
10
- #include <common>
11
- #include <uv_pars_vertex>
12
- #include <displacementmap_pars_vertex>
13
- #include <color_pars_vertex>
14
- #include <fog_pars_vertex>
15
- #include <normal_pars_vertex>
16
- #include <morphtarget_pars_vertex>
17
- #include <skinning_pars_vertex>
18
- #include <shadowmap_pars_vertex>
19
- #include <logdepthbuf_pars_vertex>
20
- #include <clipping_planes_pars_vertex>
21
-
22
- // CUSTOM START
23
- varying vec3 frag_position;
24
- varying vec3 frag_normal;
25
- // CUSTOM END
26
-
27
- void main() {
28
- #include <uv_vertex>
29
- #include <color_vertex>
30
- #include <morphcolor_vertex>
31
- #include <beginnormal_vertex>
32
- #include <morphnormal_vertex>
33
- #include <skinbase_vertex>
34
- #include <skinnormal_vertex>
35
- #include <defaultnormal_vertex>
36
- #include <normal_vertex>
37
- #include <begin_vertex>
38
- #include <morphtarget_vertex>
39
- #include <skinning_vertex>
40
- #include <displacementmap_vertex>
41
- #include <project_vertex>
42
- #include <logdepthbuf_vertex>
43
- #include <clipping_planes_vertex>
44
- vViewPosition = - mvPosition.xyz;
45
- #include <worldpos_vertex>
46
- #include <shadowmap_vertex>
47
- #include <fog_vertex>
48
- #ifdef USE_TRANSMISSION
49
- vWorldPosition = worldPosition.xyz;
50
- #endif
51
-
52
- // CUSTOM START
53
- frag_position = position;
54
- frag_normal = objectNormal;
55
- // CUSTOM END
56
- }
4
+ exports.vert = `
5
+ #define STANDARD
6
+ varying vec3 vViewPosition;
7
+ #ifdef USE_TRANSMISSION
8
+ varying vec3 vWorldPosition;
9
+ #endif
10
+ #include <common>
11
+ #include <uv_pars_vertex>
12
+ #include <displacementmap_pars_vertex>
13
+ #include <color_pars_vertex>
14
+ #include <fog_pars_vertex>
15
+ #include <normal_pars_vertex>
16
+ #include <morphtarget_pars_vertex>
17
+ #include <skinning_pars_vertex>
18
+ #include <shadowmap_pars_vertex>
19
+ #include <logdepthbuf_pars_vertex>
20
+ #include <clipping_planes_pars_vertex>
21
+
22
+ // CUSTOM START
23
+ varying vec3 frag_position;
24
+ varying vec3 frag_normal;
25
+ // CUSTOM END
26
+
27
+ void main() {
28
+ #include <uv_vertex>
29
+ #include <color_vertex>
30
+ #include <morphcolor_vertex>
31
+ #include <beginnormal_vertex>
32
+ #include <morphnormal_vertex>
33
+ #include <skinbase_vertex>
34
+ #include <skinnormal_vertex>
35
+ #include <defaultnormal_vertex>
36
+ #include <normal_vertex>
37
+ #include <begin_vertex>
38
+ #include <morphtarget_vertex>
39
+ #include <skinning_vertex>
40
+ #include <displacementmap_vertex>
41
+ #include <project_vertex>
42
+ #include <logdepthbuf_vertex>
43
+ #include <clipping_planes_vertex>
44
+ vViewPosition = - mvPosition.xyz;
45
+ #include <worldpos_vertex>
46
+ #include <shadowmap_vertex>
47
+ #include <fog_vertex>
48
+ #ifdef USE_TRANSMISSION
49
+ vWorldPosition = worldPosition.xyz;
50
+ #endif
51
+
52
+ // CUSTOM START
53
+ frag_position = position;
54
+ frag_normal = objectNormal;
55
+ // CUSTOM END
56
+ }
57
57
  `;
58
- exports.frag = `
59
- #define STANDARD
60
- #ifdef PHYSICAL
61
- #define IOR
62
- #define SPECULAR
63
- #endif
64
-
65
- // CUSTOM START
66
- #ifdef USE_IMPURITYMAP
67
- uniform sampler2D impurityMap;
68
- #endif
69
- // CUSTOM END
70
-
71
- uniform vec3 diffuse;
72
- uniform vec3 emissive;
73
- uniform float roughness;
74
- uniform float metalness;
75
- uniform float opacity;
76
- #ifdef IOR
77
- uniform float ior;
78
- #endif
79
- #ifdef SPECULAR
80
- uniform float specularIntensity;
81
- uniform vec3 specularColor;
82
- #ifdef USE_SPECULARINTENSITYMAP
83
- uniform sampler2D specularIntensityMap;
84
- #endif
85
- #ifdef USE_SPECULARCOLORMAP
86
- uniform sampler2D specularColorMap;
87
- #endif
88
- #endif
89
- #ifdef USE_CLEARCOAT
90
- uniform float clearcoat;
91
- uniform float clearcoatRoughness;
92
- #endif
93
- #ifdef USE_IRIDESCENCE
94
- uniform float iridescence;
95
- uniform float iridescenceIOR;
96
- uniform float iridescenceThicknessMinimum;
97
- uniform float iridescenceThicknessMaximum;
98
- #endif
99
- #ifdef USE_SHEEN
100
- uniform vec3 sheenColor;
101
- uniform float sheenRoughness;
102
- #ifdef USE_SHEENCOLORMAP
103
- uniform sampler2D sheenColorMap;
104
- #endif
105
- #ifdef USE_SHEENROUGHNESSMAP
106
- uniform sampler2D sheenRoughnessMap;
107
- #endif
108
- #endif
109
- varying vec3 vViewPosition;
110
- #include <common>
111
- #include <packing>
112
- #include <dithering_pars_fragment>
113
- #include <color_pars_fragment>
114
- #include <uv_pars_fragment>
115
- #include <map_pars_fragment>
116
- #include <alphamap_pars_fragment>
117
- #include <alphatest_pars_fragment>
118
- #include <aomap_pars_fragment>
119
- #include <lightmap_pars_fragment>
120
- #include <emissivemap_pars_fragment>
121
- #include <bsdfs>
122
- #include <iridescence_fragment>
123
- #include <cube_uv_reflection_fragment>
124
- #include <envmap_common_pars_fragment>
125
- #include <envmap_physical_pars_fragment>
126
- #include <fog_pars_fragment>
127
- #include <lights_pars_begin>
128
- #include <normal_pars_fragment>
129
- #include <lights_physical_pars_fragment>
130
- #include <transmission_pars_fragment>
131
- #include <shadowmap_pars_fragment>
132
- #include <bumpmap_pars_fragment>
133
- #include <normalmap_pars_fragment>
134
- #include <clearcoat_pars_fragment>
135
- #include <iridescence_pars_fragment>
136
- #include <roughnessmap_pars_fragment>
137
- #include <metalnessmap_pars_fragment>
138
- #include <logdepthbuf_pars_fragment>
139
- #include <clipping_planes_pars_fragment>
140
-
141
-
142
-
143
- // CUSTOM START
144
-
145
- varying vec4 initialPosition;
146
- varying vec3 initialNormal;
147
-
148
- varying vec3 frag_position;
149
- varying vec3 frag_normal;
150
-
151
- uniform vec3 center;
152
- uniform float radius;
153
- uniform samplerCube sphericalNormalMap;
154
- uniform mat3 normalMatrix;
155
- uniform mat4 modelMatrix;
156
-
157
- uniform float impurityScale;
158
- uniform vec3 colorTransferBegin;
159
- uniform vec3 colorTransferEnd;
160
- uniform float refractionIndex;
161
- uniform float gamma;
162
- uniform float contrast;
163
- uniform float brightness;
164
- uniform float dispersion;
165
- uniform float tracingOpacity;
166
-
167
-
168
- vec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
169
- #if defined( ENVMAP_TYPE_CUBE_UV )
170
- vec3 reflectVec = reflect( - viewDir, normal );
171
- // 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) );
173
- reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
174
- vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
175
- return min(envMapColor.rgb * envMapIntensity, vec3(1.0));
176
- #else
177
- return vec3( 0.0 );
178
- #endif
179
- }
180
-
181
- vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {
182
-
183
- vec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;
184
-
185
- mat3 normalMatrix;
186
- normalMatrix[0] = normalize(modelMatrix[0].xyz);
187
- normalMatrix[1] = normalize(modelMatrix[1].xyz);
188
- normalMatrix[2] = normalize(modelMatrix[2].xyz);
189
-
190
- // Calculate the normal vector in world space
191
- vec3 currentGeometryNormal = normalize(normalMatrix * normal);
192
-
193
- // Calculate the view direction vector in world space
194
- vec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);
195
-
196
- vec3 currentGeometryClearcoatNormal;
197
-
198
- #ifdef USE_CLEARCOAT
199
- currentGeometryClearcoatNormal = clearcoatNormal;
200
- #endif
201
-
202
- ReflectedLight rLight;
203
- IncidentLight dLight;
204
-
205
- float temp = material.roughness;
206
- material.roughness = 0.5;
207
-
208
- #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
209
-
210
- PointLight pointLight;
211
- #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
212
- PointLightShadow pointLightShadow;
213
- #endif
214
-
215
- #pragma unroll_loop_start
216
- for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
217
- pointLight = pointLights[ i ];
218
- getPointLightInfo( pointLight, currentGeometryPosition, dLight );
219
- #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
220
- 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;
222
- #endif
223
- RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
224
- }
225
- #pragma unroll_loop_end
226
- #endif
227
- #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
228
- SpotLight spotLight;
229
- #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
230
- SpotLightShadow spotLightShadow;
231
- #endif
232
- #pragma unroll_loop_start
233
- for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
234
- spotLight = spotLights[ i ];
235
- getSpotLightInfo( spotLight, currentGeometryPosition, dLight );
236
- #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
237
- spotLightShadow = spotLightShadows[ i ];
238
- dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
239
- #endif
240
- RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
241
- }
242
- #pragma unroll_loop_end
243
- #endif
244
-
245
- #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
246
- DirectionalLight directionalLight;
247
- #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
248
- DirectionalLightShadow directionalLightShadow;
249
- #endif
250
- #pragma unroll_loop_start
251
- for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
252
- directionalLight = directionalLights[ i ];
253
- getDirectionalLightInfo( directionalLight, dLight );
254
- #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
255
- directionalLightShadow = directionalLightShadows[ i ];
256
- dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
257
- #endif
258
- RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
259
- }
260
- #pragma unroll_loop_end
261
- #endif
262
- material.roughness = temp;
263
-
264
- #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
265
- RectAreaLight rectAreaLight;
266
- #pragma unroll_loop_start
267
- for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
268
- rectAreaLight = rectAreaLights[ i ];
269
- RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
270
- }
271
- #pragma unroll_loop_end
272
- #endif
273
- #if defined( RE_IndirectDiffuse )
274
- vec3 iblIrradiance = vec3( 0.0 );
275
- vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
276
-
277
- #if defined( USE_LIGHT_PROBES )
278
- irradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );
279
- #endif
280
- #if ( NUM_HEMI_LIGHTS > 0 )
281
- #pragma unroll_loop_start
282
- for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
283
- irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );
284
- }
285
- #pragma unroll_loop_end
286
- #endif
287
- #endif
288
- #if defined( RE_IndirectSpecular )
289
- vec3 radiance = vec3( 0.0 );
290
- vec3 clearcoatRadiance = vec3( 0.0 );
291
- #endif
292
-
293
-
294
- #if defined( RE_IndirectDiffuse )
295
- #ifdef USE_LIGHTMAP
296
- vec4 lightMapTexel = texture2D( lightMap, vUv2 );
297
- vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
298
- irradiance += lightMapIrradiance;
299
- #endif
300
- #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
301
- iblIrradiance += getIBLIrradiance( currentGeometryNormal );
302
- #endif
303
- #endif
304
- #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
305
- radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );
306
- #ifdef USE_CLEARCOAT
307
- clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );
308
- #endif
309
- #endif
310
-
311
- #if defined( RE_IndirectDiffuse )
312
- RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
313
- #endif
314
- #if defined( RE_IndirectSpecular )
315
- RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
316
- #endif
317
-
318
- if(depth >= 0) {
319
- float frac = float(depth) / float(TRACING_DEPTH);
320
- vec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;
321
- rLight.indirectSpecular *= colorTransfer;
322
- rLight.directSpecular *= colorTransfer;
323
- }
324
-
325
- vec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;
326
-
327
- // gamma
328
- color = pow(color, vec3(1.0/gamma));
329
-
330
- // contrast
331
- color.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5;
332
-
333
- // brightness
334
- color.r = min(max(color.r + brightness, 0.0), 1.0);
335
- color.g = min(max(color.g + brightness, 0.0), 1.0);
336
- color.b = min(max(color.b + brightness, 0.0), 1.0);
337
-
338
- return color;
339
- }
340
-
341
- vec3 normalLookUp(vec3 dir) {
342
- vec4 s = textureCube(sphericalNormalMap, dir);
343
- if(s.a < 1.0/256.0) {
344
- return normalize(vec3(-s.x, -s.y, -s.z));
345
- } else if(s.a < 3.0/256.0) {
346
- return normalize(vec3(-s.x, -s.y, s.z));
347
- } else if(s.a < 5.0/256.0) {
348
- return normalize(vec3(-s.x, s.y, -s.z));
349
- } else if(s.a < 7.0/256.0) {
350
- return normalize(vec3(s.x, -s.y, -s.z));
351
- } else if(s.a < 9.0/256.0) {
352
- return normalize(vec3(-s.x, s.y, s.z));
353
- } else if(s.a < 11.0/256.0) {
354
- return normalize(vec3(s.x, -s.y, s.z));
355
- } else if(s.a < 13.0/256.0) {
356
- return normalize(vec3(s.x, s.y, -s.z));
357
- } else {
358
- return normalize(s.xyz);
359
- }
360
- }
361
-
362
- #ifdef USE_IMPURITYMAP
363
- float impurityLookUp(vec3 dir) {
364
- vec3 c = textureCube(impurityMap, dir.xy).rgb;
365
- return (c.x + c.y + c.z) / 3.0;
366
- }
367
- #endif
368
-
369
- vec3 raySphereIntersection(vec3 o, vec3 d) {
370
-
371
- vec3 oc = o - center;
372
- float a = dot(d, d);
373
- float b = 2.0 * dot(oc, d);
374
- float c = dot(oc,oc) - radius*radius;
375
- float discriminant = b*b - 4.0*a*c;
376
- if(discriminant < 0.0){
377
- return vec3(0.0);
378
- }
379
- else{
380
- return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;
381
- }
382
- }
383
-
384
- vec3 hueToSaturatedColor(float hue) {
385
- float r,g,b;
386
- if (hue < 0.25){
387
- float t = 1.0 - (hue / 0.25);
388
- r = 1.0;
389
- g = 1.0;
390
- b = t;
391
- } else if (hue < 0.5){
392
- float t = 1.0 - (hue - 0.25 / 0.25);
393
- r = 1.0;
394
- g = t;
395
- b = 0.0;
396
- } else if (hue < 0.75){
397
- float t = 1.0 - (hue - 0.5 / 0.25);
398
- r = t;
399
- g = 0.0;
400
- b = 1.0 - t;
401
- } else {
402
- float t = hue - 0.75 / 0.25;
403
- r = t;
404
- g = t;
405
- b = 1.0;
406
- }
407
- return vec3(r, g, b) / 0.5 + 0.5;
408
- }
409
- // CUSTOM END
410
-
411
- void main() {
412
- // CUSTOM START
413
- vec3 frag_normal_normalized = frag_normal;
414
- // CUSTOM END
415
- #include <clipping_planes_fragment>
416
- vec4 diffuseColor = vec4( diffuse, opacity );
417
- ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
418
- vec3 totalEmissiveRadiance = emissive;
419
- #include <logdepthbuf_fragment>
420
- #include <map_fragment>
421
- #include <color_fragment>
422
- #include <alphamap_fragment>
423
- #include <alphatest_fragment>
424
- #include <roughnessmap_fragment>
425
- #include <metalnessmap_fragment>
426
- #include <normal_fragment_begin>
427
- #include <normal_fragment_maps>
428
- #include <clearcoat_normal_fragment_begin>
429
- #include <clearcoat_normal_fragment_maps>
430
- #include <emissivemap_fragment>
431
- #include <lights_physical_fragment>
432
- #include <lights_fragment_begin>
433
- #include <lights_fragment_maps>
434
- #include <lights_fragment_end>
435
- #include <aomap_fragment>
436
- vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
437
- vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
438
- #include <transmission_fragment>
439
- vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
440
- #ifdef USE_SHEEN
441
- float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
442
- outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;
443
- #endif
444
- #ifdef USE_CLEARCOAT
445
- float dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );
446
- vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
447
- outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;
448
- #endif
449
- #include <opaque_fragment>
450
-
451
- // CUSTOM START
452
-
453
- // Extract the translation part of the model matrix
454
- vec3 translation = modelMatrix[3].xyz;
455
-
456
- // Extract the rotation part of the model matrix (3x3 upper-left submatrix)
457
- mat3 rotationMatrix = mat3(modelMatrix);
458
-
459
- // Calculate the inverse of the rotation matrix (transpose since it's orthogonal)
460
- mat3 inverseRotationMatrix;
461
- inverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);
462
- inverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);
463
- inverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);
464
-
465
- // Calculate the camera position in model space
466
- vec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);
467
-
468
- // Calculate the initial direction
469
- vec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);
470
-
471
- vec4 outgoingLight2;
472
- float r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);
473
- r_0 = r_0*r_0;
474
-
475
- float cos_theta_0 = -dot(initialDirection, frag_normal_normalized);
476
- float r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);
477
- r_0_outside = r_0_outside*r_0_outside;
478
- float initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);
479
-
480
- outgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);
481
- // gl_FragColor = outgoingLight2;
482
- // return;
483
- if(TRACING_DEPTH > 0)
484
- outgoingLight2 *= initialProbability;
485
-
486
- vec3 tempColor;
487
-
488
- #ifdef DISPERSION
489
- const int loop = 3;
490
- vec3 dispersionColor;
491
- #else
492
- const int loop = 1;
493
- #endif
494
- #pragma unroll_loop_start
495
- for(int j = 0; j < loop; j++){
496
- vec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);
497
- vec3 newPosition = raySphereIntersection(frag_position, refractedDirection);
498
- vec3 lookUpVector = normalize(newPosition - center);
499
- vec3 newNormal = normalLookUp(lookUpVector);
500
- vec3 newDirection = reflect(refractedDirection, newNormal);
501
-
502
- float currentProbability = 1.0;
503
-
504
- #ifdef USE_IMPURITYMAP
505
- float impurityProbability = impurityLookUp(lookUpVector);
506
- currentProbability -= impurityProbability * impurityScale;
507
- // gl_FragColor = vec4(vec3(impurityProbability), 1.0);
508
- // return;
509
- #endif
510
-
511
- // if(0 == TRACING_DEPTH) {
512
- // gl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);
513
- // return;
514
- // }
515
-
516
- tempColor = vec3(0.0);
517
- #pragma unroll_loop_start
518
- for(int i = 0; i < TRACING_DEPTH; i++) {
519
- // small position correction to avoid artefacts
520
- newPosition = newPosition - lookUpVector * 1e-6;
521
- newPosition = raySphereIntersection(newPosition, newDirection);
522
- lookUpVector = normalize(newPosition - center);
523
- newNormal = normalLookUp(lookUpVector);
524
-
525
- float cos_theta = dot(newDirection, newNormal);
526
- float ratio;
527
- if(cos_theta > 0.0) {
528
- ratio = refractionIndex;
529
- } else {
530
- cos_theta = -cos_theta;
531
- ratio = 1.0 / refractionIndex;
532
- }
533
- float cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);
534
- float probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);
535
- if(cos_theta_2 < 0.0) probability = 0.0;
536
-
537
- vec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);
538
- tempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);
539
- if(i+1 == TRACING_DEPTH)
540
- tempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);
541
-
542
- newDirection = reflect(newDirection, newNormal);
543
-
544
- // if(i+1 == TRACING_DEPTH) {
545
- // gl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);
546
- // return;
547
- // }
548
-
549
- currentProbability *= (1.0 - probability);
550
- }
551
- #pragma unroll_loop_end
552
-
553
- #ifdef DISPERSION
554
- if(j == 0) {
555
- dispersionColor.r = tempColor.r;
556
- } else if(j == 1) {
557
- dispersionColor.g = tempColor.g;
558
- } else if(j == 2) {
559
- dispersionColor.b = tempColor.b;
560
- }
561
- tempColor = dispersionColor;
562
- #endif
563
- }
564
- #pragma unroll_loop_end
565
-
566
- if(TRACING_DEPTH > 0)
567
- outgoingLight2.rgb += (1.0 - initialProbability) * tempColor;
568
-
569
- float alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;
570
- gl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);
571
-
572
- // CUSTOM END
573
-
574
- #include <tonemapping_fragment>
575
- #include <colorspace_fragment>
576
- #include <fog_fragment>
577
- #include <premultiplied_alpha_fragment>
578
- #include <dithering_fragment>
579
- }
580
-
58
+ exports.frag = `
59
+ #define STANDARD
60
+ #ifdef PHYSICAL
61
+ #define IOR
62
+ #define SPECULAR
63
+ #endif
64
+
65
+ // CUSTOM START
66
+ #ifdef USE_IMPURITYMAP
67
+ uniform sampler2D impurityMap;
68
+ #endif
69
+ // CUSTOM END
70
+
71
+ uniform vec3 diffuse;
72
+ uniform vec3 emissive;
73
+ uniform float roughness;
74
+ uniform float metalness;
75
+ uniform float opacity;
76
+ #ifdef IOR
77
+ uniform float ior;
78
+ #endif
79
+ #ifdef SPECULAR
80
+ uniform float specularIntensity;
81
+ uniform vec3 specularColor;
82
+ #ifdef USE_SPECULARINTENSITYMAP
83
+ uniform sampler2D specularIntensityMap;
84
+ #endif
85
+ #ifdef USE_SPECULARCOLORMAP
86
+ uniform sampler2D specularColorMap;
87
+ #endif
88
+ #endif
89
+ #ifdef USE_CLEARCOAT
90
+ uniform float clearcoat;
91
+ uniform float clearcoatRoughness;
92
+ #endif
93
+ #ifdef USE_IRIDESCENCE
94
+ uniform float iridescence;
95
+ uniform float iridescenceIOR;
96
+ uniform float iridescenceThicknessMinimum;
97
+ uniform float iridescenceThicknessMaximum;
98
+ #endif
99
+ #ifdef USE_SHEEN
100
+ uniform vec3 sheenColor;
101
+ uniform float sheenRoughness;
102
+ #ifdef USE_SHEENCOLORMAP
103
+ uniform sampler2D sheenColorMap;
104
+ #endif
105
+ #ifdef USE_SHEENROUGHNESSMAP
106
+ uniform sampler2D sheenRoughnessMap;
107
+ #endif
108
+ #endif
109
+ varying vec3 vViewPosition;
110
+ #include <common>
111
+ #include <packing>
112
+ #include <dithering_pars_fragment>
113
+ #include <color_pars_fragment>
114
+ #include <uv_pars_fragment>
115
+ #include <map_pars_fragment>
116
+ #include <alphamap_pars_fragment>
117
+ #include <alphatest_pars_fragment>
118
+ #include <aomap_pars_fragment>
119
+ #include <lightmap_pars_fragment>
120
+ #include <emissivemap_pars_fragment>
121
+ #include <bsdfs>
122
+ #include <iridescence_fragment>
123
+ #include <cube_uv_reflection_fragment>
124
+ #include <envmap_common_pars_fragment>
125
+ #include <envmap_physical_pars_fragment>
126
+ #include <fog_pars_fragment>
127
+ #include <lights_pars_begin>
128
+ #include <normal_pars_fragment>
129
+ #include <lights_physical_pars_fragment>
130
+ #include <transmission_pars_fragment>
131
+ #include <shadowmap_pars_fragment>
132
+ #include <bumpmap_pars_fragment>
133
+ #include <normalmap_pars_fragment>
134
+ #include <clearcoat_pars_fragment>
135
+ #include <iridescence_pars_fragment>
136
+ #include <roughnessmap_pars_fragment>
137
+ #include <metalnessmap_pars_fragment>
138
+ #include <logdepthbuf_pars_fragment>
139
+ #include <clipping_planes_pars_fragment>
140
+
141
+
142
+
143
+ // CUSTOM START
144
+
145
+ varying vec4 initialPosition;
146
+ varying vec3 initialNormal;
147
+
148
+ varying vec3 frag_position;
149
+ varying vec3 frag_normal;
150
+
151
+ uniform vec3 center;
152
+ uniform float radius;
153
+ uniform samplerCube sphericalNormalMap;
154
+ uniform mat3 normalMatrix;
155
+ uniform mat4 modelMatrix;
156
+
157
+ uniform float impurityScale;
158
+ uniform vec3 colorTransferBegin;
159
+ uniform vec3 colorTransferEnd;
160
+ uniform float refractionIndex;
161
+ uniform float gamma;
162
+ uniform float contrast;
163
+ uniform float brightness;
164
+ uniform float dispersion;
165
+ uniform float tracingOpacity;
166
+
167
+
168
+ vec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
169
+ #if defined( ENVMAP_TYPE_CUBE_UV )
170
+ vec3 reflectVec = reflect( - viewDir, normal );
171
+ // 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) );
173
+ reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
174
+ vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
175
+ return min(envMapColor.rgb * envMapIntensity, vec3(1.0));
176
+ #else
177
+ return vec3( 0.0 );
178
+ #endif
179
+ }
180
+
181
+ vec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {
182
+
183
+ vec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;
184
+
185
+ mat3 normalMatrix;
186
+ normalMatrix[0] = normalize(modelMatrix[0].xyz);
187
+ normalMatrix[1] = normalize(modelMatrix[1].xyz);
188
+ normalMatrix[2] = normalize(modelMatrix[2].xyz);
189
+
190
+ // Calculate the normal vector in world space
191
+ vec3 currentGeometryNormal = normalize(normalMatrix * normal);
192
+
193
+ // Calculate the view direction vector in world space
194
+ vec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);
195
+
196
+ vec3 currentGeometryClearcoatNormal;
197
+
198
+ #ifdef USE_CLEARCOAT
199
+ currentGeometryClearcoatNormal = clearcoatNormal;
200
+ #endif
201
+
202
+ ReflectedLight rLight;
203
+ IncidentLight dLight;
204
+
205
+ float temp = material.roughness;
206
+ material.roughness = 0.5;
207
+
208
+ #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
209
+
210
+ PointLight pointLight;
211
+ #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
212
+ PointLightShadow pointLightShadow;
213
+ #endif
214
+
215
+ #pragma unroll_loop_start
216
+ for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
217
+ pointLight = pointLights[ i ];
218
+ getPointLightInfo( pointLight, currentGeometryPosition, dLight );
219
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
220
+ 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;
222
+ #endif
223
+ RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
224
+ }
225
+ #pragma unroll_loop_end
226
+ #endif
227
+ #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
228
+ SpotLight spotLight;
229
+ #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
230
+ SpotLightShadow spotLightShadow;
231
+ #endif
232
+ #pragma unroll_loop_start
233
+ for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
234
+ spotLight = spotLights[ i ];
235
+ getSpotLightInfo( spotLight, currentGeometryPosition, dLight );
236
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
237
+ spotLightShadow = spotLightShadows[ i ];
238
+ dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
239
+ #endif
240
+ RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
241
+ }
242
+ #pragma unroll_loop_end
243
+ #endif
244
+
245
+ #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
246
+ DirectionalLight directionalLight;
247
+ #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
248
+ DirectionalLightShadow directionalLightShadow;
249
+ #endif
250
+ #pragma unroll_loop_start
251
+ for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
252
+ directionalLight = directionalLights[ i ];
253
+ getDirectionalLightInfo( directionalLight, dLight );
254
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
255
+ directionalLightShadow = directionalLightShadows[ i ];
256
+ dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
257
+ #endif
258
+ RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
259
+ }
260
+ #pragma unroll_loop_end
261
+ #endif
262
+ material.roughness = temp;
263
+
264
+ #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
265
+ RectAreaLight rectAreaLight;
266
+ #pragma unroll_loop_start
267
+ for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
268
+ rectAreaLight = rectAreaLights[ i ];
269
+ RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
270
+ }
271
+ #pragma unroll_loop_end
272
+ #endif
273
+ #if defined( RE_IndirectDiffuse )
274
+ vec3 iblIrradiance = vec3( 0.0 );
275
+ vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
276
+
277
+ #if defined( USE_LIGHT_PROBES )
278
+ irradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );
279
+ #endif
280
+ #if ( NUM_HEMI_LIGHTS > 0 )
281
+ #pragma unroll_loop_start
282
+ for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
283
+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );
284
+ }
285
+ #pragma unroll_loop_end
286
+ #endif
287
+ #endif
288
+ #if defined( RE_IndirectSpecular )
289
+ vec3 radiance = vec3( 0.0 );
290
+ vec3 clearcoatRadiance = vec3( 0.0 );
291
+ #endif
292
+
293
+
294
+ #if defined( RE_IndirectDiffuse )
295
+ #ifdef USE_LIGHTMAP
296
+ vec4 lightMapTexel = texture2D( lightMap, vUv2 );
297
+ vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
298
+ irradiance += lightMapIrradiance;
299
+ #endif
300
+ #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
301
+ iblIrradiance += getIBLIrradiance( currentGeometryNormal );
302
+ #endif
303
+ #endif
304
+ #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
305
+ radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );
306
+ #ifdef USE_CLEARCOAT
307
+ clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );
308
+ #endif
309
+ #endif
310
+
311
+ #if defined( RE_IndirectDiffuse )
312
+ RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
313
+ #endif
314
+ #if defined( RE_IndirectSpecular )
315
+ RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );
316
+ #endif
317
+
318
+ if(depth >= 0) {
319
+ float frac = float(depth) / float(TRACING_DEPTH);
320
+ vec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;
321
+ rLight.indirectSpecular *= colorTransfer;
322
+ rLight.directSpecular *= colorTransfer;
323
+ }
324
+
325
+ vec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;
326
+
327
+ // gamma
328
+ color = pow(color, vec3(1.0/gamma));
329
+
330
+ // contrast
331
+ color.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5;
332
+
333
+ // brightness
334
+ color.r = min(max(color.r + brightness, 0.0), 1.0);
335
+ color.g = min(max(color.g + brightness, 0.0), 1.0);
336
+ color.b = min(max(color.b + brightness, 0.0), 1.0);
337
+
338
+ return color;
339
+ }
340
+
341
+ vec3 normalLookUp(vec3 dir) {
342
+ vec4 s = textureCube(sphericalNormalMap, dir);
343
+ if(s.a < 1.0/256.0) {
344
+ return normalize(vec3(-s.x, -s.y, -s.z));
345
+ } else if(s.a < 3.0/256.0) {
346
+ return normalize(vec3(-s.x, -s.y, s.z));
347
+ } else if(s.a < 5.0/256.0) {
348
+ return normalize(vec3(-s.x, s.y, -s.z));
349
+ } else if(s.a < 7.0/256.0) {
350
+ return normalize(vec3(s.x, -s.y, -s.z));
351
+ } else if(s.a < 9.0/256.0) {
352
+ return normalize(vec3(-s.x, s.y, s.z));
353
+ } else if(s.a < 11.0/256.0) {
354
+ return normalize(vec3(s.x, -s.y, s.z));
355
+ } else if(s.a < 13.0/256.0) {
356
+ return normalize(vec3(s.x, s.y, -s.z));
357
+ } else {
358
+ return normalize(s.xyz);
359
+ }
360
+ }
361
+
362
+ #ifdef USE_IMPURITYMAP
363
+ float impurityLookUp(vec3 dir) {
364
+ vec3 c = textureCube(impurityMap, dir.xy).rgb;
365
+ return (c.x + c.y + c.z) / 3.0;
366
+ }
367
+ #endif
368
+
369
+ vec3 raySphereIntersection(vec3 o, vec3 d) {
370
+
371
+ vec3 oc = o - center;
372
+ float a = dot(d, d);
373
+ float b = 2.0 * dot(oc, d);
374
+ float c = dot(oc,oc) - radius*radius;
375
+ float discriminant = b*b - 4.0*a*c;
376
+ if(discriminant < 0.0){
377
+ return vec3(0.0);
378
+ }
379
+ else{
380
+ return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;
381
+ }
382
+ }
383
+
384
+ vec3 hueToSaturatedColor(float hue) {
385
+ float r,g,b;
386
+ if (hue < 0.25){
387
+ float t = 1.0 - (hue / 0.25);
388
+ r = 1.0;
389
+ g = 1.0;
390
+ b = t;
391
+ } else if (hue < 0.5){
392
+ float t = 1.0 - (hue - 0.25 / 0.25);
393
+ r = 1.0;
394
+ g = t;
395
+ b = 0.0;
396
+ } else if (hue < 0.75){
397
+ float t = 1.0 - (hue - 0.5 / 0.25);
398
+ r = t;
399
+ g = 0.0;
400
+ b = 1.0 - t;
401
+ } else {
402
+ float t = hue - 0.75 / 0.25;
403
+ r = t;
404
+ g = t;
405
+ b = 1.0;
406
+ }
407
+ return vec3(r, g, b) / 0.5 + 0.5;
408
+ }
409
+ // CUSTOM END
410
+
411
+ void main() {
412
+ // CUSTOM START
413
+ vec3 frag_normal_normalized = frag_normal;
414
+ // CUSTOM END
415
+ #include <clipping_planes_fragment>
416
+ vec4 diffuseColor = vec4( diffuse, opacity );
417
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
418
+ vec3 totalEmissiveRadiance = emissive;
419
+ #include <logdepthbuf_fragment>
420
+ #include <map_fragment>
421
+ #include <color_fragment>
422
+ #include <alphamap_fragment>
423
+ #include <alphatest_fragment>
424
+ #include <roughnessmap_fragment>
425
+ #include <metalnessmap_fragment>
426
+ #include <normal_fragment_begin>
427
+ #include <normal_fragment_maps>
428
+ #include <clearcoat_normal_fragment_begin>
429
+ #include <clearcoat_normal_fragment_maps>
430
+ #include <emissivemap_fragment>
431
+ #include <lights_physical_fragment>
432
+ #include <lights_fragment_begin>
433
+ #include <lights_fragment_maps>
434
+ #include <lights_fragment_end>
435
+ #include <aomap_fragment>
436
+ vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
437
+ vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
438
+ #include <transmission_fragment>
439
+ vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
440
+ #ifdef USE_SHEEN
441
+ float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
442
+ outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;
443
+ #endif
444
+ #ifdef USE_CLEARCOAT
445
+ float dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );
446
+ vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
447
+ outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;
448
+ #endif
449
+ #include <opaque_fragment>
450
+
451
+ // CUSTOM START
452
+
453
+ // Extract the translation part of the model matrix
454
+ vec3 translation = modelMatrix[3].xyz;
455
+
456
+ // Extract the rotation part of the model matrix (3x3 upper-left submatrix)
457
+ mat3 rotationMatrix = mat3(modelMatrix);
458
+
459
+ // Calculate the inverse of the rotation matrix (transpose since it's orthogonal)
460
+ mat3 inverseRotationMatrix;
461
+ inverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);
462
+ inverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);
463
+ inverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);
464
+
465
+ // Calculate the camera position in model space
466
+ vec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);
467
+
468
+ // Calculate the initial direction
469
+ vec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);
470
+
471
+ vec4 outgoingLight2;
472
+ float r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);
473
+ r_0 = r_0*r_0;
474
+
475
+ float cos_theta_0 = -dot(initialDirection, frag_normal_normalized);
476
+ float r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);
477
+ r_0_outside = r_0_outside*r_0_outside;
478
+ float initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);
479
+
480
+ outgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);
481
+ // gl_FragColor = outgoingLight2;
482
+ // return;
483
+ if(TRACING_DEPTH > 0)
484
+ outgoingLight2 *= initialProbability;
485
+
486
+ vec3 tempColor;
487
+
488
+ #ifdef DISPERSION
489
+ const int loop = 3;
490
+ vec3 dispersionColor;
491
+ #else
492
+ const int loop = 1;
493
+ #endif
494
+ #pragma unroll_loop_start
495
+ for(int j = 0; j < loop; j++){
496
+ vec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);
497
+ vec3 newPosition = raySphereIntersection(frag_position, refractedDirection);
498
+ vec3 lookUpVector = normalize(newPosition - center);
499
+ vec3 newNormal = normalLookUp(lookUpVector);
500
+ vec3 newDirection = reflect(refractedDirection, newNormal);
501
+
502
+ float currentProbability = 1.0;
503
+
504
+ #ifdef USE_IMPURITYMAP
505
+ float impurityProbability = impurityLookUp(lookUpVector);
506
+ currentProbability -= impurityProbability * impurityScale;
507
+ // gl_FragColor = vec4(vec3(impurityProbability), 1.0);
508
+ // return;
509
+ #endif
510
+
511
+ // if(0 == TRACING_DEPTH) {
512
+ // gl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);
513
+ // return;
514
+ // }
515
+
516
+ tempColor = vec3(0.0);
517
+ #pragma unroll_loop_start
518
+ for(int i = 0; i < TRACING_DEPTH; i++) {
519
+ // small position correction to avoid artefacts
520
+ newPosition = newPosition - lookUpVector * 1e-6;
521
+ newPosition = raySphereIntersection(newPosition, newDirection);
522
+ lookUpVector = normalize(newPosition - center);
523
+ newNormal = normalLookUp(lookUpVector);
524
+
525
+ float cos_theta = dot(newDirection, newNormal);
526
+ float ratio;
527
+ if(cos_theta > 0.0) {
528
+ ratio = refractionIndex;
529
+ } else {
530
+ cos_theta = -cos_theta;
531
+ ratio = 1.0 / refractionIndex;
532
+ }
533
+ float cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);
534
+ float probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);
535
+ if(cos_theta_2 < 0.0) probability = 0.0;
536
+
537
+ vec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);
538
+ tempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);
539
+ if(i+1 == TRACING_DEPTH)
540
+ tempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);
541
+
542
+ newDirection = reflect(newDirection, newNormal);
543
+
544
+ // if(i+1 == TRACING_DEPTH) {
545
+ // gl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);
546
+ // return;
547
+ // }
548
+
549
+ currentProbability *= (1.0 - probability);
550
+ }
551
+ #pragma unroll_loop_end
552
+
553
+ #ifdef DISPERSION
554
+ if(j == 0) {
555
+ dispersionColor.r = tempColor.r;
556
+ } else if(j == 1) {
557
+ dispersionColor.g = tempColor.g;
558
+ } else if(j == 2) {
559
+ dispersionColor.b = tempColor.b;
560
+ }
561
+ tempColor = dispersionColor;
562
+ #endif
563
+ }
564
+ #pragma unroll_loop_end
565
+
566
+ if(TRACING_DEPTH > 0)
567
+ outgoingLight2.rgb += (1.0 - initialProbability) * tempColor;
568
+
569
+ float alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;
570
+ gl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);
571
+
572
+ // CUSTOM END
573
+
574
+ #include <tonemapping_fragment>
575
+ #include <colorspace_fragment>
576
+ #include <fog_fragment>
577
+ #include <premultiplied_alpha_fragment>
578
+ #include <dithering_fragment>
579
+ }
580
+
581
581
  `;
582
582
  //# sourceMappingURL=gem.js.map