Skip to content

Commit

Permalink
Add note about step100-next
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel committed Nov 17, 2024
1 parent 965f381 commit a189dcf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
32 changes: 15 additions & 17 deletions basic-3d-rendering/shader-uniforms/multiple-uniforms.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ On the CPU side, we define the very same struct:
* The same structure as in the shader, replicated in C++
*/
struct MyUniforms {
std::array<float, 4> color; // or float color[4]
float time;
std::array<float, 4> color; // or float color[4]
};
```

Expand Down Expand Up @@ -225,36 +225,34 @@ wgpuQueueWriteBuffer(queue, uniformBuffer, sizeof(float), &uniforms.color, sizeo
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:

````{tab} With webgpu.hpp
```C++
```{lit} C++, Update uniform buffer (replace)
float time = static_cast<float>(glfwGetTime());
// Upload only the time, whichever its order in the struct
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, time), &uniforms.time, sizeof(MyUniforms::time));
// Upload only the color, whichever its order in the struct
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, color), &uniforms.color, sizeof(MyUniforms::color));
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, time), &time, sizeof(float));
```
````

````{tab} Vanilla webgpu.h
```C++
```{lit} C++, Update uniform buffer (replace, for tangle root "Vanilla")
float time = static_cast<float>(glfwGetTime());
// Upload only the time, whichever its order in the struct
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, time), &uniforms.time, sizeof(MyUniforms::time));
// Upload only the color, whichever its order in the struct
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, color), &uniforms.color, sizeof(MyUniforms::color));
wgpuQueueWriteBuffer(queue, uniformBuffer, offsetof(MyUniforms, time), &time, sizeof(float));
```
````

And if we would update the color:

````{tab} With webgpu.hpp
```{lit} C++, Update uniform buffer (replace)
float time = static_cast<float>(glfwGetTime());
// Only update the 1-st float of the buffer
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, time), &time, sizeof(float));
```C++
// Upload only the color, whichever its order in the struct
queue.writeBuffer(uniformBuffer, offsetof(MyUniforms, color), &uniforms.color, sizeof(MyUniforms::color));
```
````

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

Expand Down
2 changes: 1 addition & 1 deletion basic-3d-rendering/some-interaction/lighting-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Lighting control <span class="bullet">🟡🟢</span>
````

```{important}
**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.
**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.
```

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.
Expand Down

0 comments on commit a189dcf

Please sign in to comment.