diff options
Diffstat (limited to 'wgpu/src')
| -rw-r--r-- | wgpu/src/shader/quad.frag | 26 | ||||
| -rw-r--r-- | wgpu/src/shader/quad.frag.spv | bin | 372 -> 2900 bytes | |||
| -rw-r--r-- | wgpu/src/shader/quad.vert | 5 | ||||
| -rw-r--r-- | wgpu/src/shader/quad.vert.spv | bin | 2188 -> 2364 bytes | 
4 files changed, 30 insertions, 1 deletions
diff --git a/wgpu/src/shader/quad.frag b/wgpu/src/shader/quad.frag index 1aca250f..1fc28bc1 100644 --- a/wgpu/src/shader/quad.frag +++ b/wgpu/src/shader/quad.frag @@ -1,9 +1,33 @@  #version 450  layout(location = 0) in vec4 v_Color; +layout(location = 1) in vec2 v_Pos; +layout(location = 2) in vec2 v_Scale;  layout(location = 0) out vec4 o_Color; +float rounded(in vec2 frag_coord, in vec2 position, in vec2 size, float radius, float s) +{ +    vec2 inner_size = size - vec2(radius, radius) * 2.0; +    vec2 top_left = position + vec2(radius, radius); +    vec2 bottom_right = top_left + inner_size; + +    vec2 top_left_distance = top_left - frag_coord; +    vec2 bottom_right_distance = frag_coord - bottom_right; + +    vec2 distance = vec2( +        max(max(top_left_distance.x, bottom_right_distance.x), 0), +        max(max(top_left_distance.y, bottom_right_distance.y), 0) +    ); + +    float d = sqrt(distance.x * distance.x + distance.y * distance.y); + +    return 1.0 - smoothstep(radius - s, radius + s, d); +} +  void main() { -    o_Color = v_Color; +    o_Color = vec4( +        v_Color.xyz, +        v_Color.w * rounded(gl_FragCoord.xy, v_Pos, v_Scale, 5.0, 1.0) +    );  } diff --git a/wgpu/src/shader/quad.frag.spv b/wgpu/src/shader/quad.frag.spv Binary files differindex 33218c83..19733ecf 100644 --- a/wgpu/src/shader/quad.frag.spv +++ b/wgpu/src/shader/quad.frag.spv diff --git a/wgpu/src/shader/quad.vert b/wgpu/src/shader/quad.vert index 3392d43d..87f6cc53 100644 --- a/wgpu/src/shader/quad.vert +++ b/wgpu/src/shader/quad.vert @@ -10,6 +10,8 @@ layout (set = 0, binding = 0) uniform Globals {  };  layout(location = 0) out vec4 o_Color; +layout(location = 1) out vec2 o_Pos; +layout(location = 2) out vec2 o_Scale;  void main() {      mat4 i_Transform = mat4( @@ -20,5 +22,8 @@ void main() {      );      o_Color = i_Color; +    o_Pos = i_Pos; +    o_Scale = i_Scale; +      gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0);  } diff --git a/wgpu/src/shader/quad.vert.spv b/wgpu/src/shader/quad.vert.spv Binary files differindex d517796b..0d13df6c 100644 --- a/wgpu/src/shader/quad.vert.spv +++ b/wgpu/src/shader/quad.vert.spv  | 
