@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.
- 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/EnvironmentManager.d.ts +47 -5
- package/dist/components/EnvironmentManager.d.ts.map +1 -1
- package/dist/components/EnvironmentManager.js +35 -66
- 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 +10 -0
- 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/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.map +1 -1
- package/dist/constants.js +9 -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/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/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,73 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* The landscape surface material.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this extends MeshStandardMaterial instead of being a ShaderMaterial
|
|
6
|
+
*
|
|
7
|
+
* `TerrainMaterial` is a `ShaderMaterial` with `lights: true` and the light
|
|
8
|
+
* uniform blocks merged in by hand, because it does its own atmospheric
|
|
9
|
+
* lighting. A landscape is textured, not procedurally shaded: it wants ordinary
|
|
10
|
+
* PBR, the scene's HDR environment, shadow receive, fog and tonemapping — all of
|
|
11
|
+
* which come free by extending the stock material and patching four chunks. That
|
|
12
|
+
* is also why the reference project reaches for `three-custom-shader-material`;
|
|
13
|
+
* this is the same four injection points without the dependency, which matters
|
|
14
|
+
* because `packages/*` reach the client as a hand-copied `dist`.
|
|
15
|
+
*
|
|
16
|
+
* ## Shape is compiled in
|
|
17
|
+
*
|
|
18
|
+
* Surface count, blend width and the sampling modes are `#define`s, so every
|
|
19
|
+
* loop in the fragment shader has constant bounds and unrolls, and the stochastic
|
|
20
|
+
* and triplanar paths compile out entirely when they are off. The cost is that
|
|
21
|
+
* changing one of them needs a new material — which is what `shapeKey` is for,
|
|
22
|
+
* and why the controller commits those particular knobs on release rather than
|
|
23
|
+
* live.
|
|
24
|
+
*
|
|
25
|
+
* ## What NOT to do
|
|
26
|
+
*
|
|
27
|
+
* Do not set `glslVersion: GLSL3`. three r163+ already compiles every material
|
|
28
|
+
* as `#version 300 es` and injects `#define texture2D texture` plus the
|
|
29
|
+
* `gl_FragColor` alias; asking for GLSL3 explicitly removes that alias and the
|
|
30
|
+
* stock chunks stop compiling. `sampler2DArray` and `textureGrad` work as they
|
|
31
|
+
* are.
|
|
32
|
+
*/
|
|
33
|
+
export interface LandscapeMaterialShape {
|
|
34
|
+
/** Number of surfaces, 1..8. */
|
|
35
|
+
count: number;
|
|
36
|
+
/** How many are blended per pixel, 1..4, clamped to count. */
|
|
37
|
+
samples: number;
|
|
38
|
+
/** Splat maps supplied, 0..2. Ignored when `auto`. */
|
|
39
|
+
splats: number;
|
|
40
|
+
/** Generate weights from height and slope instead of from splat maps. */
|
|
41
|
+
auto: boolean;
|
|
42
|
+
stochastic: boolean;
|
|
43
|
+
triplanar: boolean;
|
|
44
|
+
ao: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface LandscapeUniforms {
|
|
47
|
+
[key: string]: THREE.IUniform;
|
|
48
|
+
}
|
|
49
|
+
export declare function landscapeShapeKey(shape: LandscapeMaterialShape): string;
|
|
50
|
+
/** Every uniform both the surface material and the depth material read. Built
|
|
51
|
+
* once and shared by reference, so a per-frame write reaches both. */
|
|
52
|
+
export declare function createLandscapeUniforms(count: number): LandscapeUniforms;
|
|
53
|
+
export declare class LandscapeMaterial extends THREE.MeshStandardMaterial {
|
|
54
|
+
readonly uniforms: LandscapeUniforms;
|
|
55
|
+
readonly shape: LandscapeMaterialShape;
|
|
56
|
+
constructor(shape: LandscapeMaterialShape, uniforms: LandscapeUniforms);
|
|
57
|
+
/** three keys its program cache on this, and two landscapes with different
|
|
58
|
+
* defines must not share one. */
|
|
59
|
+
customProgramCacheKey(): string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The depth material for shadow casting, displaced identically.
|
|
63
|
+
*
|
|
64
|
+
* This is the thing the procedural terrain cannot have: its shadow camera would
|
|
65
|
+
* need to frame 25 km, so a mountain never shadows an object standing in its
|
|
66
|
+
* valley. A landscape is a bounded tile, so the sun's existing shadow camera
|
|
67
|
+
* already covers it and the only missing piece is a depth pass that agrees with
|
|
68
|
+
* the surface about where the ground is.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createLandscapeDepthMaterial(uniforms: LandscapeUniforms): THREE.MeshDepthMaterial;
|
|
71
|
+
/** Distance material, for point-light shadows. Same displacement again. */
|
|
72
|
+
export declare function createLandscapeDistanceMaterial(uniforms: LandscapeUniforms): THREE.MeshDistanceMaterial;
|
|
73
|
+
//# sourceMappingURL=LandscapeMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LandscapeMaterial.d.ts","sourceRoot":"","sources":["../../../src/shaders/landscape/LandscapeMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAS9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,MAAM,WAAW,sBAAsB;IACnC,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAA;IACf,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAA;IACd,yEAAyE;IACzE,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,OAAO,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,EAAE,EAAE,OAAO,CAAA;CACd;AAED,MAAM,WAAW,iBAAiB;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAA;CAChC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM,CAUvE;AAED;uEACuE;AACvE,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAgCxE;AAuBD,qBAAa,iBAAkB,SAAQ,KAAK,CAAC,oBAAoB;IAC7D,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,QAAQ,CAAC,KAAK,EAAE,sBAAsB,CAAA;gBAE1B,KAAK,EAAE,sBAAsB,EAAE,QAAQ,EAAE,iBAAiB;IA+CtE;sCACkC;IAClC,qBAAqB,IAAI,MAAM;CAGlC;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CASjG;AAED,2EAA2E;AAC3E,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,iBAAiB,GAAG,KAAK,CAAC,oBAAoB,CASvG"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { landscapeFragmentBody, landscapeFragmentPars, landscapeNormalBody, landscapeVertexBody, landscapeVertexPars, } from '../glsl/landscapeCore.glsl.js';
|
|
3
|
+
export function landscapeShapeKey(shape) {
|
|
4
|
+
return [
|
|
5
|
+
shape.count,
|
|
6
|
+
shape.samples,
|
|
7
|
+
shape.splats,
|
|
8
|
+
shape.auto ? 1 : 0,
|
|
9
|
+
shape.stochastic ? 1 : 0,
|
|
10
|
+
shape.triplanar ? 1 : 0,
|
|
11
|
+
shape.ao ? 1 : 0,
|
|
12
|
+
].join(':');
|
|
13
|
+
}
|
|
14
|
+
/** Every uniform both the surface material and the depth material read. Built
|
|
15
|
+
* once and shared by reference, so a per-frame write reaches both. */
|
|
16
|
+
export function createLandscapeUniforms(count) {
|
|
17
|
+
const vec4s = (fill) => Array.from({ length: count }, () => fill.clone());
|
|
18
|
+
return {
|
|
19
|
+
u_lsHeight: { value: null },
|
|
20
|
+
u_lsHeightSize: { value: new THREE.Vector2(1024, 1024) },
|
|
21
|
+
u_lsSmoothness: { value: 1 },
|
|
22
|
+
u_lsElevation: { value: 300 },
|
|
23
|
+
u_lsElevationBias: { value: 0 },
|
|
24
|
+
u_lsSize: { value: 2048 },
|
|
25
|
+
u_lsField: { value: null },
|
|
26
|
+
u_lsGradScale: { value: 0.05 },
|
|
27
|
+
u_lsFieldTexel: { value: new THREE.Vector2(1 / 1024, 1 / 1024) },
|
|
28
|
+
u_lsDiffuse: { value: null },
|
|
29
|
+
u_lsNormal: { value: null },
|
|
30
|
+
u_lsSplat0: { value: null },
|
|
31
|
+
u_lsSplat1: { value: null },
|
|
32
|
+
u_lsAo: { value: null },
|
|
33
|
+
u_lsSurfA: { value: vec4s(new THREE.Vector4(200, 0.6, 0.9, 0.6)) },
|
|
34
|
+
u_lsSurfB: { value: vec4s(new THREE.Vector4(1, 1, 1, 1)) },
|
|
35
|
+
u_lsSurfC: { value: vec4s(new THREE.Vector4(0, 1, 0, 0)) },
|
|
36
|
+
u_lsSurfMean: { value: Array.from({ length: count }, () => new THREE.Vector3(0.5, 0.5, 0.5)) },
|
|
37
|
+
u_lsAuto: { value: new THREE.Vector4(0.45, 0.35, 0.62, 0.12) },
|
|
38
|
+
u_lsAutoBands: { value: Array.from({ length: count }, (_, i) => i / Math.max(count - 1, 1)) },
|
|
39
|
+
u_lsNoiseScale: { value: 1 / 400 },
|
|
40
|
+
u_lsMacro: { value: 0.25 },
|
|
41
|
+
u_lsMacroScale: { value: 1 / 900 },
|
|
42
|
+
u_lsAoIntensity: { value: 0.8 },
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function defines(shape) {
|
|
46
|
+
const out = {
|
|
47
|
+
// vUv is not declared unless something asks for it, and every map here is
|
|
48
|
+
// sampled by hand rather than assigned to `material.map`.
|
|
49
|
+
USE_UV: '',
|
|
50
|
+
LS_COUNT: Math.max(1, Math.min(8, Math.round(shape.count))),
|
|
51
|
+
LS_SAMPLES: Math.max(1, Math.min(4, Math.min(shape.samples, shape.count))),
|
|
52
|
+
};
|
|
53
|
+
if (shape.auto)
|
|
54
|
+
out.LS_AUTO = '';
|
|
55
|
+
if (shape.stochastic)
|
|
56
|
+
out.LS_STOCHASTIC = '';
|
|
57
|
+
if (shape.triplanar)
|
|
58
|
+
out.LS_TRIPLANAR = '';
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function patchVertex(shader) {
|
|
62
|
+
shader.vertexShader = shader.vertexShader
|
|
63
|
+
.replace('#include <common>', `#include <common>\n${landscapeVertexPars}`)
|
|
64
|
+
.replace('#include <beginnormal_vertex>', landscapeNormalBody)
|
|
65
|
+
.replace('#include <begin_vertex>', landscapeVertexBody);
|
|
66
|
+
}
|
|
67
|
+
export class LandscapeMaterial extends THREE.MeshStandardMaterial {
|
|
68
|
+
uniforms;
|
|
69
|
+
shape;
|
|
70
|
+
constructor(shape, uniforms) {
|
|
71
|
+
super({
|
|
72
|
+
color: 0xffffff,
|
|
73
|
+
roughness: 1,
|
|
74
|
+
metalness: 0,
|
|
75
|
+
// The ground is opaque and single-sided; the winding is fixed in the
|
|
76
|
+
// RTIN emitter rather than papered over with DoubleSide.
|
|
77
|
+
side: THREE.FrontSide,
|
|
78
|
+
});
|
|
79
|
+
this.shape = shape;
|
|
80
|
+
this.uniforms = uniforms;
|
|
81
|
+
this.defines = { ...this.defines, ...defines(shape) };
|
|
82
|
+
this.onBeforeCompile = (shader) => {
|
|
83
|
+
Object.assign(shader.uniforms, uniforms);
|
|
84
|
+
patchVertex(shader);
|
|
85
|
+
let fs = shader.fragmentShader
|
|
86
|
+
.replace('#include <common>', `#include <common>\n${landscapeFragmentPars}`)
|
|
87
|
+
.replace('#include <map_fragment>', `${landscapeFragmentBody}\ndiffuseColor.rgb *= lsAlbedo;`)
|
|
88
|
+
.replace('#include <roughnessmap_fragment>', 'float roughnessFactor = clamp(lsRoughness, 0.04, 1.0);')
|
|
89
|
+
.replace('#include <metalnessmap_fragment>', 'float metalnessFactor = clamp(lsMetalness, 0.0, 1.0);')
|
|
90
|
+
.replace('#include <normal_fragment_maps>',
|
|
91
|
+
// lsNormalW is world space; three shades in view space.
|
|
92
|
+
'normal = normalize((viewMatrix * vec4(lsNormalW, 0.0)).xyz);');
|
|
93
|
+
if (shape.ao) {
|
|
94
|
+
fs = fs.replace('#include <aomap_fragment>', `float lsAo = texture2D(u_lsAo, vUv).r;
|
|
95
|
+
float ambientOcclusion = (lsAo - 1.0) * u_lsAoIntensity + 1.0;
|
|
96
|
+
reflectedLight.indirectDiffuse *= ambientOcclusion;`);
|
|
97
|
+
}
|
|
98
|
+
shader.fragmentShader = fs;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** three keys its program cache on this, and two landscapes with different
|
|
102
|
+
* defines must not share one. */
|
|
103
|
+
customProgramCacheKey() {
|
|
104
|
+
return `landscape:${landscapeShapeKey(this.shape)}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The depth material for shadow casting, displaced identically.
|
|
109
|
+
*
|
|
110
|
+
* This is the thing the procedural terrain cannot have: its shadow camera would
|
|
111
|
+
* need to frame 25 km, so a mountain never shadows an object standing in its
|
|
112
|
+
* valley. A landscape is a bounded tile, so the sun's existing shadow camera
|
|
113
|
+
* already covers it and the only missing piece is a depth pass that agrees with
|
|
114
|
+
* the surface about where the ground is.
|
|
115
|
+
*/
|
|
116
|
+
export function createLandscapeDepthMaterial(uniforms) {
|
|
117
|
+
const material = new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking });
|
|
118
|
+
material.defines = { ...material.defines, USE_UV: '' };
|
|
119
|
+
material.onBeforeCompile = (shader) => {
|
|
120
|
+
Object.assign(shader.uniforms, uniforms);
|
|
121
|
+
patchVertex(shader);
|
|
122
|
+
};
|
|
123
|
+
material.customProgramCacheKey = () => 'landscape-depth';
|
|
124
|
+
return material;
|
|
125
|
+
}
|
|
126
|
+
/** Distance material, for point-light shadows. Same displacement again. */
|
|
127
|
+
export function createLandscapeDistanceMaterial(uniforms) {
|
|
128
|
+
const material = new THREE.MeshDistanceMaterial();
|
|
129
|
+
material.defines = { ...material.defines, USE_UV: '' };
|
|
130
|
+
material.onBeforeCompile = (shader) => {
|
|
131
|
+
Object.assign(shader.uniforms, uniforms);
|
|
132
|
+
patchVertex(shader);
|
|
133
|
+
};
|
|
134
|
+
material.customProgramCacheKey = () => 'landscape-distance';
|
|
135
|
+
return material;
|
|
136
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { type ThreeElement } from '@react-three/fiber';
|
|
3
|
+
export interface OceanMaterialUniforms {
|
|
4
|
+
[key: string]: THREE.IUniform;
|
|
5
|
+
}
|
|
6
|
+
/** Uniform-space defaults. Config units are converted by `applyOceanUniforms`;
|
|
7
|
+
* these are only what the material holds before anything is applied. */
|
|
8
|
+
export declare const oceanMaterialDefaults: {
|
|
9
|
+
u_waveA: THREE.Vector4[];
|
|
10
|
+
u_waveB: THREE.Vector4[];
|
|
11
|
+
u_waveCount: number;
|
|
12
|
+
u_time: number;
|
|
13
|
+
u_waterLevel: number;
|
|
14
|
+
u_choppiness: number;
|
|
15
|
+
u_amplitudeScale: number;
|
|
16
|
+
u_bodyHalf: THREE.Vector2;
|
|
17
|
+
u_edgeFade: number;
|
|
18
|
+
u_deepColor: THREE.Color;
|
|
19
|
+
u_shallowColor: THREE.Color;
|
|
20
|
+
u_foamColor: THREE.Color;
|
|
21
|
+
u_sssColor: THREE.Color;
|
|
22
|
+
u_absorption: number;
|
|
23
|
+
u_clarity: number;
|
|
24
|
+
u_roughness: number;
|
|
25
|
+
u_specular: number;
|
|
26
|
+
u_sssStrength: number;
|
|
27
|
+
u_detailStrength: number;
|
|
28
|
+
u_detailScale: number;
|
|
29
|
+
u_detailFade: number;
|
|
30
|
+
u_pixelScale: number;
|
|
31
|
+
u_foamAmount: number;
|
|
32
|
+
u_foamDecay: number;
|
|
33
|
+
u_foamScale: number;
|
|
34
|
+
u_ambientScale: number;
|
|
35
|
+
u_fogDensity: number;
|
|
36
|
+
u_exposure: number;
|
|
37
|
+
u_curvature: number;
|
|
38
|
+
u_receiveShadows: number;
|
|
39
|
+
u_sunDir: THREE.Vector3;
|
|
40
|
+
u_sunColor: THREE.Color;
|
|
41
|
+
u_skyAmbient: THREE.Color;
|
|
42
|
+
u_groundAmbient: THREE.Color;
|
|
43
|
+
u_sunIntensity: number;
|
|
44
|
+
u_turbidity: number;
|
|
45
|
+
u_rayleigh: number;
|
|
46
|
+
u_mieCoefficient: number;
|
|
47
|
+
u_mieG: number;
|
|
48
|
+
};
|
|
49
|
+
export declare class OceanSurfaceMaterial extends THREE.ShaderMaterial {
|
|
50
|
+
constructor();
|
|
51
|
+
}
|
|
52
|
+
declare module '@react-three/fiber' {
|
|
53
|
+
interface ThreeElements {
|
|
54
|
+
oceanSurfaceMaterial: ThreeElement<typeof OceanSurfaceMaterial>;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=OceanSurfaceMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OceanSurfaceMaterial.d.ts","sourceRoot":"","sources":["../../../src/shaders/ocean/OceanSurfaceMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAmM9D,MAAM,WAAW,qBAAqB;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAA;CAChC;AAMD;yEACyE;AACzE,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CjC,CAAA;AAgBD,qBAAa,oBAAqB,SAAQ,KAAK,CAAC,cAAc;;CAa7D;AAID,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,aAAa;QACnB,oBAAoB,EAAE,YAAY,CAAC,OAAO,oBAAoB,CAAC,CAAA;KAClE;CACJ"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { extend } from '@react-three/fiber';
|
|
3
|
+
import { skyLib } from '../glsl/cloudCore.glsl.js';
|
|
4
|
+
import { oceanFull, MAX_WAVES } from '../glsl/oceanCore.glsl.js';
|
|
5
|
+
/**
|
|
6
|
+
* The water surface material. Used by both hosts — the world clipmap and a
|
|
7
|
+
* placed body — and by all four water types, which differ in the spectrum the
|
|
8
|
+
* CPU uploads, not in the shader.
|
|
9
|
+
*
|
|
10
|
+
* ## Why this is not drei's `shaderMaterial`
|
|
11
|
+
*
|
|
12
|
+
* The same reason `TerrainMaterial` is not: water has to RECEIVE the scene's
|
|
13
|
+
* shadow map, so a boat casts onto it. That needs `lights: true` and
|
|
14
|
+
* `UniformsLib.lights` merged in, and drei's helper builds neither. Everything
|
|
15
|
+
* else about the house convention is kept — `u_` uniforms, a defaults export,
|
|
16
|
+
* `/* glsl *\/` strings, `extend()` and the `ThreeElements` augmentation.
|
|
17
|
+
*
|
|
18
|
+
* ## Three shadow sources, not one
|
|
19
|
+
*
|
|
20
|
+
* - **Objects onto water** — three's shadow map, `getShadowMask()`. Sized for
|
|
21
|
+
* objects, correct for them.
|
|
22
|
+
* - **Terrain onto water** — an analytic march down the sun vector against the
|
|
23
|
+
* terrain height field, marched per vertex (phase 4). Terrain does not write
|
|
24
|
+
* into the scene shadow map at all, so this is the only route.
|
|
25
|
+
* - **Waves onto themselves** — not marched. Crests are small and a trough's
|
|
26
|
+
* occlusion is approximated from the wave's own height for a fraction of the
|
|
27
|
+
* cost.
|
|
28
|
+
*
|
|
29
|
+
* ## The vertex stage does the waves
|
|
30
|
+
*
|
|
31
|
+
* Displacement, the analytic tangent frame and the Jacobian all come out of one
|
|
32
|
+
* loop and travel down as varyings. That is the opposite of the terrain
|
|
33
|
+
* material, which re-evaluates its field per fragment, and the reason is in
|
|
34
|
+
* `oceanCore.glsl`: the LOD rule removes every wave the mesh cannot carry, so
|
|
35
|
+
* here the mesh really is the surface.
|
|
36
|
+
*/
|
|
37
|
+
const vertex = /* glsl */ `
|
|
38
|
+
#include <common>
|
|
39
|
+
#include <shadowmap_pars_vertex>
|
|
40
|
+
#include <fog_pars_vertex>
|
|
41
|
+
|
|
42
|
+
// three's <common> already supplies PI and saturate, so cloudCommon must NOT be
|
|
43
|
+
// included beside it - redefining PI with a different literal is a compile error.
|
|
44
|
+
${skyLib}
|
|
45
|
+
${oceanFull}
|
|
46
|
+
|
|
47
|
+
/** World size of this vertex's cell. Per-vertex so one material serves every
|
|
48
|
+
* clipmap ring, and a placed body sets it from its own grid. */
|
|
49
|
+
attribute float aCell;
|
|
50
|
+
/** 0 in the body of a ring, ramping to 1 across its outer band. Always 0 on a
|
|
51
|
+
* placed body, which has no neighbour to morph toward. */
|
|
52
|
+
attribute float aMorph;
|
|
53
|
+
/** Offset to the parent-grid neighbour. Zero on even indices, and on a body. */
|
|
54
|
+
attribute vec2 aCoarse;
|
|
55
|
+
|
|
56
|
+
varying vec3 vWorld;
|
|
57
|
+
varying vec3 vNormal_;
|
|
58
|
+
varying float vFoam;
|
|
59
|
+
varying float vRelHeight;
|
|
60
|
+
varying float vDist;
|
|
61
|
+
varying float vDepthFactor;
|
|
62
|
+
|
|
63
|
+
void main(){
|
|
64
|
+
// Geomorph first, waves second. The other order blends two different points on
|
|
65
|
+
// the surface and reopens the seam it is there to close: done this way,
|
|
66
|
+
// neighbouring rings evaluate the SAME world XZ at their shared boundary and
|
|
67
|
+
// therefore the same wave sum, so the surfaces coincide by construction.
|
|
68
|
+
vec2 local = position.xz + aCoarse * aMorph;
|
|
69
|
+
|
|
70
|
+
vec3 flatPos = vec3(local.x, 0.0, local.y);
|
|
71
|
+
vec4 worldFlat = modelMatrix * vec4(flatPos, 1.0);
|
|
72
|
+
vec2 wxz = worldFlat.xz;
|
|
73
|
+
|
|
74
|
+
// The LOD cell morphs with the vertex, so a ring's outer edge samples at
|
|
75
|
+
// exactly the next ring's cell size and both sides of the seam fade the same
|
|
76
|
+
// components by the same amount.
|
|
77
|
+
float cellLod = aCell * (1.0 + aMorph);
|
|
78
|
+
|
|
79
|
+
float edge = oceanEdgeMask(local);
|
|
80
|
+
|
|
81
|
+
// Where the wave field is evaluated. The world ocean is evaluated in world XZ,
|
|
82
|
+
// because its clipmap slides under a camera that moves through the world and
|
|
83
|
+
// the sea must not slide with it. A placed body is evaluated in its OWN space,
|
|
84
|
+
// so its waves rotate with it and stay inside its rim.
|
|
85
|
+
bool isBody = u_bodyHalf.x > 0.0;
|
|
86
|
+
vec2 fieldXZ = isBody ? local : wxz;
|
|
87
|
+
|
|
88
|
+
vec3 disp; vec3 nrm; float jac; float rel;
|
|
89
|
+
oceanWaveSum(fieldXZ, cellLod, u_amplitudeScale * edge, disp, nrm, jac, rel);
|
|
90
|
+
|
|
91
|
+
vFoam = oceanFoam(jac, rel, vec3(fieldXZ.x, 0.0, fieldXZ.y));
|
|
92
|
+
vRelHeight = rel;
|
|
93
|
+
|
|
94
|
+
// Open water until the refraction grab lands; the shoreline reads its depth
|
|
95
|
+
// from that, and from the terrain field when it is included.
|
|
96
|
+
vDepthFactor = 1.0;
|
|
97
|
+
|
|
98
|
+
// Displacement is in field space, which for both hosts is object space up to a
|
|
99
|
+
// translation - so it can be added to transformed directly. Deriving it from
|
|
100
|
+
// a world position instead would need inverse(modelMatrix), which GLSL ES 1.00
|
|
101
|
+
// does not have, and three compiles these as ES 1.00.
|
|
102
|
+
vec3 transformed = vec3(local.x + disp.x, disp.y, local.y + disp.z);
|
|
103
|
+
|
|
104
|
+
// Planetary curvature, applied here and only here, and only to the world
|
|
105
|
+
// ocean. It is a view-relative bend, so folding it into the surface itself
|
|
106
|
+
// would make the water move when the camera does; and a swimming pool does not
|
|
107
|
+
// need a horizon.
|
|
108
|
+
if (!isBody) {
|
|
109
|
+
vec2 fromCam = wxz - cameraPosition.xz;
|
|
110
|
+
transformed.y -= u_curvature * dot(fromCam, fromCam);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
vec3 world = (modelMatrix * vec4(transformed, 1.0)).xyz;
|
|
114
|
+
vNormal_ = normalize(mat3(modelMatrix) * normalize(mix(vec3(0.0, 1.0, 0.0), nrm, edge)));
|
|
115
|
+
|
|
116
|
+
vWorld = world;
|
|
117
|
+
vDist = distance(world, cameraPosition);
|
|
118
|
+
|
|
119
|
+
vec3 objectNormal = vec3(0.0, 1.0, 0.0);
|
|
120
|
+
vec3 transformedNormal = normalMatrix * objectNormal;
|
|
121
|
+
|
|
122
|
+
vec4 mvPosition = modelViewMatrix * vec4(transformed, 1.0);
|
|
123
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
124
|
+
|
|
125
|
+
#include <worldpos_vertex>
|
|
126
|
+
#include <shadowmap_vertex>
|
|
127
|
+
#include <fog_vertex>
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
const fragment = /* glsl */ `
|
|
131
|
+
#include <common>
|
|
132
|
+
#include <packing>
|
|
133
|
+
#include <fog_pars_fragment>
|
|
134
|
+
// lights_pars_begin declares the bool uniform receiveShadow that
|
|
135
|
+
// shadowmask_pars_fragment reads. Include the shadow chunks without it and the
|
|
136
|
+
// shader fails to compile with 'undeclared identifier: receiveShadow', and the
|
|
137
|
+
// material renders black with nothing but a console error to say why.
|
|
138
|
+
#include <lights_pars_begin>
|
|
139
|
+
#include <shadowmap_pars_fragment>
|
|
140
|
+
#include <shadowmask_pars_fragment>
|
|
141
|
+
|
|
142
|
+
${skyLib}
|
|
143
|
+
${oceanFull}
|
|
144
|
+
|
|
145
|
+
varying vec3 vWorld;
|
|
146
|
+
varying vec3 vNormal_;
|
|
147
|
+
varying float vFoam;
|
|
148
|
+
varying float vRelHeight;
|
|
149
|
+
varying float vDist;
|
|
150
|
+
varying float vDepthFactor;
|
|
151
|
+
|
|
152
|
+
void main(){
|
|
153
|
+
vec3 viewDir = normalize(vWorld - cameraPosition);
|
|
154
|
+
|
|
155
|
+
vec3 n = normalize(vNormal_);
|
|
156
|
+
float detail = oceanDetailFade(vDist);
|
|
157
|
+
n = oceanDetailNormal(n, vWorld, detail);
|
|
158
|
+
|
|
159
|
+
// Backfacing water is water seen from underneath. Flipping the normal keeps
|
|
160
|
+
// the shading sane there until the underwater pass exists.
|
|
161
|
+
if (!gl_FrontFacing) n = -n;
|
|
162
|
+
|
|
163
|
+
// Geometric specular antialiasing (Kaplanyan/Tokuyoshi): measure how much the
|
|
164
|
+
// shading normal turns across this pixel and widen the specular lobe by that
|
|
165
|
+
// much. On water this is not a nicety - the mesh carries waves down to a
|
|
166
|
+
// couple of cells and the lobe is tight enough that every crest facet flashes
|
|
167
|
+
// on and off between frames. Filtering the normal instead of softening the
|
|
168
|
+
// water keeps the glitter and loses the boil.
|
|
169
|
+
vec3 nDx = dFdx(n);
|
|
170
|
+
vec3 nDy = dFdy(n);
|
|
171
|
+
float normalVar = 0.5 * (dot(nDx, nDx) + dot(nDy, nDy));
|
|
172
|
+
float roughAA = min(sqrt(normalVar) * 0.8, 0.25);
|
|
173
|
+
// Detail the fade removed was real roughness; hand it to the lobe rather than
|
|
174
|
+
// deleting it, or distant water turns to plastic.
|
|
175
|
+
roughAA += (1.0 - detail) * u_detailStrength * 0.06;
|
|
176
|
+
|
|
177
|
+
float sceneShadow = 1.0;
|
|
178
|
+
#ifdef USE_SHADOWMAP
|
|
179
|
+
sceneShadow = mix(1.0, getShadowMask(), u_receiveShadows);
|
|
180
|
+
#endif
|
|
181
|
+
|
|
182
|
+
vec3 col = oceanLight(vWorld, n, viewDir, vFoam, vRelHeight, sceneShadow, vDepthFactor, roughAA, vec3(0.0));
|
|
183
|
+
col = oceanAerial(col, viewDir, vDist);
|
|
184
|
+
col *= u_exposure;
|
|
185
|
+
|
|
186
|
+
gl_FragColor = vec4(col, 1.0);
|
|
187
|
+
|
|
188
|
+
#include <tonemapping_fragment>
|
|
189
|
+
#include <colorspace_fragment>
|
|
190
|
+
#include <fog_fragment>
|
|
191
|
+
}
|
|
192
|
+
`;
|
|
193
|
+
function emptyWaveTable() {
|
|
194
|
+
return Array.from({ length: MAX_WAVES }, () => new THREE.Vector4());
|
|
195
|
+
}
|
|
196
|
+
/** Uniform-space defaults. Config units are converted by `applyOceanUniforms`;
|
|
197
|
+
* these are only what the material holds before anything is applied. */
|
|
198
|
+
export const oceanMaterialDefaults = {
|
|
199
|
+
u_waveA: emptyWaveTable(),
|
|
200
|
+
u_waveB: emptyWaveTable(),
|
|
201
|
+
u_waveCount: 0,
|
|
202
|
+
u_time: 0,
|
|
203
|
+
u_waterLevel: 0,
|
|
204
|
+
u_choppiness: 0.85,
|
|
205
|
+
u_amplitudeScale: 1,
|
|
206
|
+
u_bodyHalf: new THREE.Vector2(0, 0),
|
|
207
|
+
u_edgeFade: 0.15,
|
|
208
|
+
u_deepColor: new THREE.Color('#052539'),
|
|
209
|
+
u_shallowColor: new THREE.Color('#1b7f8c'),
|
|
210
|
+
u_foamColor: new THREE.Color('#eef6f8'),
|
|
211
|
+
u_sssColor: new THREE.Color('#2f8f74'),
|
|
212
|
+
u_absorption: 0.06,
|
|
213
|
+
u_clarity: 0.25,
|
|
214
|
+
u_roughness: 0.09,
|
|
215
|
+
u_specular: 1,
|
|
216
|
+
u_sssStrength: 0.7,
|
|
217
|
+
u_detailStrength: 0.55,
|
|
218
|
+
u_detailScale: 1 / 2.2,
|
|
219
|
+
u_detailFade: 1 / 900,
|
|
220
|
+
u_pixelScale: 0.0026,
|
|
221
|
+
u_foamAmount: 0.8,
|
|
222
|
+
u_foamDecay: 0.5,
|
|
223
|
+
u_foamScale: 1 / 6,
|
|
224
|
+
u_ambientScale: 1,
|
|
225
|
+
u_fogDensity: 0.00009,
|
|
226
|
+
u_exposure: 1,
|
|
227
|
+
u_curvature: 1 / (2 * 6371000),
|
|
228
|
+
u_receiveShadows: 1,
|
|
229
|
+
// Shared with the cloud and terrain materials, set by the same
|
|
230
|
+
// applySunUniforms() off the same useCloudSun state.
|
|
231
|
+
u_sunDir: new THREE.Vector3(0.35, 0.42, 0.84).normalize(),
|
|
232
|
+
u_sunColor: new THREE.Color(1, 1, 1),
|
|
233
|
+
u_skyAmbient: new THREE.Color(0.6, 0.9, 1.6),
|
|
234
|
+
u_groundAmbient: new THREE.Color(0.45, 0.42, 0.37),
|
|
235
|
+
u_sunIntensity: 1,
|
|
236
|
+
u_turbidity: 2,
|
|
237
|
+
u_rayleigh: 1,
|
|
238
|
+
u_mieCoefficient: 0.005,
|
|
239
|
+
u_mieG: 0.76,
|
|
240
|
+
};
|
|
241
|
+
function buildUniforms() {
|
|
242
|
+
const own = {};
|
|
243
|
+
for (const [key, value] of Object.entries(oceanMaterialDefaults)) {
|
|
244
|
+
own[key] = { value };
|
|
245
|
+
}
|
|
246
|
+
// The lights block first, so a name collision would resolve to ours; there
|
|
247
|
+
// are none, because everything of ours is u_-prefixed.
|
|
248
|
+
return THREE.UniformsUtils.merge([
|
|
249
|
+
THREE.UniformsLib.lights,
|
|
250
|
+
THREE.UniformsLib.fog,
|
|
251
|
+
own,
|
|
252
|
+
]);
|
|
253
|
+
}
|
|
254
|
+
export class OceanSurfaceMaterial extends THREE.ShaderMaterial {
|
|
255
|
+
constructor() {
|
|
256
|
+
super({
|
|
257
|
+
uniforms: buildUniforms(),
|
|
258
|
+
vertexShader: vertex,
|
|
259
|
+
fragmentShader: fragment,
|
|
260
|
+
lights: true,
|
|
261
|
+
fog: true,
|
|
262
|
+
});
|
|
263
|
+
// Both sides: the camera goes under the surface, and a placed body is
|
|
264
|
+
// routinely looked into from above its own rim.
|
|
265
|
+
this.side = THREE.DoubleSide;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
extend({ OceanSurfaceMaterial });
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { type ThreeElement } from '@react-three/fiber';
|
|
3
|
+
export interface TerrainMaterialUniforms {
|
|
4
|
+
[key: string]: THREE.IUniform;
|
|
5
|
+
}
|
|
6
|
+
/** Uniform-space defaults. Config units are converted by `applyTerrainUniforms`;
|
|
7
|
+
* these are only what the material holds before anything is applied. */
|
|
8
|
+
export declare const terrainMaterialDefaults: {
|
|
9
|
+
u_terrainType: number;
|
|
10
|
+
u_elevation: number;
|
|
11
|
+
u_seaLevel: number;
|
|
12
|
+
u_baseScale: number;
|
|
13
|
+
u_octaves: number;
|
|
14
|
+
u_lacunarity: number;
|
|
15
|
+
u_gain: number;
|
|
16
|
+
u_ridge: number;
|
|
17
|
+
u_warpStrength: number;
|
|
18
|
+
u_warpScale: number;
|
|
19
|
+
u_erosion: number;
|
|
20
|
+
u_terraces: number;
|
|
21
|
+
u_terraceSharp: number;
|
|
22
|
+
u_bearingDir: THREE.Vector2;
|
|
23
|
+
u_duneFreq: number;
|
|
24
|
+
u_duneAsym: number;
|
|
25
|
+
u_plateau: number;
|
|
26
|
+
u_valleyDepth: number;
|
|
27
|
+
u_valleyWidth: number;
|
|
28
|
+
u_cellSize: number;
|
|
29
|
+
u_curvature: number;
|
|
30
|
+
u_lowColor: THREE.Color;
|
|
31
|
+
u_midColor: THREE.Color;
|
|
32
|
+
u_rockColor: THREE.Color;
|
|
33
|
+
u_peakColor: THREE.Color;
|
|
34
|
+
u_slopeRockStart: number;
|
|
35
|
+
u_slopeRockEnd: number;
|
|
36
|
+
u_peakLevel: number;
|
|
37
|
+
u_peakBlend: number;
|
|
38
|
+
u_peakSlopeFalloff: number;
|
|
39
|
+
u_macroVariation: number;
|
|
40
|
+
u_macroScale: number;
|
|
41
|
+
u_detailStrength: number;
|
|
42
|
+
u_detailScale: number;
|
|
43
|
+
u_detailFade: number;
|
|
44
|
+
u_roughness: number;
|
|
45
|
+
u_specular: number;
|
|
46
|
+
u_ambient: number;
|
|
47
|
+
u_bounce: number;
|
|
48
|
+
u_sunShadow: number;
|
|
49
|
+
u_shadowSoftness: number;
|
|
50
|
+
u_shadowDistance: number;
|
|
51
|
+
u_fogDensity: number;
|
|
52
|
+
u_exposure: number;
|
|
53
|
+
u_shadowSteps: number;
|
|
54
|
+
u_receiveShadows: number;
|
|
55
|
+
u_sunDir: THREE.Vector3;
|
|
56
|
+
u_sunColor: THREE.Color;
|
|
57
|
+
u_skyAmbient: THREE.Color;
|
|
58
|
+
u_groundAmbient: THREE.Color;
|
|
59
|
+
u_sunIntensity: number;
|
|
60
|
+
u_turbidity: number;
|
|
61
|
+
u_rayleigh: number;
|
|
62
|
+
u_mieCoefficient: number;
|
|
63
|
+
u_mieG: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* `UniformsUtils.merge` clones by `Uniform.clone()`, which deep-copies Colors and
|
|
67
|
+
* Vectors but turns a plain object into a shallow copy — fine here, since every
|
|
68
|
+
* own uniform is a number, Color or Vector. The lights block must come first so
|
|
69
|
+
* a name collision would resolve to ours; there are none, because everything of
|
|
70
|
+
* ours is `u_`-prefixed.
|
|
71
|
+
*/
|
|
72
|
+
export declare class TerrainMaterial extends THREE.ShaderMaterial {
|
|
73
|
+
constructor();
|
|
74
|
+
}
|
|
75
|
+
declare module '@react-three/fiber' {
|
|
76
|
+
interface ThreeElements {
|
|
77
|
+
terrainMaterial: ThreeElement<typeof TerrainMaterial>;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=TerrainMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TerrainMaterial.d.ts","sourceRoot":"","sources":["../../../src/shaders/terrain/TerrainMaterial.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAU,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAyM9D,MAAM,WAAW,uBAAuB;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAA;CAChC;AAED;yEACyE;AACzE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEnC,CAAA;AAcD;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,KAAK,CAAC,cAAc;;CAWxD;AAID,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,aAAa;QACnB,eAAe,EAAE,YAAY,CAAC,OAAO,eAAe,CAAC,CAAA;KACxD;CACJ"}
|