@3driseai/3drise-viewer 0.1.6 → 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.
- package/dist/components/Clouds.d.ts.map +1 -1
- package/dist/components/Clouds.js +0 -1
- package/dist/components/CloudsGenerator.d.ts +32 -0
- package/dist/components/CloudsGenerator.d.ts.map +1 -0
- package/dist/components/CloudsGenerator.js +58 -0
- package/dist/components/CustomPrimitive.js +1 -1
- package/dist/components/EnvironmentManager.d.ts +47 -5
- package/dist/components/EnvironmentManager.d.ts.map +1 -1
- package/dist/components/EnvironmentManager.js +35 -66
- package/dist/components/GeometryShape.d.ts.map +1 -1
- package/dist/components/GeometryShape.js +19 -3
- package/dist/components/HdrEnvironment.d.ts +20 -0
- package/dist/components/HdrEnvironment.d.ts.map +1 -0
- package/dist/components/HdrEnvironment.js +44 -0
- package/dist/components/LandscapeBuilder.d.ts +23 -0
- package/dist/components/LandscapeBuilder.d.ts.map +1 -0
- package/dist/components/LandscapeBuilder.js +25 -0
- package/dist/components/LandscapeObject.d.ts +24 -0
- package/dist/components/LandscapeObject.d.ts.map +1 -0
- package/dist/components/LandscapeObject.js +27 -0
- package/dist/components/ObjectNode.d.ts.map +1 -1
- package/dist/components/ObjectNode.js +11 -9
- package/dist/components/OceanBuilder.d.ts +35 -0
- package/dist/components/OceanBuilder.d.ts.map +1 -0
- package/dist/components/OceanBuilder.js +53 -0
- package/dist/components/ParticlesR3f.d.ts.map +1 -1
- package/dist/components/ParticlesR3f.js +63 -12
- package/dist/components/PointCloud.d.ts.map +1 -1
- package/dist/components/PointCloud.js +50 -10
- package/dist/components/SceneBuilder.d.ts.map +1 -1
- package/dist/components/SkySystem.d.ts +27 -6
- package/dist/components/SkySystem.d.ts.map +1 -1
- package/dist/components/SkySystem.js +6 -5
- package/dist/components/SunLight.d.ts.map +1 -1
- package/dist/components/SunLight.js +4 -1
- package/dist/components/TerrainBuilder.d.ts +30 -0
- package/dist/components/TerrainBuilder.d.ts.map +1 -0
- package/dist/components/TerrainBuilder.js +44 -0
- package/dist/components/index.d.ts +17 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +10 -0
- package/dist/components/landscape/LandscapeMesh.d.ts +18 -0
- package/dist/components/landscape/LandscapeMesh.d.ts.map +1 -0
- package/dist/components/landscape/LandscapeMesh.js +278 -0
- package/dist/components/landscape/index.d.ts +3 -0
- package/dist/components/landscape/index.d.ts.map +1 -0
- package/dist/components/landscape/index.js +1 -0
- package/dist/components/landscape/types.d.ts +13 -0
- package/dist/components/landscape/types.d.ts.map +1 -0
- package/dist/components/landscape/types.js +1 -0
- package/dist/components/terrain/Canyon.d.ts +23 -0
- package/dist/components/terrain/Canyon.d.ts.map +1 -0
- package/dist/components/terrain/Canyon.js +29 -0
- package/dist/components/terrain/Dunes.d.ts +22 -0
- package/dist/components/terrain/Dunes.d.ts.map +1 -0
- package/dist/components/terrain/Dunes.js +25 -0
- package/dist/components/terrain/Hills.d.ts +17 -0
- package/dist/components/terrain/Hills.d.ts.map +1 -0
- package/dist/components/terrain/Hills.js +20 -0
- package/dist/components/terrain/Mountains.d.ts +19 -0
- package/dist/components/terrain/Mountains.d.ts.map +1 -0
- package/dist/components/terrain/Mountains.js +22 -0
- package/dist/components/terrain/TerrainSurface.d.ts +22 -0
- package/dist/components/terrain/TerrainSurface.d.ts.map +1 -0
- package/dist/components/terrain/TerrainSurface.js +94 -0
- package/dist/components/terrain/index.d.ts +7 -0
- package/dist/components/terrain/index.d.ts.map +1 -0
- package/dist/components/terrain/index.js +7 -0
- package/dist/components/terrain/types.d.ts +17 -0
- package/dist/components/terrain/types.d.ts.map +1 -0
- package/dist/components/terrain/types.js +1 -0
- package/dist/components/volumetricClouds/Cirrus.d.ts +14 -0
- package/dist/components/volumetricClouds/Cirrus.d.ts.map +1 -0
- package/dist/components/volumetricClouds/Cirrus.js +13 -0
- package/dist/components/volumetricClouds/Cumulonimbus.d.ts +17 -0
- package/dist/components/volumetricClouds/Cumulonimbus.d.ts.map +1 -0
- package/dist/components/volumetricClouds/Cumulonimbus.js +20 -0
- package/dist/components/volumetricClouds/Cumulus.d.ts +14 -0
- package/dist/components/volumetricClouds/Cumulus.d.ts.map +1 -0
- package/dist/components/volumetricClouds/Cumulus.js +17 -0
- package/dist/components/volumetricClouds/Stratocumulus.d.ts +12 -0
- package/dist/components/volumetricClouds/Stratocumulus.d.ts.map +1 -0
- package/dist/components/volumetricClouds/Stratocumulus.js +16 -0
- package/dist/components/volumetricClouds/VolumetricCloudsPass.d.ts +42 -0
- package/dist/components/volumetricClouds/VolumetricCloudsPass.d.ts.map +1 -0
- package/dist/components/volumetricClouds/VolumetricCloudsPass.js +298 -0
- package/dist/components/volumetricClouds/index.d.ts +8 -0
- package/dist/components/volumetricClouds/index.d.ts.map +1 -0
- package/dist/components/volumetricClouds/index.js +7 -0
- package/dist/components/volumetricClouds/types.d.ts +17 -0
- package/dist/components/volumetricClouds/types.d.ts.map +1 -0
- package/dist/components/volumetricClouds/types.js +1 -0
- package/dist/components/water/Host.d.ts +12 -0
- package/dist/components/water/Host.d.ts.map +1 -0
- package/dist/components/water/Host.js +12 -0
- package/dist/components/water/Lake.d.ts +18 -0
- package/dist/components/water/Lake.d.ts.map +1 -0
- package/dist/components/water/Lake.js +21 -0
- package/dist/components/water/OceanSurface.d.ts +27 -0
- package/dist/components/water/OceanSurface.d.ts.map +1 -0
- package/dist/components/water/OceanSurface.js +60 -0
- package/dist/components/water/Sea.d.ts +18 -0
- package/dist/components/water/Sea.d.ts.map +1 -0
- package/dist/components/water/Sea.js +17 -0
- package/dist/components/water/Shore.d.ts +16 -0
- package/dist/components/water/Shore.d.ts.map +1 -0
- package/dist/components/water/Shore.js +15 -0
- package/dist/components/water/Storm.d.ts +14 -0
- package/dist/components/water/Storm.d.ts.map +1 -0
- package/dist/components/water/Storm.js +13 -0
- package/dist/components/water/WaterBody.d.ts +31 -0
- package/dist/components/water/WaterBody.d.ts.map +1 -0
- package/dist/components/water/WaterBody.js +76 -0
- package/dist/components/water/index.d.ts +9 -0
- package/dist/components/water/index.d.ts.map +1 -0
- package/dist/components/water/index.js +11 -0
- package/dist/components/water/types.d.ts +20 -0
- package/dist/components/water/types.d.ts.map +1 -0
- package/dist/components/water/types.js +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +15 -0
- package/dist/hooks/index.d.ts +24 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +12 -0
- package/dist/hooks/useClipmap.d.ts +71 -0
- package/dist/hooks/useClipmap.d.ts.map +1 -0
- package/dist/hooks/useClipmap.js +81 -0
- package/dist/hooks/useCloudLive.d.ts +29 -0
- package/dist/hooks/useCloudLive.d.ts.map +1 -0
- package/dist/hooks/useCloudLive.js +43 -0
- package/dist/hooks/useCloudNoise.d.ts +28 -0
- package/dist/hooks/useCloudNoise.d.ts.map +1 -0
- package/dist/hooks/useCloudNoise.js +128 -0
- package/dist/hooks/useCloudSun.d.ts +49 -0
- package/dist/hooks/useCloudSun.d.ts.map +1 -0
- package/dist/hooks/useCloudSun.js +84 -0
- package/dist/hooks/useCubeCamera.d.ts +27 -9
- package/dist/hooks/useCubeCamera.d.ts.map +1 -1
- package/dist/hooks/useCubeCamera.js +28 -70
- package/dist/hooks/useEnvironmentProbe.d.ts +32 -0
- package/dist/hooks/useEnvironmentProbe.d.ts.map +1 -0
- package/dist/hooks/useEnvironmentProbe.js +35 -0
- package/dist/hooks/useFrameRenderer.d.ts +15 -0
- package/dist/hooks/useFrameRenderer.d.ts.map +1 -0
- package/dist/hooks/useFrameRenderer.js +23 -0
- package/dist/hooks/useLandscapeLive.d.ts +29 -0
- package/dist/hooks/useLandscapeLive.d.ts.map +1 -0
- package/dist/hooks/useLandscapeLive.js +41 -0
- package/dist/hooks/useLandscapeMaps.d.ts +32 -0
- package/dist/hooks/useLandscapeMaps.d.ts.map +1 -0
- package/dist/hooks/useLandscapeMaps.js +138 -0
- package/dist/hooks/useMaterialApplication.d.ts.map +1 -1
- package/dist/hooks/useMaterialApplication.js +2 -3
- package/dist/hooks/useMaterialOptions.d.ts +2 -2
- package/dist/hooks/useMaterialOptions.d.ts.map +1 -1
- package/dist/hooks/useMaterialOptions.js +13 -31
- package/dist/hooks/useObjectEdges.d.ts.map +1 -1
- package/dist/hooks/useObjectEdges.js +3 -49
- package/dist/hooks/useOceanLive.d.ts +29 -0
- package/dist/hooks/useOceanLive.d.ts.map +1 -0
- package/dist/hooks/useOceanLive.js +38 -0
- package/dist/hooks/useOceanMaterial.d.ts +39 -0
- package/dist/hooks/useOceanMaterial.d.ts.map +1 -0
- package/dist/hooks/useOceanMaterial.js +65 -0
- package/dist/hooks/useTerrainClipmap.d.ts +12 -0
- package/dist/hooks/useTerrainClipmap.d.ts.map +1 -0
- package/dist/hooks/useTerrainClipmap.js +10 -0
- package/dist/hooks/useTerrainLive.d.ts +34 -0
- package/dist/hooks/useTerrainLive.d.ts.map +1 -0
- package/dist/hooks/useTerrainLive.js +45 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/presets/landscapePresets.d.ts +60 -0
- package/dist/presets/landscapePresets.d.ts.map +1 -0
- package/dist/presets/landscapePresets.js +194 -0
- package/dist/presets/landscapeTypes.d.ts +195 -0
- package/dist/presets/landscapeTypes.d.ts.map +1 -0
- package/dist/presets/landscapeTypes.js +315 -0
- package/dist/presets/oceanSurfacePresets.d.ts +33 -0
- package/dist/presets/oceanSurfacePresets.d.ts.map +1 -0
- package/dist/presets/oceanSurfacePresets.js +245 -0
- package/dist/presets/terrainPresets.d.ts +28 -0
- package/dist/presets/terrainPresets.d.ts.map +1 -0
- package/dist/presets/terrainPresets.js +293 -0
- package/dist/presets/volumetricCloudPresets.d.ts +38 -0
- package/dist/presets/volumetricCloudPresets.d.ts.map +1 -0
- package/dist/presets/volumetricCloudPresets.js +480 -0
- package/dist/shaders/clouds/CirrusMaterial.d.ts +84 -0
- package/dist/shaders/clouds/CirrusMaterial.d.ts.map +1 -0
- package/dist/shaders/clouds/CirrusMaterial.js +167 -0
- package/dist/shaders/clouds/CloudCompositeMaterial.d.ts +20 -0
- package/dist/shaders/clouds/CloudCompositeMaterial.d.ts.map +1 -0
- package/dist/shaders/clouds/CloudCompositeMaterial.js +82 -0
- package/dist/shaders/clouds/CloudResolveMaterial.d.ts +22 -0
- package/dist/shaders/clouds/CloudResolveMaterial.d.ts.map +1 -0
- package/dist/shaders/clouds/CloudResolveMaterial.js +77 -0
- package/dist/shaders/clouds/CloudVolumeMaterial.d.ts +143 -0
- package/dist/shaders/clouds/CloudVolumeMaterial.d.ts.map +1 -0
- package/dist/shaders/clouds/CloudVolumeMaterial.js +249 -0
- package/dist/shaders/clouds/SkyBackgroundMaterial.d.ts +21 -0
- package/dist/shaders/clouds/SkyBackgroundMaterial.d.ts.map +1 -0
- package/dist/shaders/clouds/SkyBackgroundMaterial.js +42 -0
- package/dist/shaders/glsl/cloudCore.glsl.d.ts +24 -0
- package/dist/shaders/glsl/cloudCore.glsl.d.ts.map +1 -0
- package/dist/shaders/glsl/cloudCore.glsl.js +348 -0
- package/dist/shaders/glsl/landscapeCore.glsl.d.ts +49 -0
- package/dist/shaders/glsl/landscapeCore.glsl.d.ts.map +1 -0
- package/dist/shaders/glsl/landscapeCore.glsl.js +518 -0
- package/dist/shaders/glsl/noiseBake.glsl.d.ts +30 -0
- package/dist/shaders/glsl/noiseBake.glsl.d.ts.map +1 -0
- package/dist/shaders/glsl/noiseBake.glsl.js +164 -0
- package/dist/shaders/glsl/oceanCore.glsl.d.ts +52 -0
- package/dist/shaders/glsl/oceanCore.glsl.d.ts.map +1 -0
- package/dist/shaders/glsl/oceanCore.glsl.js +421 -0
- package/dist/shaders/glsl/terrainCore.glsl.d.ts +78 -0
- package/dist/shaders/glsl/terrainCore.glsl.d.ts.map +1 -0
- package/dist/shaders/glsl/terrainCore.glsl.js +625 -0
- package/dist/shaders/landscape/LandscapeMaterial.d.ts +73 -0
- package/dist/shaders/landscape/LandscapeMaterial.d.ts.map +1 -0
- package/dist/shaders/landscape/LandscapeMaterial.js +136 -0
- package/dist/shaders/ocean/OceanSurfaceMaterial.d.ts +57 -0
- package/dist/shaders/ocean/OceanSurfaceMaterial.d.ts.map +1 -0
- package/dist/shaders/ocean/OceanSurfaceMaterial.js +268 -0
- package/dist/shaders/terrain/TerrainMaterial.d.ts +80 -0
- package/dist/shaders/terrain/TerrainMaterial.d.ts.map +1 -0
- package/dist/shaders/terrain/TerrainMaterial.js +291 -0
- package/dist/types/cloudConfigs.d.ts +244 -0
- package/dist/types/cloudConfigs.d.ts.map +1 -0
- package/dist/types/cloudConfigs.js +282 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -1
- package/dist/types/landscapeConfigs.d.ts +218 -0
- package/dist/types/landscapeConfigs.d.ts.map +1 -0
- package/dist/types/landscapeConfigs.js +256 -0
- package/dist/types/oceanConfigs.d.ts +290 -0
- package/dist/types/oceanConfigs.d.ts.map +1 -0
- package/dist/types/oceanConfigs.js +380 -0
- package/dist/types/terrainConfigs.d.ts +251 -0
- package/dist/types/terrainConfigs.d.ts.map +1 -0
- package/dist/types/terrainConfigs.js +292 -0
- package/dist/utils/cloudUniforms.d.ts +14 -0
- package/dist/utils/cloudUniforms.d.ts.map +1 -0
- package/dist/utils/cloudUniforms.js +122 -0
- package/dist/utils/frameRenderer.d.ts +33 -0
- package/dist/utils/frameRenderer.d.ts.map +1 -0
- package/dist/utils/frameRenderer.js +24 -0
- package/dist/utils/handleCloudsAnimations.d.ts +16 -0
- package/dist/utils/handleCloudsAnimations.d.ts.map +1 -0
- package/dist/utils/handleCloudsAnimations.js +64 -0
- package/dist/utils/landscapeGeometry.d.ts +61 -0
- package/dist/utils/landscapeGeometry.d.ts.map +1 -0
- package/dist/utils/landscapeGeometry.js +126 -0
- package/dist/utils/landscapeHeight.d.ts +44 -0
- package/dist/utils/landscapeHeight.d.ts.map +1 -0
- package/dist/utils/landscapeHeight.js +65 -0
- package/dist/utils/landscapeTextures.d.ts +94 -0
- package/dist/utils/landscapeTextures.d.ts.map +1 -0
- package/dist/utils/landscapeTextures.js +290 -0
- package/dist/utils/landscapeUniforms.d.ts +20 -0
- package/dist/utils/landscapeUniforms.d.ts.map +1 -0
- package/dist/utils/landscapeUniforms.js +61 -0
- package/dist/utils/oceanUniforms.d.ts +47 -0
- package/dist/utils/oceanUniforms.d.ts.map +1 -0
- package/dist/utils/oceanUniforms.js +216 -0
- package/dist/utils/pointsMaterialOwnership.d.ts +9 -0
- package/dist/utils/pointsMaterialOwnership.d.ts.map +1 -0
- package/dist/utils/pointsMaterialOwnership.js +14 -0
- package/dist/utils/rtin.d.ts +63 -0
- package/dist/utils/rtin.d.ts.map +1 -0
- package/dist/utils/rtin.js +202 -0
- package/dist/utils/terrainUniforms.d.ts +14 -0
- package/dist/utils/terrainUniforms.d.ts.map +1 -0
- package/dist/utils/terrainUniforms.js +196 -0
- package/package.json +2 -2
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Config to uniform mapping for the terrain material.
|
|
4
|
+
*
|
|
5
|
+
* The config speaks in the units a person thinks in — "6 km features", "340 m
|
|
6
|
+
* dune wavelength", "#6b6248" — and the shader wants reciprocals, angular
|
|
7
|
+
* frequencies, direction vectors and linear-space colours. Doing the conversion
|
|
8
|
+
* here rather than storing shader-space numbers means the settings panel, the
|
|
9
|
+
* presets and the AI agent all read in world units.
|
|
10
|
+
*
|
|
11
|
+
* Mutates in place and is called every frame, for the same reason
|
|
12
|
+
* `cloudUniforms` does: a 45-uniform shader driven through React props would
|
|
13
|
+
* re-render the tree once per frame.
|
|
14
|
+
*/
|
|
15
|
+
const TYPE_INDEX = {
|
|
16
|
+
mountains: 0,
|
|
17
|
+
dunes: 1,
|
|
18
|
+
hills: 2,
|
|
19
|
+
canyon: 3,
|
|
20
|
+
};
|
|
21
|
+
const _dir = new THREE.Vector2();
|
|
22
|
+
function bearingToVector(degrees, out) {
|
|
23
|
+
const a = THREE.MathUtils.degToRad(degrees);
|
|
24
|
+
return out.set(Math.sin(a), Math.cos(a)).normalize();
|
|
25
|
+
}
|
|
26
|
+
/** Guard against a zero or negative size producing an infinite scale. */
|
|
27
|
+
function inverse(size, fallback) {
|
|
28
|
+
return size > 1e-6 ? 1 / size : 1 / fallback;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Colours are authored as hex and consumed as linear.
|
|
32
|
+
*
|
|
33
|
+
* `setStyle(hex, SRGBColorSpace)` and NOT `set(hex).convertSRGBToLinear()`. Under
|
|
34
|
+
* three's ColorManagement — on by default since r152 — `set()` already treats a
|
|
35
|
+
* hex string as sRGB and converts it into the working (linear) space, so the
|
|
36
|
+
* explicit call applies the conversion a second time. That is a factor of about
|
|
37
|
+
* eight on a mid-tone: #6b6248 arrives as linear 0.019 instead of 0.147, and every
|
|
38
|
+
* terrain in the app renders near-black no matter what the lighting does. It cost
|
|
39
|
+
* a long detour through the lighting maths before anyone thought to read the
|
|
40
|
+
* uniform back off the material.
|
|
41
|
+
*/
|
|
42
|
+
function setColor(uniform, hex) {
|
|
43
|
+
if (!uniform)
|
|
44
|
+
return;
|
|
45
|
+
uniform.value.setStyle(hex, THREE.SRGBColorSpace);
|
|
46
|
+
}
|
|
47
|
+
export function applyTerrainUniforms(material, config, quality) {
|
|
48
|
+
const u = material.uniforms;
|
|
49
|
+
if (!u)
|
|
50
|
+
return;
|
|
51
|
+
u.u_terrainType.value = TYPE_INDEX[config.terrainType] ?? 2;
|
|
52
|
+
u.u_elevation.value = Math.max(config.elevation, 0.01);
|
|
53
|
+
u.u_seaLevel.value = config.seaLevel;
|
|
54
|
+
u.u_baseScale.value = inverse(config.featureSize, 2600);
|
|
55
|
+
u.u_octaves.value = Math.round(THREE.MathUtils.clamp(config.octaves, 1, 12));
|
|
56
|
+
u.u_lacunarity.value = config.lacunarity;
|
|
57
|
+
u.u_gain.value = config.gain;
|
|
58
|
+
u.u_ridge.value = config.ridgeSharpness;
|
|
59
|
+
u.u_warpStrength.value = config.warpStrength;
|
|
60
|
+
u.u_warpScale.value = config.warpSize;
|
|
61
|
+
u.u_erosion.value = config.erosion;
|
|
62
|
+
u.u_terraces.value = Math.round(config.terraces);
|
|
63
|
+
u.u_terraceSharp.value = config.terraceSharpness;
|
|
64
|
+
u.u_bearingDir.value.copy(bearingToVector(config.bearing, _dir));
|
|
65
|
+
u.u_duneFreq.value = (Math.PI * 2) / Math.max(config.duneWavelength, 1);
|
|
66
|
+
u.u_duneAsym.value = config.duneAsymmetry;
|
|
67
|
+
u.u_plateau.value = config.plateau;
|
|
68
|
+
u.u_valleyDepth.value = config.valleyDepth;
|
|
69
|
+
u.u_valleyWidth.value = config.valleyWidth;
|
|
70
|
+
setColor(u.u_lowColor, config.lowColor);
|
|
71
|
+
setColor(u.u_midColor, config.midColor);
|
|
72
|
+
setColor(u.u_rockColor, config.rockColor);
|
|
73
|
+
setColor(u.u_peakColor, config.peakColor);
|
|
74
|
+
u.u_slopeRockStart.value = Math.min(config.slopeRockStart, config.slopeRockEnd - 0.005);
|
|
75
|
+
u.u_slopeRockEnd.value = config.slopeRockEnd;
|
|
76
|
+
u.u_peakLevel.value = config.peakLevel;
|
|
77
|
+
u.u_peakBlend.value = Math.max(config.peakBlend, 0.005);
|
|
78
|
+
u.u_peakSlopeFalloff.value = config.peakSlopeFalloff;
|
|
79
|
+
u.u_macroVariation.value = config.macroVariation;
|
|
80
|
+
u.u_macroScale.value = inverse(config.macroSize, 1400);
|
|
81
|
+
u.u_detailStrength.value = config.detailStrength;
|
|
82
|
+
u.u_detailScale.value = inverse(config.detailSize, 6);
|
|
83
|
+
u.u_roughness.value = config.roughness;
|
|
84
|
+
u.u_specular.value = config.specular;
|
|
85
|
+
u.u_ambient.value = config.ambient;
|
|
86
|
+
u.u_bounce.value = config.bounce;
|
|
87
|
+
u.u_sunShadow.value = config.sunShadow;
|
|
88
|
+
u.u_shadowSoftness.value = config.shadowSoftness;
|
|
89
|
+
u.u_fogDensity.value = config.aerialPerspective;
|
|
90
|
+
u.u_cellSize.value = quality.cellSize;
|
|
91
|
+
u.u_curvature.value = quality.curvature;
|
|
92
|
+
u.u_shadowSteps.value = Math.round(quality.shadowSteps);
|
|
93
|
+
u.u_shadowDistance.value = Math.max(quality.shadowDistance ?? 5000, 1);
|
|
94
|
+
u.u_detailFade.value = inverse(quality.detailFadeDistance, 900);
|
|
95
|
+
u.u_exposure.value = quality.exposure;
|
|
96
|
+
u.u_receiveShadows.value = quality.receiveShadows ? 1 : 0;
|
|
97
|
+
material.wireframe = !!quality.wireframe;
|
|
98
|
+
}
|
|
99
|
+
export default applyTerrainUniforms;
|
|
100
|
+
// -----------------------------------------------------------------------------
|
|
101
|
+
// Ambient
|
|
102
|
+
// -----------------------------------------------------------------------------
|
|
103
|
+
/**
|
|
104
|
+
* The sky-dome fill, computed on the CPU.
|
|
105
|
+
*
|
|
106
|
+
* A port of `skyRadiance` from `cloudCore.glsl` — the same function that draws the
|
|
107
|
+
* sky and lights the clouds. It is the same for every pixel on the screen, so
|
|
108
|
+
* paying an acos, a pow and three exps per fragment for it was waste.
|
|
109
|
+
*
|
|
110
|
+
* Two things this must NOT be, both of which it has been:
|
|
111
|
+
*
|
|
112
|
+
* 1. **`CloudSunState.skyAmbient`.** That is a hand-tuned curve for cloud
|
|
113
|
+
* interiors — roughly twice too bright at midday, half as bright at sunset, and
|
|
114
|
+
* differently balanced. Terrain lit by it goes almost black under a bright
|
|
115
|
+
* sunset sky, which is exactly what it did.
|
|
116
|
+
* 2. **The zenith alone.** The dome is not one colour. At midday the zenith is a
|
|
117
|
+
* fair stand-in for the average, but at low sun almost all the light in the sky
|
|
118
|
+
* is in a bright band around the horizon and the zenith is the darkest part of
|
|
119
|
+
* it — so a zenith-only fill makes a sunset landscape black under a blazing
|
|
120
|
+
* sky. Three samples, weighted, are enough to fix it and still cost nothing.
|
|
121
|
+
*/
|
|
122
|
+
const RAYLEIGH_BASE = [0.0487, 0.113, 0.278];
|
|
123
|
+
function airMassAt(cosZenith) {
|
|
124
|
+
const cy = Math.max(cosZenith, -0.02);
|
|
125
|
+
const zenithDeg = (Math.acos(THREE.MathUtils.clamp(cy, -1, 1)) * 180) / Math.PI;
|
|
126
|
+
return Math.min(1 / (Math.max(cy, 0) + 0.15 * Math.pow(Math.max(93.885 - zenithDeg, 0.5), -1.253)), 40);
|
|
127
|
+
}
|
|
128
|
+
/** skyRadiance(rd), in the units the shader returns. */
|
|
129
|
+
export function skyRadianceAt(rd, sun, out) {
|
|
130
|
+
const mu = rd.dot(sun.direction);
|
|
131
|
+
const am = airMassAt(Math.max(rd.y, -0.02));
|
|
132
|
+
const bR = [
|
|
133
|
+
RAYLEIGH_BASE[0] * sun.turbidity * sun.rayleigh,
|
|
134
|
+
RAYLEIGH_BASE[1] * sun.turbidity * sun.rayleigh,
|
|
135
|
+
RAYLEIGH_BASE[2] * sun.turbidity * sun.rayleigh,
|
|
136
|
+
];
|
|
137
|
+
const bM = sun.mieCoefficient * sun.turbidity * 4.25;
|
|
138
|
+
const rayleighPhase = (3 / (16 * Math.PI)) * (1 + mu * mu);
|
|
139
|
+
const g2 = sun.mieG * sun.mieG;
|
|
140
|
+
const miePhase = (1 - g2) / (4 * Math.PI * Math.pow(Math.max(1 + g2 - 2 * sun.mieG * mu, 1e-4), 1.5));
|
|
141
|
+
const c = [sun.color.r, sun.color.g, sun.color.b];
|
|
142
|
+
const rgb = [0, 0, 0];
|
|
143
|
+
for (let i = 0; i < 3; i++) {
|
|
144
|
+
const ext = bR[i] * am + bM * am * 1.2;
|
|
145
|
+
// Same whitening the shader applies: most of the light reaching the eye
|
|
146
|
+
// from the sky has been multiply scattered, so the Rayleigh term sees a
|
|
147
|
+
// partly whitened sun rather than the full reddened beam.
|
|
148
|
+
const rayCol = c[i] + (1 - c[i]) * 0.6;
|
|
149
|
+
const insR = bR[i] * am * rayleighPhase * rayCol;
|
|
150
|
+
const insM = bM * am * miePhase * 1.3 * c[i];
|
|
151
|
+
rgb[i] = ((insR + insM) / Math.max(ext, 1e-4)) * (1 - Math.exp(-ext)) * 26;
|
|
152
|
+
}
|
|
153
|
+
return out.setRGB(rgb[0], rgb[1], rgb[2]);
|
|
154
|
+
}
|
|
155
|
+
const _zenith = new THREE.Color();
|
|
156
|
+
const _toward = new THREE.Color();
|
|
157
|
+
const _rd = new THREE.Vector3();
|
|
158
|
+
/**
|
|
159
|
+
* Sets the two ambient uniforms. Call after `applySunUniforms`, which fills them
|
|
160
|
+
* from the cloud curve — this overwrites that with the sky the terrain is actually
|
|
161
|
+
* standing under.
|
|
162
|
+
*/
|
|
163
|
+
export function applyTerrainAmbient(material, sun) {
|
|
164
|
+
const u = material.uniforms;
|
|
165
|
+
if (!u || !u.u_skyAmbient)
|
|
166
|
+
return;
|
|
167
|
+
skyRadianceAt(_rd.set(0, 1, 0), sun, _zenith);
|
|
168
|
+
// Four samples around the compass at 20 degrees, where the bright low band
|
|
169
|
+
// lives, averaged. Four and not two: a single sample toward the sun sits
|
|
170
|
+
// inside the mie aureole and reads several times the rest of the dome, so
|
|
171
|
+
// weighting it on its own hands the ground more ambient than direct sun.
|
|
172
|
+
// Averaging puts the aureole at a quarter of the low term, which is roughly
|
|
173
|
+
// the solid angle it actually occupies.
|
|
174
|
+
const hx = sun.direction.x, hz = sun.direction.z;
|
|
175
|
+
const hl = Math.hypot(hx, hz) || 1;
|
|
176
|
+
const ux = hx / hl, uz = hz / hl;
|
|
177
|
+
const c = 0.94, y = 0.342; // cos/sin of 20 degrees
|
|
178
|
+
let lr = 0, lg = 0, lb = 0;
|
|
179
|
+
const dirs = [[ux, uz], [-ux, -uz], [-uz, ux], [uz, -ux]];
|
|
180
|
+
for (const [dx, dz] of dirs) {
|
|
181
|
+
skyRadianceAt(_rd.set(dx * c, y, dz * c), sun, _toward);
|
|
182
|
+
lr += _toward.r;
|
|
183
|
+
lg += _toward.g;
|
|
184
|
+
lb += _toward.b;
|
|
185
|
+
}
|
|
186
|
+
lr /= 4;
|
|
187
|
+
lg /= 4;
|
|
188
|
+
lb /= 4;
|
|
189
|
+
u.u_skyAmbient.value.setRGB(_zenith.r * 0.45 + lr * 0.55, _zenith.g * 0.45 + lg * 0.55, _zenith.b * 0.45 + lb * 0.55);
|
|
190
|
+
// Bounce is that fill re-reflected off lit ground, so it carries the sun's own
|
|
191
|
+
// colour and dies with its elevation. Keeps north faces and overhangs off pure
|
|
192
|
+
// black without the flattening that raising ambient causes.
|
|
193
|
+
const lit = Math.max(sun.direction.y, 0);
|
|
194
|
+
const sky = u.u_skyAmbient.value;
|
|
195
|
+
u.u_groundAmbient.value.setRGB(sky.r * 0.45 + sun.color.r * lit * 0.35, sky.g * 0.45 + sun.color.g * lit * 0.35, sky.b * 0.45 + sun.color.b * lit * 0.35);
|
|
196
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3driseai/3drise-viewer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@3driseai/3drise-common": "^1.0.1",
|
|
42
|
-
"@3driseai/3drise-core": "^1.0.
|
|
42
|
+
"@3driseai/3drise-core": "^1.0.5"
|
|
43
43
|
}
|
|
44
44
|
}
|