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