Search Unity

Question Edit shader

Discussion in 'Shaders' started by MatheusMarkies, Sep 26, 2020.

  1. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    67
    Good afternoon.
    I would like help to edit this shader.
    https://github.com/keijiro/KinoStreak

    Code (CSharp):
    1.  
    2. // Kino/Streak - Anamorphic lens flare effect for Unity
    3. // https://github.com/keijiro/KinoStreak
    4.  
    5. #include "UnityCG.cginc"
    6.  
    7. sampler2D _MainTex;
    8. float4 _MainTex_TexelSize;
    9.  
    10. sampler2D _HighTex;
    11. float4 _HighTex_TexelSize;
    12.  
    13. float _Threshold;
    14. float _Stretch;
    15. float _Intensity;
    16. half3 _Color;
    17.  
    18. // Prefilter: Shrink horizontally and apply threshold.
    19. half4 frag_prefilter(v2f_img i) : SV_Target
    20. {
    21.     // Actually this should be 1, but we assume you need more blur...
    22.     const float vscale = 1.5;
    23.     const float dy = _MainTex_TexelSize.y * vscale / 2;
    24.  
    25.     half3 c0 = tex2D(_MainTex, float2(i.uv.x, i.uv.y - dy));
    26.     half3 c1 = tex2D(_MainTex, float2(i.uv.x, i.uv.y + dy));
    27.     half3 c = (c0 + c1) / 2;
    28.  
    29.     float br = max(c.r, max(c.g, c.b));
    30.     c *= max(0, br - _Threshold) / max(br, 1e-5);
    31.  
    32.     return half4(c, 1);
    33. }
    34.  
    35. // Downsampler
    36. half4 frag_down(v2f_img i) : SV_Target
    37. {
    38.     // Actually this should be 1, but we assume you need more blur...
    39.     const float hscale = 1.25;
    40.     const float dx = _MainTex_TexelSize.x * hscale;
    41.  
    42.     float u0 = i.uv.x - dx * 5;
    43.     float u1 = i.uv.x - dx * 3;
    44.     float u2 = i.uv.x - dx * 1;
    45.     float u3 = i.uv.x + dx * 1;
    46.     float u4 = i.uv.x + dx * 3;
    47.     float u5 = i.uv.x + dx * 5;
    48.  
    49.     half3 c0 = tex2D(_MainTex, float2(u0, i.uv.y));
    50.     half3 c1 = tex2D(_MainTex, float2(u1, i.uv.y));
    51.     half3 c2 = tex2D(_MainTex, float2(u2, i.uv.y));
    52.     half3 c3 = tex2D(_MainTex, float2(u3, i.uv.y));
    53.     half3 c4 = tex2D(_MainTex, float2(u4, i.uv.y));
    54.     half3 c5 = tex2D(_MainTex, float2(u5, i.uv.y));
    55.  
    56.     // Simple box filter
    57.     half3 c = (c0 + c1 + c2 + c3 + c4 + c5) / 6;
    58.  
    59.     return half4(c, 1);
    60. }
    61.  
    62. // Upsampler
    63. half4 frag_up(v2f_img i) : SV_Target
    64. {
    65.     half3 c0 = tex2D(_MainTex, i.uv) / 4;
    66.     half3 c1 = tex2D(_MainTex, i.uv) / 2;
    67.     half3 c2 = tex2D(_MainTex, i.uv) / 4;
    68.     half3 c3 = tex2D(_HighTex, i.uv);
    69.     return half4(lerp(c3, c0 + c1 + c2, _Stretch), 1);
    70. }
    71.  
    72. // Final composition
    73. half4 frag_composite(v2f_img i) : SV_Target
    74. {
    75.     half3 c0 = tex2D(_MainTex, i.uv) / 4;
    76.     half3 c1 = tex2D(_MainTex, i.uv) / 2;
    77.     half3 c2 = tex2D(_MainTex, i.uv) / 4;
    78.     half3 c3 = tex2D(_HighTex, i.uv);
    79.     half3 cf = (c0 + c1 + c2) * _Color * _Intensity * 5;
    80.     return half4(cf + c3, 1);
    81. }
    82.  
    687474703a2f2f692e696d6775722e636f6d2f424562303569792e676966 (1).gif
    I would like to take this rays (Anamorphic Flare) and duplicate them on the Y axis.
    Something like:
    Sem Título-1.jpg

    Or create angles between them and do something like this:
    Sem Título-1.png

    I tried to do it by publishing the terms and putting the uv * -1, but it didn't work.

    Is there a way to put all this code in just one Pass?
    Credits: https://github.com/keijiro