@3driseai/3drise-viewer 0.1.7 → 0.1.8

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 (259) hide show
  1. package/dist/components/Clouds.d.ts.map +1 -1
  2. package/dist/components/Clouds.js +0 -1
  3. package/dist/components/CloudsGenerator.d.ts +32 -0
  4. package/dist/components/CloudsGenerator.d.ts.map +1 -0
  5. package/dist/components/CloudsGenerator.js +58 -0
  6. package/dist/components/EnvironmentManager.d.ts +47 -5
  7. package/dist/components/EnvironmentManager.d.ts.map +1 -1
  8. package/dist/components/EnvironmentManager.js +35 -66
  9. package/dist/components/HdrEnvironment.d.ts +20 -0
  10. package/dist/components/HdrEnvironment.d.ts.map +1 -0
  11. package/dist/components/HdrEnvironment.js +44 -0
  12. package/dist/components/LandscapeBuilder.d.ts +23 -0
  13. package/dist/components/LandscapeBuilder.d.ts.map +1 -0
  14. package/dist/components/LandscapeBuilder.js +25 -0
  15. package/dist/components/LandscapeObject.d.ts +24 -0
  16. package/dist/components/LandscapeObject.d.ts.map +1 -0
  17. package/dist/components/LandscapeObject.js +27 -0
  18. package/dist/components/ObjectNode.d.ts.map +1 -1
  19. package/dist/components/ObjectNode.js +10 -0
  20. package/dist/components/OceanBuilder.d.ts +35 -0
  21. package/dist/components/OceanBuilder.d.ts.map +1 -0
  22. package/dist/components/OceanBuilder.js +53 -0
  23. package/dist/components/SceneBuilder.d.ts.map +1 -1
  24. package/dist/components/SkySystem.d.ts +27 -6
  25. package/dist/components/SkySystem.d.ts.map +1 -1
  26. package/dist/components/SkySystem.js +6 -5
  27. package/dist/components/SunLight.d.ts.map +1 -1
  28. package/dist/components/SunLight.js +4 -1
  29. package/dist/components/TerrainBuilder.d.ts +30 -0
  30. package/dist/components/TerrainBuilder.d.ts.map +1 -0
  31. package/dist/components/TerrainBuilder.js +44 -0
  32. package/dist/components/index.d.ts +17 -1
  33. package/dist/components/index.d.ts.map +1 -1
  34. package/dist/components/index.js +10 -0
  35. package/dist/components/landscape/LandscapeMesh.d.ts +18 -0
  36. package/dist/components/landscape/LandscapeMesh.d.ts.map +1 -0
  37. package/dist/components/landscape/LandscapeMesh.js +278 -0
  38. package/dist/components/landscape/index.d.ts +3 -0
  39. package/dist/components/landscape/index.d.ts.map +1 -0
  40. package/dist/components/landscape/index.js +1 -0
  41. package/dist/components/landscape/types.d.ts +13 -0
  42. package/dist/components/landscape/types.d.ts.map +1 -0
  43. package/dist/components/landscape/types.js +1 -0
  44. package/dist/components/terrain/Canyon.d.ts +23 -0
  45. package/dist/components/terrain/Canyon.d.ts.map +1 -0
  46. package/dist/components/terrain/Canyon.js +29 -0
  47. package/dist/components/terrain/Dunes.d.ts +22 -0
  48. package/dist/components/terrain/Dunes.d.ts.map +1 -0
  49. package/dist/components/terrain/Dunes.js +25 -0
  50. package/dist/components/terrain/Hills.d.ts +17 -0
  51. package/dist/components/terrain/Hills.d.ts.map +1 -0
  52. package/dist/components/terrain/Hills.js +20 -0
  53. package/dist/components/terrain/Mountains.d.ts +19 -0
  54. package/dist/components/terrain/Mountains.d.ts.map +1 -0
  55. package/dist/components/terrain/Mountains.js +22 -0
  56. package/dist/components/terrain/TerrainSurface.d.ts +22 -0
  57. package/dist/components/terrain/TerrainSurface.d.ts.map +1 -0
  58. package/dist/components/terrain/TerrainSurface.js +94 -0
  59. package/dist/components/terrain/index.d.ts +7 -0
  60. package/dist/components/terrain/index.d.ts.map +1 -0
  61. package/dist/components/terrain/index.js +7 -0
  62. package/dist/components/terrain/types.d.ts +17 -0
  63. package/dist/components/terrain/types.d.ts.map +1 -0
  64. package/dist/components/terrain/types.js +1 -0
  65. package/dist/components/volumetricClouds/Cirrus.d.ts +14 -0
  66. package/dist/components/volumetricClouds/Cirrus.d.ts.map +1 -0
  67. package/dist/components/volumetricClouds/Cirrus.js +13 -0
  68. package/dist/components/volumetricClouds/Cumulonimbus.d.ts +17 -0
  69. package/dist/components/volumetricClouds/Cumulonimbus.d.ts.map +1 -0
  70. package/dist/components/volumetricClouds/Cumulonimbus.js +20 -0
  71. package/dist/components/volumetricClouds/Cumulus.d.ts +14 -0
  72. package/dist/components/volumetricClouds/Cumulus.d.ts.map +1 -0
  73. package/dist/components/volumetricClouds/Cumulus.js +17 -0
  74. package/dist/components/volumetricClouds/Stratocumulus.d.ts +12 -0
  75. package/dist/components/volumetricClouds/Stratocumulus.d.ts.map +1 -0
  76. package/dist/components/volumetricClouds/Stratocumulus.js +16 -0
  77. package/dist/components/volumetricClouds/VolumetricCloudsPass.d.ts +42 -0
  78. package/dist/components/volumetricClouds/VolumetricCloudsPass.d.ts.map +1 -0
  79. package/dist/components/volumetricClouds/VolumetricCloudsPass.js +298 -0
  80. package/dist/components/volumetricClouds/index.d.ts +8 -0
  81. package/dist/components/volumetricClouds/index.d.ts.map +1 -0
  82. package/dist/components/volumetricClouds/index.js +7 -0
  83. package/dist/components/volumetricClouds/types.d.ts +17 -0
  84. package/dist/components/volumetricClouds/types.d.ts.map +1 -0
  85. package/dist/components/volumetricClouds/types.js +1 -0
  86. package/dist/components/water/Host.d.ts +12 -0
  87. package/dist/components/water/Host.d.ts.map +1 -0
  88. package/dist/components/water/Host.js +12 -0
  89. package/dist/components/water/Lake.d.ts +18 -0
  90. package/dist/components/water/Lake.d.ts.map +1 -0
  91. package/dist/components/water/Lake.js +21 -0
  92. package/dist/components/water/OceanSurface.d.ts +27 -0
  93. package/dist/components/water/OceanSurface.d.ts.map +1 -0
  94. package/dist/components/water/OceanSurface.js +60 -0
  95. package/dist/components/water/Sea.d.ts +18 -0
  96. package/dist/components/water/Sea.d.ts.map +1 -0
  97. package/dist/components/water/Sea.js +17 -0
  98. package/dist/components/water/Shore.d.ts +16 -0
  99. package/dist/components/water/Shore.d.ts.map +1 -0
  100. package/dist/components/water/Shore.js +15 -0
  101. package/dist/components/water/Storm.d.ts +14 -0
  102. package/dist/components/water/Storm.d.ts.map +1 -0
  103. package/dist/components/water/Storm.js +13 -0
  104. package/dist/components/water/WaterBody.d.ts +31 -0
  105. package/dist/components/water/WaterBody.d.ts.map +1 -0
  106. package/dist/components/water/WaterBody.js +76 -0
  107. package/dist/components/water/index.d.ts +9 -0
  108. package/dist/components/water/index.d.ts.map +1 -0
  109. package/dist/components/water/index.js +11 -0
  110. package/dist/components/water/types.d.ts +20 -0
  111. package/dist/components/water/types.d.ts.map +1 -0
  112. package/dist/components/water/types.js +1 -0
  113. package/dist/constants.d.ts.map +1 -1
  114. package/dist/constants.js +9 -0
  115. package/dist/hooks/index.d.ts +24 -1
  116. package/dist/hooks/index.d.ts.map +1 -1
  117. package/dist/hooks/index.js +12 -0
  118. package/dist/hooks/useClipmap.d.ts +71 -0
  119. package/dist/hooks/useClipmap.d.ts.map +1 -0
  120. package/dist/hooks/useClipmap.js +81 -0
  121. package/dist/hooks/useCloudLive.d.ts +29 -0
  122. package/dist/hooks/useCloudLive.d.ts.map +1 -0
  123. package/dist/hooks/useCloudLive.js +43 -0
  124. package/dist/hooks/useCloudNoise.d.ts +28 -0
  125. package/dist/hooks/useCloudNoise.d.ts.map +1 -0
  126. package/dist/hooks/useCloudNoise.js +128 -0
  127. package/dist/hooks/useCloudSun.d.ts +49 -0
  128. package/dist/hooks/useCloudSun.d.ts.map +1 -0
  129. package/dist/hooks/useCloudSun.js +84 -0
  130. package/dist/hooks/useCubeCamera.d.ts +27 -9
  131. package/dist/hooks/useCubeCamera.d.ts.map +1 -1
  132. package/dist/hooks/useCubeCamera.js +28 -70
  133. package/dist/hooks/useEnvironmentProbe.d.ts +32 -0
  134. package/dist/hooks/useEnvironmentProbe.d.ts.map +1 -0
  135. package/dist/hooks/useEnvironmentProbe.js +35 -0
  136. package/dist/hooks/useFrameRenderer.d.ts +15 -0
  137. package/dist/hooks/useFrameRenderer.d.ts.map +1 -0
  138. package/dist/hooks/useFrameRenderer.js +23 -0
  139. package/dist/hooks/useLandscapeLive.d.ts +29 -0
  140. package/dist/hooks/useLandscapeLive.d.ts.map +1 -0
  141. package/dist/hooks/useLandscapeLive.js +41 -0
  142. package/dist/hooks/useLandscapeMaps.d.ts +32 -0
  143. package/dist/hooks/useLandscapeMaps.d.ts.map +1 -0
  144. package/dist/hooks/useLandscapeMaps.js +138 -0
  145. package/dist/hooks/useOceanLive.d.ts +29 -0
  146. package/dist/hooks/useOceanLive.d.ts.map +1 -0
  147. package/dist/hooks/useOceanLive.js +38 -0
  148. package/dist/hooks/useOceanMaterial.d.ts +39 -0
  149. package/dist/hooks/useOceanMaterial.d.ts.map +1 -0
  150. package/dist/hooks/useOceanMaterial.js +65 -0
  151. package/dist/hooks/useTerrainClipmap.d.ts +12 -0
  152. package/dist/hooks/useTerrainClipmap.d.ts.map +1 -0
  153. package/dist/hooks/useTerrainClipmap.js +10 -0
  154. package/dist/hooks/useTerrainLive.d.ts +34 -0
  155. package/dist/hooks/useTerrainLive.d.ts.map +1 -0
  156. package/dist/hooks/useTerrainLive.js +45 -0
  157. package/dist/index.d.ts +26 -0
  158. package/dist/index.d.ts.map +1 -1
  159. package/dist/index.js +16 -0
  160. package/dist/presets/landscapePresets.d.ts +60 -0
  161. package/dist/presets/landscapePresets.d.ts.map +1 -0
  162. package/dist/presets/landscapePresets.js +194 -0
  163. package/dist/presets/landscapeTypes.d.ts +195 -0
  164. package/dist/presets/landscapeTypes.d.ts.map +1 -0
  165. package/dist/presets/landscapeTypes.js +315 -0
  166. package/dist/presets/oceanSurfacePresets.d.ts +33 -0
  167. package/dist/presets/oceanSurfacePresets.d.ts.map +1 -0
  168. package/dist/presets/oceanSurfacePresets.js +245 -0
  169. package/dist/presets/terrainPresets.d.ts +28 -0
  170. package/dist/presets/terrainPresets.d.ts.map +1 -0
  171. package/dist/presets/terrainPresets.js +293 -0
  172. package/dist/presets/volumetricCloudPresets.d.ts +38 -0
  173. package/dist/presets/volumetricCloudPresets.d.ts.map +1 -0
  174. package/dist/presets/volumetricCloudPresets.js +480 -0
  175. package/dist/shaders/clouds/CirrusMaterial.d.ts +84 -0
  176. package/dist/shaders/clouds/CirrusMaterial.d.ts.map +1 -0
  177. package/dist/shaders/clouds/CirrusMaterial.js +167 -0
  178. package/dist/shaders/clouds/CloudCompositeMaterial.d.ts +20 -0
  179. package/dist/shaders/clouds/CloudCompositeMaterial.d.ts.map +1 -0
  180. package/dist/shaders/clouds/CloudCompositeMaterial.js +82 -0
  181. package/dist/shaders/clouds/CloudResolveMaterial.d.ts +22 -0
  182. package/dist/shaders/clouds/CloudResolveMaterial.d.ts.map +1 -0
  183. package/dist/shaders/clouds/CloudResolveMaterial.js +77 -0
  184. package/dist/shaders/clouds/CloudVolumeMaterial.d.ts +143 -0
  185. package/dist/shaders/clouds/CloudVolumeMaterial.d.ts.map +1 -0
  186. package/dist/shaders/clouds/CloudVolumeMaterial.js +249 -0
  187. package/dist/shaders/clouds/SkyBackgroundMaterial.d.ts +21 -0
  188. package/dist/shaders/clouds/SkyBackgroundMaterial.d.ts.map +1 -0
  189. package/dist/shaders/clouds/SkyBackgroundMaterial.js +42 -0
  190. package/dist/shaders/glsl/cloudCore.glsl.d.ts +24 -0
  191. package/dist/shaders/glsl/cloudCore.glsl.d.ts.map +1 -0
  192. package/dist/shaders/glsl/cloudCore.glsl.js +348 -0
  193. package/dist/shaders/glsl/landscapeCore.glsl.d.ts +49 -0
  194. package/dist/shaders/glsl/landscapeCore.glsl.d.ts.map +1 -0
  195. package/dist/shaders/glsl/landscapeCore.glsl.js +518 -0
  196. package/dist/shaders/glsl/noiseBake.glsl.d.ts +30 -0
  197. package/dist/shaders/glsl/noiseBake.glsl.d.ts.map +1 -0
  198. package/dist/shaders/glsl/noiseBake.glsl.js +164 -0
  199. package/dist/shaders/glsl/oceanCore.glsl.d.ts +52 -0
  200. package/dist/shaders/glsl/oceanCore.glsl.d.ts.map +1 -0
  201. package/dist/shaders/glsl/oceanCore.glsl.js +421 -0
  202. package/dist/shaders/glsl/terrainCore.glsl.d.ts +78 -0
  203. package/dist/shaders/glsl/terrainCore.glsl.d.ts.map +1 -0
  204. package/dist/shaders/glsl/terrainCore.glsl.js +625 -0
  205. package/dist/shaders/landscape/LandscapeMaterial.d.ts +73 -0
  206. package/dist/shaders/landscape/LandscapeMaterial.d.ts.map +1 -0
  207. package/dist/shaders/landscape/LandscapeMaterial.js +136 -0
  208. package/dist/shaders/ocean/OceanSurfaceMaterial.d.ts +57 -0
  209. package/dist/shaders/ocean/OceanSurfaceMaterial.d.ts.map +1 -0
  210. package/dist/shaders/ocean/OceanSurfaceMaterial.js +268 -0
  211. package/dist/shaders/terrain/TerrainMaterial.d.ts +80 -0
  212. package/dist/shaders/terrain/TerrainMaterial.d.ts.map +1 -0
  213. package/dist/shaders/terrain/TerrainMaterial.js +291 -0
  214. package/dist/types/cloudConfigs.d.ts +244 -0
  215. package/dist/types/cloudConfigs.d.ts.map +1 -0
  216. package/dist/types/cloudConfigs.js +282 -0
  217. package/dist/types/index.d.ts +8 -0
  218. package/dist/types/index.d.ts.map +1 -1
  219. package/dist/types/index.js +4 -1
  220. package/dist/types/landscapeConfigs.d.ts +218 -0
  221. package/dist/types/landscapeConfigs.d.ts.map +1 -0
  222. package/dist/types/landscapeConfigs.js +256 -0
  223. package/dist/types/oceanConfigs.d.ts +290 -0
  224. package/dist/types/oceanConfigs.d.ts.map +1 -0
  225. package/dist/types/oceanConfigs.js +380 -0
  226. package/dist/types/terrainConfigs.d.ts +251 -0
  227. package/dist/types/terrainConfigs.d.ts.map +1 -0
  228. package/dist/types/terrainConfigs.js +292 -0
  229. package/dist/utils/cloudUniforms.d.ts +14 -0
  230. package/dist/utils/cloudUniforms.d.ts.map +1 -0
  231. package/dist/utils/cloudUniforms.js +122 -0
  232. package/dist/utils/frameRenderer.d.ts +33 -0
  233. package/dist/utils/frameRenderer.d.ts.map +1 -0
  234. package/dist/utils/frameRenderer.js +24 -0
  235. package/dist/utils/handleCloudsAnimations.d.ts +16 -0
  236. package/dist/utils/handleCloudsAnimations.d.ts.map +1 -0
  237. package/dist/utils/handleCloudsAnimations.js +64 -0
  238. package/dist/utils/landscapeGeometry.d.ts +61 -0
  239. package/dist/utils/landscapeGeometry.d.ts.map +1 -0
  240. package/dist/utils/landscapeGeometry.js +126 -0
  241. package/dist/utils/landscapeHeight.d.ts +44 -0
  242. package/dist/utils/landscapeHeight.d.ts.map +1 -0
  243. package/dist/utils/landscapeHeight.js +65 -0
  244. package/dist/utils/landscapeTextures.d.ts +94 -0
  245. package/dist/utils/landscapeTextures.d.ts.map +1 -0
  246. package/dist/utils/landscapeTextures.js +290 -0
  247. package/dist/utils/landscapeUniforms.d.ts +20 -0
  248. package/dist/utils/landscapeUniforms.d.ts.map +1 -0
  249. package/dist/utils/landscapeUniforms.js +61 -0
  250. package/dist/utils/oceanUniforms.d.ts +47 -0
  251. package/dist/utils/oceanUniforms.d.ts.map +1 -0
  252. package/dist/utils/oceanUniforms.js +216 -0
  253. package/dist/utils/rtin.d.ts +63 -0
  254. package/dist/utils/rtin.d.ts.map +1 -0
  255. package/dist/utils/rtin.js +202 -0
  256. package/dist/utils/terrainUniforms.d.ts +14 -0
  257. package/dist/utils/terrainUniforms.d.ts.map +1 -0
  258. package/dist/utils/terrainUniforms.js +196 -0
  259. package/package.json +2 -2
@@ -0,0 +1,249 @@
1
+ import * as THREE from 'three';
2
+ import { shaderMaterial } from '@react-three/drei';
3
+ import { extend } from '@react-three/fiber';
4
+ import { cloudFull } from '../glsl/cloudCore.glsl.js';
5
+ /**
6
+ * The volumetric march. Used by Cumulus, Stratocumulus and Cumulonimbus — they are one
7
+ * density model with different vertical profiles, not three shaders.
8
+ *
9
+ * Two hosts, selected by u_host:
10
+ * 0 object — analytic sphere intersection, rendered on a back-faced container mesh
11
+ * 1 layer — analytic curved-slab intersection, rendered by <CloudSky> at half res
12
+ *
13
+ * Writes premultiplied scattering in rgb and transmittance in a, so the consumer does
14
+ * `dst = dst * a + rgb`. In object mode that is ordinary alpha blending with
15
+ * blendSrc ONE / blendDst SRC_ALPHA; the layer path composites explicitly.
16
+ */
17
+ const vertex = /* glsl */ `
18
+ out vec2 vUv;
19
+ out vec3 vWorld;
20
+ void main(){
21
+ vUv = uv;
22
+ vec4 wp = modelMatrix * vec4(position, 1.0);
23
+ vWorld = wp.xyz;
24
+ gl_Position = projectionMatrix * viewMatrix * wp;
25
+ }
26
+ `;
27
+ const fragment = /* glsl */ `
28
+ ${cloudFull}
29
+
30
+ in vec2 vUv;
31
+ in vec3 vWorld;
32
+ out vec4 outColor;
33
+
34
+ uniform sampler2D u_depth;
35
+ uniform float u_hasDepth;
36
+ uniform vec3 u_camPos, u_camFwd;
37
+ uniform mat4 u_invProj, u_camWorld;
38
+ uniform float u_near, u_far, u_frame;
39
+ uniform vec2 u_resolution;
40
+ uniform int u_steps;
41
+ uniform float u_stepGrowth, u_maxSpan, u_fogDensity, u_detailFade;
42
+ uniform float u_screenSpace;
43
+
44
+ #define MAX_STEPS 256
45
+
46
+ /** Interleaved gradient noise. Cheap, and it decorrelates well under a golden-ratio
47
+ * per-frame offset, which is what lets the temporal pass turn it into detail. */
48
+ float ign(vec2 p){
49
+ return fract(52.9829189 * fract(0.06711056 * p.x + 0.00583715 * p.y));
50
+ }
51
+
52
+ void main(){
53
+ vec2 uv = (u_screenSpace > 0.5) ? vUv : (gl_FragCoord.xy / u_resolution);
54
+ vec2 ndc = uv * 2.0 - 1.0;
55
+
56
+ vec4 vp = u_invProj * vec4(ndc, -1.0, 1.0);
57
+ vp /= vp.w;
58
+ vec3 rd = normalize(mat3(u_camWorld) * vp.xyz);
59
+ vec3 ro = u_camPos;
60
+
61
+ // Scene depth caps the march, so geometry can sit inside or behind the cloud rather
62
+ // than always in front of or behind it.
63
+ float maxT = 1e7;
64
+ if (u_hasDepth > 0.5){
65
+ float dz = texture(u_depth, uv).x;
66
+ if (dz < 0.999999){
67
+ float viewZ = (u_near * u_far) / ((u_far - u_near) * dz - u_far);
68
+ maxT = -viewZ / max(dot(rd, u_camFwd), 1e-4);
69
+ }
70
+ }
71
+
72
+ vec3 scattering = vec3(0.0);
73
+ float transmittance = 1.0;
74
+ float cloudDist = 0.0, distW = 0.0;
75
+
76
+ float t0, t1;
77
+ bool hit = (u_host < 0.5)
78
+ ? sphereRange(ro, rd, u_center, u_radius, t0, t1)
79
+ : layerRange(ro, rd, u_layerBottom, u_layerTop, t0, t1);
80
+
81
+ if (hit){
82
+ t1 = min(min(t1, maxT), t0 + u_maxSpan);
83
+ if (t1 > t0){
84
+ float mu = dot(rd, u_sunDir);
85
+ float span = t1 - t0;
86
+ float thick = (u_host < 0.5) ? (2.0 * u_radius) : max(u_layerTop - u_layerBottom, 1.0);
87
+
88
+ // The fine step is tied to CLOUD DEPTH, not to the span. A ray grazing a 2 km deck
89
+ // spans 100 km; dividing that by the step budget gives kilometre steps and every
90
+ // feature dissolves into fog. Empty space is skipped 2.8x coarser, and the step
91
+ // grows with distance to hold screen-space error roughly constant.
92
+ float dt0 = min(thick * 2.0 / float(u_steps), span / 8.0);
93
+ dt0 = max(dt0, thick * 0.004);
94
+ float big = dt0 * 2.8;
95
+
96
+ float jitter = fract(ign(gl_FragCoord.xy) + u_frame * 0.6180339887);
97
+ float t = t0 + dt0 * jitter;
98
+
99
+ bool inside = false;
100
+ int empty = 0;
101
+
102
+ for (int i = 0; i < MAX_STEPS; i++){
103
+ if (t >= t1 || transmittance < 0.015) break;
104
+
105
+ // Step size proportional to distance, which is what "constant screen-space
106
+ // error" actually means: a cloud 80 km out subtends a fraction of the pixels
107
+ // one 2 km out does. Without this a near-horizontal ray, which can span a
108
+ // hundred kilometres inside the deck, exhausts MAX_STEPS long before it
109
+ // exits and the deck simply stops along a straight line.
110
+ float dt = max(dt0, t * u_stepGrowth);
111
+ float grow = dt / dt0;
112
+ vec3 p = ro + rd * t;
113
+ float h = heightAt(p, t);
114
+
115
+ if (!inside){
116
+ if (cloudDensityCheap(p, h) > 0.0){
117
+ inside = true; empty = 0;
118
+ t = max(t - big * grow, t0); // step back once, then refine
119
+ continue;
120
+ }
121
+ t += big * grow;
122
+ continue;
123
+ }
124
+
125
+ float d = cloudDensity(p, h, saturate(1.0 - t * u_detailFade));
126
+ if (d <= 0.0){
127
+ empty++;
128
+ if (empty > 8){ inside = false; empty = 0; }
129
+ t += dt;
130
+ continue;
131
+ }
132
+ empty = 0;
133
+
134
+ float sigmaE = d * u_sigmaT;
135
+ float lightD = lightMarch(p, t);
136
+
137
+ vec3 amb = (u_skyAmbient * pow(saturate(h), 0.7)
138
+ + u_groundAmbient * pow(saturate(1.0 - h), 0.9) * 0.5)
139
+ * u_ambient * exp(-lightD * u_sigmaT * 0.08);
140
+
141
+ // Powder / dark-edge. Only when looking away from the sun, or it double-darkens
142
+ // backlit rims that should be the brightest thing in frame.
143
+ float pw = 1.0 - exp(-lightD * u_sigmaT * 2.4);
144
+ pw = mix(1.0, pw, saturate(-mu * 0.5 + 0.5) * u_powder);
145
+
146
+ vec3 S = (u_sunColor * (u_sunIntensity * SUN_RADIANCE)
147
+ * scatterEnergy(lightD, mu) * pw * cloudAlbedo(h)
148
+ + amb) * sigmaE;
149
+
150
+ // Hillaire's energy-conserving integration, not S * dt * T.
151
+ float trs = exp(-sigmaE * dt);
152
+ scattering += transmittance * ((S - S * trs) / max(sigmaE, 1e-6));
153
+
154
+ float wgt = transmittance * (1.0 - trs);
155
+ cloudDist += t * wgt; distW += wgt;
156
+ transmittance *= trs;
157
+ t += dt;
158
+ }
159
+
160
+ // Aerial perspective. Deliberately does NOT blend toward skyRadiance(): the
161
+ // visible background is whatever SkyController / Skybox drew, and fading a
162
+ // distant deck toward a DIFFERENT, analytic sky paints a glowing band along
163
+ // the horizon that exists in no other part of the scene.
164
+ //
165
+ // Physically the air between camera and cloud both attenuates the cloud and
166
+ // adds its own in-scattered light — and that in-scattered light is, to a good
167
+ // approximation, exactly the background you would see looking that way with no
168
+ // cloud there. So attenuate the cloud and open the transmittance; the composite
169
+ // then lets the real background through and the two terms come out right,
170
+ // whatever sky is behind.
171
+ if (distW > 0.0){
172
+ float dist = cloudDist / distW;
173
+ float fogT = exp(-dist * u_fogDensity);
174
+ scattering *= fogT;
175
+ transmittance = mix(1.0, transmittance, fogT);
176
+ }
177
+ }
178
+ }
179
+
180
+ outColor = vec4(scattering, transmittance);
181
+ }
182
+ `;
183
+ export const cloudVolumeDefaults = {
184
+ u_base: null,
185
+ u_detail: null,
186
+ u_weather: null,
187
+ u_curl: null,
188
+ u_depth: null,
189
+ u_hasDepth: 0,
190
+ u_time: 0,
191
+ u_frame: 0,
192
+ u_sunDir: new THREE.Vector3(0.3, 0.4, 0.86).normalize(),
193
+ u_sunColor: new THREE.Color(1, 1, 1),
194
+ u_sunIntensity: 1,
195
+ u_turbidity: 1,
196
+ u_rayleigh: 1,
197
+ u_mieCoefficient: 0.005,
198
+ u_mieG: 0.76,
199
+ u_skyAmbient: new THREE.Color(0.32, 0.5, 0.86),
200
+ u_groundAmbient: new THREE.Color(0.24, 0.22, 0.19),
201
+ u_coverage: 0.52,
202
+ u_density: 2.6,
203
+ u_cloudType: 0.52,
204
+ u_baseScale: 1 / 2600,
205
+ u_detailScale: 1 / 400,
206
+ u_detailStrength: 0.5,
207
+ u_curlStrength: 0.55,
208
+ u_layerBottom: 1500,
209
+ u_layerTop: 3400,
210
+ u_shear: 0.08,
211
+ u_anvil: 0,
212
+ u_precip: 0,
213
+ u_weatherScale: 1 / 24000,
214
+ u_evolution: 0.45,
215
+ u_windDir: new THREE.Vector2(1, 0.22).normalize(),
216
+ u_windSpeed: 6,
217
+ u_rise: 1.4,
218
+ u_churn: 4.5,
219
+ u_sigmaT: 0.013,
220
+ u_g1: 0.8,
221
+ u_g2: 0.32,
222
+ u_msExtinction: 0.55,
223
+ u_msEnergy: 0.58,
224
+ u_msPhase: 0.6,
225
+ u_powder: 0.85,
226
+ u_silver: 0.9,
227
+ u_ambient: 1,
228
+ u_steps: 96,
229
+ u_lightSteps: 6,
230
+ u_lightStep: 0.024,
231
+ u_stepGrowth: 0.0045,
232
+ u_maxSpan: 120000,
233
+ u_detailFade: 1 / 16000,
234
+ u_host: 0,
235
+ u_center: new THREE.Vector3(0, 620, 0),
236
+ u_radius: 520,
237
+ u_curvature: 1 / (2 * 6371000),
238
+ u_fogDensity: 0.000026,
239
+ u_camPos: new THREE.Vector3(),
240
+ u_camFwd: new THREE.Vector3(0, 0, -1),
241
+ u_invProj: new THREE.Matrix4(),
242
+ u_camWorld: new THREE.Matrix4(),
243
+ u_near: 1,
244
+ u_far: 100000,
245
+ u_resolution: new THREE.Vector2(1, 1),
246
+ u_screenSpace: 0
247
+ };
248
+ export const CloudVolumeMaterial = shaderMaterial(cloudVolumeDefaults, vertex, fragment);
249
+ extend({ CloudVolumeMaterial });
@@ -0,0 +1,21 @@
1
+ import * as THREE from 'three';
2
+ import { type ThreeElement } from '@react-three/fiber';
3
+ export declare const SkyBackgroundMaterial: import("@react-three/fiber").ConstructorRepresentation<THREE.ShaderMaterial & {
4
+ u_sunDir: THREE.Vector3;
5
+ u_sunColor: THREE.Color;
6
+ u_sunIntensity: number;
7
+ u_turbidity: number;
8
+ u_rayleigh: number;
9
+ u_mieCoefficient: number;
10
+ u_mieG: number;
11
+ u_invProj: THREE.Matrix4;
12
+ u_camWorld: THREE.Matrix4;
13
+ }> & {
14
+ key: string;
15
+ };
16
+ declare module '@react-three/fiber' {
17
+ interface ThreeElements {
18
+ skyBackgroundMaterial: ThreeElement<typeof SkyBackgroundMaterial>;
19
+ }
20
+ }
21
+ //# sourceMappingURL=SkyBackgroundMaterial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SkyBackgroundMaterial.d.ts","sourceRoot":"","sources":["../../../src/shaders/clouds/SkyBackgroundMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAgC9D,eAAO,MAAM,qBAAqB;;;;;;;;;;;;CAcjC,CAAA;AAID,OAAO,QAAQ,oBAAoB,CAAC;IAClC,UAAU,aAAa;QACrB,qBAAqB,EAAE,YAAY,CAAC,OAAO,qBAAqB,CAAC,CAAA;KAClE;CACF"}
@@ -0,0 +1,42 @@
1
+ import * as THREE from 'three';
2
+ import { shaderMaterial } from '@react-three/drei';
3
+ import { extend } from '@react-three/fiber';
4
+ import { cloudCommon, skyLib } from '../glsl/cloudCore.glsl.js';
5
+ /**
6
+ * The analytic sky the clouds are lit against. Sharing one sky function between the
7
+ * background, the clouds' ambient term and their aerial perspective is what keeps a
8
+ * cloud looking like it belongs in the sky behind it rather than pasted onto it.
9
+ *
10
+ * Drawn as a fullscreen quad with depth writes off, so the depth buffer stays clear and
11
+ * the cloud march still sees "no geometry here".
12
+ */
13
+ const vertex = /* glsl */ `
14
+ out vec2 vUv;
15
+ void main(){ vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }
16
+ `;
17
+ const fragment = /* glsl */ `
18
+ ${cloudCommon}
19
+ precision highp float;
20
+ ${skyLib}
21
+ in vec2 vUv;
22
+ out vec4 outColor;
23
+ uniform mat4 u_invProj, u_camWorld;
24
+ void main(){
25
+ vec2 ndc = vUv * 2.0 - 1.0;
26
+ vec4 vp = u_invProj * vec4(ndc, -1.0, 1.0); vp /= vp.w;
27
+ vec3 rd = normalize(mat3(u_camWorld) * vp.xyz);
28
+ outColor = vec4(skyRadiance(rd) + sunDisc(rd), 1.0);
29
+ }
30
+ `;
31
+ export const SkyBackgroundMaterial = shaderMaterial({
32
+ u_sunDir: new THREE.Vector3(0.3, 0.4, 0.86).normalize(),
33
+ u_sunColor: new THREE.Color(1, 1, 1),
34
+ u_sunIntensity: 1,
35
+ u_turbidity: 1,
36
+ u_rayleigh: 1,
37
+ u_mieCoefficient: 0.005,
38
+ u_mieG: 0.76,
39
+ u_invProj: new THREE.Matrix4(),
40
+ u_camWorld: new THREE.Matrix4()
41
+ }, vertex, fragment);
42
+ extend({ SkyBackgroundMaterial });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shared cloud core. Imported by CloudVolumeMaterial and by any surface material that
3
+ * wants cloud shadows. Nothing here is per-type: the four cloud models differ by the
4
+ * height-gradient blend (u_cloudType), the shear/anvil/precipitation terms, and their
5
+ * configs — not by separate shader code.
6
+ *
7
+ * Fragment shaders including this MUST be compiled with glslVersion: THREE.GLSL3.
8
+ * GLSL ES 3.00 declares no default precision for sampler3D, so the precision lines
9
+ * below are required, not decoration.
10
+ */
11
+ export declare const cloudCommon = "\n#define PI 3.14159265359\n#define saturate(x) clamp(x, 0.0, 1.0)\nfloat remap(float v, float a, float b, float c, float d){\n return c + (v - a) * (d - c) / max(b - a, 1e-6);\n}\n";
12
+ /** Analytic single-scattering sky. Also supplies the clouds' ambient and aerial perspective. */
13
+ export declare const skyLib = "\nuniform vec3 u_sunDir;\nuniform vec3 u_sunColor;\nuniform float u_sunIntensity;\n\n// The four Preetham parameters, taken straight from SkySettings so the clouds are\n// lit by the same atmosphere SkyController draws. Hardcoding them here is exactly\n// what makes cloud lighting drift away from the sky behind it.\nuniform float u_turbidity;\nuniform float u_rayleigh;\nuniform float u_mieCoefficient;\nuniform float u_mieG;\n\n/** Sun radiance in the same units skyRadiance() returns. Phase functions integrate to 1\n * over the sphere, so they return ~1/4pi; without a real radiance the clouds render black. */\nconst float SUN_RADIANCE = 22.0;\n\nfloat rayleighPhase(float mu){ return (3.0 / (16.0 * PI)) * (1.0 + mu * mu); }\nfloat miePhaseHG(float mu, float g){\n float g2 = g * g;\n return (1.0 - g2) / (4.0 * PI * pow(max(1.0 + g2 - 2.0 * g * mu, 1e-4), 1.5));\n}\n/** Kasten-Young relative air mass. */\nfloat airMass(float cy){\n float z = degrees(acos(clamp(cy, -1.0, 1.0)));\n return min(1.0 / (max(cy, 0.0) + 0.15 * pow(max(93.885 - z, 0.5), -1.253)), 40.0);\n}\n\nvec3 skyRadiance(vec3 rd){\n float mu = dot(rd, u_sunDir);\n float up = rd.y;\n float am = airMass(max(up, -0.02));\n\n vec3 bR = vec3(0.0487, 0.1130, 0.2780) * u_turbidity * u_rayleigh;\n float bM = u_mieCoefficient * u_turbidity * 4.25;\n vec3 ext = bR * am + vec3(bM * am * 1.2);\n\n // A single-scattering model that applies the full reddened beam everywhere turns the\n // zenith teal at low sun. Most zenith light is in reality multiply scattered, so the\n // Rayleigh term sees a partly whitened sun; only the Mie glow keeps the full depth.\n vec3 rayCol = mix(u_sunColor, vec3(1.0), 0.60);\n vec3 insR = bR * am * rayleighPhase(mu) * rayCol;\n vec3 insM = vec3(bM * am * miePhaseHG(mu, u_mieG) * 1.3) * u_sunColor;\n\n vec3 col = ((insR + insM) / max(ext, vec3(1e-4))) * (1.0 - exp(-ext)) * 26.0;\n\n float below = saturate(-up * 14.0);\n vec3 groundCol = vec3(0.055, 0.052, 0.048) * u_sunColor * (0.25 + 0.75 * saturate(u_sunDir.y));\n return mix(col, groundCol, below);\n}\n\nvec3 sunDisc(vec3 rd){\n float mu = dot(rd, u_sunDir);\n float d = smoothstep(0.99976, 0.99992, mu);\n float limb = 1.0 - 0.42 * saturate((0.99992 - mu) / 0.00016);\n return u_sunColor * u_sunIntensity * d * limb * 42.0;\n}\n";
14
+ /** Every uniform the density field reads. Include before cloudDensity. */
15
+ export declare const cloudUniforms = "\nprecision highp float;\nprecision highp sampler3D;\nprecision highp sampler2D;\n\nuniform sampler3D u_base;\nuniform sampler3D u_detail;\nuniform sampler2D u_weather;\nuniform sampler2D u_curl;\nuniform float u_time;\n\nuniform float u_coverage, u_density, u_cloudType;\nuniform float u_baseScale, u_detailScale, u_detailStrength, u_curlStrength;\nuniform float u_layerBottom, u_layerTop, u_shear, u_anvil, u_precip;\nuniform float u_weatherScale, u_evolution;\nuniform vec2 u_windDir;\nuniform float u_windSpeed, u_rise, u_churn;\nuniform float u_host, u_radius, u_curvature;\nuniform vec3 u_center;\n";
16
+ export declare const cloudDensity = "\n/**\n * Height fraction inside the cloud body.\n * In layer mode the ray is bent by planetary curvature (t^2 / 2R) so the deck meets a\n * real horizon instead of running to infinity as a flat slab would. Bending the ray is\n * equivalent to raising the sample's altitude and keeps coordinates small, which a\n * literal 6371 km sphere does not.\n */\nfloat heightAt(vec3 p, float t){\n if (u_host < 0.5){\n return saturate((p.y - (u_center.y - u_radius)) / max(2.0 * u_radius, 1.0));\n }\n float y = p.y + t * t * u_curvature;\n return saturate((y - u_layerBottom) / max(u_layerTop - u_layerBottom, 1.0));\n}\n\n/** Two scales scrolling at different rates: coverage evolves rather than slides past. */\nvec4 sampleWeather(vec3 p){\n vec2 b = p.xz * u_weatherScale;\n vec2 drift = u_windDir * (u_time * u_windSpeed * 0.16) * u_weatherScale;\n vec4 a = texture(u_weather, b + drift);\n vec4 c = texture(u_weather, b * 2.17 - drift * 1.63 + vec2(0.31, 0.73));\n return mix(a, c, 0.36);\n}\n\n/**\n * Three archetypal vertical profiles, blended by type. This is what makes the four\n * models genuinely different shapes rather than one shape with different noise.\n * 0.0 stratus thin, bottom-weighted, flat top\n * 0.5 cumulus flat base, bulge in the upper middle, eroded cauliflower top\n * 1.0 cumulonimbus holds density to the tropopause, then spreads\n */\nfloat heightGradient(float h, float ty){\n float stratus = saturate(remap(h, 0.00, 0.06, 0.0, 1.0)) * saturate(remap(h, 0.20, 0.36, 1.0, 0.0));\n float cumulus = saturate(remap(h, 0.02, 0.20, 0.0, 1.0)) * saturate(remap(h, 0.56, 0.96, 1.0, 0.0));\n float cumulon = saturate(remap(h, 0.01, 0.09, 0.0, 1.0)) * saturate(remap(h, 0.82, 1.00, 1.0, 0.0));\n return mix(mix(stratus, cumulus, saturate(ty * 2.0)), cumulon, saturate((ty - 0.5) * 2.0));\n}\n\n/**\n * @param detail 0..1 \u2014 fades high-frequency erosion out with distance. Without it the\n * finest worley octave beats against the step size and the far field speckles.\n */\nfloat cloudDensity(vec3 p, float h, float detail){\n if (h <= 0.001 || h >= 0.999) return 0.0;\n\n vec4 w = sampleWeather(p);\n float ty = saturate(u_cloudType + (w.b - 0.5) * 0.30);\n\n float cov = mix(w.r, w.g, 0.40);\n // Slow formation and decay: the coverage threshold itself breathes.\n cov += sin(u_time * 0.041 + w.b * 12.6) * 0.5 * u_evolution * 0.16;\n\n // The window slides AND narrows with coverage. Remapping to a fixed upper bound of 1.0\n // caps effective coverage near the weather map's median (~0.5), so overcast is\n // unreachable no matter how high the slider goes.\n cov = saturate(remap(cov, 1.0 - u_coverage, 1.0 - u_coverage * 0.35, 0.0, 1.0));\n if (cov <= 0.0) return 0.0;\n\n // Anvil: above the equilibrium level a storm spreads laterally. Gated on type so a\n // fair-weather cumulus never grows one.\n float anvil = saturate(remap(h, 0.70, 1.0, 0.0, 1.0)) * u_anvil * saturate((ty - 0.5) * 2.0);\n cov = saturate(mix(cov, cov * 1.9, anvil));\n\n // Object host: fade coverage toward the bounding sphere so the volume is not sliced\n // flat by its own container. Through coverage, not final density, so the detail\n // erosion still bites into the boundary and the silhouette stays ragged.\n if (u_host < 0.5){\n float rad = length(p - u_center) / max(u_radius, 1.0);\n cov *= saturate(remap(rad, 0.50, 0.97, 1.0, 0.0));\n if (cov <= 0.0) return 0.0;\n }\n\n // Wind shear tilts the column with altitude; then advection; then convective rise.\n // Three decoupled timescales is what reads as delicate rather than scrolling.\n vec3 sp = p;\n float thick = (u_host < 0.5) ? (2.0 * u_radius) : max(u_layerTop - u_layerBottom, 1.0);\n sp.xz += u_windDir * (h * u_shear * thick);\n sp.xz += u_windDir * (u_time * u_windSpeed);\n sp.y -= u_time * u_rise;\n\n vec4 b = texture(u_base, sp * u_baseScale);\n float lowFbm = b.g * 0.625 + b.b * 0.25 + b.a * 0.125;\n float shape = saturate(remap(b.r, lowFbm - 1.0, 1.0, 0.0, 1.0));\n shape *= heightGradient(h, ty);\n\n float d = saturate(remap(shape, 1.0 - cov, 1.0, 0.0, 1.0)) * cov;\n if (d <= 0.0) return 0.0;\n\n if (detail > 0.01){\n vec2 curl = texture(u_curl, sp.xz * u_baseScale * 2.4).rg * 2.0 - 1.0;\n vec3 dp = sp;\n // Curl warp is strongest at the base, where a cloud shears out into wisps.\n dp.xz += curl * u_curlStrength * (1.0 - h) * 260.0;\n dp.y -= u_time * u_churn;\n vec3 dn = texture(u_detail, dp * u_detailScale).rgb;\n float dFbm = dn.r * 0.625 + dn.g * 0.25 + dn.b * 0.125;\n // Wispy erosion low down, billowy erosion up top.\n float m = mix(1.0 - dFbm, dFbm, saturate(h * 3.2));\n d = saturate(remap(d, m * u_detailStrength * detail, 1.0, 0.0, 1.0));\n }\n\n return d * u_density;\n}\n\n/**\n * Scattering albedo. Rain-bearing cloud base holds large drops, which absorb far more\n * than the small droplets higher up \u2014 this is why a storm base is charcoal while its\n * top is brilliant white, and it is not something extinction alone reproduces.\n */\nfloat cloudAlbedo(float h){\n return mix(1.0, 0.22, u_precip * saturate(remap(h, 0.30, 0.02, 0.0, 1.0)));\n}\n\nfloat cloudDensityCheap(vec3 p, float h){ return cloudDensity(p, h, 0.0); }\n";
17
+ /** Ray/layer and ray/sphere intersection. */
18
+ export declare const cloudGeometry = "\n/**\n * Roots of a*t^2 + rd.y*t + (ro.y - h) = 0 with a = 1/(2R).\n * The naive quadratic formula cancels catastrophically here: a is ~1e-7, so\n * (-b + sqrt(b*b - 4ac)) / 2a returns noise for steep rays and the deck vanishes\n * directly overhead. The stable form below is not optional.\n */\nint layerRoots(vec3 ro, vec3 rd, float h, out float r1, out float r2){\n float a = u_curvature, b = rd.y, c = ro.y - h;\n r1 = 1e20; r2 = 1e20;\n if (a < 1e-12){\n if (abs(b) < 1e-7) return 0;\n float t = -c / b;\n if (t > 0.0){ r1 = t; return 1; }\n return 0;\n }\n float disc = b * b - 4.0 * a * c;\n if (disc < 0.0) return 0;\n float sq = sqrt(disc);\n float q = -0.5 * (b + (b >= 0.0 ? sq : -sq));\n if (abs(q) < 1e-20) return 0;\n float ta = q / a;\n float tb = c / q;\n float lo = min(ta, tb), hi = max(ta, tb);\n int n = 0;\n if (lo > 0.0){ r1 = lo; n = 1; }\n if (hi > 0.0){ if (n == 0){ r1 = hi; n = 1; } else { r2 = hi; n = 2; } }\n return n;\n}\n\nbool layerRange(vec3 ro, vec3 rd, float hb, float ht, out float t0, out float t1){\n float b1, b2, c1, c2;\n int nb = layerRoots(ro, rd, hb, b1, b2);\n int nt = layerRoots(ro, rd, ht, c1, c2);\n float ts[4]; int n = 0;\n if (nb > 0){ ts[n] = b1; n++; }\n if (nb > 1){ ts[n] = b2; n++; }\n if (nt > 0){ ts[n] = c1; n++; }\n if (nt > 1){ ts[n] = c2; n++; }\n if (n == 0){\n if (ro.y > hb && ro.y < ht){ t0 = 0.0; t1 = 120000.0; return true; }\n return false;\n }\n for (int i = 0; i < 4; i++)\n for (int j = i + 1; j < 4; j++){\n if (j < n && ts[j] < ts[i]){ float tmp = ts[i]; ts[i] = ts[j]; ts[j] = tmp; }\n }\n bool inside = (ro.y > hb && ro.y < ht);\n if (inside){ t0 = 0.0; t1 = ts[0]; }\n else { t0 = ts[0]; t1 = (n > 1) ? ts[n - 1] : ts[0] + 6000.0; }\n return t1 > t0;\n}\n\nbool sphereRange(vec3 ro, vec3 rd, vec3 c, float r, out float t0, out float t1){\n vec3 oc = ro - c;\n float b = dot(oc, rd);\n float cc = dot(oc, oc) - r * r;\n float disc = b * b - cc;\n if (disc < 0.0) return false;\n float sq = sqrt(disc);\n t0 = max(-b - sq, 0.0);\n t1 = -b + sq;\n return t1 > t0;\n}\n";
19
+ export declare const cloudLighting = "\nuniform float u_sigmaT, u_g1, u_g2;\nuniform float u_msExtinction, u_msEnergy, u_msPhase;\nuniform float u_powder, u_silver, u_ambient;\nuniform vec3 u_skyAmbient, u_groundAmbient;\nuniform int u_lightSteps;\nuniform float u_lightStep;\n\nfloat hg(float mu, float g){\n float g2 = g * g;\n return (1.0 - g2) / (4.0 * PI * pow(max(1.0 + g2 - 2.0 * g * mu, 1e-4), 1.5));\n}\n/** Forward lobe carries the silver lining; the small backward lobe is the glow you get\n * when the sun is behind you. A single lobe cannot do both. */\nfloat dualLobe(float mu, float g1, float g2){\n return mix(hg(mu, g1), hg(mu, -abs(g2)), 0.42);\n}\n\nconst vec3 kCone[6] = vec3[6](\n vec3( 0.38, 0.35, 0.14), vec3(-0.20, 0.60,-0.30), vec3(-0.50,-0.20, 0.40),\n vec3( 0.10,-0.55,-0.35), vec3( 0.55, 0.10,-0.55), vec3(-0.15, 0.25, 0.62)\n);\n\n/**\n * Six exponentially growing samples toward the sun, spread inside a cone so the\n * self-shadow is soft instead of banded, plus one long-range probe for distant occluders.\n * The step is a FRACTION of cloud depth, not metres: the same absolute value is wrong\n * for an 800 m deck and an 8 km tower.\n */\nfloat lightMarch(vec3 p, float rayT){\n float thick = (u_host < 0.5) ? (2.0 * u_radius) : max(u_layerTop - u_layerBottom, 1.0);\n float st = u_lightStep * thick;\n float acc = 0.0;\n float t = 0.0;\n for (int i = 0; i < 6; i++){\n if (i >= u_lightSteps) break;\n vec3 sp = p + u_sunDir * (t + st * 0.5) + kCone[i] * (t * 0.38);\n acc += cloudDensityCheap(sp, heightAt(sp, rayT)) * st;\n t += st;\n st *= 1.62;\n }\n vec3 fp = p + u_sunDir * (t * 2.6);\n acc += cloudDensityCheap(fp, heightAt(fp, rayT)) * st * 2.0;\n return acc;\n}\n\n/**\n * Wrenninge / Hillaire multiple-scattering octaves: each octave scales extinction,\n * energy and phase anisotropy down. A real cumulus has optical depth 5-40 and stays\n * white only because photons scatter hundreds of times; first-order exp(-tau) alone\n * renders it black. This approximation is the single biggest difference between a\n * physically-grounded cloud and a generic one.\n */\nvec3 scatterEnergy(float lightD, float mu){\n vec3 L = vec3(0.0);\n float a = 1.0, b = 1.0, c = 1.0;\n for (int n = 0; n < 3; n++){\n float ph = dualLobe(mu, u_g1 * c, u_g2 * c);\n L += vec3(b * ph * exp(-lightD * u_sigmaT * a));\n a *= u_msExtinction; b *= u_msEnergy; c *= u_msPhase;\n }\n L += vec3(u_silver * pow(saturate(mu), 8.0) * exp(-lightD * u_sigmaT * 0.35));\n return L;\n}\n";
20
+ /** Everything a fragment shader needs to evaluate the density field. */
21
+ export declare const cloudField: string;
22
+ /** The full model, including scattering. */
23
+ export declare const cloudFull: string;
24
+ //# sourceMappingURL=cloudCore.glsl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudCore.glsl.d.ts","sourceRoot":"","sources":["../../../src/shaders/glsl/cloudCore.glsl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,eAAO,MAAM,WAAW,2LAMvB,CAAA;AAED,gGAAgG;AAChG,eAAO,MAAM,MAAM,qxEAyDlB,CAAA;AAED,0EAA0E;AAC1E,eAAO,MAAM,aAAa,mmBAmBzB,CAAA;AAED,eAAO,MAAM,YAAY,spKAmHxB,CAAA;AAED,6CAA6C;AAC7C,eAAO,MAAM,aAAa,kkEAgEzB,CAAA;AAED,eAAO,MAAM,aAAa,88EAgEzB,CAAA;AAED,wEAAwE;AACxE,eAAO,MAAM,UAAU,QAA+E,CAAA;AAEtG,4CAA4C;AAC5C,eAAO,MAAM,SAAS,QAAyC,CAAA"}