Skip to content

Commit a9666c6

Browse files
committed
Improved webgpu water example.
1 parent 319461b commit a9666c6

File tree

3 files changed

+73
-20
lines changed

3 files changed

+73
-20
lines changed

examples/screenshots/webgpu_water.jpg

-17.2 KB
Loading
469 KB
Loading

examples/webgpu_water.html

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div id="info">
1313
<a href="https://threejs.org" target="_blank" rel="noopener noreferrer">three.js</a> - water<br />
1414
<a href="https://skfb.ly/6WOOR" target="_blank" rel="noopener">The Night Pool</a> by
15-
<a href="https://sketchfab.com/syntheticplants" target="_blank" rel="noopener">syntheticplants</a> is licensed under <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">Creative Commons Attribution</a>.<br />
15+
<a href="https://sketchfab.com/syntheticplants" target="_blank" rel="noopener">syntheticplants</a> is licensed under <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">CC BY 4.0</a><br />
1616
</div>
1717

1818
<script type="importmap">
@@ -34,34 +34,45 @@
3434
import { bloom } from 'three/addons/tsl/display/BloomNode.js';
3535

3636
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
37+
3738
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
39+
import { UltraHDRLoader } from 'three/addons/loaders/UltraHDRLoader.js';
40+
3841
import { WaterMesh } from 'three/addons/objects/Water2Mesh.js';
3942
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
4043
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
4144

4245
let scene, camera, renderer, water, postProcessing, controls;
4346

4447
const params = {
45-
color: '#ffffff',
48+
color: '#99e0ff',
4649
scale: 2,
47-
flowX: 0.25,
48-
flowY: 0.25
50+
flowX: 1,
51+
flowY: 1
4952
};
5053

5154
init();
5255

5356
async function init() {
5457

55-
// scene
56-
5758
scene = new THREE.Scene();
58-
scene.backgroundNode = screenUV.distance( .5 ).remap( 0, 0.5 ).mix( color( 0x666666 ), color( 0x111111 ) );
59+
60+
const loader = new UltraHDRLoader();
61+
loader.setDataType( THREE.HalfFloatType );
62+
loader.load( `textures/equirectangular/moonless_golf_2k.hdr.jpg`, function ( texture ) {
63+
64+
texture.mapping = THREE.EquirectangularReflectionMapping;
65+
texture.needsUpdate = true;
66+
67+
scene.background = texture;
68+
scene.environment = texture;
69+
70+
} );
5971

6072
// camera
6173

6274
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 200 );
63-
camera.position.set( - 25, 10, - 25 );
64-
camera.lookAt( scene.position );
75+
camera.position.set( - 20, 6, - 30 );
6576

6677
// asset loading
6778

@@ -79,6 +90,7 @@
7990
textureLoader.loadAsync( 'textures/water/Water_2_M_Normal.jpg' )
8091
] );
8192

93+
gltf.scene.position.z = 2;
8294
gltf.scene.scale.setScalar( 0.1 );
8395
scene.add( gltf.scene );
8496

@@ -102,24 +114,65 @@
102114
water.renderOrder = Infinity;
103115
scene.add( water );
104116

105-
// light
117+
// floor
118+
119+
const floorGeometry = new THREE.PlaneGeometry( 1, 1 );
120+
floorGeometry.rotateX( - Math.PI * 0.5 );
121+
const floorMaterial = new THREE.MeshStandardMaterial( {
122+
color: 0x444444,
123+
roughness: 1,
124+
metalness: 0,
125+
side: THREE.DoubleSide
126+
} );
127+
128+
{
129+
130+
const floor = new THREE.Mesh( floorGeometry, floorMaterial );
131+
floor.position.set( 20, 0, 0 );
132+
floor.scale.set( 15, 1, 80 );
133+
scene.add( floor );
134+
135+
}
136+
137+
{
106138

107-
const ambientLight = new THREE.AmbientLight( 0xccccccc, 0.4 );
108-
scene.add( ambientLight );
139+
const floor = new THREE.Mesh( floorGeometry, floorMaterial );
140+
floor.position.set( - 20, 0, 0 );
141+
floor.scale.set( 15, 1, 80 );
142+
scene.add( floor );
143+
144+
}
109145

110-
const directionalLight = new THREE.DirectionalLight( 0xf435ab, 3 );
111-
directionalLight.position.set( - 1, 1, 1 );
112-
scene.add( directionalLight );
146+
{
147+
148+
const floor = new THREE.Mesh( floorGeometry, floorMaterial );
149+
floor.position.set( 0, 0, 30 );
150+
floor.scale.set( 30, 1, 20 );
151+
scene.add( floor );
152+
153+
}
154+
155+
{
156+
157+
const floor = new THREE.Mesh( floorGeometry, floorMaterial );
158+
floor.position.set( 0, 0, - 30 );
159+
floor.scale.set( 30, 1, 20 );
160+
scene.add( floor );
161+
162+
}
113163

114164
// renderer
115165

116-
renderer = new THREE.WebGPURenderer();
166+
renderer = new THREE.WebGPURenderer( { antialias: true } );
117167
renderer.setSize( window.innerWidth, window.innerHeight );
118168
renderer.setPixelRatio( window.devicePixelRatio );
119169
renderer.setAnimationLoop( animate );
120-
renderer.toneMapping = THREE.NeutralToneMapping;
170+
renderer.toneMapping = THREE.ACESFilmicToneMapping;
171+
renderer.toneMappingExposure = 0.5;
121172
document.body.appendChild( renderer.domElement );
122173

174+
// postprocessing
175+
123176
postProcessing = new THREE.PostProcessing( renderer );
124177

125178
const scenePass = pass( scene, camera );
@@ -131,7 +184,7 @@
131184
const outputPass = scenePass.getTextureNode();
132185
const emissivePass = scenePass.getTextureNode( 'emissive' );
133186

134-
const bloomPass = bloom( emissivePass );
187+
const bloomPass = bloom( emissivePass, 2 );
135188

136189
postProcessing.outputNode = outputPass.add( bloomPass );
137190

@@ -168,9 +221,9 @@
168221
//
169222

170223
controls = new OrbitControls( camera, renderer.domElement );
171-
controls.minDistance = 5;
172-
controls.maxDistance = 50;
173224
controls.enableDamping = true;
225+
controls.target.set( 0, 0, -5 );
226+
controls.update();
174227

175228
//
176229

0 commit comments

Comments
 (0)