Warning, /frameworks/kirigami/src/scenegraph/shaders6/shadowedbordertexture.frag is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #version 440 0008 0009 #extension GL_GOOGLE_include_directive: enable 0010 #include "sdf.glsl" 0011 // See sdf.glsl for the SDF related functions. 0012 0013 // This shader renders a rectangle with rounded corners and a shadow below it. 0014 // In addition it renders a border around it. 0015 0016 #include "uniforms.glsl" 0017 layout(binding = 1) uniform sampler2D textureSource; 0018 0019 layout(location = 0) in lowp vec2 uv; 0020 layout(location = 0) out lowp vec4 out_color; 0021 0022 const lowp float minimum_shadow_radius = 0.05; 0023 0024 void main() 0025 { 0026 // Scaling factor that is the inverse of the amount of scaling applied to the geometry. 0027 lowp float inverse_scale = 1.0 / (1.0 + ubuf.size + length(ubuf.offset) * 2.0); 0028 0029 // Correction factor to round the corners of a larger shadow. 0030 // We want to account for size in regards to shadow radius, so that a larger shadow is 0031 // more rounded, but only if we are not already rounding the corners due to corner radius. 0032 lowp vec4 size_factor = 0.5 * (minimum_shadow_radius / max(ubuf.radius, minimum_shadow_radius)); 0033 lowp vec4 shadow_radius = ubuf.radius + ubuf.size * size_factor; 0034 0035 lowp vec4 col = vec4(0.0); 0036 0037 // Calculate the shadow's distance field. 0038 lowp float shadow = sdf_rounded_rectangle(uv - ubuf.offset * 2.0 * inverse_scale, ubuf.aspect * inverse_scale, shadow_radius * inverse_scale); 0039 // Render it, interpolating the color over the distance. 0040 col = mix(col, ubuf.shadowColor * sign(ubuf.size), 1.0 - smoothstep(-ubuf.size * 0.5, ubuf.size * 0.5, shadow)); 0041 0042 // Scale corrected corner radius 0043 lowp vec4 corner_radius = ubuf.radius * inverse_scale; 0044 0045 // Calculate the outer rectangle distance field and render it. 0046 lowp float outer_rect = sdf_rounded_rectangle(uv, ubuf.aspect * inverse_scale, corner_radius); 0047 0048 col = sdf_render(outer_rect, col, ubuf.borderColor); 0049 0050 // The inner rectangle distance field is the outer reduced by twice the border width. 0051 lowp float inner_rect = outer_rect + (ubuf.borderWidth * inverse_scale) * 2.0; 0052 0053 // Render the inner rectangle. 0054 col = sdf_render(inner_rect, col, ubuf.color); 0055 0056 // Sample the texture, then blend it on top of the background color. 0057 lowp vec2 texture_uv = ((uv / ubuf.aspect) + (1.0 * inverse_scale)) / (2.0 * inverse_scale); 0058 lowp vec4 texture_color = texture(textureSource, texture_uv); 0059 col = sdf_render(inner_rect, col, texture_color, texture_color.a, sdf_default_smoothing); 0060 0061 out_color = col * ubuf.opacity; 0062 }