@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.19.2 → 3.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/RenderingEngine.d.ts +5 -2
  2. package/dist/RenderingEngine.d.ts.map +1 -1
  3. package/dist/RenderingEngine.js +34 -15
  4. package/dist/RenderingEngine.js.map +1 -1
  5. package/dist/index.d.ts +2 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/interfaces/IRenderingEngine.d.ts +2 -1
  10. package/dist/interfaces/IRenderingEngine.d.ts.map +1 -1
  11. package/dist/loaders/EnvironmentMapLoader.d.ts.map +1 -1
  12. package/dist/loaders/EnvironmentMapLoader.js.map +1 -1
  13. package/dist/loaders/GeometryLoader.d.ts +7 -0
  14. package/dist/loaders/GeometryLoader.d.ts.map +1 -1
  15. package/dist/loaders/GeometryLoader.js +27 -6
  16. package/dist/loaders/GeometryLoader.js.map +1 -1
  17. package/dist/loaders/LightLoader.d.ts +1 -1
  18. package/dist/loaders/MaterialLoader.d.ts +5 -2
  19. package/dist/loaders/MaterialLoader.d.ts.map +1 -1
  20. package/dist/loaders/MaterialLoader.js +78 -8
  21. package/dist/loaders/MaterialLoader.js.map +1 -1
  22. package/dist/managers/RenderingManager.d.ts +5 -0
  23. package/dist/managers/RenderingManager.d.ts.map +1 -1
  24. package/dist/managers/RenderingManager.js +120 -11
  25. package/dist/managers/RenderingManager.js.map +1 -1
  26. package/dist/managers/SceneTreeManager.d.ts +1 -1
  27. package/dist/managers/SceneTreeManager.d.ts.map +1 -1
  28. package/dist/managers/SceneTreeManager.js +1 -0
  29. package/dist/managers/SceneTreeManager.js.map +1 -1
  30. package/dist/managers/postprocessing/ao/ao/AOPass.d.ts +2 -2
  31. package/dist/managers/postprocessing/ao/ao/AOPass.d.ts.map +1 -1
  32. package/dist/managers/postprocessing/ao/ao/AOPass.js +7 -4
  33. package/dist/managers/postprocessing/ao/ao/AOPass.js.map +1 -1
  34. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.d.ts +1 -1
  35. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.d.ts.map +1 -1
  36. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js +2 -1
  37. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js.map +1 -1
  38. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.d.ts +2 -2
  39. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.d.ts.map +1 -1
  40. package/dist/managers/postprocessing/utils/FullScreenQuad.d.ts +2 -2
  41. package/dist/managers/postprocessing/utils/FullScreenQuad.d.ts.map +1 -1
  42. package/dist/managers/postprocessing/utils/NormalPass.d.ts +2 -2
  43. package/dist/managers/postprocessing/utils/NormalPass.d.ts.map +1 -1
  44. package/dist/materials/SpecularGlossinessMaterial.d.ts.map +1 -1
  45. package/dist/materials/SpecularGlossinessMaterial.js +12 -3
  46. package/dist/materials/SpecularGlossinessMaterial.js.map +1 -1
  47. package/dist/shaders/PCSS.d.ts +2 -2
  48. package/dist/shaders/PCSS.d.ts.map +1 -1
  49. package/dist/shaders/PCSS.js +108 -87
  50. package/dist/shaders/PCSS.js.map +1 -1
  51. package/dist/shaders/gem.d.ts +2 -2
  52. package/dist/shaders/gem.d.ts.map +1 -1
  53. package/dist/shaders/gem.js +24 -20
  54. package/dist/shaders/gem.js.map +1 -1
  55. package/package.json +20 -20
@@ -1 +1 @@
1
- {"version":3,"file":"ToneMappingEffect.d.ts","sourceRoot":"","sources":["../../../../../src/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,aAAa,EACb,MAAM,EAEN,aAAa,EACb,eAAe,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAIN,aAAa,E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H,IAAW,IAAI,WAEd;IAED,IAAW,IAAI,CAAC,KAAK,QAAA,EA4DpB;IAED;;;;OAIG;IAEH,IAAW,UAAU,WAEpB;IAED,IAAW,UAAU,CAAC,KAAK,QAAA,EAO1B;IAED;;;;;;OAMG;IAEH,IAAW,UAAU,QAEpB;IAED,IAAW,UAAU,CAAC,KAAK,KAAA,EAE1B;IAED;;;;;OAKG;IAEI,4BAA4B;IAInC;;;;;OAKG;IAEI,OAAO;IAId;;;;;OAKG;IAEI,aAAa;IAIpB;;;;;;OAMG;IAEI,UAAU,CAChB,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,MAAM;IAKxB;;;;;OAKG;IAEI,OAAO,CAAC,KAAK,EAAE,eAAe;IAIrC;;;;;OAKG;IAEI,aAAa,CAAC,KAAK,EAAE,MAAM;IAIlC;;;;;;OAMG;IAEI,MAAM,CACZ,QAAQ,EAAE,aAAa,EACvB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,MAAM;CAOlB"}
1
+ {"version":3,"file":"ToneMappingEffect.d.ts","sourceRoot":"","sources":["../../../../../src/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,aAAa,EACb,MAAM,EAEN,aAAa,EACb,eAAe,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAIN,aAAa,EACb,iBAAiB,EACjB,MAAM,OAAO,CAAC;AAGf;;;;;;;;GAQG;AAEH,qBAAa,iBAAkB,SAAQ,MAAM;IAC5C,qBAAqB,EAAE,qBAAqB,CAAC;IACtC,aAAa,EAAE,aAAa,CAAC;IAC7B,qBAAqB,EAAE,iBAAiB,CAAC;IAEhD;;;;;;;;;;;;;;;;OAgBG;gBACS,EACX,aAAiC,EACjC,QAAgB,EAChB,IAEsB,EACtB,UAAgB,EAChB,YAAkB,EAClB,UAAyB,EACzB,UAAgB,EAChB,YAAmB,EACnB,gBAAsB,EAC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QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,MAAM;IAKxB;;;;;OAKG;IAEI,OAAO,CAAC,KAAK,EAAE,eAAe;IAIrC;;;;;OAKG;IAEI,aAAa,CAAC,KAAK,EAAE,MAAM;IAIlC;;;;;;OAMG;IAEI,MAAM,CACZ,QAAQ,EAAE,aAAa,EACvB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,MAAM;CAOlB"}
@@ -4,7 +4,7 @@ export declare class FullScreenQuad {
4
4
  constructor(material: Material);
5
5
  dispose(): void;
6
6
  render(renderer: WebGLRenderer): void;
7
- get material(): Material | Material[];
8
- set material(value: Material | Material[]);
7
+ get material(): Material<import("three").MaterialEventMap> | Material<import("three").MaterialEventMap>[];
8
+ set material(value: Material<import("three").MaterialEventMap> | Material<import("three").MaterialEventMap>[]);
9
9
  }
10
10
  //# sourceMappingURL=FullScreenQuad.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FullScreenQuad.d.ts","sourceRoot":"","sources":["../../../../src/managers/postprocessing/utils/FullScreenQuad.ts"],"names":[],"mappings":"AAEA,OAAO,EAGN,QAAQ,EACR,IAAI,EAEJ,aAAa,EACb,MAAM,OAAO,CAAC;AAaf,qBAAa,cAAc;IAC1B,KAAK,EAAE,IAAI,CAAC;gBAEA,QAAQ,EAAE,QAAQ;IAI9B,OAAO;IAIP,MAAM,CAAC,QAAQ,EAAE,aAAa;IAI9B,IAAI,QAAQ,0BAEX;IAED,IAAI,QAAQ,CAAC,KAAK,uBAAA,EAEjB;CACD"}
1
+ {"version":3,"file":"FullScreenQuad.d.ts","sourceRoot":"","sources":["../../../../src/managers/postprocessing/utils/FullScreenQuad.ts"],"names":[],"mappings":"AAEA,OAAO,EAGN,QAAQ,EACR,IAAI,EAEJ,aAAa,EACb,MAAM,OAAO,CAAC;AAaf,qBAAa,cAAc;IAC1B,KAAK,EAAE,IAAI,CAAC;gBAEA,QAAQ,EAAE,QAAQ;IAI9B,OAAO;IAIP,MAAM,CAAC,QAAQ,EAAE,aAAa;IAI9B,IAAI,QAAQ,8FAEX;IAED,IAAI,QAAQ,CAAC,KAAK,2FAAA,EAEjB;CACD"}
@@ -37,8 +37,8 @@ export declare class NormalPass extends Pass {
37
37
  *
38
38
  * @type {Texture}
39
39
  */
40
- get texture(): Texture | undefined;
41
- get depthTexture(): DepthTexture | undefined;
40
+ get texture(): Texture<unknown, import("three").TextureEventMap> | undefined;
41
+ get depthTexture(): DepthTexture | null | undefined;
42
42
  /**
43
43
  * The normal texture.
44
44
  *
@@ -1 +1 @@
1
- {"version":3,"file":"NormalPass.d.ts","sourceRoot":"","sources":["../../../../src/managers/postprocessing/utils/NormalPass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACN,MAAM,EAGN,YAAY,EAGZ,KAAK,EACL,OAAO,EAGP,aAAa,EACb,iBAAiB,EACjB,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAExC;;GAEG;AAEH,qBAAa,UAAW,SAAQ,IAAI;IACnC,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC5C,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,GAAG,CAAC;IAEd;;;;;;;;;;;;OAYG;gBAGF,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,EACC,YAAY,EACZ,eAAqB,EACrB,KAA4B,EAC5B,MAA6B,EAC7B,WAAmB,EACnB,WAAoB,GACpB,GAAE;QACF,YAAY,CAAC,EAAE,iBAAiB,CAAC;QACjC,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAA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Q,oBAAoB;IAG5D,gCAAgC,EAAE,OAAO,CAAC;gBAMrC,MAAM,EAAE,oCAAoC;IAyJjD,IAAI,CAAC,MAAM,EAAE,0BAA0B;CAe9C"}
1
+ {"version":3,"file":"SpecularGlossinessMaterial.d.ts","sourceRoot":"","sources":["../../src/materials/SpecularGlossinessMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAC,oBAAoB,EAAE,8BAA8B,EAAC,MAAM,OAAO,CAAC;AAE3E,MAAM,WAAW,oCAChB,SAAQ,8BAA8B;IAGtC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,aAAa,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IACjD,QAAQ,CAAC,EAAE,KAAK,CAAC,mBAAmB,GAAG,SAAS,CAAC;IACjD,YAAY,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;CAGhD;AAED,qBAAa,0BAA2B,SAAQ,oBAAoB;IAG5D,gCAAgC,EAAE,OAAO,CAAC;gBAMrC,MAAM,EAAE,oCAAoC;IAkKjD,IAAI,CAAC,MAAM,EAAE,0BAA0B;CAe9C"}
@@ -71,13 +71,20 @@ class SpecularGlossinessMaterial extends three_1.MeshStandardMaterial {
71
71
  ].join("\n");
72
72
  const lightPhysicalFragmentChunk = [
73
73
  "PhysicalMaterial material;",
74
- "material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );",
75
- "vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );",
74
+ "material.diffuseColor = diffuseColor.rgb * ( 1.0 - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );",
75
+ "material.diffuseContribution = material.diffuseColor;",
76
+ "material.metalness = 0.0;",
77
+ "vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );",
76
78
  "float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );",
77
79
  "material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.",
78
80
  "material.roughness += geometryRoughness;",
79
81
  "material.roughness = min( material.roughness, 1.0 );",
80
82
  "material.specularColor = specularFactor;",
83
+ "material.specularColorBlended = specularFactor;",
84
+ "material.specularF90 = 1.0;",
85
+ "#ifdef USE_DISPERSION",
86
+ "\tmaterial.dispersion = dispersion;",
87
+ "#endif",
81
88
  ].join("\n");
82
89
  const uniforms = {
83
90
  specular: { value: new THREE.Color().setHex(0xffffff) },
@@ -115,10 +122,12 @@ class SpecularGlossinessMaterial extends three_1.MeshStandardMaterial {
115
122
  set: function (v) {
116
123
  uniforms.specularMap2.value = v;
117
124
  if (v) {
118
- this.defines.USE_SPECULARMAP2 = ""; // USE_UV is set by the renderer for specular maps
125
+ this.defines.USE_SPECULARMAP2 = "";
126
+ this.defines.USE_UV = "";
119
127
  }
120
128
  else {
121
129
  delete this.defines.USE_SPECULARMAP2;
130
+ delete this.defines.USE_UV;
122
131
  }
123
132
  },
124
133
  },
@@ -1 +1 @@
1
- {"version":3,"file":"SpecularGlossinessMaterial.js","sourceRoot":"","sources":["../../src/materials/SpecularGlossinessMaterial.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,iCAA2E;AAc3E,MAAa,0BAA2B,SAAQ,4BAAoB;IAKnE,4BAA4B;IAE5B,2BAA2B;IAE3B,YAAY,MAA4C;QACvD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,gCAAgC,GAAG,IAAI,CAAC;QAE7C,oCAAoC;QACpC,MAAM,6BAA6B,GAAG;YACrC,yBAAyB;YACzB,kCAAkC;YAClC,QAAQ;SACR,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,MAAM,8BAA8B,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6B;IAEtB,IAAI,CAAC,MAAkC;QAC7C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEb,IAAK,CAAC,YAAY,GAAS,MAAO,CAAC,YAAY,CAAC;QAChD,IAAK,CAAC,QAAQ,CAAC,IAAI,CAAO,MAAO,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAK,CAAC,aAAa,GAAS,MAAO,CAAC,aAAa,CAAC;QAClD,IAAK,CAAC,UAAU,GAAS,MAAO,CAAC,UAAU,CAAC;QAClD,OAAa,IAAK,CAAC,SAAS,CAAC;QAC7B,OAAa,IAAK,CAAC,SAAS,CAAC;QAC7B,OAAa,IAAK,CAAC,YAAY,CAAC;QAChC,OAAa,IAAK,CAAC,YAAY,CAAC;QAChC,OAAO,IAAI,CAAC;IACb,CAAC;CAGD;AA1LD,gEA0LC"}
@@ -1,3 +1,3 @@
1
- export declare const main = "\n\nuniform float lightSizeUV;\nuniform float blending;\n\n#ifdef SHADOWMAP_TYPE_PCF\n\n#define NEAR_PLANE 0.1\n#define NUM_SAMPLES 20\n#define NUM_RINGS 11\n\nvec2 poissonDisk[NUM_SAMPLES];\n\nvoid initPoissonSamples( const in vec2 randomSeed ) {\n float ANGLE_STEP = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES);\n float INV_NUM_SAMPLES = 1.0 / float(NUM_SAMPLES);\n\n // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/\n float angle = rand(randomSeed) * PI2;\n float radius = INV_NUM_SAMPLES;\n float radiusStep = radius;\n\n for (int i = 0; i < int(NUM_SAMPLES); i++ ) {\n poissonDisk[i] = vec2(cos(angle), sin(angle)) * pow(radius, 0.75);\n radius += radiusStep;\n angle += ANGLE_STEP;\n }\n}\n\nfloat penumbraSize( const in float zReceiver, const in float zBlocker ) { // Parallel plane estimation\n return (zReceiver - zBlocker) / zBlocker;\n}\n\nfloat findBlocker(sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {\n // This uses similar triangles to compute what\n // area of the shadow map we should search\n float searchRadius = lightSizeUV * (zReceiver - NEAR_PLANE) / zReceiver;\n float blockerDepthSum = 0.0;\n int numBlockers = 0;\n\n for (int i = 0; i < int(NUM_SAMPLES); i++ ) {\n float shadowMapDepth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * searchRadius));\n if (shadowMapDepth < zReceiver) {\n blockerDepthSum += shadowMapDepth;\n numBlockers++;\n }\n }\n\n if (numBlockers == 0) return -1.0;\n\n return blockerDepthSum / float(numBlockers);\n}\n\nfloat PCF_Filter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRadius) {\n float sum = 0.0;\n for (int i = 0; i < int(NUM_SAMPLES); i++ ) {\n float depth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * filterRadius));\n if (zReceiver <= depth) sum += 1.0;\n }\n for (int i = 0; i < int(NUM_SAMPLES); i++ ) {\n float depth = unpackRGBAToDepth(texture2D(shadowMap, uv + -poissonDisk[i].yx * filterRadius));\n if (zReceiver <= depth) sum += 1.0;\n }\n return sum / (2.0 * float(NUM_SAMPLES));\n}\n\nfloat PCSS(sampler2D shadowMap, vec4 coords) {\n vec2 uv = coords.xy;\n float zReceiver = coords.z; // Assumed to be eye-space z in this code\n\n initPoissonSamples(uv);\n // STEP 1: blocker search\n float avgBlockerDepth = findBlocker(shadowMap, uv, zReceiver);\n\n //There are no occluders so early out (this saves filtering)\n if (avgBlockerDepth == -1.0) return 1.0;\n\n // STEP 2: penumbra size\n float penumbraRatio = penumbraSize(zReceiver, avgBlockerDepth);\n float filterRadius = penumbraRatio * lightSizeUV * NEAR_PLANE / zReceiver;\n\n // STEP 3: filtering\n //return avgBlockerDepth;\n return PCF_Filter(shadowMap, uv, zReceiver, filterRadius);\n}\n#endif\n";
2
- export declare const entry = "\n// PCSS implementation\nvec2 texelSize = vec2( 1.0 / 1024.0 ); // Always use 1024 for consistency\nfloat dx = texelSize.x;\nfloat dy = texelSize.y;\nvec2 uv = shadowCoord.xy;\nvec2 f = fract( uv * shadowMapSize + 0.5 );\nuv -= f * texelSize;\nfloat shadow1 = (\n texture2DCompare( shadowMap, uv, shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n f.x ),\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n f.x ),\n f.y )\n) * ( 1.0 / 9.0 );\nfloat shadow2 = PCSS( shadowMap, shadowCoord );\nshadow = shadow1 * (1.0 - blending) + blending * shadow2;\n ";
1
+ export declare const main = "\n\n// PCSS implementation\nuniform float lightSizeUV;\nuniform float blending;\n\n#if defined( SHADOWMAP_TYPE_BASIC )\n\n#define PCSS_NEAR_PLANE 0.1\n#define PCSS_NUM_SAMPLES 20\n#define PCSS_NUM_RINGS 11\n\nvec2 pcssPoissonDisk[PCSS_NUM_SAMPLES];\n\nvoid initPCSSPoissonSamples( const in vec2 randomSeed ) {\n float angleStep = PI2 * float( PCSS_NUM_RINGS ) / float( PCSS_NUM_SAMPLES );\n float invNumSamples = 1.0 / float( PCSS_NUM_SAMPLES );\n\n float angle = rand( randomSeed ) * PI2;\n float radius = invNumSamples;\n float radiusStep = radius;\n\n for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {\n pcssPoissonDisk[ i ] = vec2( cos( angle ), sin( angle ) ) * pow( radius, 0.75 );\n radius += radiusStep;\n angle += angleStep;\n }\n}\n\nfloat getPCSSDepth( sampler2D shadowMap, const in vec2 uv ) {\n float depth = texture2D( shadowMap, uv ).r;\n\n #ifdef USE_REVERSED_DEPTH_BUFFER\n depth = 1.0 - depth;\n #endif\n\n return depth;\n}\n\nfloat getPCSSDepthCompare( sampler2D shadowMap, const in vec2 uv, const in float compare ) {\n return step( compare, getPCSSDepth( shadowMap, uv ) );\n}\n\nfloat findPCSSBlocker( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {\n float searchRadius = lightSizeUV * ( zReceiver - PCSS_NEAR_PLANE ) / max( zReceiver, 0.0001 );\n float blockerDepthSum = 0.0;\n int numBlockers = 0;\n\n for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {\n float shadowMapDepth = getPCSSDepth( shadowMap, uv + pcssPoissonDisk[ i ] * searchRadius );\n if ( shadowMapDepth < zReceiver ) {\n blockerDepthSum += shadowMapDepth;\n numBlockers ++;\n }\n }\n\n if ( numBlockers == 0 ) return -1.0;\n\n return blockerDepthSum / float( numBlockers );\n}\n\nfloat getPCSSFilteredShadow( sampler2D shadowMap, const in vec2 uv, const in float zReceiver, const in float filterRadius ) {\n float shadow = 0.0;\n\n for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {\n shadow += getPCSSDepthCompare( shadowMap, uv + pcssPoissonDisk[ i ] * filterRadius, zReceiver );\n }\n for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {\n shadow += getPCSSDepthCompare( shadowMap, uv - pcssPoissonDisk[ i ].yx * filterRadius, zReceiver );\n }\n\n return shadow / ( 2.0 * float( PCSS_NUM_SAMPLES ) );\n}\n\nfloat getPCSSShadow( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {\n initPCSSPoissonSamples( uv );\n\n float avgBlockerDepth = findPCSSBlocker( shadowMap, uv, zReceiver );\n if ( avgBlockerDepth == -1.0 ) return 1.0;\n\n float penumbraRatio = ( zReceiver - avgBlockerDepth ) / max( avgBlockerDepth, 0.0001 );\n float filterRadius = penumbraRatio * lightSizeUV * PCSS_NEAR_PLANE / max( zReceiver, 0.0001 );\n\n return getPCSSFilteredShadow( shadowMap, uv, zReceiver, filterRadius );\n}\n\n#endif\n";
2
+ export declare const getShadow = "\nfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n float shadow = 1.0;\n\n shadowCoord.xyz /= shadowCoord.w;\n\n #ifdef USE_REVERSED_DEPTH_BUFFER\n shadowCoord.z -= shadowBias;\n #else\n shadowCoord.z += shadowBias;\n #endif\n\n bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n bool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\n if ( frustumTest ) {\n vec2 texelSize = vec2( 1.0 / 1024.0 );\n float dx = texelSize.x;\n float dy = texelSize.y;\n vec2 uv = shadowCoord.xy;\n vec2 f = fract( uv * shadowMapSize + 0.5 );\n uv -= f * texelSize;\n\n float pcfShadow = (\n getPCSSDepthCompare( shadowMap, uv, shadowCoord.z ) +\n getPCSSDepthCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n getPCSSDepthCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n f.x ) +\n mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n f.x ) +\n mix( getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( getPCSSDepthCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n getPCSSDepthCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n f.x ),\n mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n f.x ),\n f.y )\n ) * ( 1.0 / 9.0 );\n\n float pcssShadow = getPCSSShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n shadow = mix( pcfShadow, pcssShadow, blending );\n }\n\n return mix( 1.0, shadow, shadowIntensity );\n}\n";
3
3
  //# sourceMappingURL=PCSS.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PCSS.d.ts","sourceRoot":"","sources":["../../src/shaders/PCSS.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,82FAsFhB,CAAC;AAEF,eAAO,MAAM,KAAK,gyDAmCL,CAAC"}
1
+ {"version":3,"file":"PCSS.d.ts","sourceRoot":"","sources":["../../src/shaders/PCSS.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,61FAuFhB,CAAC;AAEF,eAAO,MAAM,SAAS,yoFAuDrB,CAAC"}
@@ -1,127 +1,148 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.entry = exports.main = void 0;
3
+ exports.getShadow = exports.main = void 0;
4
4
  exports.main = `
5
5
 
6
+ // PCSS implementation
6
7
  uniform float lightSizeUV;
7
8
  uniform float blending;
8
9
 
9
- #ifdef SHADOWMAP_TYPE_PCF
10
+ #if defined( SHADOWMAP_TYPE_BASIC )
10
11
 
11
- #define NEAR_PLANE 0.1
12
- #define NUM_SAMPLES 20
13
- #define NUM_RINGS 11
12
+ #define PCSS_NEAR_PLANE 0.1
13
+ #define PCSS_NUM_SAMPLES 20
14
+ #define PCSS_NUM_RINGS 11
14
15
 
15
- vec2 poissonDisk[NUM_SAMPLES];
16
+ vec2 pcssPoissonDisk[PCSS_NUM_SAMPLES];
16
17
 
17
- void initPoissonSamples( const in vec2 randomSeed ) {
18
- float ANGLE_STEP = PI2 * float(NUM_RINGS) / float(NUM_SAMPLES);
19
- float INV_NUM_SAMPLES = 1.0 / float(NUM_SAMPLES);
18
+ void initPCSSPoissonSamples( const in vec2 randomSeed ) {
19
+ float angleStep = PI2 * float( PCSS_NUM_RINGS ) / float( PCSS_NUM_SAMPLES );
20
+ float invNumSamples = 1.0 / float( PCSS_NUM_SAMPLES );
20
21
 
21
- // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
22
- float angle = rand(randomSeed) * PI2;
23
- float radius = INV_NUM_SAMPLES;
22
+ float angle = rand( randomSeed ) * PI2;
23
+ float radius = invNumSamples;
24
24
  float radiusStep = radius;
25
25
 
26
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
27
- poissonDisk[i] = vec2(cos(angle), sin(angle)) * pow(radius, 0.75);
26
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
27
+ pcssPoissonDisk[ i ] = vec2( cos( angle ), sin( angle ) ) * pow( radius, 0.75 );
28
28
  radius += radiusStep;
29
- angle += ANGLE_STEP;
29
+ angle += angleStep;
30
30
  }
31
31
  }
32
32
 
33
- float penumbraSize( const in float zReceiver, const in float zBlocker ) { // Parallel plane estimation
34
- return (zReceiver - zBlocker) / zBlocker;
33
+ float getPCSSDepth( sampler2D shadowMap, const in vec2 uv ) {
34
+ float depth = texture2D( shadowMap, uv ).r;
35
+
36
+ #ifdef USE_REVERSED_DEPTH_BUFFER
37
+ depth = 1.0 - depth;
38
+ #endif
39
+
40
+ return depth;
35
41
  }
36
42
 
37
- float findBlocker(sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {
38
- // This uses similar triangles to compute what
39
- // area of the shadow map we should search
40
- float searchRadius = lightSizeUV * (zReceiver - NEAR_PLANE) / zReceiver;
43
+ float getPCSSDepthCompare( sampler2D shadowMap, const in vec2 uv, const in float compare ) {
44
+ return step( compare, getPCSSDepth( shadowMap, uv ) );
45
+ }
46
+
47
+ float findPCSSBlocker( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {
48
+ float searchRadius = lightSizeUV * ( zReceiver - PCSS_NEAR_PLANE ) / max( zReceiver, 0.0001 );
41
49
  float blockerDepthSum = 0.0;
42
50
  int numBlockers = 0;
43
51
 
44
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
45
- float shadowMapDepth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * searchRadius));
46
- if (shadowMapDepth < zReceiver) {
52
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
53
+ float shadowMapDepth = getPCSSDepth( shadowMap, uv + pcssPoissonDisk[ i ] * searchRadius );
54
+ if ( shadowMapDepth < zReceiver ) {
47
55
  blockerDepthSum += shadowMapDepth;
48
- numBlockers++;
56
+ numBlockers ++;
49
57
  }
50
58
  }
51
59
 
52
- if (numBlockers == 0) return -1.0;
60
+ if ( numBlockers == 0 ) return -1.0;
53
61
 
54
- return blockerDepthSum / float(numBlockers);
62
+ return blockerDepthSum / float( numBlockers );
55
63
  }
56
64
 
57
- float PCF_Filter(sampler2D shadowMap, vec2 uv, float zReceiver, float filterRadius) {
58
- float sum = 0.0;
59
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
60
- float depth = unpackRGBAToDepth(texture2D(shadowMap, uv + poissonDisk[i] * filterRadius));
61
- if (zReceiver <= depth) sum += 1.0;
65
+ float getPCSSFilteredShadow( sampler2D shadowMap, const in vec2 uv, const in float zReceiver, const in float filterRadius ) {
66
+ float shadow = 0.0;
67
+
68
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
69
+ shadow += getPCSSDepthCompare( shadowMap, uv + pcssPoissonDisk[ i ] * filterRadius, zReceiver );
62
70
  }
63
- for (int i = 0; i < int(NUM_SAMPLES); i++ ) {
64
- float depth = unpackRGBAToDepth(texture2D(shadowMap, uv + -poissonDisk[i].yx * filterRadius));
65
- if (zReceiver <= depth) sum += 1.0;
71
+ for ( int i = 0; i < PCSS_NUM_SAMPLES; i ++ ) {
72
+ shadow += getPCSSDepthCompare( shadowMap, uv - pcssPoissonDisk[ i ].yx * filterRadius, zReceiver );
66
73
  }
67
- return sum / (2.0 * float(NUM_SAMPLES));
68
- }
69
74
 
70
- float PCSS(sampler2D shadowMap, vec4 coords) {
71
- vec2 uv = coords.xy;
72
- float zReceiver = coords.z; // Assumed to be eye-space z in this code
75
+ return shadow / ( 2.0 * float( PCSS_NUM_SAMPLES ) );
76
+ }
73
77
 
74
- initPoissonSamples(uv);
75
- // STEP 1: blocker search
76
- float avgBlockerDepth = findBlocker(shadowMap, uv, zReceiver);
78
+ float getPCSSShadow( sampler2D shadowMap, const in vec2 uv, const in float zReceiver ) {
79
+ initPCSSPoissonSamples( uv );
77
80
 
78
- //There are no occluders so early out (this saves filtering)
79
- if (avgBlockerDepth == -1.0) return 1.0;
81
+ float avgBlockerDepth = findPCSSBlocker( shadowMap, uv, zReceiver );
82
+ if ( avgBlockerDepth == -1.0 ) return 1.0;
80
83
 
81
- // STEP 2: penumbra size
82
- float penumbraRatio = penumbraSize(zReceiver, avgBlockerDepth);
83
- float filterRadius = penumbraRatio * lightSizeUV * NEAR_PLANE / zReceiver;
84
+ float penumbraRatio = ( zReceiver - avgBlockerDepth ) / max( avgBlockerDepth, 0.0001 );
85
+ float filterRadius = penumbraRatio * lightSizeUV * PCSS_NEAR_PLANE / max( zReceiver, 0.0001 );
84
86
 
85
- // STEP 3: filtering
86
- //return avgBlockerDepth;
87
- return PCF_Filter(shadowMap, uv, zReceiver, filterRadius);
87
+ return getPCSSFilteredShadow( shadowMap, uv, zReceiver, filterRadius );
88
88
  }
89
+
89
90
  #endif
90
91
  `;
91
- exports.entry = `
92
- // PCSS implementation
93
- vec2 texelSize = vec2( 1.0 / 1024.0 ); // Always use 1024 for consistency
94
- float dx = texelSize.x;
95
- float dy = texelSize.y;
96
- vec2 uv = shadowCoord.xy;
97
- vec2 f = fract( uv * shadowMapSize + 0.5 );
98
- uv -= f * texelSize;
99
- float shadow1 = (
100
- texture2DCompare( shadowMap, uv, shadowCoord.z ) +
101
- texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
102
- texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
103
- texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
104
- mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
105
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
106
- f.x ) +
107
- mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
108
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
109
- f.x ) +
110
- mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
111
- texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
112
- f.y ) +
113
- mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
114
- texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
115
- f.y ) +
116
- mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
117
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
118
- f.x ),
119
- mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
120
- texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
121
- f.x ),
122
- f.y )
123
- ) * ( 1.0 / 9.0 );
124
- float shadow2 = PCSS( shadowMap, shadowCoord );
125
- shadow = shadow1 * (1.0 - blending) + blending * shadow2;
126
- `;
92
+ exports.getShadow = `
93
+ float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
94
+ float shadow = 1.0;
95
+
96
+ shadowCoord.xyz /= shadowCoord.w;
97
+
98
+ #ifdef USE_REVERSED_DEPTH_BUFFER
99
+ shadowCoord.z -= shadowBias;
100
+ #else
101
+ shadowCoord.z += shadowBias;
102
+ #endif
103
+
104
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
105
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
106
+
107
+ if ( frustumTest ) {
108
+ vec2 texelSize = vec2( 1.0 / 1024.0 );
109
+ float dx = texelSize.x;
110
+ float dy = texelSize.y;
111
+ vec2 uv = shadowCoord.xy;
112
+ vec2 f = fract( uv * shadowMapSize + 0.5 );
113
+ uv -= f * texelSize;
114
+
115
+ float pcfShadow = (
116
+ getPCSSDepthCompare( shadowMap, uv, shadowCoord.z ) +
117
+ getPCSSDepthCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
118
+ getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
119
+ getPCSSDepthCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
120
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
121
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
122
+ f.x ) +
123
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
124
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
125
+ f.x ) +
126
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
127
+ getPCSSDepthCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
128
+ f.y ) +
129
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
130
+ getPCSSDepthCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
131
+ f.y ) +
132
+ mix( mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
133
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
134
+ f.x ),
135
+ mix( getPCSSDepthCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
136
+ getPCSSDepthCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
137
+ f.x ),
138
+ f.y )
139
+ ) * ( 1.0 / 9.0 );
140
+
141
+ float pcssShadow = getPCSSShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
142
+ shadow = mix( pcfShadow, pcssShadow, blending );
143
+ }
144
+
145
+ return mix( 1.0, shadow, shadowIntensity );
146
+ }
147
+ `;
127
148
  //# sourceMappingURL=PCSS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PCSS.js","sourceRoot":"","sources":["../../src/shaders/PCSS.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFnB,CAAC;AAEW,QAAA,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAmCR,CAAC"}
1
+ {"version":3,"file":"PCSS.js","sourceRoot":"","sources":["../../src/shaders/PCSS.ts"],"names":[],"mappings":";;;AAAa,QAAA,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFnB,CAAC;AAEW,QAAA,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDxB,CAAC"}
@@ -1,3 +1,3 @@
1
- export declare const vert = "\n#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\n// CUSTOM START\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n// CUSTOM END\n\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n #ifdef USE_TRANSMISSION\n vWorldPosition = worldPosition.xyz;\n #endif\n\n // CUSTOM START\n frag_position = position;\n frag_normal = objectNormal;\n // CUSTOM END\n}\n";
2
- export declare const frag = "\n#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define SPECULAR\n#endif\n\n// CUSTOM START\n#ifdef USE_IMPURITYMAP\n\tuniform sampler2D impurityMap;\n#endif\n// CUSTOM END\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULARINTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULARCOLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n\n\n// CUSTOM START\n\nvarying vec4 initialPosition;\nvarying vec3 initialNormal;\n\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n\nuniform vec3 center;\nuniform float radius;\nuniform samplerCube sphericalNormalMap;\nuniform mat3 normalMatrix;\nuniform mat4 modelMatrix;\n\nuniform float impurityScale;\nuniform vec3 colorTransferBegin;\nuniform vec3 colorTransferEnd;\nuniform float refractionIndex;\nuniform float gamma;\nuniform float contrast;\nuniform float brightness;\nuniform float dispersion;\nuniform float tracingOpacity;\n\n\nvec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.\n\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\treturn min(envMapColor.rgb * envMapIntensity, vec3(1.0));\n\t#else\n\t\treturn vec3( 0.0 );\n\t#endif\n}\n\nvec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {\n\t\n\tvec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;\n\n\tmat3 normalMatrix;\n\tnormalMatrix[0] = normalize(modelMatrix[0].xyz);\n\tnormalMatrix[1] = normalize(modelMatrix[1].xyz);\n\tnormalMatrix[2] = normalize(modelMatrix[2].xyz);\n\t\n\t// Calculate the normal vector in world space\n\tvec3 currentGeometryNormal = normalize(normalMatrix * normal);\n\t\n\t// Calculate the view direction vector in world space\n\tvec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);\n\n vec3 currentGeometryClearcoatNormal;\n\t\n\t#ifdef USE_CLEARCOAT\n currentGeometryClearcoatNormal = clearcoatNormal;\n #endif\n\n\tReflectedLight rLight;\n\tIncidentLight dLight;\n\n\tfloat temp = material.roughness;\n\tmaterial.roughness = 0.5;\n\n\t#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\t\tPointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n\t #pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\t\tpointLight = pointLights[ i ];\n getPointLightInfo( pointLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\t\t RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n\t\t}\n #pragma unroll_loop_end\n\t#endif\n\t#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n\t#endif\n\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n dLight.color *= all( bvec2( dLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n\tmaterial.roughness = temp;\n\t\n #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t\t\n\t\t#if defined( USE_LIGHT_PROBES )\n \tirradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );\n\t\t#endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );\n }\n #pragma unroll_loop_end\n #endif\n #endif\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n\n #if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vUv2 );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( currentGeometryNormal );\n #endif\n #endif\n #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );\n #endif\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n\n\tif(depth >= 0) {\n\t\tfloat frac = float(depth) / float(TRACING_DEPTH);\n\t\tvec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;\n\t\trLight.indirectSpecular *= colorTransfer;\n\t\trLight.directSpecular *= colorTransfer;\n\t}\n\n\tvec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;\n\n\t// gamma\n\tcolor = pow(color, vec3(1.0/gamma)); \n\n\t// contrast\n\tcolor.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5; \n\n\t// brightness\n\tcolor.r = min(max(color.r + brightness, 0.0), 1.0);\n\tcolor.g = min(max(color.g + brightness, 0.0), 1.0);\n\tcolor.b = min(max(color.b + brightness, 0.0), 1.0);\n\n\treturn color;\n}\n\nvec3 normalLookUp(vec3 dir) {\n\tvec4 s = textureCube(sphericalNormalMap, dir);\n\tif(s.a < 1.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, -s.z));\n\t} else if(s.a < 3.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, s.z));\n\t} else if(s.a < 5.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, -s.z));\n\t} else if(s.a < 7.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, -s.z));\n\t} else if(s.a < 9.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, s.z));\n\t} else if(s.a < 11.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, s.z));\n\t} else if(s.a < 13.0/256.0) {\n\t\treturn normalize(vec3(s.x, s.y, -s.z));\n\t} else {\n\t\treturn normalize(s.xyz);\n\t}\n}\n\n#ifdef USE_IMPURITYMAP\n\tfloat impurityLookUp(vec3 dir) {\n\t\tvec3 c = textureCube(impurityMap, dir.xy).rgb;\n\t\treturn (c.x + c.y + c.z) / 3.0;\n\t}\n#endif\n\nvec3 raySphereIntersection(vec3 o, vec3 d) {\n\n\tvec3 oc = o - center;\n float a = dot(d, d);\n float b = 2.0 * dot(oc, d);\n float c = dot(oc,oc) - radius*radius;\n float discriminant = b*b - 4.0*a*c;\n if(discriminant < 0.0){\n return vec3(0.0);\n }\n else{\n return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;\n }\n}\n\nvec3 hueToSaturatedColor(float hue) {\n float r,g,b;\n if (hue < 0.25){\n\t\tfloat t = 1.0 - (hue / 0.25);\n r = 1.0;\n g = 1.0;\n b = t; \n\t} else if (hue < 0.5){\n \tfloat t = 1.0 - (hue - 0.25 / 0.25);\n\t\tr = 1.0;\n g = t;\n b = 0.0;\n\t} else if (hue < 0.75){\n \tfloat t = 1.0 - (hue - 0.5 / 0.25);\n\t\tr = t;\n g = 0.0;\n b = 1.0 - t;\n } else {\n \tfloat t = hue - 0.75 / 0.25;\n r = t;\n g = t;\n b = 1.0;\n }\n return vec3(r, g, b) / 0.5 + 0.5;\n}\n// CUSTOM END\n\nvoid main() { \n // CUSTOM START\n vec3 frag_normal_normalized = frag_normal;\n // CUSTOM END\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\n // CUSTOM START\n\t\n // Extract the translation part of the model matrix\n\tvec3 translation = modelMatrix[3].xyz;\n\n\t// Extract the rotation part of the model matrix (3x3 upper-left submatrix)\n\tmat3 rotationMatrix = mat3(modelMatrix);\n\n\t// Calculate the inverse of the rotation matrix (transpose since it's orthogonal)\n\tmat3 inverseRotationMatrix;\n\tinverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);\n\tinverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);\n\tinverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);\n\n\t// Calculate the camera position in model space\n\tvec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);\n\n\t// Calculate the initial direction\n\tvec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);\n\n\tvec4 outgoingLight2;\n\tfloat r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);\n\tr_0 = r_0*r_0;\n\n\tfloat cos_theta_0 = -dot(initialDirection, frag_normal_normalized);\n\tfloat r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);\n\tr_0_outside = r_0_outside*r_0_outside;\n\tfloat initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);\n\n\toutgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);\n\t// gl_FragColor = outgoingLight2;\n\t// return;\n\tif(TRACING_DEPTH > 0) \n\t\toutgoingLight2 *= initialProbability;\n\t\t\n\tvec3 tempColor;\n\n\t#ifdef DISPERSION\n\t\tconst int loop = 3;\n\t\tvec3 dispersionColor;\n\t#else\n\t\tconst int loop = 1;\n\t#endif\n\t\t#pragma unroll_loop_start\n\t\tfor(int j = 0; j < loop; j++){\n\t\t\tvec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);\n\t\t\tvec3 newPosition = raySphereIntersection(frag_position, refractedDirection);\n\t\t\tvec3 lookUpVector = normalize(newPosition - center);\n\t\t\tvec3 newNormal = normalLookUp(lookUpVector);\n\t\t\tvec3 newDirection = reflect(refractedDirection, newNormal);\n\n\t\t\tfloat currentProbability = 1.0;\n\n\t\t\t#ifdef USE_IMPURITYMAP\n\t\t\t\tfloat impurityProbability = impurityLookUp(lookUpVector);\n\t\t\t\tcurrentProbability -= impurityProbability * impurityScale;\n\t\t\t\t// gl_FragColor = vec4(vec3(impurityProbability), 1.0);\n\t\t\t\t// return;\n\t\t\t#endif\n\t\t\t\n\t\t\t// if(0 == TRACING_DEPTH) {\n\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t// \treturn;\n\t\t\t// }\n\n\t\t\ttempColor = vec3(0.0);\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor(int i = 0; i < TRACING_DEPTH; i++) {\n\t\t\t\t// small position correction to avoid artefacts\n\t\t\t\tnewPosition = newPosition - lookUpVector * 1e-6;\n\t\t\t\tnewPosition = raySphereIntersection(newPosition, newDirection);\n\t\t\t\tlookUpVector = normalize(newPosition - center);\n\t\t\t\tnewNormal = normalLookUp(lookUpVector);\n\t\t\t\n\t\t\t\tfloat cos_theta = dot(newDirection, newNormal);\n\t\t\t\tfloat ratio;\n\t\t\t\tif(cos_theta > 0.0) {\n\t\t\t\t\tratio = refractionIndex;\n\t\t\t\t} else {\n\t\t\t\t\tcos_theta = -cos_theta;\n\t\t\t\t\tratio = 1.0 / refractionIndex;\n\t\t\t\t}\n\t\t\t\tfloat cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);\n\t\t\t\tfloat probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);\n\t\t\t\tif(cos_theta_2 < 0.0) probability = 0.0;\n\n\t\t\t\tvec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);\n\t\t\t\ttempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);\n\t\t\t\tif(i+1 == TRACING_DEPTH)\n\t\t\t\t\ttempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);\n\n\t\t\t\tnewDirection = reflect(newDirection, newNormal);\n\n\t\t\t\t// if(i+1 == TRACING_DEPTH) {\n\t\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t\t// \treturn;\n\t\t\t\t// }\n\n\t\t\t\tcurrentProbability *= (1.0 - probability);\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\n\t\t\t#ifdef DISPERSION\n\t\t\t\tif(j == 0) {\n\t\t\t\t\tdispersionColor.r = tempColor.r;\t\n\t\t\t\t} else if(j == 1) {\n\t\t\t\t\tdispersionColor.g = tempColor.g;\t\n\t\t\t\t} else if(j == 2) {\n\t\t\t\t\tdispersionColor.b = tempColor.b;\t\n\t\t\t\t}\n\t\t\t\ttempColor = dispersionColor;\n\t\t\t#endif\n\t\t}\t\n\t\t#pragma unroll_loop_end\n\n\tif(TRACING_DEPTH > 0)\n\t\toutgoingLight2.rgb += (1.0 - initialProbability) * tempColor;\n\n\tfloat alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;\n\tgl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);\n\n // CUSTOM END\n\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n\n";
1
+ export declare const vert = "\n#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\n// CUSTOM START\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n// CUSTOM END\n\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n #ifdef USE_TRANSMISSION\n vWorldPosition = worldPosition.xyz;\n #endif\n\n // CUSTOM START\n frag_position = position;\n frag_normal = objectNormal;\n // CUSTOM END\n}\n";
2
+ export declare const frag = "\n#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\n\n// CUSTOM START\n#ifdef USE_IMPURITYMAP\n\tuniform sampler2D impurityMap;\n#endif\n// CUSTOM END\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n\n\n// CUSTOM START\n\nvarying vec4 initialPosition;\nvarying vec3 initialNormal;\n\nvarying vec3 frag_position;\nvarying vec3 frag_normal;\n\nuniform vec3 center;\nuniform float radius;\nuniform samplerCube sphericalNormalMap;\nuniform mat3 normalMatrix;\nuniform mat4 modelMatrix;\n\nuniform float impurityScale;\nuniform vec3 colorTransferBegin;\nuniform vec3 colorTransferEnd;\nuniform float refractionIndex;\nuniform float gamma;\nuniform float contrast;\nuniform float brightness;\nuniform float dispersion;\nuniform float tracingOpacity;\n\n\nvec3 getIBLRadianceVariation( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.\n\t\treflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t#else\n\t\treturn vec3( 0.0 );\n\t#endif\n}\n\nvec3 calculateReflectedLight(vec3 position, vec3 normal, vec3 viewDir, PhysicalMaterial material, int depth) {\n\t\n\tvec3 currentGeometryPosition = (modelMatrix * vec4(position, 1.0)).xyz;\n\n\tmat3 normalMatrix;\n\tnormalMatrix[0] = normalize(modelMatrix[0].xyz);\n\tnormalMatrix[1] = normalize(modelMatrix[1].xyz);\n\tnormalMatrix[2] = normalize(modelMatrix[2].xyz);\n\t\n\t// Calculate the normal vector in world space\n\tvec3 currentGeometryNormal = normalize(normalMatrix * normal);\n\t\n\t// Calculate the view direction vector in world space\n\tvec3 currentGeometryViewDir = normalize(normalMatrix * -viewDir);\n\n vec3 currentGeometryClearcoatNormal = vec3( 0.0 );\n\t\n\t#ifdef USE_CLEARCOAT\n currentGeometryClearcoatNormal = clearcoatNormal;\n #endif\n\n\tReflectedLight rLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tIncidentLight dLight;\n\n\tfloat temp = material.roughness;\n\tmaterial.roughness = 0.5;\n\n\t#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n\t\tPointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n\t #pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\t\tpointLight = pointLights[ i ];\n getPointLightInfo( pointLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n dLight.color *= ( dLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\t\t RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n\t\t}\n #pragma unroll_loop_end\n\t#endif\n\t#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, currentGeometryPosition, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n dLight.color *= ( dLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n\t#endif\n\n #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, dLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n dLight.color *= ( dLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( dLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n\tmaterial.roughness = temp;\n\t\n #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n }\n #pragma unroll_loop_end\n #endif\n #if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t\t\n\t\t#if defined( USE_LIGHT_PROBES )\n \tirradiance += getLightProbeIrradiance( lightProbe, currentGeometryNormal );\n\t\t#endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], currentGeometryNormal );\n }\n #pragma unroll_loop_end\n #endif\n #endif\n #if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n #endif\n\n\n #if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( currentGeometryNormal );\n #endif\n #endif\n #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n radiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryNormal, material.roughness );\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadianceVariation( currentGeometryViewDir, currentGeometryClearcoatNormal, material.clearcoatRoughness );\n #endif\n #endif\n\n #if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n #if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, currentGeometryPosition, currentGeometryNormal, currentGeometryViewDir, currentGeometryClearcoatNormal, material, rLight );\n #endif\n\n\tif(depth >= 0) {\n\t\tfloat frac = float(depth) / float(TRACING_DEPTH);\n\t\tvec3 colorTransfer = (1.0-frac) * colorTransferBegin + frac * colorTransferEnd;\n\t\trLight.indirectSpecular *= colorTransfer;\n\t\trLight.directSpecular *= colorTransfer;\n\t}\n\n\tvec3 color = rLight.indirectSpecular + rLight.directSpecular + rLight.indirectDiffuse + rLight.directDiffuse;\n\n\t// gamma\n\tcolor = pow(color, vec3(1.0/gamma)); \n\n\t// contrast\n\tcolor.rgb = ((color.rgb - 0.5) * max(contrast, 0.0)) + 0.5; \n\n\t// brightness\n\tcolor.r = min(max(color.r + brightness, 0.0), 1.0);\n\tcolor.g = min(max(color.g + brightness, 0.0), 1.0);\n\tcolor.b = min(max(color.b + brightness, 0.0), 1.0);\n\n\treturn color;\n}\n\nvec3 normalLookUp(vec3 dir) {\n\tvec4 s = textureCube(sphericalNormalMap, dir);\n\tif(s.a < 1.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, -s.z));\n\t} else if(s.a < 3.0/256.0) {\n\t\treturn normalize(vec3(-s.x, -s.y, s.z));\n\t} else if(s.a < 5.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, -s.z));\n\t} else if(s.a < 7.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, -s.z));\n\t} else if(s.a < 9.0/256.0) {\n\t\treturn normalize(vec3(-s.x, s.y, s.z));\n\t} else if(s.a < 11.0/256.0) {\n\t\treturn normalize(vec3(s.x, -s.y, s.z));\n\t} else if(s.a < 13.0/256.0) {\n\t\treturn normalize(vec3(s.x, s.y, -s.z));\n\t} else {\n\t\treturn normalize(s.xyz);\n\t}\n}\n\n#ifdef USE_IMPURITYMAP\n\tfloat impurityLookUp(vec3 dir) {\n\t\tvec3 c = texture2D(impurityMap, dir.xy * 0.5 + 0.5).rgb;\n\t\treturn (c.x + c.y + c.z) / 3.0;\n\t}\n#endif\n\nvec3 raySphereIntersection(vec3 o, vec3 d) {\n\n\tvec3 oc = o - center;\n float a = dot(d, d);\n float b = 2.0 * dot(oc, d);\n float c = dot(oc,oc) - radius*radius;\n float discriminant = b*b - 4.0*a*c;\n if(discriminant < 0.0){\n return vec3(0.0);\n }\n else{\n return o +( (-b + sqrt(discriminant)) / (2.0*a)) * d;\n }\n}\n\nvec3 hueToSaturatedColor(float hue) {\n float r,g,b;\n if (hue < 0.25){\n\t\tfloat t = 1.0 - (hue / 0.25);\n r = 1.0;\n g = 1.0;\n b = t; \n\t} else if (hue < 0.5){\n \tfloat t = 1.0 - (hue - 0.25 / 0.25);\n\t\tr = 1.0;\n g = t;\n b = 0.0;\n\t} else if (hue < 0.75){\n \tfloat t = 1.0 - (hue - 0.5 / 0.25);\n\t\tr = t;\n g = 0.0;\n b = 1.0 - t;\n } else {\n \tfloat t = hue - 0.75 / 0.25;\n r = t;\n g = t;\n b = 1.0;\n }\n return vec3(r, g, b) / 0.5 + 0.5;\n}\n// CUSTOM END\n\nvoid main() { \n // CUSTOM START\n vec3 frag_normal_normalized = frag_normal;\n // CUSTOM END\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\toutgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\n // CUSTOM START\n\t\n // Extract the translation part of the model matrix\n\tvec3 translation = modelMatrix[3].xyz;\n\n\t// Extract the rotation part of the model matrix (3x3 upper-left submatrix)\n\tmat3 rotationMatrix = mat3(modelMatrix);\n\n\t// Calculate the inverse of the rotation matrix (transpose since it's orthogonal)\n\tmat3 inverseRotationMatrix;\n\tinverseRotationMatrix[0] = vec3(rotationMatrix[0].x, rotationMatrix[1].x, rotationMatrix[2].x);\n\tinverseRotationMatrix[1] = vec3(rotationMatrix[0].y, rotationMatrix[1].y, rotationMatrix[2].y);\n\tinverseRotationMatrix[2] = vec3(rotationMatrix[0].z, rotationMatrix[1].z, rotationMatrix[2].z);\n\n\t// Calculate the camera position in model space\n\tvec3 cameraPositionInModelSpace = inverseRotationMatrix * (cameraPosition - translation);\n\n\t// Calculate the initial direction\n\tvec3 initialDirection = normalize(frag_position.xyz - cameraPositionInModelSpace);\n\n\tvec4 outgoingLight2;\n\tfloat r_0 = (1.0-refractionIndex)/(1.0+refractionIndex);\n\tr_0 = r_0*r_0;\n\n\tfloat cos_theta_0 = -dot(initialDirection, frag_normal_normalized);\n\tfloat r_0_outside = (refractionIndex-1.0)/(refractionIndex+1.0);\n\tr_0_outside = r_0_outside*r_0_outside;\n\tfloat initialProbability = r_0_outside + (1.0 - r_0_outside)*pow(1.0 - cos_theta_0, 5.0);\n\n\toutgoingLight2 = vec4(calculateReflectedLight(frag_position, frag_normal_normalized, initialDirection, material, -1), 1.0);\n\t// gl_FragColor = outgoingLight2;\n\t// return;\n\tif(TRACING_DEPTH > 0) \n\t\toutgoingLight2 *= initialProbability;\n\t\t\n\tvec3 tempColor;\n\n\t#ifdef DISPERSION\n\t\tconst int loop = 3;\n\t\tvec3 dispersionColor;\n\t#else\n\t\tconst int loop = 1;\n\t#endif\n\t\t#pragma unroll_loop_start\n\t\tfor(int j = 0; j < loop; j++){\n\t\t\tvec3 refractedDirection = refract(initialDirection, frag_normal_normalized, 1.0/refractionIndex + float(j)*dispersion * 0.025);\n\t\t\tvec3 newPosition = raySphereIntersection(frag_position, refractedDirection);\n\t\t\tvec3 lookUpVector = normalize(newPosition - center);\n\t\t\tvec3 newNormal = normalLookUp(lookUpVector);\n\t\t\tvec3 newDirection = reflect(refractedDirection, newNormal);\n\n\t\t\tfloat currentProbability = 1.0;\n\n\t\t\t#ifdef USE_IMPURITYMAP\n\t\t\t\tfloat impurityProbability = impurityLookUp(lookUpVector);\n\t\t\t\tcurrentProbability -= impurityProbability * impurityScale;\n\t\t\t\t// gl_FragColor = vec4(vec3(impurityProbability), 1.0);\n\t\t\t\t// return;\n\t\t\t#endif\n\t\t\t\n\t\t\t// if(0 == TRACING_DEPTH) {\n\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t// \treturn;\n\t\t\t// }\n\n\t\t\ttempColor = vec3(0.0);\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor(int i = 0; i < TRACING_DEPTH; i++) {\n\t\t\t\t// small position correction to avoid artefacts\n\t\t\t\tnewPosition = newPosition - lookUpVector * 1e-6;\n\t\t\t\tnewPosition = raySphereIntersection(newPosition, newDirection);\n\t\t\t\tlookUpVector = normalize(newPosition - center);\n\t\t\t\tnewNormal = normalLookUp(lookUpVector);\n\t\t\t\n\t\t\t\tfloat cos_theta = dot(newDirection, newNormal);\n\t\t\t\tfloat ratio;\n\t\t\t\tif(cos_theta > 0.0) {\n\t\t\t\t\tratio = refractionIndex;\n\t\t\t\t} else {\n\t\t\t\t\tcos_theta = -cos_theta;\n\t\t\t\t\tratio = 1.0 / refractionIndex;\n\t\t\t\t}\n\t\t\t\tfloat cos_theta_2 = 1.0 - ratio*ratio * (1.0 - cos_theta*cos_theta);\n\t\t\t\tfloat probability = r_0 + (1.0 - r_0)*pow(1.0 - cos_theta, 5.0);\n\t\t\t\tif(cos_theta_2 < 0.0) probability = 0.0;\n\n\t\t\t\tvec3 refracted = refract(newDirection, newNormal*-1.0, 1.0/refractionIndex);\n\t\t\t\ttempColor += probability * currentProbability * calculateReflectedLight(newPosition, newNormal*-1.0, reflect(refracted, newNormal), material, i);\n\t\t\t\tif(i+1 == TRACING_DEPTH)\n\t\t\t\t\ttempColor += (1.0 - probability) * currentProbability * calculateReflectedLight(newPosition, newNormal, newDirection, material, i);\n\n\t\t\t\tnewDirection = reflect(newDirection, newNormal);\n\n\t\t\t\t// if(i+1 == TRACING_DEPTH) {\n\t\t\t\t// \tgl_FragColor = vec4(0.5 * newNormal + 0.5, 1.0);\n\t\t\t\t// \treturn;\n\t\t\t\t// }\n\n\t\t\t\tcurrentProbability *= (1.0 - probability);\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\n\t\t\t#ifdef DISPERSION\n\t\t\t\tif(j == 0) {\n\t\t\t\t\tdispersionColor.r = tempColor.r;\t\n\t\t\t\t} else if(j == 1) {\n\t\t\t\t\tdispersionColor.g = tempColor.g;\t\n\t\t\t\t} else if(j == 2) {\n\t\t\t\t\tdispersionColor.b = tempColor.b;\t\n\t\t\t\t}\n\t\t\t\ttempColor = dispersionColor;\n\t\t\t#endif\n\t\t}\t\n\t\t#pragma unroll_loop_end\n\n\tif(TRACING_DEPTH > 0)\n\t\toutgoingLight2.rgb += (1.0 - initialProbability) * tempColor;\n\n\tfloat alpha = (1.0 - initialProbability) + initialProbability*tracingOpacity;\n\tgl_FragColor = vec4(outgoingLight2.rgb, alpha*diffuseColor.a);\n\n // CUSTOM END\n\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}\n\n";
3
3
  //# sourceMappingURL=gem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gem.d.ts","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,s3CAqDhB,CAAC;AAEF,eAAO,MAAM,IAAI,q9lBA2gBhB,CAAC"}
1
+ {"version":3,"file":"gem.d.ts","sourceRoot":"","sources":["../../src/shaders/gem.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,w9CAwDhB,CAAC;AAEF,eAAO,MAAM,IAAI,8rmBA4gBhB,CAAC"}