@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.3.3 → 3.3.6

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