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.

Question Inflate image effect

Discussion in 'Shaders' started by oukibt_unity, Oct 12, 2022.

  1. oukibt_unity

    oukibt_unity

    Joined:
    May 6, 2022
    Posts:
    19
    Hello everyone.
    I wanna to make shader, that will be inflate texture in center.
    Like a Spherize effect in Photoshop

    Before:


    After:


    Unforunately all my attempts failed.
    I would be very grateful if someone could help me with this
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,399
    The simplest implementation of this is to simply shift the UV value towards center based on its distance from center UV range (0.5, 0.5).

    Example:
    Code (CSharp):
    1.  
    2. // "Amount" is some Vector2 defined in your shader/material that allows you to control the X and Y expand directions
    3. float uvDist = distance(UV, 0.5); //Get distance between UV and UV center (0.5,0.5)
    4. uvDist = min(0.5, uvDist); //Clamp the distance to the radius of the UV range (0.5)
    5. uvDist = uvDist * 2; // Multiply the dist by 2, scaling it from 0-0.5 to 0-1 range to use as scaling factor
    6. uvDist = 1 - uvDist; //Flip our distance so the closer to center we are, the greater the scaling
    7. float2 factor = uvDist * Amount; //Adjust the factor by our material property controlled amount.
    8. factor = saturate(factor); //Clamp to 0-1 range to ensure our lerp() stays within A/B
    9. float2 inflatedUV = lerp(UV, float2(0.5, 0.5), factor); //Shift our UV value towards center based on our factor intensity.
     
    Last edited: Oct 14, 2022
    oukibt_unity likes this.