Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed shadows not respecting offset #63

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/render/fx_renderer/shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct box_shadow_shader {
GLint pos_attrib;
GLint position;
GLint size;
GLint offset;
GLint blur_sigma;
GLint corner_radius;
};
Expand Down
1 change: 1 addition & 0 deletions render/fx_renderer/fx_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ void fx_render_pass_add_box_shadow(struct fx_gles_render_pass *pass,
glUniform1f(renderer->shaders.box_shadow.blur_sigma, shadow_data->blur_sigma);
glUniform1f(renderer->shaders.box_shadow.corner_radius, options->corner_radius);
glUniform2f(renderer->shaders.box_shadow.size, shadow_box.width, shadow_box.height);
glUniform2f(renderer->shaders.box_shadow.offset, options->shadow_data->offset_x, options->shadow_data->offset_y);
glUniform2f(renderer->shaders.box_shadow.position, shadow_box.x, shadow_box.y);

render(&shadow_box, &render_region, renderer->shaders.box_shadow.pos_attrib);
Expand Down
6 changes: 5 additions & 1 deletion render/fx_renderer/gles2/shaders/box_shadow.frag
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ varying vec2 v_texcoord;

uniform vec2 position;
uniform vec2 size;
uniform vec2 offset;
uniform float blur_sigma;
uniform float corner_radius;

Expand Down Expand Up @@ -80,7 +81,10 @@ void main() {
shadow_alpha += (random() - 0.5) / 128.0;

// get the window alpha so we can render around the window
float window_alpha = 1.0 - smoothstep(-1.0, 1.0, roundRectSDF((size * 0.5) - blur_sigma, position + blur_sigma, corner_radius));
float window_alpha = 1.0 - smoothstep(-1.0, 1.0,
roundRectSDF((size * 0.5) - blur_sigma,
vec2(position.x + blur_sigma - offset.x, position.y + blur_sigma - offset.y),
corner_radius));

gl_FragColor = vec4(v_color.rgb, shadow_alpha * (1.0 - window_alpha));
}
1 change: 1 addition & 0 deletions render/fx_renderer/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ bool link_box_shadow_program(struct box_shadow_shader *shader) {
shader->pos_attrib = glGetAttribLocation(prog, "pos");
shader->position = glGetUniformLocation(prog, "position");
shader->size = glGetUniformLocation(prog, "size");
shader->offset = glGetUniformLocation(prog, "offset");
shader->blur_sigma = glGetUniformLocation(prog, "blur_sigma");
shader->corner_radius = glGetUniformLocation(prog, "corner_radius");

Expand Down