diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-01-01 11:58:02 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-02-11 12:09:55 +0100 |
commit | 6310354cdeb9e9412a9b7e210a0cf341dabbcfda (patch) | |
tree | f0ab82a70d63e3070b95a9de9966e922cb83dae3 /servers/visual/rasterizer_rd | |
parent | e241057a98ab2c684f4174f6b3dab78b3446b470 (diff) |
Vulkan: Fix false positive in ninepatch axis stretch code
Adapted from e4907e50feab1af05f514a66adc0086d1c141885,
supersedes and closes #34704.
Diffstat (limited to 'servers/visual/rasterizer_rd')
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/canvas.glsl | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/servers/visual/rasterizer_rd/shaders/canvas.glsl b/servers/visual/rasterizer_rd/shaders/canvas.glsl index 63f3ca1c08..57e9451e48 100644 --- a/servers/visual/rasterizer_rd/shaders/canvas.glsl +++ b/servers/visual/rasterizer_rd/shaders/canvas.glsl @@ -283,26 +283,29 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo draw_center--; } - if (np_repeat == 0) { //stretch - //convert to ratio + // np_repeat is passed as uniform using NinePatchRect::AxisStretchMode enum. + if (np_repeat == 0) { // Stretch. + // Convert to ratio. float ratio = (pixel - margin_begin) / (draw_size - margin_begin - margin_end); - //scale to source texture + // Scale to source texture. return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size; - } else if (np_repeat == 1) { //tile - //convert to ratio + } else if (np_repeat == 1) { // Tile. + // Convert to offset. float ofs = mod((pixel - margin_begin), tex_size - margin_begin - margin_end); - //scale to source texture + // Scale to source texture. return (margin_begin + ofs) * tex_pixel_size; - } else if (np_repeat == 2) { //tile fit - //convert to ratio + } else if (np_repeat == 2) { // Tile Fit. + // Calculate scale. float src_area = draw_size - margin_begin - margin_end; float dst_area = tex_size - margin_begin - margin_end; float scale = max(1.0, floor(src_area / max(dst_area, 0.0000001) + 0.5)); - - //convert to ratio + // Convert to ratio. float ratio = (pixel - margin_begin) / src_area; ratio = mod(ratio * scale, 1.0); + // Scale to source texture. return (margin_begin + ratio * dst_area) * tex_pixel_size; + } else { // Shouldn't happen, but silences compiler warning. + return 0.0; } } } |