Enable blending
Francesco Pasa 11 months ago
Francesco Pasa 11 months ago
demo.c M +3 -3
13 +0.5, -0.5,
14 +0.5, +0.5,
15 //
16- -1.0, 0.0,
17+ 0.8, 0.0,
18 -0.5, 0.75
19 };
20 const float color[] = {
21 1.0, 0.0, 0.0, 1.0,
22 0.0, 1.0, 0.0, 1.0,
23 0.0, 0.0, 1.0, 1.0,
24- 1.0, 1.0, 1.0, 1.0,
25- 1.0, 1.0, 1.0, 1.0,
26+ 1.0, 1.0, 1.0, 0.5,
27+ 1.0, 1.0, 1.0, 0.2,
28 };
29 const uint32_t indices[] = {0, 1, 2, 0, 3, 4};
30 draw_triangles(window, 5, 6, vertices, color, indices);
src/window.c M +14 -1
127 };
128
129 // Fragment shader
130+ const WGPUBlendState blend_state = {
131+ .color = {
132+ .operation = WGPUBlendOperation_Add,
133+ .srcFactor = WGPUBlendFactor_SrcAlpha,
134+ .dstFactor = WGPUBlendFactor_OneMinusSrcAlpha,
135+ },
136+ .alpha = {
137+ .operation = WGPUBlendOperation_Add,
138+ .srcFactor = WGPUBlendFactor_Zero,
139+ .dstFactor = WGPUBlendFactor_One,
140+ }
141+ };
142 WGPUColorTargetState color_state = {0};
143- color_state.format = WGPUTextureFormat_BGRA8UnormSrgb;
144+ color_state.format = WGPUTextureFormat_BGRA8UnormSrgb; // TODO: avoid hardcoding
145+ color_state.blend = &blend_state;
146 color_state.writeMask = WGPUColorWriteMask_All;
147 WGPUFragmentState fragment_state = {0};
148 fragment_state.module = window->shaders;