|
12 | 12 | <div id="info">
|
13 | 13 | <a href="https://threejs.org" target="_blank" rel="noopener noreferrer">three.js</a> - water<br />
|
14 | 14 | <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 /> |
16 | 16 | </div>
|
17 | 17 |
|
18 | 18 | <script type="importmap">
|
|
34 | 34 | import { bloom } from 'three/addons/tsl/display/BloomNode.js';
|
35 | 35 |
|
36 | 36 | import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
| 37 | + |
37 | 38 | import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
| 39 | + import { UltraHDRLoader } from 'three/addons/loaders/UltraHDRLoader.js'; |
| 40 | + |
38 | 41 | import { WaterMesh } from 'three/addons/objects/Water2Mesh.js';
|
39 | 42 | import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
|
40 | 43 | import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
41 | 44 |
|
42 | 45 | let scene, camera, renderer, water, postProcessing, controls;
|
43 | 46 |
|
44 | 47 | const params = {
|
45 |
| - color: '#ffffff', |
| 48 | + color: '#99e0ff', |
46 | 49 | scale: 2,
|
47 |
| - flowX: 0.25, |
48 |
| - flowY: 0.25 |
| 50 | + flowX: 1, |
| 51 | + flowY: 1 |
49 | 52 | };
|
50 | 53 |
|
51 | 54 | init();
|
52 | 55 |
|
53 | 56 | async function init() {
|
54 | 57 |
|
55 |
| - // scene |
56 |
| - |
57 | 58 | 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 | + } ); |
59 | 71 |
|
60 | 72 | // camera
|
61 | 73 |
|
62 | 74 | 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 ); |
65 | 76 |
|
66 | 77 | // asset loading
|
67 | 78 |
|
|
79 | 90 | textureLoader.loadAsync( 'textures/water/Water_2_M_Normal.jpg' )
|
80 | 91 | ] );
|
81 | 92 |
|
| 93 | + gltf.scene.position.z = 2; |
82 | 94 | gltf.scene.scale.setScalar( 0.1 );
|
83 | 95 | scene.add( gltf.scene );
|
84 | 96 |
|
|
102 | 114 | water.renderOrder = Infinity;
|
103 | 115 | scene.add( water );
|
104 | 116 |
|
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 | + { |
106 | 138 |
|
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 | + } |
109 | 145 |
|
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 | + } |
113 | 163 |
|
114 | 164 | // renderer
|
115 | 165 |
|
116 |
| - renderer = new THREE.WebGPURenderer(); |
| 166 | + renderer = new THREE.WebGPURenderer( { antialias: true } ); |
117 | 167 | renderer.setSize( window.innerWidth, window.innerHeight );
|
118 | 168 | renderer.setPixelRatio( window.devicePixelRatio );
|
119 | 169 | renderer.setAnimationLoop( animate );
|
120 |
| - renderer.toneMapping = THREE.NeutralToneMapping; |
| 170 | + renderer.toneMapping = THREE.ACESFilmicToneMapping; |
| 171 | + renderer.toneMappingExposure = 0.5; |
121 | 172 | document.body.appendChild( renderer.domElement );
|
122 | 173 |
|
| 174 | + // postprocessing |
| 175 | + |
123 | 176 | postProcessing = new THREE.PostProcessing( renderer );
|
124 | 177 |
|
125 | 178 | const scenePass = pass( scene, camera );
|
|
131 | 184 | const outputPass = scenePass.getTextureNode();
|
132 | 185 | const emissivePass = scenePass.getTextureNode( 'emissive' );
|
133 | 186 |
|
134 |
| - const bloomPass = bloom( emissivePass ); |
| 187 | + const bloomPass = bloom( emissivePass, 2 ); |
135 | 188 |
|
136 | 189 | postProcessing.outputNode = outputPass.add( bloomPass );
|
137 | 190 |
|
|
168 | 221 | //
|
169 | 222 |
|
170 | 223 | controls = new OrbitControls( camera, renderer.domElement );
|
171 |
| - controls.minDistance = 5; |
172 |
| - controls.maxDistance = 50; |
173 | 224 | controls.enableDamping = true;
|
| 225 | + controls.target.set( 0, 0, -5 ); |
| 226 | + controls.update(); |
174 | 227 |
|
175 | 228 | //
|
176 | 229 |
|
|
0 commit comments