feat: quad shadows
This commit is contained in:
parent
b3e3f6e3c9
commit
cc906c83cd
33 changed files with 305 additions and 25 deletions
|
|
@ -6,6 +6,9 @@ struct SolidVertexInput {
|
|||
@location(3) border_color: vec4<f32>,
|
||||
@location(4) border_radius: vec4<f32>,
|
||||
@location(5) border_width: f32,
|
||||
@location(6) shadow_color: vec4<f32>,
|
||||
@location(7) shadow_offset: vec2<f32>,
|
||||
@location(8) shadow_blur_radius: f32,
|
||||
}
|
||||
|
||||
struct SolidVertexOutput {
|
||||
|
|
@ -16,14 +19,19 @@ struct SolidVertexOutput {
|
|||
@location(3) scale: vec2<f32>,
|
||||
@location(4) border_radius: vec4<f32>,
|
||||
@location(5) border_width: f32,
|
||||
@location(6) shadow_color: vec4<f32>,
|
||||
@location(7) shadow_offset: vec2<f32>,
|
||||
@location(8) shadow_blur_radius: f32,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput {
|
||||
var out: SolidVertexOutput;
|
||||
|
||||
var pos: vec2<f32> = input.pos * globals.scale;
|
||||
var scale: vec2<f32> = input.scale * globals.scale;
|
||||
var pos: vec2<f32> = (input.pos + min(input.shadow_offset, vec2<f32>(0.0, 0.0)) - input.shadow_blur_radius) * globals.scale;
|
||||
var quad_pos: vec2<f32> = input.pos * globals.scale;
|
||||
var scale: vec2<f32> = (input.scale + vec2<f32>(abs(input.shadow_offset.x), abs(input.shadow_offset.y)) + input.shadow_blur_radius * 2.0) * globals.scale;
|
||||
var quad_scale: vec2<f32> = input.scale * globals.scale;
|
||||
|
||||
var min_border_radius = min(input.scale.x, input.scale.y) * 0.5;
|
||||
var border_radius: vec4<f32> = vec4<f32>(
|
||||
|
|
@ -43,10 +51,13 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput {
|
|||
out.position = globals.transform * transform * vec4<f32>(vertex_position(input.vertex_index), 0.0, 1.0);
|
||||
out.color = input.color;
|
||||
out.border_color = input.border_color;
|
||||
out.pos = pos;
|
||||
out.scale = scale;
|
||||
out.pos = quad_pos;
|
||||
out.scale = quad_scale;
|
||||
out.border_radius = border_radius * globals.scale;
|
||||
out.border_width = input.border_width * globals.scale;
|
||||
out.shadow_color = input.shadow_color;
|
||||
out.shadow_offset = input.shadow_offset * globals.scale;
|
||||
out.shadow_blur_radius = input.shadow_blur_radius * globals.scale;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
@ -95,5 +106,20 @@ fn solid_fs_main(
|
|||
dist
|
||||
);
|
||||
|
||||
return vec4<f32>(mixed_color.x, mixed_color.y, mixed_color.z, mixed_color.w * radius_alpha);
|
||||
let quad_color = vec4<f32>(mixed_color.x, mixed_color.y, mixed_color.z, mixed_color.w * radius_alpha);
|
||||
|
||||
if input.shadow_color.a > 0.0 {
|
||||
let shadow_distance = rounded_box_sdf(input.position.xy - input.pos - input.shadow_offset - (input.scale / 2.0), input.scale / 2.0, border_radius);
|
||||
let shadow_alpha = 1.0 - smoothstep(-input.shadow_blur_radius, input.shadow_blur_radius, shadow_distance);
|
||||
let shadow_color = input.shadow_color;
|
||||
let base_color = select(
|
||||
vec4<f32>(shadow_color.x, shadow_color.y, shadow_color.z, 0.0),
|
||||
quad_color,
|
||||
quad_color.a > 0.0
|
||||
);
|
||||
|
||||
return mix(base_color, shadow_color, (1.0 - radius_alpha) * shadow_alpha);
|
||||
} else {
|
||||
return quad_color;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue