Search Unity

Resolved AspectFill Shader Graph

Discussion in 'Shader Graph' started by adamgolden, Apr 7, 2021.

  1. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    I put this together today because I needed a shader that would fill a quad of any aspect with a texture while:
    - preserving the aspect of the texture itself / not distorting it.
    - not having any "empty" space.
    - not repeating the texture.
    - resizable by scale alone.

    I'll be using this myself for splash screens, to have the center of the image in the center of the screen and the rest of the texture expanded to fill the screen regardless of resolution or screen aspect. If you have a quad that's always the size of the screen this will do that.

    The AspectFillExample shader that demonstrates how to implement the subgraph is set to Unlit Transparent and the alpha channel is wired, but if you only need Opaque or want it to be Lit, just change that stuff in the Graph Inspector.

    AspectFill.landscape.jpg AspectFill.portrait.jpg
    AspectFill.subgraph.jpg AspectFillExample.jpg
     

    Attached Files:

    lilacsky824 and florianBrn like this.