Search Unity

how to get the dimensions of an UI element?

Discussion in 'Shaders' started by MrMatthias, Dec 4, 2019.

  1. MrMatthias


    Sep 18, 2012
    Is it possible to get the dimensions or aspect ratio of an ui element in a shader, without extra script?
    I want to render the texture of an image as aspect-fit, but i also want to render the background that isn't covered by the image using the tint color.
    I could also use a stencil mask with an additional image in the background, but having just one material/shader would be nicer.
    The problem i'm trying to solve is, that a separate background image becomes apparent when fading the canvas. It doesn't look like a single image, you see the parts that aren't covered by the texture (they seem lighter since they don't overlap with the texture).