@zephyr3d/scene 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animation.js +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import { Application } from '../app.js';
|
|
2
|
+
import { Vector4, Interpolator, Vector2, Plane, Matrix4x4, Vector3 } from '@zephyr3d/base';
|
|
3
|
+
import '../scene/octree.js';
|
|
4
|
+
import '../material/material.js';
|
|
5
|
+
import '@zephyr3d/device';
|
|
6
|
+
import '../shaders/framework.js';
|
|
7
|
+
import { decodeNormalizedFloatFromRGBA, linearToGamma } from '../shaders/misc.js';
|
|
8
|
+
import '../render/scatteringlut.js';
|
|
9
|
+
import '../material/lambert.js';
|
|
10
|
+
import '../material/blinn.js';
|
|
11
|
+
import '../material/unlit.js';
|
|
12
|
+
import '../material/lightmodel.js';
|
|
13
|
+
import '../render/forward.js';
|
|
14
|
+
import '../render/sky.js';
|
|
15
|
+
import '../render/clipmap.js';
|
|
16
|
+
import { TemporalCache } from '../render/temporalcache.js';
|
|
17
|
+
import { WaterMesh } from '../render/watermesh.js';
|
|
18
|
+
import { AbstractPostEffect } from './posteffect.js';
|
|
19
|
+
import { Camera } from '../camera/camera.js';
|
|
20
|
+
import { CopyBlitter } from '../blitter/copy.js';
|
|
21
|
+
import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The post water effect
|
|
25
|
+
* @public
|
|
26
|
+
*/ class PostWater extends AbstractPostEffect {
|
|
27
|
+
_elevation;
|
|
28
|
+
_region;
|
|
29
|
+
_gridScale;
|
|
30
|
+
_reflectSize;
|
|
31
|
+
_copyBlitter;
|
|
32
|
+
_renderingReflections;
|
|
33
|
+
_antiReflectanceLeak;
|
|
34
|
+
_displace;
|
|
35
|
+
_depthMulti;
|
|
36
|
+
_refractionStrength;
|
|
37
|
+
_absorptionGrad;
|
|
38
|
+
_scatterGrad;
|
|
39
|
+
_rampTex;
|
|
40
|
+
_foamWidth;
|
|
41
|
+
_foamContrast;
|
|
42
|
+
_waterAlignment;
|
|
43
|
+
_waterWireframe;
|
|
44
|
+
_waterWind;
|
|
45
|
+
_waveLength0;
|
|
46
|
+
_waveStrength0;
|
|
47
|
+
_waveCroppiness0;
|
|
48
|
+
_waveLength1;
|
|
49
|
+
_waveStrength1;
|
|
50
|
+
_waveCroppiness1;
|
|
51
|
+
_waveLength2;
|
|
52
|
+
_waveStrength2;
|
|
53
|
+
_waveCroppiness2;
|
|
54
|
+
_currentWaterMesh;
|
|
55
|
+
_waterMeshes;
|
|
56
|
+
/**
|
|
57
|
+
* Creates an instance of PostWater.
|
|
58
|
+
* @param elevation - Elevation of the water
|
|
59
|
+
*/ constructor(elevation){
|
|
60
|
+
super();
|
|
61
|
+
this._elevation = elevation ?? 0;
|
|
62
|
+
this._region = new Vector4(-1000, -1000, 1000, 1000);
|
|
63
|
+
this._gridScale = 1;
|
|
64
|
+
this._reflectSize = 512;
|
|
65
|
+
this._antiReflectanceLeak = 0.5;
|
|
66
|
+
this._opaque = true;
|
|
67
|
+
this._displace = 16;
|
|
68
|
+
this._depthMulti = 0.1;
|
|
69
|
+
this._refractionStrength = 0;
|
|
70
|
+
this._copyBlitter = new CopyBlitter();
|
|
71
|
+
this._renderingReflections = false;
|
|
72
|
+
this._absorptionGrad = new Interpolator('linear', 'vec3', new Float32Array([
|
|
73
|
+
0,
|
|
74
|
+
0.082,
|
|
75
|
+
0.318,
|
|
76
|
+
0.665,
|
|
77
|
+
1
|
|
78
|
+
]), new Float32Array([
|
|
79
|
+
1,
|
|
80
|
+
1,
|
|
81
|
+
1,
|
|
82
|
+
0.22,
|
|
83
|
+
0.87,
|
|
84
|
+
0.87,
|
|
85
|
+
0,
|
|
86
|
+
0.47,
|
|
87
|
+
0.49,
|
|
88
|
+
0,
|
|
89
|
+
0.275,
|
|
90
|
+
0.44,
|
|
91
|
+
0,
|
|
92
|
+
0,
|
|
93
|
+
0
|
|
94
|
+
]));
|
|
95
|
+
this._scatterGrad = new Interpolator('linear', 'vec3', new Float32Array([
|
|
96
|
+
0,
|
|
97
|
+
0.15,
|
|
98
|
+
0.42,
|
|
99
|
+
1
|
|
100
|
+
]), new Float32Array([
|
|
101
|
+
0,
|
|
102
|
+
0,
|
|
103
|
+
0,
|
|
104
|
+
0.08,
|
|
105
|
+
0.41,
|
|
106
|
+
0.34,
|
|
107
|
+
0.13,
|
|
108
|
+
0.40,
|
|
109
|
+
0.45,
|
|
110
|
+
0.21,
|
|
111
|
+
0.5,
|
|
112
|
+
0.6
|
|
113
|
+
]));
|
|
114
|
+
this._rampTex = null;
|
|
115
|
+
this.addIntermediateFramebuffer('reflection', 'temporal');
|
|
116
|
+
this._foamWidth = 1.2;
|
|
117
|
+
this._foamContrast = 7.2;
|
|
118
|
+
this._waterWireframe = false;
|
|
119
|
+
this._waterAlignment = 1;
|
|
120
|
+
this._waterWind = new Vector2(2, 2);
|
|
121
|
+
this._waveLength0 = 400;
|
|
122
|
+
this._waveStrength0 = 0.4;
|
|
123
|
+
this._waveCroppiness0 = -1.5;
|
|
124
|
+
this._waveLength1 = 100;
|
|
125
|
+
this._waveStrength1 = 0.4;
|
|
126
|
+
this._waveCroppiness1 = -1.2;
|
|
127
|
+
this._waveLength2 = 15;
|
|
128
|
+
this._waveStrength2 = 0.2;
|
|
129
|
+
this._waveCroppiness2 = -0.5;
|
|
130
|
+
this._currentWaterMesh = null;
|
|
131
|
+
this._waterMeshes = {};
|
|
132
|
+
}
|
|
133
|
+
get wireframe() {
|
|
134
|
+
return this._waterWireframe;
|
|
135
|
+
}
|
|
136
|
+
set wireframe(val) {
|
|
137
|
+
this._waterWireframe = val;
|
|
138
|
+
if (this._currentWaterMesh) {
|
|
139
|
+
this._currentWaterMesh.wireframe = this._waterWireframe;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
get alignment() {
|
|
143
|
+
return this._waterAlignment;
|
|
144
|
+
}
|
|
145
|
+
set alignment(val) {
|
|
146
|
+
this._waterAlignment = val;
|
|
147
|
+
if (this._currentWaterMesh) {
|
|
148
|
+
this._currentWaterMesh.alignment = this._waterAlignment;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
get wind() {
|
|
152
|
+
return this._waterWind;
|
|
153
|
+
}
|
|
154
|
+
set wind(val) {
|
|
155
|
+
this._waterWind.set(val);
|
|
156
|
+
}
|
|
157
|
+
get foamWidth() {
|
|
158
|
+
return this._foamWidth;
|
|
159
|
+
}
|
|
160
|
+
set foamWidth(val) {
|
|
161
|
+
this._foamWidth = val;
|
|
162
|
+
if (this._currentWaterMesh) {
|
|
163
|
+
this._currentWaterMesh.foamWidth = this._foamWidth;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
get foamContrast() {
|
|
167
|
+
return this._foamContrast;
|
|
168
|
+
}
|
|
169
|
+
set foamContrast(val) {
|
|
170
|
+
this._foamContrast = val;
|
|
171
|
+
if (this._currentWaterMesh) {
|
|
172
|
+
this._currentWaterMesh.foamContrast = this._foamContrast;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
get waveLength0() {
|
|
176
|
+
return this._waveLength0;
|
|
177
|
+
}
|
|
178
|
+
set waveLength0(val) {
|
|
179
|
+
this._waveLength0 = val;
|
|
180
|
+
if (this._currentWaterMesh) {
|
|
181
|
+
this._currentWaterMesh.setWaveLength(0, this._waveLength0);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
get waveStrength0() {
|
|
185
|
+
return this._waveStrength0;
|
|
186
|
+
}
|
|
187
|
+
set waveStrength0(val) {
|
|
188
|
+
this._waveStrength0 = val;
|
|
189
|
+
if (this._currentWaterMesh) {
|
|
190
|
+
this._currentWaterMesh.setWaveStrength(0, this._waveStrength0);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
get waveCroppiness0() {
|
|
194
|
+
return this._waveCroppiness0;
|
|
195
|
+
}
|
|
196
|
+
set waveCroppiness0(val) {
|
|
197
|
+
this._waveCroppiness0 = val;
|
|
198
|
+
if (this._currentWaterMesh) {
|
|
199
|
+
this._currentWaterMesh.setWaveCroppiness(0, this._waveCroppiness0);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
get waveLength1() {
|
|
203
|
+
return this._waveLength1;
|
|
204
|
+
}
|
|
205
|
+
set waveLength1(val) {
|
|
206
|
+
this._waveLength1 = val;
|
|
207
|
+
if (this._currentWaterMesh) {
|
|
208
|
+
this._currentWaterMesh.setWaveLength(1, this._waveLength1);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
get waveStrength1() {
|
|
212
|
+
return this._waveStrength1;
|
|
213
|
+
}
|
|
214
|
+
set waveStrength1(val) {
|
|
215
|
+
this._waveStrength1 = val;
|
|
216
|
+
if (this._currentWaterMesh) {
|
|
217
|
+
this._currentWaterMesh.setWaveStrength(1, this._waveStrength1);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
get waveCroppiness1() {
|
|
221
|
+
return this._waveCroppiness1;
|
|
222
|
+
}
|
|
223
|
+
set waveCroppiness1(val) {
|
|
224
|
+
this._waveCroppiness1 = val;
|
|
225
|
+
if (this._currentWaterMesh) {
|
|
226
|
+
this._currentWaterMesh.setWaveCroppiness(1, this._waveCroppiness1);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
get waveLength2() {
|
|
230
|
+
return this._waveLength2;
|
|
231
|
+
}
|
|
232
|
+
set waveLength2(val) {
|
|
233
|
+
this._waveLength2 = val;
|
|
234
|
+
if (this._currentWaterMesh) {
|
|
235
|
+
this._currentWaterMesh.setWaveLength(2, this._waveLength2);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
get waveStrength2() {
|
|
239
|
+
return this._waveStrength2;
|
|
240
|
+
}
|
|
241
|
+
set waveStrength2(val) {
|
|
242
|
+
this._waveStrength2 = val;
|
|
243
|
+
if (this._currentWaterMesh) {
|
|
244
|
+
this._currentWaterMesh.setWaveStrength(2, this._waveStrength2);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
get waveCroppiness2() {
|
|
248
|
+
return this._waveCroppiness2;
|
|
249
|
+
}
|
|
250
|
+
set waveCroppiness2(val) {
|
|
251
|
+
this._waveCroppiness2 = val;
|
|
252
|
+
if (this._currentWaterMesh) {
|
|
253
|
+
this._currentWaterMesh.setWaveCroppiness(2, this._waveCroppiness2);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/** Refraction strength */ get refractionStrength() {
|
|
257
|
+
return this._refractionStrength;
|
|
258
|
+
}
|
|
259
|
+
set refractionStrength(val) {
|
|
260
|
+
this._refractionStrength = val;
|
|
261
|
+
}
|
|
262
|
+
/** Water depth multiply factor */ get depthMulti() {
|
|
263
|
+
return this._depthMulti;
|
|
264
|
+
}
|
|
265
|
+
set depthMulti(val) {
|
|
266
|
+
this._depthMulti = val;
|
|
267
|
+
}
|
|
268
|
+
/** Water elevation in world space */ get elevation() {
|
|
269
|
+
return this._elevation;
|
|
270
|
+
}
|
|
271
|
+
set elevation(val) {
|
|
272
|
+
this._elevation = val;
|
|
273
|
+
}
|
|
274
|
+
/** Water boundary in world space ( minX, minZ, maxX, maxZ ) */ get boundary() {
|
|
275
|
+
return this._region;
|
|
276
|
+
}
|
|
277
|
+
set boundary(val) {
|
|
278
|
+
this._region.set(val);
|
|
279
|
+
if (this._currentWaterMesh) {
|
|
280
|
+
this._currentWaterMesh.regionMin.setXY(this._region.x, this._region.y);
|
|
281
|
+
this._currentWaterMesh.regionMax.setXY(this._region.z, this._region.w);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/** Water clipmap grid scale */ get gridScale() {
|
|
285
|
+
return this._gridScale;
|
|
286
|
+
}
|
|
287
|
+
set gridScale(val) {
|
|
288
|
+
this._gridScale = val;
|
|
289
|
+
if (this._currentWaterMesh) {
|
|
290
|
+
this._currentWaterMesh.gridScale = this._gridScale;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/** The amount for increasing the water elevation to reduce leaking artifact */ get antiReflectanceLeak() {
|
|
294
|
+
return this._antiReflectanceLeak;
|
|
295
|
+
}
|
|
296
|
+
set antiReflectanceLeak(val) {
|
|
297
|
+
this._antiReflectanceLeak = val;
|
|
298
|
+
}
|
|
299
|
+
/** Texture displace */ get displace() {
|
|
300
|
+
return this._displace;
|
|
301
|
+
}
|
|
302
|
+
set displace(val) {
|
|
303
|
+
this._displace = val;
|
|
304
|
+
}
|
|
305
|
+
/** {@inheritDoc AbstractPostEffect.requireLinearDepthTexture} */ requireLinearDepthTexture() {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
/** {@inheritDoc AbstractPostEffect.requireDepthAttachment} */ requireDepthAttachment() {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
/** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
312
|
+
const device = Application.instance.device;
|
|
313
|
+
const rampTex = this._getRampTexture(device);
|
|
314
|
+
this._copyBlitter.srgbOut = srgbOutput;
|
|
315
|
+
this._copyBlitter.blit(inputColorTexture, device.getFramebuffer(), device.createSampler({
|
|
316
|
+
magFilter: 'nearest',
|
|
317
|
+
minFilter: 'nearest',
|
|
318
|
+
mipFilter: 'none',
|
|
319
|
+
addressU: 'clamp',
|
|
320
|
+
addressV: 'clamp'
|
|
321
|
+
}));
|
|
322
|
+
if (this._renderingReflections) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
this._renderingReflections = true;
|
|
326
|
+
const fbRefl = TemporalCache.getFramebufferFixedSize(this._reflectSize, this._reflectSize, 1, inputColorTexture.format, ctx.depthFormat, '2d', '2d', false);
|
|
327
|
+
const plane = new Plane(0, -1, 0, this._elevation);
|
|
328
|
+
const clipPlane = new Plane(0, -1, 0, this._elevation - this._antiReflectanceLeak);
|
|
329
|
+
const matReflectionR = Matrix4x4.invert(Matrix4x4.reflection(-plane.a, -plane.b, -plane.c, -plane.d));
|
|
330
|
+
const reflCamera = new Camera(ctx.scene);
|
|
331
|
+
reflCamera.framebuffer = fbRefl;
|
|
332
|
+
Matrix4x4.multiply(matReflectionR, ctx.camera.worldMatrix).decompose(reflCamera.scale, reflCamera.rotation, reflCamera.position);
|
|
333
|
+
reflCamera.setProjectionMatrix(ctx.camera.getProjectionMatrix());
|
|
334
|
+
reflCamera.clipPlane = clipPlane;
|
|
335
|
+
reflCamera.render(ctx.scene, ctx.compositor);
|
|
336
|
+
reflCamera.remove();
|
|
337
|
+
this._renderingReflections = false;
|
|
338
|
+
const cameraNearFar = new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane());
|
|
339
|
+
const waterMesh = this._getWaterMesh(ctx);
|
|
340
|
+
waterMesh.regionMin.setXY(this._region.x, this._region.y);
|
|
341
|
+
waterMesh.regionMax.setXY(this._region.z, this._region.w);
|
|
342
|
+
waterMesh.wind = this._waterWind;
|
|
343
|
+
if (waterMesh !== this._currentWaterMesh) {
|
|
344
|
+
waterMesh.wireframe = this._waterWireframe;
|
|
345
|
+
waterMesh.gridScale = this._gridScale;
|
|
346
|
+
waterMesh.alignment = this._waterAlignment;
|
|
347
|
+
waterMesh.foamWidth = this._foamWidth;
|
|
348
|
+
waterMesh.foamContrast = this._foamContrast;
|
|
349
|
+
waterMesh.setWaveLength(0, this._waveLength0);
|
|
350
|
+
waterMesh.setWaveLength(1, this._waveLength1);
|
|
351
|
+
waterMesh.setWaveLength(2, this._waveLength2);
|
|
352
|
+
waterMesh.setWaveStrength(0, this._waveStrength0);
|
|
353
|
+
waterMesh.setWaveStrength(1, this._waveStrength1);
|
|
354
|
+
waterMesh.setWaveStrength(2, this._waveStrength2);
|
|
355
|
+
waterMesh.setWaveCroppiness(0, this._waveCroppiness0);
|
|
356
|
+
waterMesh.setWaveCroppiness(1, this._waveCroppiness1);
|
|
357
|
+
waterMesh.setWaveCroppiness(2, this._waveCroppiness2);
|
|
358
|
+
this._currentWaterMesh = waterMesh;
|
|
359
|
+
}
|
|
360
|
+
waterMesh.bindGroup.setTexture('tex', inputColorTexture);
|
|
361
|
+
waterMesh.bindGroup.setTexture('depthTex', sceneDepthTexture);
|
|
362
|
+
waterMesh.bindGroup.setTexture('rampTex', rampTex);
|
|
363
|
+
waterMesh.bindGroup.setTexture('reflectionTex', fbRefl.getColorAttachments()[0]);
|
|
364
|
+
waterMesh.bindGroup.setValue('invViewProj', ctx.camera.invViewProjectionMatrix);
|
|
365
|
+
waterMesh.bindGroup.setValue('cameraNearFar', cameraNearFar);
|
|
366
|
+
waterMesh.bindGroup.setValue('cameraPos', ctx.camera.getWorldPosition());
|
|
367
|
+
waterMesh.bindGroup.setValue('displace', this._displace / fbRefl.getColorAttachments()[0].width);
|
|
368
|
+
waterMesh.bindGroup.setValue('depthMulti', this._depthMulti);
|
|
369
|
+
waterMesh.bindGroup.setValue('refractionStrength', this._refractionStrength);
|
|
370
|
+
waterMesh.bindGroup.setValue('targetSize', new Vector2(device.getViewport().width, device.getViewport().height));
|
|
371
|
+
waterMesh.bindGroup.setValue('envLightStrength', ctx.env.light.strength);
|
|
372
|
+
waterMesh.bindGroup.setValue('waterLevel', this._elevation);
|
|
373
|
+
waterMesh.bindGroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
374
|
+
if (ctx.sunLight) {
|
|
375
|
+
waterMesh.bindGroup.setValue('lightDir', ctx.sunLight.directionAndCutoff.xyz());
|
|
376
|
+
waterMesh.bindGroup.setValue('lightShininess', 0.7);
|
|
377
|
+
waterMesh.bindGroup.setValue('lightDiffuseAndIntensity', ctx.sunLight.diffuseAndIntensity);
|
|
378
|
+
}
|
|
379
|
+
ctx.env.light.envLight.updateBindGroup(waterMesh.bindGroup);
|
|
380
|
+
waterMesh.render(ctx.camera, this.needFlip(device));
|
|
381
|
+
TemporalCache.releaseFramebuffer(fbRefl);
|
|
382
|
+
}
|
|
383
|
+
/** @internal */ _getRampTexture(device) {
|
|
384
|
+
if (!this._rampTex) {
|
|
385
|
+
const width = 128;
|
|
386
|
+
const height = 64;
|
|
387
|
+
this._rampTex = device.createTexture2D('rgba8unorm', width, height, {
|
|
388
|
+
samplerOptions: {
|
|
389
|
+
mipFilter: 'none'
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
const numTexels = width * height;
|
|
393
|
+
const data = new Uint8Array(numTexels * 4);
|
|
394
|
+
const tmpcolor = new Vector3();
|
|
395
|
+
for(let i = 0; i < numTexels; i++){
|
|
396
|
+
const grad = i >= numTexels / 2 ? this._scatterGrad : this._absorptionGrad;
|
|
397
|
+
grad.interpolate(i % width / width, 1, tmpcolor);
|
|
398
|
+
data[i * 4 + 0] = tmpcolor.x * 255 >> 0;
|
|
399
|
+
data[i * 4 + 1] = tmpcolor.y * 255 >> 0;
|
|
400
|
+
data[i * 4 + 2] = tmpcolor.z * 255 >> 0;
|
|
401
|
+
data[i * 4 + 3] = 255;
|
|
402
|
+
}
|
|
403
|
+
this._rampTex.update(data, 0, 0, this._rampTex.width, this._rampTex.height);
|
|
404
|
+
this._rampTex.name = 'WaterRampTex';
|
|
405
|
+
}
|
|
406
|
+
return this._rampTex;
|
|
407
|
+
}
|
|
408
|
+
/** @internal */ _getWaterMesh(ctx) {
|
|
409
|
+
const hash = `${ctx.sunLight ? 1 : 0}:${ctx.env.light.getHash(ctx)}`;
|
|
410
|
+
let waterMesh = this._waterMeshes[hash];
|
|
411
|
+
if (!waterMesh) {
|
|
412
|
+
const device = Application.instance.device;
|
|
413
|
+
waterMesh = new WaterMesh(device, {
|
|
414
|
+
setupUniforms (scope) {
|
|
415
|
+
const pb = scope.$builder;
|
|
416
|
+
if (pb.shaderKind === 'fragment') {
|
|
417
|
+
scope.tex = pb.tex2D().uniform(0);
|
|
418
|
+
scope.depthTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);
|
|
419
|
+
scope.rampTex = pb.tex2D().uniform(0);
|
|
420
|
+
scope.reflectionTex = pb.tex2D().uniform(0);
|
|
421
|
+
scope.displace = pb.float().uniform(0);
|
|
422
|
+
scope.depthMulti = pb.float().uniform(0);
|
|
423
|
+
scope.refractionStrength = pb.float().uniform(0);
|
|
424
|
+
scope.cameraNearFar = pb.vec2().uniform(0);
|
|
425
|
+
scope.cameraPos = pb.vec3().uniform(0);
|
|
426
|
+
scope.invViewProj = pb.mat4().uniform(0);
|
|
427
|
+
scope.targetSize = pb.vec2().uniform(0);
|
|
428
|
+
scope.envLightStrength = pb.float().uniform(0);
|
|
429
|
+
scope.waterLevel = pb.float().uniform(0);
|
|
430
|
+
scope.srgbOut = pb.int().uniform(0);
|
|
431
|
+
if (ctx.sunLight) {
|
|
432
|
+
scope.lightDir = pb.vec3().uniform(0);
|
|
433
|
+
scope.lightShininess = pb.float().uniform(0);
|
|
434
|
+
scope.lightDiffuseAndIntensity = pb.vec4().uniform(0);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
ctx.env.light.envLight.initShaderBindings(pb);
|
|
438
|
+
},
|
|
439
|
+
shading (scope, worldPos, worldNormal, foamFactor) {
|
|
440
|
+
const pb = scope.$builder;
|
|
441
|
+
pb.func('getAbsorption', [
|
|
442
|
+
pb.float('depth')
|
|
443
|
+
], function() {
|
|
444
|
+
this.$l.c = pb.textureSampleLevel(this.rampTex, pb.vec2(pb.mul(this.depth, this.depthMulti), 0.25), 0).rgb;
|
|
445
|
+
this.$return(pb.mul(this.c, this.c));
|
|
446
|
+
});
|
|
447
|
+
pb.func('getScattering', [
|
|
448
|
+
pb.float('depth')
|
|
449
|
+
], function() {
|
|
450
|
+
this.$l.c = pb.textureSampleLevel(this.rampTex, pb.vec2(pb.mul(this.depth, this.depthMulti), 0.75), 0).rgb;
|
|
451
|
+
this.$return(pb.mul(this.c, this.c));
|
|
452
|
+
});
|
|
453
|
+
pb.func('getPositionWS', [
|
|
454
|
+
pb.vec2('uv')
|
|
455
|
+
], function() {
|
|
456
|
+
this.$l.depthValue = pb.textureSampleLevel(this.depthTex, this.uv, 0);
|
|
457
|
+
if (device.type === 'webgl') {
|
|
458
|
+
this.$l.linearDepth = decodeNormalizedFloatFromRGBA(this, this.depthValue);
|
|
459
|
+
} else {
|
|
460
|
+
this.$l.linearDepth = this.depthValue.r;
|
|
461
|
+
}
|
|
462
|
+
this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(this.cameraNearFar.x, this.linearDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
|
|
463
|
+
this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.nonLinearDepth, 0, 1), 2), 1), 1);
|
|
464
|
+
this.$l.wPos = pb.mul(this.invViewProj, this.clipSpacePos);
|
|
465
|
+
this.$return(pb.div(this.wPos.xyz, this.wPos.w));
|
|
466
|
+
});
|
|
467
|
+
pb.func('fresnel', [
|
|
468
|
+
pb.vec3('normal'),
|
|
469
|
+
pb.vec3('eyeVec')
|
|
470
|
+
], function() {
|
|
471
|
+
this.$return(pb.clamp(pb.sub(pb.pow(pb.sub(1, pb.dot(this.normal, this.eyeVec)), 5), this.refractionStrength), 0, 1));
|
|
472
|
+
});
|
|
473
|
+
pb.func('waterShading', [
|
|
474
|
+
pb.vec3('worldPos'),
|
|
475
|
+
pb.vec3('worldNormal'),
|
|
476
|
+
pb.float('foamFactor')
|
|
477
|
+
], function() {
|
|
478
|
+
this.$l.screenUV = pb.div(pb.vec2(this.$builtins.fragCoord.xy), this.targetSize);
|
|
479
|
+
this.$l.dist = pb.length(pb.sub(this.worldPos, this.cameraPos));
|
|
480
|
+
this.$l.normalScale = pb.pow(pb.clamp(pb.div(100, this.dist), 0, 1), 4);
|
|
481
|
+
this.$l.myNormal = pb.normalize(pb.mul(this.worldNormal, pb.vec3(this.normalScale, 1, this.normalScale)));
|
|
482
|
+
this.$l.displacedTexCoord = pb.add(this.screenUV, pb.mul(this.myNormal.xz, this.displace));
|
|
483
|
+
this.$l.wPos = this.getPositionWS(this.displacedTexCoord);
|
|
484
|
+
this.$l.eyeVec = pb.sub(this.wPos.xyz, this.cameraPos);
|
|
485
|
+
this.$l.eyeVecNorm = pb.normalize(this.eyeVec);
|
|
486
|
+
this.$l.surfacePoint = this.worldPos;
|
|
487
|
+
this.$l.depth = pb.length(pb.sub(this.wPos.xyz, this.surfacePoint));
|
|
488
|
+
this.$l.reflectance = pb.textureSampleLevel(this.reflectionTex, pb.clamp(this.displacedTexCoord, pb.vec2(0.01), pb.vec2(0.99)), 0);
|
|
489
|
+
this.$l.wPosRefract = this.getPositionWS(this.displacedTexCoord);
|
|
490
|
+
this.$l.refractionTexCoord = this.$choice(pb.greaterThan(this.wPos.y, this.waterLevel), this.screenUV, this.displacedTexCoord);
|
|
491
|
+
this.$l.refraction = pb.textureSampleLevel(this.tex, this.refractionTexCoord, 0).rgb;
|
|
492
|
+
this.$l.fresnelTerm = this.fresnel(this.myNormal, pb.normalize(pb.sub(this.cameraPos, this.surfacePoint)));
|
|
493
|
+
this.refraction = pb.mul(this.refraction, this.getAbsorption(this.depth));
|
|
494
|
+
this.$l.finalColor = pb.mix(pb.mix(this.refraction, this.reflectance.rgb, this.fresnelTerm), pb.vec3(1), this.foamFactor);
|
|
495
|
+
if (ctx.sunLight) {
|
|
496
|
+
this.$l.roughness = pb.float(0.04);
|
|
497
|
+
this.$l.f0 = pb.vec3(0.02);
|
|
498
|
+
this.$l.f90 = pb.vec3(1);
|
|
499
|
+
this.$l.L = pb.neg(this.lightDir);
|
|
500
|
+
this.$l.V = pb.neg(this.eyeVecNorm);
|
|
501
|
+
this.$l.halfVec = pb.normalize(pb.add(this.L, this.V));
|
|
502
|
+
this.$l.NoH = pb.clamp(pb.dot(this.myNormal, this.halfVec), 0, 1);
|
|
503
|
+
this.$l.NoL = pb.clamp(pb.dot(this.myNormal, this.L), 0, 1);
|
|
504
|
+
this.$l.VoH = pb.clamp(pb.dot(this.V, this.halfVec), 0, 1);
|
|
505
|
+
this.$l.NoV = pb.clamp(pb.dot(this.myNormal, this.V), 0, 1);
|
|
506
|
+
this.$l.F = fresnelSchlick(this, this.VoH, this.f0, this.f90);
|
|
507
|
+
this.$l.alphaRoughness = pb.mul(this.roughness, this.roughness);
|
|
508
|
+
this.$l.D = distributionGGX(this, this.NoH, this.alphaRoughness);
|
|
509
|
+
this.$l.VIS = visGGX(this, this.NoV, this.NoL, this.alphaRoughness);
|
|
510
|
+
this.$l.specular = pb.mul(this.D, this.VIS, this.F, this.lightDiffuseAndIntensity.rgb, this.lightDiffuseAndIntensity.a);
|
|
511
|
+
this.finalColor = pb.add(this.finalColor, this.specular);
|
|
512
|
+
}
|
|
513
|
+
const irradiance = ctx.env.light.envLight.getIrradiance(this, this.myNormal);
|
|
514
|
+
if (irradiance) {
|
|
515
|
+
this.$l.sss = pb.mul(this.getScattering(this.depth), irradiance, this.envLightStrength);
|
|
516
|
+
this.finalColor = pb.add(this.finalColor, this.sss);
|
|
517
|
+
}
|
|
518
|
+
this.$if(pb.notEqual(this.srgbOut, 0), function() {
|
|
519
|
+
this.finalColor = linearToGamma(this, this.finalColor);
|
|
520
|
+
});
|
|
521
|
+
//this.$return(pb.vec4(pb.vec3(this.wPos.z), 1));
|
|
522
|
+
this.$return(pb.vec4(this.finalColor, 1));
|
|
523
|
+
});
|
|
524
|
+
return pb.getGlobalScope()['waterShading'](worldPos, worldNormal, foamFactor);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
this._waterMeshes[hash] = waterMesh;
|
|
528
|
+
}
|
|
529
|
+
waterMesh.level = this._elevation;
|
|
530
|
+
return waterMesh;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export { PostWater };
|
|
535
|
+
//# sourceMappingURL=water.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"water.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|