From 38952d88ab13ecfb74afbc755ec0cd0c11e2664d Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Mon, 10 Feb 2025 18:39:09 -0500 Subject: [PATCH 1/3] add gradients to scene_rect --- include/render/fx_renderer/shaders.h | 8 ++-- include/scenefx/render/pass.h | 25 ++-------- include/scenefx/types/fx/gradient.h | 16 +++++++ include/scenefx/types/wlr_scene.h | 18 +++++++- render/fx_renderer/fx_pass.c | 22 ++++----- .../fx_renderer/gles2/shaders/gradient.frag | 7 +-- .../fx_renderer/gles2/shaders/quad_grad.frag | 10 ++-- .../gles2/shaders/quad_grad_round.frag | 14 ++++-- render/fx_renderer/shaders.c | 8 ++-- tinywl/tinywl.c | 28 +++++++---- types/scene/wlr_scene.c | 46 +++++++++++++++---- 11 files changed, 131 insertions(+), 71 deletions(-) create mode 100644 include/scenefx/types/fx/gradient.h diff --git a/include/render/fx_renderer/shaders.h b/include/render/fx_renderer/shaders.h index 9ed5a87..0c2db97 100644 --- a/include/render/fx_renderer/shaders.h +++ b/include/render/fx_renderer/shaders.h @@ -47,10 +47,10 @@ struct quad_grad_shader { GLint degree; GLint grad_box; GLint pos_attrib; - GLint linear; + GLint is_linear; GLint origin; GLint count; - GLint blend; + GLint should_blend; }; bool link_quad_grad_program(struct quad_grad_shader *shader, int max_len); @@ -93,10 +93,10 @@ struct quad_grad_round_shader { GLint grad_size; GLint degree; GLint grad_box; - GLint linear; + GLint is_linear; GLint origin; GLint count; - GLint blend; + GLint should_blend; GLint round_top_left; GLint round_top_right; diff --git a/include/scenefx/render/pass.h b/include/scenefx/render/pass.h index affa69d..24dd204 100644 --- a/include/scenefx/render/pass.h +++ b/include/scenefx/render/pass.h @@ -9,6 +9,7 @@ #include "render/egl.h" #include "scenefx/types/fx/clipped_region.h" #include "scenefx/types/fx/corner_location.h" +#include "scenefx/types/fx/gradient.h" struct fx_gles_render_pass { struct wlr_render_pass base; @@ -36,20 +37,6 @@ struct fx_gles_render_pass *fx_renderer_begin_buffer_pass(struct wlr_renderer *w struct wlr_buffer *wlr_buffer, struct wlr_output *output, const struct fx_buffer_pass_options *options); -struct fx_gradient { - float degree; - /* The full area the gradient fit too, for borders use the window size */ - struct wlr_box range; - /* The center of the gradient, {0.5, 0.5} for normal*/ - float origin[2]; - /* 1 = Linear, 2 = Conic */ - int linear; - /* Whether or not to blend the colors */ - int blend; - int count; - float *colors; -}; - struct fx_render_texture_options { struct wlr_render_texture_options base; const struct wlr_box *clip_box; // Used to clip csd. Ignored if NULL @@ -64,8 +51,8 @@ struct fx_render_rect_options { }; struct fx_render_rect_grad_options { - struct wlr_render_rect_options base; - struct fx_gradient gradient; + struct fx_render_rect_options rect_options; + struct gradient gradient; }; struct fx_render_rounded_rect_options { @@ -76,10 +63,8 @@ struct fx_render_rounded_rect_options { }; struct fx_render_rounded_rect_grad_options { - struct wlr_render_rect_options base; - struct fx_gradient gradient; - int corner_radius; - enum corner_location corners; + struct fx_render_rounded_rect_options rounded_rect_options; + struct gradient gradient; }; struct fx_render_box_shadow_options { diff --git a/include/scenefx/types/fx/gradient.h b/include/scenefx/types/fx/gradient.h new file mode 100644 index 0000000..fa65bff --- /dev/null +++ b/include/scenefx/types/fx/gradient.h @@ -0,0 +1,16 @@ +#ifndef TYPES_FX_GRADIENT_H +#define TYPES_FX_GRADIENT_H + +struct gradient { + float degree; + struct wlr_box range; // the full area the gradient fit too, for borders use the window size + float origin[2]; // center of the gradient, { 0.5, 0.5 } for normal + bool is_linear; // else is conic + float should_blend; + + int count; + float *colors; +}; + + +#endif // TYPES_FX_GRADIENT_H diff --git a/include/scenefx/types/wlr_scene.h b/include/scenefx/types/wlr_scene.h index 3d055b7..c495e6f 100644 --- a/include/scenefx/types/wlr_scene.h +++ b/include/scenefx/types/wlr_scene.h @@ -31,6 +31,7 @@ #include "scenefx/types/fx/blur_data.h" #include "scenefx/types/fx/clipped_region.h" #include "scenefx/types/fx/corner_location.h" +#include "scenefx/types/fx/gradient.h" struct wlr_output; struct wlr_output_layout; @@ -91,6 +92,11 @@ enum wlr_scene_debug_damage_option { WLR_SCENE_DEBUG_DAMAGE_HIGHLIGHT }; +enum wlr_scene_rect_fill_type { + SOLID_COLOR, + GRADIENT, +}; + /** A sub-tree in the scene-graph. */ struct wlr_scene_tree { struct wlr_scene_node node; @@ -143,12 +149,17 @@ struct wlr_scene_surface { struct wlr_scene_rect { struct wlr_scene_node node; int width, height; - float color[4]; int corner_radius; enum corner_location corners; bool backdrop_blur; bool backdrop_blur_optimized; + union { + float color[4]; + struct gradient gradient; + }; + enum wlr_scene_rect_fill_type fill_type; + bool accepts_input; struct clipped_region clipped_region; }; @@ -441,6 +452,11 @@ void wlr_scene_rect_set_clipped_region(struct wlr_scene_rect *rect, */ void wlr_scene_rect_set_color(struct wlr_scene_rect *rect, const float color[static 4]); +/** + * Change the gradient of an existing rectangle node. + */ +void wlr_scene_rect_set_gradient(struct wlr_scene_rect *rect, const struct gradient gradient); + /** * Sets whether or not the buffer should render backdrop blur */ diff --git a/render/fx_renderer/fx_pass.c b/render/fx_renderer/fx_pass.c index 1fdf75e..c5f8bf7 100644 --- a/render/fx_renderer/fx_pass.c +++ b/render/fx_renderer/fx_pass.c @@ -404,7 +404,7 @@ void fx_render_pass_add_rect(struct fx_gles_render_pass *pass, void fx_render_pass_add_rect_grad(struct fx_gles_render_pass *pass, const struct fx_render_rect_grad_options *fx_options) { - const struct wlr_render_rect_options *options = &fx_options->base; + const struct wlr_render_rect_options *options = &fx_options->rect_options.base; struct fx_renderer *renderer = pass->buffer->renderer; @@ -429,8 +429,8 @@ void fx_render_pass_add_rect_grad(struct fx_gles_render_pass *pass, glUniform1i(renderer->shaders.quad_grad.count, fx_options->gradient.count); glUniform2f(renderer->shaders.quad_grad.size, fx_options->gradient.range.width, fx_options->gradient.range.height); glUniform1f(renderer->shaders.quad_grad.degree, fx_options->gradient.degree); - glUniform1f(renderer->shaders.quad_grad.linear, fx_options->gradient.linear); - glUniform1f(renderer->shaders.quad_grad.blend, fx_options->gradient.blend); + glUniform1f(renderer->shaders.quad_grad.is_linear, fx_options->gradient.is_linear); + glUniform1f(renderer->shaders.quad_grad.should_blend, fx_options->gradient.should_blend); glUniform2f(renderer->shaders.quad_grad.grad_box, fx_options->gradient.range.x, fx_options->gradient.range.y); glUniform2f(renderer->shaders.quad_grad.origin, fx_options->gradient.origin[0], fx_options->gradient.origin[1]); @@ -517,7 +517,7 @@ void fx_render_pass_add_rounded_rect(struct fx_gles_render_pass *pass, void fx_render_pass_add_rounded_rect_grad(struct fx_gles_render_pass *pass, const struct fx_render_rounded_rect_grad_options *fx_options) { - const struct wlr_render_rect_options *options = &fx_options->base; + const struct wlr_render_rect_options *options = &fx_options->rounded_rect_options.base; struct fx_renderer *renderer = pass->buffer->renderer; @@ -542,25 +542,25 @@ void fx_render_pass_add_rounded_rect_grad(struct fx_gles_render_pass *pass, glUniform2f(shader.size, box.width, box.height); glUniform2f(shader.position, box.x, box.y); - glUniform1f(shader.radius, fx_options->corner_radius); + glUniform1f(shader.radius, fx_options->rounded_rect_options.corner_radius); glUniform4fv(shader.colors, fx_options->gradient.count, (GLfloat*)fx_options->gradient.colors); glUniform1i(shader.count, fx_options->gradient.count); glUniform2f(shader.grad_size, fx_options->gradient.range.width, fx_options->gradient.range.height); glUniform1f(shader.degree, fx_options->gradient.degree); - glUniform1f(shader.linear, fx_options->gradient.linear); - glUniform1f(shader.blend, fx_options->gradient.blend); + glUniform1f(shader.is_linear, fx_options->gradient.is_linear); + glUniform1f(shader.should_blend, fx_options->gradient.should_blend); glUniform2f(shader.grad_box, fx_options->gradient.range.x, fx_options->gradient.range.y); glUniform2f(shader.origin, fx_options->gradient.origin[0], fx_options->gradient.origin[1]); glUniform1f(shader.round_top_left, - (CORNER_LOCATION_TOP_LEFT & fx_options->corners) == CORNER_LOCATION_TOP_LEFT); + (CORNER_LOCATION_TOP_LEFT & fx_options->rounded_rect_options.corners) == CORNER_LOCATION_TOP_LEFT); glUniform1f(shader.round_top_right, - (CORNER_LOCATION_TOP_RIGHT & fx_options->corners) == CORNER_LOCATION_TOP_RIGHT); + (CORNER_LOCATION_TOP_RIGHT & fx_options->rounded_rect_options.corners) == CORNER_LOCATION_TOP_RIGHT); glUniform1f(shader.round_bottom_left, - (CORNER_LOCATION_BOTTOM_LEFT & fx_options->corners) == CORNER_LOCATION_BOTTOM_LEFT); + (CORNER_LOCATION_BOTTOM_LEFT & fx_options->rounded_rect_options.corners) == CORNER_LOCATION_BOTTOM_LEFT); glUniform1f(shader.round_bottom_right, - (CORNER_LOCATION_BOTTOM_RIGHT & fx_options->corners) == CORNER_LOCATION_BOTTOM_RIGHT); + (CORNER_LOCATION_BOTTOM_RIGHT & fx_options->rounded_rect_options.corners) == CORNER_LOCATION_BOTTOM_RIGHT); render(&box, options->clip, shader.pos_attrib); diff --git a/render/fx_renderer/gles2/shaders/gradient.frag b/render/fx_renderer/gles2/shaders/gradient.frag index c2a499f..10ef93e 100644 --- a/render/fx_renderer/gles2/shaders/gradient.frag +++ b/render/fx_renderer/gles2/shaders/gradient.frag @@ -1,4 +1,5 @@ -vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, vec2 origin, float degree, bool linear, bool blend) { +vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, + vec2 origin, float degree, bool is_linear, bool should_blend) { float step; vec2 normal = (gl_FragCoord.xy - grad_box)/size; @@ -6,7 +7,7 @@ vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, vec2 origin float rad = radians(degree); - if (linear) { + if (is_linear) { uv *= vec2(1.0)/vec2(abs(cos(rad)) + abs(sin(rad))); vec2 rotated = vec2(uv.x * cos(rad) - uv.y * sin(rad) + origin.x, @@ -22,7 +23,7 @@ vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, vec2 origin step = uv.x; } - if (!blend) { + if (!should_blend) { float smooth = 1.0/float(count); int ind = int(step/smooth); diff --git a/render/fx_renderer/gles2/shaders/quad_grad.frag b/render/fx_renderer/gles2/shaders/quad_grad.frag index 6fe3981..5519d23 100644 --- a/render/fx_renderer/gles2/shaders/quad_grad.frag +++ b/render/fx_renderer/gles2/shaders/quad_grad.frag @@ -12,12 +12,14 @@ uniform vec2 size; uniform float degree; uniform vec2 grad_box; uniform vec2 origin; -uniform bool linear; -uniform bool blend; +uniform bool is_linear; +uniform bool should_blend; uniform int count; -vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, vec2 origin, float degree, bool linear, bool blend); +vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, + vec2 origin, float degree, bool is_linear, bool should_blend); void main(){ - gl_FragColor = gradient(colors, count, size, grad_box, origin, degree, linear, blend); + gl_FragColor = gradient(colors, count, size, grad_box, + origin, degree, is_linear, should_blend); } diff --git a/render/fx_renderer/gles2/shaders/quad_grad_round.frag b/render/fx_renderer/gles2/shaders/quad_grad_round.frag index cca4915..ab59628 100644 --- a/render/fx_renderer/gles2/shaders/quad_grad_round.frag +++ b/render/fx_renderer/gles2/shaders/quad_grad_round.frag @@ -11,8 +11,8 @@ uniform vec2 grad_size; uniform float degree; uniform vec2 grad_box; uniform vec2 origin; -uniform bool linear; -uniform bool blend; +uniform bool is_linear; +uniform bool should_blend; uniform int count; uniform bool round_top_left; @@ -20,11 +20,11 @@ uniform bool round_top_right; uniform bool round_bottom_left; uniform bool round_bottom_right; -vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, vec2 origin, float degree, bool linear, bool blend); +vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, + vec2 origin, float degree, bool is_linear, bool should_blend); float corner_alpha(vec2 size, vec2 position, float round_tl, float round_tr, float round_bl, float round_br); -// TODO: void main() { float quad_corner_alpha = corner_alpha( size, @@ -36,5 +36,9 @@ void main() { ); float rect_alpha = v_color.a * quad_corner_alpha; - gl_FragColor = mix(vec4(0), gradient(colors, count, size, grad_box, origin, degree, linear, blend), rect_alpha); + gl_FragColor = mix( + vec4(0.0), + gradient(colors, count, size, grad_box, origin, degree, is_linear, should_blend), + rect_alpha + ); } diff --git a/render/fx_renderer/shaders.c b/render/fx_renderer/shaders.c index cd5c389..1510025 100644 --- a/render/fx_renderer/shaders.c +++ b/render/fx_renderer/shaders.c @@ -145,10 +145,10 @@ bool link_quad_grad_program(struct quad_grad_shader *shader, int max_len) { shader->colors = glGetUniformLocation(prog, "colors"); shader->degree = glGetUniformLocation(prog, "degree"); shader->grad_box = glGetUniformLocation(prog, "grad_box"); - shader->linear = glGetUniformLocation(prog, "linear"); + shader->is_linear = glGetUniformLocation(prog, "is_linear"); shader->origin = glGetUniformLocation(prog, "origin"); shader->count = glGetUniformLocation(prog, "count"); - shader->blend = glGetUniformLocation(prog, "blend"); + shader->should_blend = glGetUniformLocation(prog, "should_blend"); shader->max_len = max_len; @@ -210,10 +210,10 @@ bool link_quad_grad_round_program(struct quad_grad_round_shader *shader, int max shader->colors = glGetUniformLocation(prog, "colors"); shader->degree = glGetUniformLocation(prog, "degree"); shader->grad_box = glGetUniformLocation(prog, "grad_box"); - shader->linear = glGetUniformLocation(prog, "linear"); + shader->is_linear = glGetUniformLocation(prog, "is_linear"); shader->origin = glGetUniformLocation(prog, "origin"); shader->count = glGetUniformLocation(prog, "count"); - shader->blend = glGetUniformLocation(prog, "blend"); + shader->should_blend = glGetUniformLocation(prog, "should_blend"); shader->round_top_left = glGetUniformLocation(prog, "round_top_left"); shader->round_top_right = glGetUniformLocation(prog, "round_top_right"); diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index 69d6789..32e0b9e 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -1142,26 +1142,34 @@ int main(int argc, char *argv[]) { /* Create all of the basic scene layers */ server.layers.bottom_layer = wlr_scene_tree_create(&server.scene->tree); + /* Add a bottom rect to demonstrate optimized blur */ float bottom_rect_color[4] = { 1, 1, 1, 1 }; wlr_scene_rect_create(server.layers.bottom_layer, 200, 200, bottom_rect_color); + /* + wlr_scene_rect_set_gradient( + bottom_rect, + (struct gradient) { + .degree = 0.0, + .range = (struct wlr_box) { + }, + .origin = {}, + .is_linear = true, + .should_blend = true, + .count = 0, + .colors = {}, + } + ); + */ + /* Set the size later */ server.layers.blur_layer = wlr_scene_optimized_blur_create(&server.scene->tree, 0, 0); server.layers.toplevel_layer = wlr_scene_tree_create(&server.scene->tree); + /* Add a top rect that won't get blurred by optimized */ float top_rect_color[4] = { 1, 0, 0, 1 }; struct wlr_scene_rect *rect = wlr_scene_rect_create(server.layers.toplevel_layer, 200, 200, top_rect_color); - wlr_scene_rect_set_clipped_region(rect, (struct clipped_region) { - .corner_radius = 12, - .corners = CORNER_LOCATION_TOP, - .area = { - .x = 50, - .y = 50, - .width = 100, - .height = 100, - }, - }); wlr_scene_node_set_position(&rect->node, 200, 200); // blur diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 2676043..056541e 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -689,7 +689,7 @@ void wlr_scene_rect_set_size(struct wlr_scene_rect *rect, int width, int height) } void wlr_scene_rect_set_color(struct wlr_scene_rect *rect, const float color[static 4]) { - if (memcmp(rect->color, color, sizeof(rect->color)) == 0) { + if (rect->fill_type == SOLID_COLOR && memcmp(rect->color, color, sizeof(rect->color)) == 0) { return; } @@ -697,6 +697,18 @@ void wlr_scene_rect_set_color(struct wlr_scene_rect *rect, const float color[sta scene_node_update(&rect->node, NULL); } +void wlr_scene_rect_set_gradient(struct wlr_scene_rect *rect, const struct gradient gradient) { + // TODO: proper check + if (rect->fill_type == GRADIENT && false) { + return; + } + + rect->fill_type = GRADIENT; + rect->gradient = gradient; + + scene_node_update(&rect->node, NULL); +} + void wlr_scene_rect_set_backdrop_blur(struct wlr_scene_rect *rect, bool enabled) { if (rect->backdrop_blur == enabled) { @@ -1555,6 +1567,7 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren wlr_output_transform_compose(WL_OUTPUT_TRANSFORM_NORMAL, data->transform); struct wlr_scene *scene = data->output->scene; + // TODO: function for each case? switch (node->type) { case WLR_SCENE_NODE_TREE: assert(false); @@ -1619,15 +1632,18 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren transform_output_box(&rect_clipped_region_box, data); corner_location_transform(node_transform, &rect_clipped_corners); + struct wlr_render_color rect_color = { 0.0, 0.0, 0.0, 1.0 }; + if (scene_rect->fill_type == SOLID_COLOR) { + rect_color.r = scene_rect->color[0]; + rect_color.g = scene_rect->color[1]; + rect_color.b = scene_rect->color[2]; + rect_color.a = scene_rect->color[3]; + } + struct fx_render_rect_options rect_options = { .base = { .box = dst_box, - .color = { - .r = scene_rect->color[0], - .g = scene_rect->color[1], - .b = scene_rect->color[2], - .a = scene_rect->color[3], - }, + .color = rect_color, .clip = &render_region, }, .clipped_region = { @@ -1644,9 +1660,21 @@ static void scene_entry_render(struct render_list_entry *entry, const struct ren .corners = rect_corners, .clipped_region = rect_options.clipped_region, }; - fx_render_pass_add_rounded_rect(data->render_pass, &rounded_rect_options); + if (scene_rect->fill_type == SOLID_COLOR) { + fx_render_pass_add_rounded_rect(data->render_pass, &rounded_rect_options); + } else { + struct fx_render_rounded_rect_grad_options rounded_rect_grad_options = { + rounded_rect_options, scene_rect->gradient }; + fx_render_pass_add_rounded_rect_grad(data->render_pass, &rounded_rect_grad_options); + } } else { - fx_render_pass_add_rect(data->render_pass, &rect_options); + if (scene_rect->fill_type == SOLID_COLOR) { + fx_render_pass_add_rect(data->render_pass, &rect_options); + } else { + struct fx_render_rect_grad_options rect_grad_options = { + rect_options, scene_rect->gradient }; + fx_render_pass_add_rect_grad(data->render_pass, &rect_grad_options); + } } break; case WLR_SCENE_NODE_OPTIMIZED_BLUR:; From ca8e655aaa9158cf7de104bd2d2b01b6f712963b Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Mon, 10 Feb 2025 18:42:08 -0500 Subject: [PATCH 2/3] spelling --- include/scenefx/types/fx/gradient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/scenefx/types/fx/gradient.h b/include/scenefx/types/fx/gradient.h index fa65bff..fd97680 100644 --- a/include/scenefx/types/fx/gradient.h +++ b/include/scenefx/types/fx/gradient.h @@ -3,7 +3,7 @@ struct gradient { float degree; - struct wlr_box range; // the full area the gradient fit too, for borders use the window size + struct wlr_box range; // the full area the gradient fit to, for borders use the window size float origin[2]; // center of the gradient, { 0.5, 0.5 } for normal bool is_linear; // else is conic float should_blend; From 26fe336122e01fb6f9b3dadea2767bd08e0866a3 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Mon, 10 Feb 2025 18:54:36 -0500 Subject: [PATCH 3/3] add gradient rect to tinywl --- include/scenefx/types/fx/gradient.h | 2 -- render/fx_renderer/gles2/shaders/gradient.frag | 12 ++++++------ tinywl/tinywl.c | 15 +++++++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/scenefx/types/fx/gradient.h b/include/scenefx/types/fx/gradient.h index fd97680..dd6bf07 100644 --- a/include/scenefx/types/fx/gradient.h +++ b/include/scenefx/types/fx/gradient.h @@ -7,10 +7,8 @@ struct gradient { float origin[2]; // center of the gradient, { 0.5, 0.5 } for normal bool is_linear; // else is conic float should_blend; - int count; float *colors; }; - #endif // TYPES_FX_GRADIENT_H diff --git a/render/fx_renderer/gles2/shaders/gradient.frag b/render/fx_renderer/gles2/shaders/gradient.frag index 10ef93e..803ecae 100644 --- a/render/fx_renderer/gles2/shaders/gradient.frag +++ b/render/fx_renderer/gles2/shaders/gradient.frag @@ -19,20 +19,20 @@ vec4 gradient(vec4 colors[LEN], int count, vec2 size, vec2 grad_box, uv = vec2(uv.x * cos(rad) - uv.y * sin(rad), uv.x * sin(rad) + uv.y * cos(rad)); - uv = vec2(-atan(uv.y, uv.x)/3.14159265 * 0.5 + 0.5, 0.0); + uv = vec2(-atan(uv.y, uv.x) / 3.14159265 * 0.5 + 0.5, 0.0); step = uv.x; } if (!should_blend) { - float smooth = 1.0/float(count); - int ind = int(step/smooth); + float smooth = 1.0 / float(count); + int ind = int(step / smooth); return colors[ind]; } - float smooth = 1.0/float(count - 1); - int ind = int(step/smooth); - float at = float(ind)*smooth; + float smooth = 1.0 / float(count - 1); + int ind = int(step / smooth); + float at = float(ind) * smooth; vec4 color = colors[ind]; if(ind > 0) color = mix(colors[ind - 1], color, smoothstep(at - smooth, at, step)); diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index 32e0b9e..7b892a9 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -1145,22 +1145,25 @@ int main(int argc, char *argv[]) { /* Add a bottom rect to demonstrate optimized blur */ float bottom_rect_color[4] = { 1, 1, 1, 1 }; - wlr_scene_rect_create(server.layers.bottom_layer, 200, 200, bottom_rect_color); - /* + struct wlr_scene_rect *bottom_rect = wlr_scene_rect_create(server.layers.bottom_layer, + 200, 200, bottom_rect_color); wlr_scene_rect_set_gradient( bottom_rect, (struct gradient) { .degree = 0.0, .range = (struct wlr_box) { + .x = 0, + .y = 0, + .width = 200, + .height = 200, }, - .origin = {}, + .origin = { 0.5, 0.5 }, .is_linear = true, .should_blend = true, - .count = 0, - .colors = {}, + .count = 1, + .colors = bottom_rect_color, } ); - */ /* Set the size later */ server.layers.blur_layer = wlr_scene_optimized_blur_create(&server.scene->tree, 0, 0);