Skip to content

Commit e806f76

Browse files
authored
impr: Make clouds use the texture.write() API and move from rgba8unorm to r8unorm since only one channel was used (#2157)
1 parent 8678073 commit e806f76

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

  • apps/typegpu-docs/src/examples/rendering/clouds

apps/typegpu-docs/src/examples/rendering/clouds/index.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@ const resolutionUniform = root.createUniform(
3838
d.vec2f(canvas.width, canvas.height),
3939
);
4040

41-
const noiseData = new Uint8Array(NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE * 4);
42-
for (let i = 0; i < noiseData.length; i += 4) {
43-
const value = Math.random() * 255;
44-
noiseData[i] = value;
45-
noiseData[i + 1] = Math.random() * 255;
46-
noiseData[i + 2] = value;
47-
noiseData[i + 3] = 255;
41+
const noiseData = new Uint8Array(NOISE_TEXTURE_SIZE * NOISE_TEXTURE_SIZE);
42+
for (let i = 0; i < noiseData.length; i += 1) {
43+
noiseData[i] = Math.random() * 255;
4844
}
4945

5046
const sampler = root['~unstable'].createSampler({
@@ -57,16 +53,10 @@ const sampler = root['~unstable'].createSampler({
5753
const noiseTexture = root['~unstable']
5854
.createTexture({
5955
size: [NOISE_TEXTURE_SIZE, NOISE_TEXTURE_SIZE],
60-
format: 'rgba8unorm',
56+
format: 'r8unorm',
6157
})
6258
.$usage('sampled', 'render');
63-
64-
root.device.queue.writeTexture(
65-
{ texture: root.unwrap(noiseTexture) },
66-
noiseData,
67-
{ bytesPerRow: NOISE_TEXTURE_SIZE * 4 },
68-
{ width: NOISE_TEXTURE_SIZE, height: NOISE_TEXTURE_SIZE },
69-
);
59+
noiseTexture.write(noiseData);
7060

7161
const bindGroup = root.createBindGroup(cloudsLayout, {
7262
params: paramsUniform.buffer,

0 commit comments

Comments
 (0)