Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Applying blur to texture

Discussion in 'Shaders' started by Diablo404, Dec 11, 2015.

  1. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    First thing to know, I barely don't understand anything about shaders. I'm learning slowly how this works but I'm in lack of so many notions. I know it's not the best way to introduce a question but it is, I think, necessary for the potential answer.

    So, I've been trying to tweak every blur shader I could find on the interwebs for weeks that could be added to the default UI Sprite shader.

    I've found something ( https://www.shadertoy.com/view/Mtl3Rj ) that I've been able to "translate?", but I have an issue that I can't manage to resolve ( Last thing to know, for now, I've been able to only perform a single pass blur ), anyway:

    The texture gets quite blurry, so it's a small win, but I would like to expand the blur over the "end" of the texture, where the aliasing appears.

    testShader.png original.png

    Here is the fragment part modified from the original (Default Sprite UI ) one:

    Code (csharp):
    1.  
    2. fixed4 frag(v2f IN) : SV_Target
    3.  {
    4. return BlurV(_MainTex, fixed2(128,128), IN.texcoord, 5);
    5. }
    6.  
    Hope someone could give a hint to make it works.

    PS: I can show the BlurV implementation if it's relevant

    Thanks in advance
     
  2. Fallc

    Fallc

    Joined:
    Mar 13, 2015
    Posts:
    48
    Please show it! :p

    And just for understanding: are you trying to achive anti-aliasing or do you want to blur the whole texture?
     
  3. Flailer

    Flailer

    Joined:
    Apr 1, 2014
    Posts:
    66
    Haha yeah, it seems pretty damn integral to solving your issue, most of us know what a function call in a fragment shader looks like ;)

    Seriously tho, per shader pixel blue is expensive. If you have too, try looking up seperable blurs.

    Essentially you want to have multiple texture samples around a pixel and use the offset of that sample to control the amount of each blur, this can then be weighted to give a falloff.