|
28 | 28 | import * as THREE from 'three'; |
29 | 29 | import { Fn, vec2, vec4, texture, uv, textureBicubic, rangeFogFactor, reflector, time } from 'three/tsl'; |
30 | 30 |
|
31 | | - import { RGBELoader } from 'three/addons/loaders/RGBELoader.js'; |
32 | | - |
33 | 31 | import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; |
| 32 | + import { UltraHDRLoader } from 'three/addons/loaders/UltraHDRLoader.js'; |
34 | 33 |
|
35 | 34 | import Stats from 'three/addons/libs/stats.module.js'; |
36 | 35 |
|
|
43 | 42 | async function init() { |
44 | 43 |
|
45 | 44 | camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.25, 30 ); |
46 | | - camera.position.set( - 4, 2, 4 ); |
47 | | - camera.lookAt( 0, .4, 0 ); |
| 45 | + camera.position.set( - 4, 1, 4 ); |
48 | 46 |
|
49 | 47 | scene = new THREE.Scene(); |
50 | 48 |
|
51 | | - // |
52 | | - |
53 | | - new RGBELoader() |
54 | | - .setPath( 'textures/equirectangular/' ) |
55 | | - .load( 'moonless_golf_1k.hdr', function ( texture ) { |
| 49 | + const loader = new UltraHDRLoader(); |
| 50 | + loader.setDataType( THREE.HalfFloatType ); |
| 51 | + loader.load( `textures/equirectangular/spruit_sunrise_2k.hdr.jpg`, function ( texture ) { |
56 | 52 |
|
57 | | - texture.mapping = THREE.EquirectangularReflectionMapping; |
| 53 | + texture.mapping = THREE.EquirectangularReflectionMapping; |
| 54 | + texture.needsUpdate = true; |
58 | 55 |
|
59 | | - scene.background = texture; |
60 | | - scene.environment = texture; |
| 56 | + scene.background = texture; |
| 57 | + scene.environment = texture; |
61 | 58 |
|
62 | | - } ); |
| 59 | + } ); |
63 | 60 |
|
64 | 61 | // textures |
65 | 62 |
|
|
73 | 70 | perlinMap.wrapT = THREE.RepeatWrapping; |
74 | 71 | perlinMap.colorSpace = THREE.SRGBColorSpace; |
75 | 72 |
|
76 | | - // uv map for debugging |
77 | | - |
78 | | - const uvMaterial = new THREE.MeshStandardNodeMaterial( { |
79 | | - map: uvMap, |
80 | | - emissiveMap: uvMap, |
81 | | - emissive: 0xffffff, |
82 | | - side: THREE.DoubleSide |
83 | | - } ); |
84 | | - |
85 | | - const uvMesh = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), uvMaterial ); |
86 | | - uvMesh.position.set( 0, 1, 0 ); |
87 | | - scene.add( uvMesh ); |
| 73 | + // uv box for debugging |
| 74 | + |
| 75 | + const mesh = new THREE.Mesh( |
| 76 | + new THREE.BoxGeometry( 1, 1, 1 ), |
| 77 | + new THREE.MeshStandardNodeMaterial( { |
| 78 | + map: uvMap, |
| 79 | + roughnessMap: uvMap, |
| 80 | + emissiveMap: uvMap, |
| 81 | + emissive: 0xffffff |
| 82 | + } ) |
| 83 | + ); |
| 84 | + mesh.position.set( 0, 1.25, 0 ); |
| 85 | + mesh.scale.setScalar( 2 ); |
| 86 | + scene.add( mesh ); |
88 | 87 |
|
89 | 88 | // reflection |
90 | 89 |
|
|
117 | 116 |
|
118 | 117 | // renderer |
119 | 118 |
|
120 | | - renderer = new THREE.WebGPURenderer(); |
| 119 | + renderer = new THREE.WebGPURenderer( { antialias: true } ); |
121 | 120 | renderer.setPixelRatio( window.devicePixelRatio ); |
122 | 121 | renderer.setSize( window.innerWidth, window.innerHeight ); |
123 | 122 | renderer.setAnimationLoop( animate ); |
124 | 123 | renderer.toneMapping = THREE.NeutralToneMapping; |
125 | | - renderer.toneMappingExposure = 2; |
| 124 | + renderer.toneMappingExposure = 1.5; |
126 | 125 | document.body.appendChild( renderer.domElement ); |
127 | 126 |
|
128 | 127 | stats = new Stats(); |
|
134 | 133 | controls.maxPolarAngle = Math.PI / 2; |
135 | 134 | controls.autoRotate = true; |
136 | 135 | controls.autoRotateSpeed = - .1; |
137 | | - controls.target.set( 0, .5, 0 ); |
| 136 | + controls.target.set( 0, .75, 0 ); |
138 | 137 | controls.update(); |
139 | 138 |
|
140 | 139 | // events |
|
152 | 151 |
|
153 | 152 | } |
154 | 153 |
|
155 | | - function animate() { |
| 154 | + function animate( time ) { |
156 | 155 |
|
157 | 156 | stats.update(); |
158 | 157 |
|
|
0 commit comments