Skip to content

Commit a189dcf

Browse files
committed
Add note about step100-next
1 parent 965f381 commit a189dcf

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

basic-3d-rendering/shader-uniforms/multiple-uniforms.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ On the CPU side, we define the very same struct:
9696
* The same structure as in the shader, replicated in C++
9797
*/
9898
struct MyUniforms {
99-
std::array<float, 4> color; // or float color[4]
10099
float time;
100+
std::array<float, 4> color; // or float color[4]
101101
};
102102
```
103103

@@ -225,36 +225,34 @@ wgpuQueueWriteBuffer(queue, uniformBuffer, sizeof(float), &uniforms.color, sizeo
225225
Better yet, if we forget the offset, or want to be flexible to the addition of new fields, we can use the built-in `offsetof` macro:
226226
227227
````{tab} With webgpu.hpp
228-
```C++
228+
```{lit} C++, Update uniform buffer (replace)
229+
float time = static_cast<float>(glfwGetTime());
229230
// Upload only the time, whichever its order in the struct
230-
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, time), &uniforms.time, sizeof(MyUniforms::time));
231-
// Upload only the color, whichever its order in the struct
232-
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, color), &uniforms.color, sizeof(MyUniforms::color));
231+
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, time), &time, sizeof(float));
233232
```
234233
````
235234
236235
````{tab} Vanilla webgpu.h
237-
```C++
236+
```{lit} C++, Update uniform buffer (replace, for tangle root "Vanilla")
237+
float time = static_cast<float>(glfwGetTime());
238238
// Upload only the time, whichever its order in the struct
239-
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, time), &uniforms.time, sizeof(MyUniforms::time));
240-
// Upload only the color, whichever its order in the struct
241-
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, color), &uniforms.color, sizeof(MyUniforms::color));
239+
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, time), &time, sizeof(float));
242240
```
243241
````
244242

243+
And if we would update the color:
244+
245245
````{tab} With webgpu.hpp
246-
```{lit} C++, Update uniform buffer (replace)
247-
float time = static_cast<float>(glfwGetTime());
248-
// Only update the 1-st float of the buffer
249-
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, time), &time, sizeof(float));
246+
```C++
247+
// Upload only the color, whichever its order in the struct
248+
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, color), &uniforms.color, sizeof(MyUniforms::color));
250249
```
251250
````
252251

253252
````{tab} Vanilla webgpu.h
254-
```{lit} C++, Update uniform buffer (replace, for tangle root "Vanilla")
255-
float time = static_cast<float>(glfwGetTime());
256-
// Only update the 1-st float of the buffer
257-
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, time), &time, sizeof(float));
253+
```C++
254+
// Upload only the color, whichever its order in the struct
255+
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, color), &uniforms.color, sizeof(MyUniforms::color));
258256
```
259257
````
260258

basic-3d-rendering/some-interaction/lighting-control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Lighting control <span class="bullet">🟡🟢</span>
1010
````
1111

1212
```{important}
13-
**October 25, 2024:** This chapter is marked with a secondary **green bullet 🟢** only to draw attention because there is a preview of the accompanying code available for a recent version of Dawn: [`step100-dawn`](https://github.com/eliemichel/LearnWebGPU-Code/tree/step100-dawn). The content of this chapter still relies on older versions.
13+
**November 17, 2024:** This chapter is marked with a secondary **green bullet 🟢** only to draw attention because there is a preview of the accompanying code available for a more recent version of Dawn and `wgpu-native`: [`step100-next`](https://github.com/eliemichel/LearnWebGPU-Code/tree/step100-next). The content of this chapter still relies on older versions.
1414
```
1515

1616
Now that we have elements of GUI, we can use them to expose for instance the **lighting settings** to the user. We want them to be able to **live tweak** the direction and color of our light sources.

0 commit comments

Comments
 (0)