@@ -4,10 +4,9 @@ import normalMapWGSL from './normalMap.wgsl';
4
4
import { createMeshRenderable } from '../../meshes/mesh' ;
5
5
import { createBoxMeshWithTangents } from '../../meshes/box' ;
6
6
import {
7
- PBRDescriptor ,
8
- createPBRDescriptor ,
9
7
createBindGroupDescriptor ,
10
8
create3DRenderPipeline ,
9
+ createTextureFromImage ,
11
10
} from './utils' ;
12
11
13
12
const MAT4X4_BYTES = 64 ;
@@ -89,35 +88,101 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
89
88
usage : GPUBufferUsage . UNIFORM | GPUBufferUsage . COPY_DST ,
90
89
} ) ;
91
90
92
- // Create PBR info (diffuse, normal, and depth/height textures)
93
- let spiralPBR : Required < PBRDescriptor > ;
91
+ // Fetch the image and upload it into a GPUTexture.
92
+ let woodDiffuseTexture : GPUTexture ;
94
93
{
95
- const response = await createPBRDescriptor ( device , [
96
- 'wood_diffuse.png' ,
97
- 'spiral_normal.png' ,
98
- 'spiral_height.png' ,
99
- ] ) ;
100
- spiralPBR = response as Required < PBRDescriptor > ;
94
+ const response = await fetch (
95
+ new URL (
96
+ '../../../assets/img/wood_diffuse.png' ,
97
+ import . meta. url
98
+ ) . toString ( )
99
+ ) ;
100
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
101
+ woodDiffuseTexture = createTextureFromImage ( device , imageBitmap ) ;
101
102
}
102
103
103
- let toyboxPBR : Required < PBRDescriptor > ;
104
+ let spiralNormalTexture : GPUTexture ;
104
105
{
105
- const response = await createPBRDescriptor ( device , [
106
- 'wood_diffuse.png' ,
107
- 'toybox_normal.png' ,
108
- 'toybox_height.png' ,
109
- ] ) ;
110
- toyboxPBR = response as Required < PBRDescriptor > ;
106
+ const response = await fetch (
107
+ new URL (
108
+ '../../../assets/img/spiral_normal.png' ,
109
+ import . meta. url
110
+ ) . toString ( )
111
+ ) ;
112
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
113
+ spiralNormalTexture = createTextureFromImage ( device , imageBitmap ) ;
111
114
}
112
115
113
- let brickWallPBR : Required < PBRDescriptor > ;
116
+ let spiralHeightTexture : GPUTexture ;
114
117
{
115
- const response = await createPBRDescriptor ( device , [
116
- 'brickwall_diffuse.png' ,
117
- 'brickwall_normal.png' ,
118
- 'brickwall_height.png' ,
119
- ] ) ;
120
- brickWallPBR = response as Required < PBRDescriptor > ;
118
+ const response = await fetch (
119
+ new URL (
120
+ '../../../assets/img/spiral_height.png' ,
121
+ import . meta. url
122
+ ) . toString ( )
123
+ ) ;
124
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
125
+ spiralHeightTexture = createTextureFromImage ( device , imageBitmap ) ;
126
+ }
127
+
128
+ let toyboxNormalTexture : GPUTexture ;
129
+ {
130
+ const response = await fetch (
131
+ new URL (
132
+ '../../../assets/img/toybox_normal.png' ,
133
+ import . meta. url
134
+ ) . toString ( )
135
+ ) ;
136
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
137
+ toyboxNormalTexture = createTextureFromImage ( device , imageBitmap ) ;
138
+ }
139
+
140
+ let toyboxHeightTexture : GPUTexture ;
141
+ {
142
+ const response = await fetch (
143
+ new URL (
144
+ '../../../assets/img/toybox_height.png' ,
145
+ import . meta. url
146
+ ) . toString ( )
147
+ ) ;
148
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
149
+ toyboxHeightTexture = createTextureFromImage ( device , imageBitmap ) ;
150
+ }
151
+
152
+ let brickwallDiffuseTexture : GPUTexture ;
153
+ {
154
+ const response = await fetch (
155
+ new URL (
156
+ '../../../assets/img/brickwall_diffuse.png' ,
157
+ import . meta. url
158
+ ) . toString ( )
159
+ ) ;
160
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
161
+ brickwallDiffuseTexture = createTextureFromImage ( device , imageBitmap ) ;
162
+ }
163
+
164
+ let brickwallNormalTexture : GPUTexture ;
165
+ {
166
+ const response = await fetch (
167
+ new URL (
168
+ '../../../assets/img/brickwall_normal.png' ,
169
+ import . meta. url
170
+ ) . toString ( )
171
+ ) ;
172
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
173
+ brickwallNormalTexture = createTextureFromImage ( device , imageBitmap ) ;
174
+ }
175
+
176
+ let brickwallHeightTexture : GPUTexture ;
177
+ {
178
+ const response = await fetch (
179
+ new URL (
180
+ '../../../assets/img/brickwall_height.png' ,
181
+ import . meta. url
182
+ ) . toString ( )
183
+ ) ;
184
+ const imageBitmap = await createImageBitmap ( await response . blob ( ) ) ;
185
+ brickwallHeightTexture = createTextureFromImage ( device , imageBitmap ) ;
121
186
}
122
187
123
188
// Create a sampler with linear filtering for smooth interpolation.
@@ -179,21 +244,21 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
179
244
[
180
245
[
181
246
sampler ,
182
- spiralPBR . diffuse . createView ( ) ,
183
- spiralPBR . normal . createView ( ) ,
184
- spiralPBR . height . createView ( ) ,
247
+ woodDiffuseTexture . createView ( ) ,
248
+ spiralNormalTexture . createView ( ) ,
249
+ spiralHeightTexture . createView ( ) ,
185
250
] ,
186
251
[
187
252
sampler ,
188
- toyboxPBR . diffuse . createView ( ) ,
189
- toyboxPBR . normal . createView ( ) ,
190
- toyboxPBR . height . createView ( ) ,
253
+ woodDiffuseTexture . createView ( ) ,
254
+ toyboxNormalTexture . createView ( ) ,
255
+ toyboxHeightTexture . createView ( ) ,
191
256
] ,
192
257
[
193
258
sampler ,
194
- brickWallPBR . diffuse . createView ( ) ,
195
- brickWallPBR . normal . createView ( ) ,
196
- brickWallPBR . height . createView ( ) ,
259
+ brickwallDiffuseTexture . createView ( ) ,
260
+ brickwallNormalTexture . createView ( ) ,
261
+ brickwallHeightTexture . createView ( ) ,
197
262
] ,
198
263
] ,
199
264
'Surface' ,
@@ -219,7 +284,6 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
219
284
function getModelMatrix ( ) {
220
285
const modelMatrix = mat4 . create ( ) ;
221
286
mat4 . identity ( modelMatrix ) ;
222
- mat4 . rotateX ( modelMatrix , 10 , modelMatrix ) ;
223
287
const now = Date . now ( ) / 1000 ;
224
288
mat4 . rotateY ( modelMatrix , now * - 0.5 , modelMatrix ) ;
225
289
return modelMatrix ;
@@ -275,8 +339,8 @@ const init: SampleInit = async ({ canvas, pageState, gui }) => {
275
339
const depthFolder = gui . addFolder ( 'Depth' ) ;
276
340
lightFolder . add ( settings , 'Reset Light' ) . onChange ( ( ) => {
277
341
lightPosXController . setValue ( 1.7 ) ;
278
- lightPosYController . setValue ( - 0.7 ) ;
279
- lightPosZController . setValue ( 1.9 ) ;
342
+ lightPosYController . setValue ( 0.7 ) ;
343
+ lightPosZController . setValue ( - 1.9 ) ;
280
344
lightIntensityController . setValue ( 0.02 ) ;
281
345
} ) ;
282
346
const lightPosXController = lightFolder
0 commit comments