@threepipe/webgi-plugins 0.6.3 → 0.7.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 (110) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +13 -23
  3. package/THIRD_PARTY_NOTICES.md +243 -0
  4. package/dist/dependencies.txt +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +4537 -19
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +4546 -19
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
  11. package/dist/plugins/extras/AdvancedGroundPlugin.d.ts +3 -2
  12. package/dist/plugins/extras/AdvancedGroundPlugin.d.ts.map +1 -1
  13. package/dist/plugins/extras/AnisotropyPlugin.d.ts.map +1 -1
  14. package/dist/plugins/extras/WatchHandsPlugin.d.ts.map +1 -1
  15. package/dist/plugins/index.d.ts +24 -24
  16. package/dist/plugins/postprocessing/SSGIPlugin.d.ts +3 -2
  17. package/dist/plugins/postprocessing/SSGIPlugin.d.ts.map +1 -1
  18. package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts +1 -1
  19. package/dist/utils/ShadowMapBaker.d.ts +1 -1
  20. package/dist/utils/ShadowMapBaker.d.ts.map +1 -1
  21. package/docs/assets/hierarchy.js +1 -0
  22. package/docs/assets/highlight.css +22 -0
  23. package/docs/assets/icons.js +18 -0
  24. package/docs/assets/icons.svg +1 -0
  25. package/docs/assets/main.js +60 -0
  26. package/docs/assets/navigation.js +1 -0
  27. package/docs/assets/search.js +1 -0
  28. package/docs/assets/style.css +1633 -0
  29. package/docs/classes/AdvancedGroundPlugin.html +69 -0
  30. package/docs/classes/AnisotropyPlugin.html +40 -0
  31. package/docs/classes/BloomPlugin.html +37 -0
  32. package/docs/classes/BloomPluginPass.html +34 -0
  33. package/docs/classes/DepthOfFieldPlugin.html +41 -0
  34. package/docs/classes/DepthOfFieldPluginPass.html +37 -0
  35. package/docs/classes/OutlinePlugin.html +75 -0
  36. package/docs/classes/OutlineRenderPass.html +25 -0
  37. package/docs/classes/SSContactShadowsPlugin.html +37 -0
  38. package/docs/classes/SSGIPlugin.html +42 -0
  39. package/docs/classes/SSGIPluginPass.html +44 -0
  40. package/docs/classes/SSReflectionPlugin.html +43 -0
  41. package/docs/classes/SSReflectionPluginPass.html +45 -0
  42. package/docs/classes/SSVelocityMaterial.html +7 -0
  43. package/docs/classes/TemporalAAPlugin.html +37 -0
  44. package/docs/classes/TemporalAAPluginPass.html +33 -0
  45. package/docs/classes/VelocityBufferPlugin.html +41 -0
  46. package/docs/classes/WatchHandsPlugin.html +39 -0
  47. package/docs/hierarchy.html +1 -0
  48. package/docs/index.html +1 -0
  49. package/docs/types/OutlinePluginPass.html +1 -0
  50. package/docs/types/OutlinePluginTarget.html +1 -0
  51. package/docs/types/SSGIPluginTarget.html +1 -0
  52. package/docs/types/SSReflectionPluginTarget.html +1 -0
  53. package/docs/types/VelocityBufferPluginPass.html +1 -0
  54. package/docs/types/VelocityBufferPluginTarget.html +1 -0
  55. package/docs/variables/anisotropyGLTFExtension.html +1 -0
  56. package/docs/variables/webgiPlugins.html +1 -0
  57. package/package.json +23 -22
  58. package/src/global.d.ts +27 -0
  59. package/src/index.ts +1 -0
  60. package/src/passes/BilateralFilterPass.ts +62 -0
  61. package/src/passes/shaders/ssaoBilateral.glsl +89 -0
  62. package/src/plugins/buffer/VelocityBufferPlugin.ts +270 -0
  63. package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.frag.glsl +46 -0
  64. package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.vert.glsl +51 -0
  65. package/src/plugins/buffer/shaders/VelocityBufferPlugin.unpack.glsl +8 -0
  66. package/src/plugins/extras/AdvancedGroundPlugin.ts +385 -0
  67. package/src/plugins/extras/AnisotropyPlugin.ts +519 -0
  68. package/src/plugins/extras/WatchHandsPlugin.ts +156 -0
  69. package/src/plugins/extras/shaders/anisotropyBsdf.glsl +64 -0
  70. package/src/plugins/extras/shaders/anisotropyTBN.glsl +35 -0
  71. package/src/plugins/index.ts +38 -0
  72. package/src/plugins/postprocessing/BloomPlugin.ts +374 -0
  73. package/src/plugins/postprocessing/DepthOfFieldPlugin.ts +470 -0
  74. package/src/plugins/postprocessing/OutlinePlugin.ts +476 -0
  75. package/src/plugins/postprocessing/SSContactShadowsPlugin.ts +374 -0
  76. package/src/plugins/postprocessing/SSGIPlugin.ts +597 -0
  77. package/src/plugins/postprocessing/SSReflectionPlugin.ts +563 -0
  78. package/src/plugins/postprocessing/TemporalAAPlugin.ts +301 -0
  79. package/src/plugins/postprocessing/shaders/dofBlurBox.glsl +46 -0
  80. package/src/plugins/postprocessing/shaders/dofCombine.glsl +68 -0
  81. package/src/plugins/postprocessing/shaders/dofComputeCoC.glsl +21 -0
  82. package/src/plugins/postprocessing/shaders/dofExpandCoC.glsl +56 -0
  83. package/src/plugins/postprocessing/shaders/dofPoissonBox.glsl +90 -0
  84. package/src/plugins/postprocessing/shaders/giPatch.glsl +53 -0
  85. package/src/plugins/postprocessing/shaders/hdrBloom.glsl +101 -0
  86. package/src/plugins/postprocessing/shaders/outline.glsl +60 -0
  87. package/src/plugins/postprocessing/shaders/outlineDepthFrag.glsl +22 -0
  88. package/src/plugins/postprocessing/shaders/outlineDepthVert.glsl +26 -0
  89. package/src/plugins/postprocessing/shaders/poissonDiskSamples.glsl +19 -0
  90. package/src/plugins/postprocessing/shaders/samplePointHelpers.glsl +3 -0
  91. package/src/plugins/postprocessing/shaders/ssrPatch.glsl +145 -0
  92. package/src/plugins/postprocessing/shaders/ssreflectionMain.glsl +69 -0
  93. package/src/plugins/postprocessing/shaders/ssrt.glsl +118 -0
  94. package/src/utils/FSShadowMaterial.ts +65 -0
  95. package/src/utils/RandomizedDirectionalLight.ts +288 -0
  96. package/src/utils/Reflector2.ts +309 -0
  97. package/src/utils/ShadowMapBaker.ts +527 -0
  98. package/src/utils/shaders/computeScreenSpaceVelocity.glsl +16 -0
  99. package/src/utils/shaders/getWorldPositionFromViewZ.glsl +9 -0
  100. package/src/utils/shaders/poissonDiskSamples.glsl +19 -0
  101. package/src/utils/shaders/reflectorSample.glsl +54 -0
  102. package/src/utils/shaders/seperableBlurShaderMasked.glsl +28 -0
  103. package/src/utils/shaders/seperableShadowBlur.glsl +21 -0
  104. package/src/utils/shaders/ssreflection.glsl +141 -0
  105. package/src/utils/shaders/ssrtao.glsl +275 -0
  106. package/src/utils/shaders/temporalaa.glsl +233 -0
  107. package/src/utils/shaders.ts +24 -0
  108. package/tsconfig.json +39 -44
  109. package/dist/version.d.ts +0 -2
  110. package/dist/version.d.ts.map +0 -1
@@ -0,0 +1,101 @@
1
+ #include <packing>
2
+ // todo use this after threepipe update
3
+ // include <gbuffer_unpack>
4
+
5
+ uniform float intensity;
6
+ uniform float opacity;
7
+ uniform vec2 tDiffuseSize;
8
+ varying vec2 vUv;
9
+ uniform float weight;
10
+
11
+ #if PASS_STEP == 0
12
+ uniform vec4 prefilter;
13
+ vec4 Prefilter (vec4 c) {
14
+ // float brightness = max(c.r, max(c.g, c.b));
15
+ // float contribution = max(0., brightness - prefilter.x);
16
+ // contribution /= max(brightness, 0.00001);
17
+ // return vec4((c.rgb) * contribution, c.a);
18
+ // return (c - vec3(prefilterThreshold)) * contribution;
19
+
20
+ #ifdef HAS_GBUFFER
21
+ #if !BACKGROUND_BLOOM
22
+ if(getDepth(vUv) > 0.999) {
23
+ return vec4(0.0);
24
+ }
25
+ #endif
26
+ #endif
27
+
28
+ float brightness = max(c.r, max(c.g, c.b));
29
+ float soft = brightness + prefilter.x * (prefilter.y - 1.);
30
+ soft = clamp(soft, 0., prefilter.z);
31
+ soft = soft * soft * prefilter.w;
32
+ float contribution = max(soft, brightness - prefilter.x);
33
+ contribution /= max(brightness, 0.001);
34
+ return vec4(c.rgb * contribution, c.a);
35
+
36
+ }
37
+ #endif
38
+
39
+ vec4 Sample (vec2 uv) {
40
+ return min(vec4(MAX_INTENSITY, MAX_INTENSITY, MAX_INTENSITY, 1.), tDiffuseTexelToLinear( texture2D( tDiffuse, uv ) ));
41
+ }
42
+
43
+ vec4 SampleBox (vec2 uv, float delta) {
44
+ vec4 o = vec2(-delta, delta).xxyy / tDiffuseSize.xyxy;
45
+ vec4 s =
46
+ Sample(uv + o.xy) + Sample(uv + o.zy) +
47
+ Sample(uv + o.xw) + Sample(uv + o.zw);
48
+ return s * 0.25;
49
+ }
50
+
51
+ int getBloomBit(in int number) {
52
+ #ifdef WebGL2Context
53
+ return (number/4) % 2;
54
+ #else
55
+ return int(mod(floor(float(number)/4.), 2.));
56
+ #endif
57
+ }
58
+
59
+ void main() {
60
+ #if PASS_STEP == 0 //prefilter + down
61
+
62
+ #ifdef GBUFFER_HAS_FLAGS
63
+ int doBloom = getBloomBit(getGBufferFlags(vUv).a);
64
+ #else
65
+ int doBloom = 1;
66
+ #endif
67
+
68
+ gl_FragColor = float(doBloom) * weight * Prefilter(SampleBox(vUv, 1.));
69
+ gl_FragColor.a = 1.;
70
+
71
+ #elif PASS_STEP == 1 //down
72
+
73
+ gl_FragColor = weight * (SampleBox(vUv, 1.));
74
+ gl_FragColor.a = 1.;
75
+
76
+ #elif PASS_STEP == 2 //up
77
+
78
+ gl_FragColor = (SampleBox(vUv, 0.5));
79
+ gl_FragColor.a = 1.;
80
+
81
+ #elif PASS_STEP == 3 //final
82
+
83
+ vec4 texel = tSourceTexelToLinear ( texture2D(tSource, vUv) );
84
+ vec4 bloom = intensity * SampleBox(vUv, 0.5).rgba;
85
+ float brightness = max(bloom.r, max(bloom.g, bloom.b));
86
+ texel.rgb += bloom.rgb;
87
+ texel.a = min(1., texel.a + brightness);
88
+ gl_FragColor = texel;
89
+
90
+ #elif PASS_STEP == 4 //debug
91
+
92
+ vec4 texel = vec4(0.);
93
+ texel.rgb += intensity * SampleBox(vUv, 0.5).rgb;
94
+ texel.a = 1.;
95
+ gl_FragColor = texel;
96
+
97
+ #endif
98
+
99
+ #include <colorspace_fragment>
100
+
101
+ }
@@ -0,0 +1,60 @@
1
+ uniform sampler2D outlineBuffer;
2
+ uniform vec2 tDiffuseSize;
3
+ uniform vec3 outlineColor;
4
+ uniform float outlineThickness;
5
+ uniform float outlineIntensity;
6
+ uniform float highlightTransparency;
7
+ uniform bool enableHighlight;
8
+ uniform float dpr;
9
+
10
+ float isSelected(vec2 uv) {
11
+ return 1. - texture2D(outlineBuffer, uv).b;
12
+ }
13
+
14
+ vec4 outline(in vec4 color) {
15
+ vec2 invSize = 1.0 / tDiffuseSize;
16
+
17
+ #if DEBUG_OUTLINE > 0
18
+ color = vec4(0., 0., 0., 1.);
19
+ // return texture2D(outlineBuffer, vUv);
20
+ #endif
21
+
22
+ vec3 finalColor = color.rgb;
23
+
24
+ float c = isSelected(vUv);
25
+
26
+ // return vec4(c,c,c,1.);
27
+
28
+ if(c > 0.) {
29
+ vec4 uvOffset = 1.5 * dpr * outlineThickness * vec4(1.0, 0.0, -1.0, 1.0) * vec4(invSize, invSize);
30
+
31
+ float c1 = isSelected(vUv + uvOffset.xy);
32
+ float c2 = isSelected(vUv - uvOffset.xy);
33
+ float c3 = isSelected(vUv + uvOffset.yw);
34
+ float c4 = isSelected(vUv - uvOffset.yw);
35
+ float diff1 = (c1 - c2) * 0.5;
36
+ float diff2 = (c3 - c4) * 0.5;
37
+
38
+ float d = length(vec2(diff1, diff2));
39
+ // float trans = min(1., 10. * (1. - highlightTransparency));
40
+
41
+ vec4 highlightColor = enableHighlight ? vec4(c * outlineColor, (1. - highlightTransparency) * c) : vec4(0.);
42
+ vec4 edgeColor = vec4(outlineColor, 1.) * vec4(d);
43
+
44
+ float gbufferDepth = getDepth(vUv);
45
+ float outlineDepth = unpack16(texture2D(outlineBuffer, vUv).xy);
46
+ outlineDepth *= outlineDepth;
47
+ outlineDepth -= 0.005;
48
+
49
+ if(gbufferDepth < outlineDepth) {
50
+ highlightColor.rgb = highlightColor.rgb * 0.3;
51
+ edgeColor.rgb = edgeColor.rgb * 0.5;
52
+ }
53
+
54
+ vec4 outColor = edgeColor + highlightColor * (1. - d);
55
+ finalColor = mix(color.rgb, outlineIntensity * outColor.rgb, outColor.a);
56
+ } else {
57
+ finalColor.rgb = color.rgb;
58
+ }
59
+ return vec4(finalColor.rgb, color.a);
60
+ }
@@ -0,0 +1,22 @@
1
+ uniform vec2 cameraNearFar;
2
+ varying vec3 vViewPosition;
3
+
4
+ vec2 pack16(float value) {
5
+ float sMax = 65535.0;
6
+ int v = int(clamp(value, 0.0, 1.0)*sMax+0.5);
7
+ int digit0 = v/256;
8
+ int digit1 = v-digit0*256;
9
+ return vec2(float(digit0)/255.0, float(digit1)/255.0);
10
+ }
11
+
12
+ float linstep(float edge0, float edge1, float value) {
13
+ return clamp((value-edge0)/(edge1-edge0), 0.0, 1.0);
14
+ }
15
+
16
+ void main() {
17
+
18
+ float linearZ = linstep(-cameraNearFar.x, -cameraNearFar.y, -vViewPosition.z);
19
+ vec2 packedZ = pack16(pow(max(0., linearZ), 0.5));
20
+
21
+ gl_FragColor = vec4(packedZ.x, packedZ.y, 0., 0.);
22
+ }
@@ -0,0 +1,26 @@
1
+ #ifdef USE_ALPHAMAP
2
+ #define USE_UV
3
+ #endif
4
+
5
+ #include <morphtarget_pars_vertex>
6
+ #include <skinning_pars_vertex>
7
+ #include <logdepthbuf_pars_vertex>
8
+ #include <clipping_planes_pars_vertex>
9
+
10
+ varying vec3 vViewPosition;
11
+
12
+ void main() {
13
+
14
+ #include <skinbase_vertex>
15
+
16
+ #include <begin_vertex>
17
+ #include <morphtarget_vertex>
18
+ #include <skinning_vertex>
19
+ #include <displacementmap_vertex>
20
+ #include <project_vertex>
21
+ #include <logdepthbuf_vertex>
22
+ #include <clipping_planes_vertex>
23
+
24
+ vViewPosition = - mvPosition.xyz;
25
+
26
+ }
@@ -0,0 +1,19 @@
1
+ vec2 poisson_disk_samples[16];
2
+ void setPds(){
3
+ poisson_disk_samples[0] = vec2(-0.399691779231, 0.728591545584);
4
+ poisson_disk_samples[1] = vec2(-0.48622557676, -0.84016533712);
5
+ poisson_disk_samples[2] = vec2(0.770309468987, -0.24906070432);
6
+ poisson_disk_samples[3] = vec2(0.556596796154, 0.820359876432);
7
+ poisson_disk_samples[4] = vec2(-0.933902004071, 0.0600539051593);
8
+ poisson_disk_samples[5] = vec2(0.330144964342, 0.207477293384);
9
+ poisson_disk_samples[6] = vec2(0.289013230975, -0.686749271417);
10
+ poisson_disk_samples[7] = vec2(-0.0832470893559, -0.187351643125);
11
+ poisson_disk_samples[8] = vec2(-0.296314525615, 0.254474834305);
12
+ poisson_disk_samples[9] = vec2(-0.850977666059, 0.484642744689);
13
+ poisson_disk_samples[10] = vec2(0.829287915319, 0.2345063545);
14
+ poisson_disk_samples[11] = vec2(-0.773042143899, -0.543741521254);
15
+ poisson_disk_samples[12] = vec2(0.0561133030864, 0.928419742597);
16
+ poisson_disk_samples[13] = vec2(-0.205799249508, -0.562072714492);
17
+ poisson_disk_samples[14] = vec2(-0.526991665882, -0.193690188118);
18
+ poisson_disk_samples[15] = vec2(-0.051789270667, -0.935374050821);
19
+ }
@@ -0,0 +1,3 @@
1
+ // Provides the PI constant for the SSGI and SSReflection shaders.
2
+ // Sampling helpers (tangent basis, hemisphere, disk) were removed on 2026-10-01 (provenance); none had a caller.
3
+ #define PI 3.141592653589793
@@ -0,0 +1,145 @@
1
+ // reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
2
+ //float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;
3
+ #if defined(SSREFL_ENABLED) && SSREFL_ENABLED > 0
4
+
5
+ vec3 screenPos = viewToScreen(geometryPosition);
6
+
7
+ #if SSREFL_ENABLED == 2 // split mode
8
+ if(screenPos.x > ssrSplitX){
9
+ #endif
10
+
11
+ //vec4 ssrColor = texture2D( tSSReflMap, screenPos.xy);
12
+ vec4 ssrColor = vec4(0,0,0,0);
13
+ float alphaModifier = 1.0 - clamp(material.roughness * .3, 0., 1.);
14
+ alphaModifier *= ssrIntensity;
15
+
16
+ #if defined(SSR_MASK_FRONT_RAYS) && SSR_MASK_FRONT_RAYS > 0
17
+ alphaModifier *= clamp(-4.0 * dot(geometryViewDir, normal) + (4.0 + ssrMaskFrontFactor), 0.0, 1.0);
18
+ #endif
19
+
20
+ #ifdef USE_TRANSMISSION
21
+ alphaModifier *= 1.-transmission;
22
+ #endif
23
+
24
+ float vignette = 1.;
25
+ // applyEdgeFade
26
+ if(true)
27
+ {
28
+ float fadeStrength = 0.1;
29
+
30
+ // vec2 itsP = vec2(1.0, 1.0) - screenPos.xy;
31
+ float dist = max(0.,min(min(1.-screenPos.x, 1.-screenPos.y), min(screenPos.x, screenPos.y)));
32
+ float fade = dist*dist / (fadeStrength + 0.001);
33
+ fade = clamp(fade, 0.0, 1.0);
34
+ fade = pow(fade, 0.3);
35
+
36
+ vignette = fade;
37
+ }
38
+ alphaModifier *= vignette;
39
+
40
+ vec3 specularColor = EnvironmentBRDF(geometryNormal, geometryViewDir, material.specularColor.rgb, material.specularF90, material.roughness);
41
+
42
+ if(length(specularColor.rgb) * alphaModifier > 0.01 && roughnessFactor < 0.9){ // Note: using material.roughness here causes some clipping issues at edges because of geometryRoughness
43
+ #if defined(SSR_INLINE) && SSR_INLINE > 0
44
+ vec3 scPos = vec3(screenPos.xy, geometryPosition.z);
45
+ // ssrColor = calculateSSR(8., scPos, geometryNormal, 1., material.roughness);
46
+ vec4 scol = vec4(0,0,0,0);
47
+
48
+ #pragma unroll_loop_start
49
+ for( int i = 0; i < 8; i++ ) {
50
+ if(SSR_RAY_COUNT > UNROLLED_LOOP_INDEX) {
51
+ scol = calculateSSR(float(UNROLLED_LOOP_INDEX), scPos, geometryNormal, UNROLLED_LOOP_INDEX%3==0?1.:UNROLLED_LOOP_INDEX%3==1?0.5:1.5, material.roughness);
52
+ #ifdef SSR_RAY_BLEND_MAX
53
+ ssrColor = max(ssrColor, scol);
54
+ #else
55
+ ssrColor += scol;
56
+ #endif
57
+ }
58
+ }
59
+ #pragma unroll_loop_end
60
+
61
+ #ifndef SSR_RAY_BLEND_MAX
62
+ ssrColor *= ssrColor.a > 0.001 ? 1.0 / ssrColor.a : 1.0;
63
+ #endif
64
+ //
65
+ // #if SSR_RAY_COUNT > 1
66
+ // ssrColor += calculateSSR(1., scPos, geometryNormal, 0.4, material.roughness);
67
+ // #endif
68
+ // #if SSR_RAY_COUNT > 2
69
+ // ssrColor += calculateSSR(1., scPos, geometryNormal, 0.25, material.roughness);
70
+ // #endif
71
+ // #if SSR_RAY_COUNT > 3
72
+ // ssrColor += calculateSSR(1., scPos, geometryNormal, 1.5, material.roughness);
73
+ // #endif
74
+ // #if SSR_RAY_COUNT > 3
75
+ // ssrColor += calculateSSR(1., scPos, geometryNormal, 1.25, material.roughness);
76
+ // #endif
77
+ // #if SSR_RAY_COUNT > 4
78
+ // ssrColor += calculateSSR(1., scPos, geometryNormal, 1.25, material.roughness);
79
+ // #endif
80
+ //
81
+ // if(gl_FragCoord.x < 680.){
82
+ // ssrColor += calculateSSR(1., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 0.4, material.roughness);
83
+ // ssrColor += calculateSSR(4., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 0.25, material.roughness);
84
+ // ssrColor += calculateSSR(123., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness);
85
+ // ssrColor += calculateSSR(11., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness);
86
+ // ssrColor += calculateSSR(1273., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness);
87
+ // ssrColor += calculateSSR(13., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness);
88
+ // ssrColor += calculateSSR(38., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness);
89
+ // ssrColor *= 0.125;
90
+ // }else {
91
+ // ssrColor = max(ssrColor, calculateSSR(1., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 0.4, material.roughness));
92
+ // ssrColor = max(ssrColor, calculateSSR(4., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 0.25, material.roughness));
93
+ // ssrColor = max(ssrColor, calculateSSR(123., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness));
94
+ // ssrColor = max(ssrColor, calculateSSR(11., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness));
95
+ // ssrColor = max(ssrColor, calculateSSR(1273., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness));
96
+ // ssrColor = max(ssrColor, calculateSSR(13., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness));
97
+ // ssrColor = max(ssrColor, calculateSSR(38., vec3(screenPos.xy, geometryPosition.z), geometryNormal, 1., material.roughness));
98
+ // }
99
+ #else
100
+ ssrColor = tSSReflMapTexelToLinear( texture2D( tSSReflMap, screenPos.xy) );
101
+ #endif //SSR_INLINE
102
+ }
103
+ ssrColor.rgb *= ssrBoost;
104
+
105
+ ssrColor.a *= alphaModifier;
106
+
107
+ // pow is slow, shouldnt use for no reason
108
+ ssrColor.rgb = pow(max(vec3(0.), ssrColor.rgb), vec3(ssrPower));
109
+
110
+ ssrColor.a = min(ssrColor.a, 1.0);
111
+
112
+ //#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined ( USE_AOMAP )
113
+ //ssrColor.rgb *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
114
+ //#endif
115
+
116
+ // this non-physical is used in ground plugin
117
+ #if defined(SSR_NON_PHYSICAL) && SSR_NON_PHYSICAL > 0
118
+ diffuseColor.a = max(ssrColor.a, diffuseColor.a * diffuseColor.a);
119
+ reflectedLight.indirectSpecular = mix(reflectedLight.indirectSpecular, saturate(diffuseColor.rgb * ssrColor.rgb), 1.0);
120
+ reflectedLight.indirectDiffuse = diffuseColor.rgb * (1.0-ssrColor.a);
121
+ reflectedLight.directDiffuse = vec3(0.0);
122
+ reflectedLight.directSpecular = vec3(0.0);
123
+ //diffuseColor.a = min(1.0, ssrColor.a + diffuseColor.a);
124
+ #else
125
+ // todo is mix clamping
126
+ reflectedLight.indirectSpecular = mix(reflectedLight.indirectSpecular, (specularColor.rgb * ssrColor.rgb), ssrColor.a);
127
+ // todo saturate for noise?
128
+ //reflectedLight.indirectSpecular = mix(reflectedLight.indirectSpecular, saturate(specularColor.rgb * ssrColor.rgb), ssrColor.a);
129
+ #endif
130
+
131
+
132
+ #if SSREFL_ENABLED == 2
133
+ }
134
+ #endif
135
+
136
+ #endif
137
+
138
+
139
+ //#if DEBUG
140
+ // just show ssrColor
141
+ //reflectedLight.indirectSpecular = ssrColor.rgb;
142
+ //reflectedLight.indirectDiffuse = vec3(0.0);
143
+ //reflectedLight.directDiffuse = vec3(0.0);
144
+ //reflectedLight.directSpecular = vec3(0.0);
145
+ //#endif
@@ -0,0 +1,69 @@
1
+ //uniform sampler2D tLastThis;
2
+
3
+ void main() {
4
+
5
+ vec4 texel = tDiffuseTexelToLinear(texture2D( tDiffuse, vUv ));
6
+ vec4 lastAO = tLastThisTexelToLinear(texture2D( tLastThis, vUv ));
7
+ float depth;
8
+ vec3 normal;
9
+ // float alpha = opacity;
10
+ getDepthNormal(vUv, depth, normal);
11
+
12
+ if (depth >= 0.999) {
13
+ discard;
14
+ }
15
+
16
+ float viewZ = depthToViewZ(depth);
17
+ vec3 screenPos = vec3(vUv.x, vUv.y, viewZ);
18
+ vec3 viewPos = screenToView3(screenPos.xy, screenPos.z);
19
+ viewPos.z = viewZ/viewPos.z;
20
+ vec4 ao = vec4(0.);
21
+ // screenPos.z += 0.001;
22
+ ao += calculateSSR(8., screenPos, normal, 1., 0.1);
23
+ // ao += getSSR(0.5, normal, viewPos, -normalize(viewPos));
24
+ // if(radius > 0.5)
25
+ // ao = max(ao, calculateSSR(2., screenPos, normal, 0.4));
26
+ // if(radius > 1.)
27
+ // ao = max(ao, calculateSSR(1., screenPos, normal, 0.6));
28
+ // if(radius > 1.5)
29
+ // ao = max(ao, calculateSSR(3., screenPos, normal, 2.));
30
+
31
+
32
+ // ao += calculateSSR(3., screenPos, normal, 1.);
33
+ // ao += calculateSSR(4., screenPos, normal, 1.);
34
+ // ao += calculateSSR(5., screenPos, normal, 1.);
35
+ // ao += calculateSSR(6., screenPos, normal, 1.);
36
+ // ao += calculateSSR(7., screenPos, normal, 1.);
37
+ //
38
+ // ao = ao / 6.;
39
+ // ao = ao / 3.;
40
+
41
+ // gl_FragColor = vec4(texel) * (1.-ao);
42
+
43
+ // ao = ao;
44
+ // ao *= intensity/1.;
45
+
46
+ ao.rgb = min(vec3(3.), ao.rgb);
47
+ ao.rgb = max(vec3(0.), ao.rgb);
48
+
49
+ if(currentFrameCount < 2.){
50
+ gl_FragColor = ao;
51
+ return;
52
+ }
53
+ if(ao.a < 0.01){
54
+ gl_FragColor.rgb = lastAO.rgb;
55
+ gl_FragColor.a = (((lastAO.a) * currentFrameCount)/(currentFrameCount+1.));
56
+ }else {
57
+ gl_FragColor = ((ao + (lastAO) * currentFrameCount)/(currentFrameCount+1.));
58
+ }
59
+ // gl_FragColor = ((ao + (lastAO) * currentFrameCount)/(currentFrameCount+1.));
60
+ // gl_FragColor.r = ((ao.a + (lastAO.r) * currentFrameCount)/(currentFrameCount+1.));
61
+ // gl_FragColor.g = power/10.;
62
+ // gl_FragColor.rgb = texel.rgb;
63
+ // gl_FragColor.a = ((texel.a + (lastAO.a) * currentFrameCount)/(currentFrameCount+1.));
64
+ // gl_FragColor.a = 1.;
65
+ // gl_FragColor = texel;
66
+
67
+ #include <colorspace_fragment>
68
+
69
+ }
@@ -0,0 +1,118 @@
1
+ #ifndef SSRT_PARS_SNIP
2
+ #define SSRT_PARS_SNIP
3
+
4
+ #define pow2(a) a*a
5
+
6
+ float getDepth2(const in vec2 uv, const in float lod) {
7
+ float viewDepth = getDepth(uv);
8
+ return depthToViewZ(viewDepth);
9
+ }
10
+
11
+ #define LOD_DEPTH 1.0// todo: generate mipmap depth and set.
12
+ #define LOD_COLOR 5.0
13
+
14
+ // multiple of 4
15
+ //#define I_STEP_COUNT (1./float(STEP_COUNT))
16
+
17
+ void _traceRay(in vec4 ray_origin, in vec4 ray_dir, in float tolerance, inout vec3 state, in int loopMax, in float iStepCount){
18
+ vec4 sample_uv;
19
+ float d, hit;
20
+ float dLod = 0.;//floor(LOD_DEPTH * roughness);
21
+
22
+ #pragma unroll_loop_start
23
+ for (int i = 0; i < 8; i++){
24
+ if ( UNROLLED_LOOP_INDEX < loopMax ){
25
+
26
+ sample_uv = ray_origin + ray_dir * state.y;
27
+ d = getDepth2(sample_uv.xy, dLod);
28
+ d = sample_uv.z/sample_uv.w - d;
29
+ if (abs(d + tolerance) < tolerance){
30
+
31
+ hit = clamp(state.x / (state.x - d), 0., 1.) - 1.;
32
+ hit = (state.y + hit * iStepCount);
33
+ state.z = min(state.z, hit);
34
+
35
+ }
36
+ state.x = d;//depth diff
37
+ state.y += 1. * iStepCount;
38
+
39
+ }
40
+ }
41
+ #pragma unroll_loop_end
42
+
43
+ }
44
+
45
+ vec3 traceRay(in vec3 ray_origin_view, in vec3 ray_dir_view, in float tolerance, inout vec3 state, in int _STEP_COUNT){
46
+ vec4 sample_uv;
47
+ // float stepCount = float(_STEP_COUNT);
48
+
49
+ vec4 ray_origin = viewToScreen3(ray_origin_view);
50
+
51
+ vec3 ray_end_view = ray_origin_view + ray_dir_view;
52
+ vec4 ray_dir = viewToScreen3(ray_end_view); // ray_end
53
+
54
+ // clamp ray to screen edge.
55
+ vec2 clamp_end = clamp(ray_dir.xy, vec2(0.), vec2(1.));
56
+ vec2 correction = abs(ray_dir.xy - clamp_end);
57
+ correction = ( step(0.01, correction) * correction / (abs(clamp_end - ray_origin.xy) + 0.01) ) + 1.; // = ((b-c)/(c-a) + 1) see bottom
58
+ correction.x = 1./min(max(correction.y, correction.x), 10.);
59
+
60
+ ray_dir = ray_dir - ray_origin;
61
+
62
+ ray_dir.xyw *= correction.x;
63
+ // tolerance /= correction.x;
64
+
65
+ // if(len(ray_dir.xyw) < 0.1){
66
+ // ray_dir.xyw = normalize(ray_dir.xyw)*0.1;
67
+ // }
68
+
69
+ float iStepCount = 1./float(_STEP_COUNT);
70
+ tolerance *= 0.125;
71
+ // tolerance *= iStepCount;
72
+
73
+ _traceRay(ray_origin, ray_dir, tolerance, state, _STEP_COUNT, iStepCount);
74
+ if(_STEP_COUNT > 8 && state.z > 0.98) _traceRay(ray_origin, ray_dir, tolerance, state, _STEP_COUNT-8, iStepCount);
75
+ if(_STEP_COUNT > 15 && state.z > 0.98) _traceRay(ray_origin, ray_dir, tolerance, state, _STEP_COUNT-16, iStepCount);
76
+ if(_STEP_COUNT > 23 && state.z > 0.98) _traceRay(ray_origin, ray_dir, tolerance, state, _STEP_COUNT-16, iStepCount);
77
+
78
+
79
+ sample_uv = ray_origin + ray_dir * state.z;
80
+ sample_uv.z /= sample_uv.w;
81
+
82
+ state.z = state.z < 0.999 ? state.z : 9999999.;
83
+ return sample_uv.xyz;
84
+ }
85
+
86
+
87
+
88
+ /**
89
+ for ray clipping
90
+
91
+ a = ray_origin
92
+ b = ray_end
93
+ c = clamp(b)
94
+ x = c.y - a.y
95
+ y = b.y - c.y
96
+ (c.y-a.y)/(b.y-c.y) = m/(l-m)
97
+ m/(l-m) = k
98
+ m = kl - km
99
+ m = kl/(1+k)
100
+
101
+ ((c-a)/(b-c) ) / (1 + (c-a)/(b-c))
102
+ x/(y*(1+x/y))
103
+ x/(y+x)
104
+ 1/(y/x+1)
105
+
106
+ x/(y + yx)
107
+ 1/(y/x + y)
108
+
109
+ ray scale =
110
+
111
+ k/(1+k)
112
+ 1/(1/k+1)
113
+
114
+ =
115
+ 1/((b-c)/(c-a) + 1)
116
+
117
+ **/
118
+ #endif
@@ -0,0 +1,65 @@
1
+ import {AnyOptions, glsl, ITexture, Shader, ShadowMaterial, uniform, WebGLRenderer} from 'threepipe'
2
+
3
+ // Full screen shadow material, used for baking shadow maps.
4
+ export class FSShadowMaterial extends ShadowMaterial /*implements IMaterial*/ {
5
+ public readonly typeSlug = 'fsShadow'
6
+ assetType: 'material' = 'material'
7
+
8
+ private _uniforms: any = {}
9
+ @uniform({propKey: 'tLastThis'})
10
+ public lastFrameTexture: ITexture | null = null
11
+
12
+ get materialObject(): ShadowMaterial {
13
+ return this
14
+ }
15
+
16
+ onBeforeCompile(shader: Shader, renderer: WebGLRenderer): void {
17
+ shader.vertexShader = shader.vertexShader.replace('#include <project_vertex>', `
18
+ #include <project_vertex>
19
+ gl_Position = vec4(uv*2.-1., 0, 1.);
20
+ `) // todo: write to uv2?
21
+ shader.vertexShader = shader.vertexShader.replace('void main() {', `
22
+ varying vec2 vUv;
23
+ void main() {
24
+ vUv = uv;
25
+ `)
26
+ shader.fragmentShader = shader.fragmentShader.replace('void main() {', `
27
+ varying vec2 vUv;
28
+ uniform sampler2D tLastThis;
29
+ void main() {
30
+ `)
31
+ shader.fragmentShader = shader.fragmentShader.replace('gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );', glsl`
32
+ float shadow = getShadowMask();
33
+
34
+ //shift the color by dither_shift
35
+ shadow = clamp(shadow + mix(-1./512., 1./512., rand( gl_FragCoord.xy )), 0., 1.);
36
+
37
+ float last = unpackRGBAToDepth(texture2D(tLastThis, vUv));
38
+ gl_FragColor = packDepthToRGBA(mix(last, shadow, opacity));
39
+ //if not useMovingAverage:
40
+ //gl_FragColor = packDepthToRGBA(shadow * opacity + last);
41
+ `)
42
+ Object.assign(shader.uniforms, this._uniforms)
43
+ super.onBeforeCompile(shader, renderer)
44
+ }
45
+
46
+ customProgramCacheKey(): string {
47
+ return super.customProgramCacheKey()
48
+ }
49
+
50
+ toJSON(): any {
51
+ throw new Error('Method not supported for this material.')
52
+ }
53
+ fromJSON(): this | null {
54
+ throw new Error('Method not supported for this material.')
55
+ }
56
+
57
+ copyProps(): this {
58
+ throw new Error('Method not supported for this material.')
59
+ }
60
+
61
+ setDirty(options?: AnyOptions): void {
62
+ this.needsUpdate = true
63
+ this.dispatchEvent({...options, type: 'materialUpdate'}) // this sets sceneUpdate in root scene
64
+ }
65
+ }