37 const float2 cornervec[36] = {
51 const float2 center_offset[4] = {
55 float4 recti = srt.parameters[0];
56 float4 rect = srt.parameters[1];
57 float radsi = srt.parameters[2].
x;
58 float rads = srt.parameters[2].y;
59 float4 roundCorners = srt.parameters[3];
64 constexpr uint BOTTOM_LEFT = 0u;
65 constexpr uint BOTTOM_RIGHT = 1u;
66 constexpr uint TOP_RIGHT = 2u;
69 constexpr uint CNR_FLAG_RANGE = uint((1 << 2) - 1);
71 constexpr uint CORNER_VEC_OFS = 2u;
72 constexpr uint CORNER_VEC_RANGE = uint((1 << 4) - 1);
74 constexpr uint INNER_FLAG = uint(1 << 10);
76 uint cflag = v_in.vflag & CNR_FLAG_RANGE;
77 uint vofs = (v_in.vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE;
79 bool is_inner = (v_in.vflag & INNER_FLAG) != 0u;
81 float shadow_width = rads - radsi;
82 float shadow_width_top = rect.
w - recti.
w;
84 float rad_inner = radsi * roundCorners[cflag];
85 float rad_outer = rad_inner + shadow_width;
86 float radius = (is_inner) ? rad_inner : rad_outer;
88 float shadow_offset = (is_inner && (cflag > BOTTOM_RIGHT)) ? (shadow_width - shadow_width_top) :
91 float2 c = center_offset[cflag];
92 float2 center_outer = rad_outer * c;
93 float2 center = radius * c;
96 float2 v = rad_outer * cornervec[cflag * 9u + vofs];
101 if (is_inner && (cflag > BOTTOM_RIGHT) && (v.y < (shadow_offset - rad_outer))) {
102 v.y += shadow_width_top;
106 v = radius *
normalize(v - (center_outer +
float2(0.0f, shadow_offset))) + center;
110 float4 rct = (is_inner) ? recti : rect;
111 if (cflag == BOTTOM_LEFT) {
114 else if (cflag == BOTTOM_RIGHT) {
117 else if (cflag == TOP_RIGHT) {
124 float inner_shadow_strength =
min((rect.
w - v.y) / rad_outer + 0.1f, 1.0f);
125 v_out.shadowFalloff = (is_inner) ? inner_shadow_strength : 0.0f;
126 v_out.innerMask = (is_inner) ? 0.0f : 1.0f;
128 out_pos = srt.ModelViewProjectionMatrix *
float4(v, 0.0f, 1.0f);
136 float falloff = v_out.shadowFalloff;
137 float falloff_sqr = falloff * falloff;
138 float shadow_alpha = srt.alpha * (falloff_sqr * 0.722f + falloff * 0.277f);
139 float inner_alpha =
smoothstep(0.0f, 0.05f, v_out.innerMask);
141 frag_out.color =
float4(0.0f, 0.0f, 0.0f, inner_alpha * shadow_alpha);