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 Deform objects

Discussion in 'Shaders' started by MatheusMarkies, Aug 31, 2020.

  1. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    67
    Good afternoon.
    I created a shader to pixelate an image.
    Now I want to deform the pixels into a X shape.

    Pixelated Image:
    Capturar.PNG

    Capturar3.PNG
    dasf.PNG

    I want them to be deformed like this:
    Sem Título-1.png

    Code:
    Code (CSharp):
    1.  
    2. float4 GetSource(float2 fxUV) {
    3.     return SAMPLE_TEXTURE2D(_PostFXSource, sampler_PostFXSource, fxUV);
    4. }
    5.  
    6. float lightIntensity(float2 fxUV, float thr) {
    7.     float4 colorChannel = GetSourceThreshold(fxUV, thr);
    8.     colorChannel = (pow(colorChannel, 4) * 2) / 333;
    9.     float greyscale = (colorChannel.r + colorChannel.g + colorChannel.b) / 3.0f;
    10.     return greyscale;
    11. }
    12.  
    13. float4 frag(Varyings i) : SV_Target
    14. {
    15.  
    16.                 float4 colorChannel = GetSource(i.fxUV);
    17.                 float2 uvFX = i.fxUV.xy;
    18.  
    19.                 float4 result = float4(0, 0, 0, 0);
    20.                
    21.                     uvFX.x *= _PixelColumns;
    22.                     uvFX.y *= _PixelRows;
    23.  
    24.                     uvFX.x = round(uvFX.x);
    25.                     uvFX.y = round(uvFX.y);
    26.  
    27.                     uvFX.x /= _PixelColumns;
    28.                     uvFX.y /= _PixelRows;
    29.  
    30.                     float greyscale = lightIntensity(uvFX, 1);
    31.  
    32.                     float4 r = float4(greyscale, greyscale, greyscale, 1);
    33.                     result += normalize(r);
    34.  
    35.                 if (_Debug == 0)
    36.                 return float4(colorChannel.rgb + result, colorChannel.a);
    37.                 else {
    38.                 return float4(result.rgb, 1);
    39.                 }
    40.  
    41.              }
    42.  
    How can I create this effect?
     

    Attached Files: