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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

image effect draw circle and outline it with textures and use noise to make jiggle effect

Discussion in 'Image Effects' started by kaluxx, Aug 7, 2021.

  1. kaluxx

    kaluxx

    Joined:
    May 9, 2015
    Posts:
    4
    hey guys any one have an idea how to make a circle with a white outline ??
    i managed to make a circle mask with a mask alpha texture

    Code (CSharp):
    1. Shader "Hidden/Grayscale Effect"
    2. {
    3.     Properties
    4.     {
    5.         //2D TEXTURES VALUES
    6.         _MainTex("Base (RGB)", 2D) = "white" {}
    7.         _RampTex("Base (RGB)", 2D) = "grayscaleRamp" {}
    8.         _RampTexB("Base (RGB)", 2D) = "grayscaleRamp" {}
    9.         _MaskTex("Base (RGB)", 2D) = "white" {}
    10.  
    11.         //FLOAT VALUES
    12.         _MaskRadius("Radisu Mask", Float) = 0.5
    13.         _MaskCenterPosition_X("MaskCenterPosition_X", Float) = 0.5
    14.         _MaskCenterPosition_Y("MaskCenterPosition_Y", Float) = 0.5
    15.        
    16.         //COLOR VALUES
    17.         _outlinColor ("outlineColor",Color) = (1, 1, 1, 1)
    18.     }
    19.  
    20.     SubShader
    21.     {
    22.             Pass
    23.             {
    24.                 ZTest Always Cull Off ZWrite Off
    25.                 Fog { Mode off }
    26.  
    27.                 CGPROGRAM
    28.                 #pragma vertex vert_img
    29.                 #pragma fragment frag
    30.                 #pragma fragmentoption ARB_precision_hint_fastest
    31.  
    32.                 #include "UnityCG.cginc"
    33.  
    34.                 uniform sampler2D _MainTex;
    35.                 uniform sampler2D _RampTex;
    36.                 uniform sampler2D _RampTexB;
    37.                 uniform sampler2D _MaskTex;
    38.                 uniform half _RampOffset;
    39.                 float4 screenPos : TEXCOORD1;
    40.  
    41.                 uniform float _MaskRadius;
    42.  
    43.                 uniform float _MaskCenterPosition_X;
    44.                 uniform float _MaskCenterPosition_Y;
    45.  
    46.                 // Circle function
    47.                     float circle(in float2 _st, in float _radius) {
    48.                          float2 dist = _st - float2(0.5f,0.5f);
    49.                          return 1.0f - smoothstep(_radius - (_radius * 0.01f),_radius + (_radius * 0.01f),dot(dist, dist) * 4.0f);
    50.                     }
    51.  
    52.                     fixed4 frag(v2f_img i) : SV_Target {
    53.  
    54.                     fixed4 original = tex2D(_MainTex, i.uv);
    55.                     ///// HERE IS MY (FAILED) ATTEMPT TO MAKE AN OUTLINE /////////////////////////////////////////////
    56.  
    57.                     fixed4 original2 = tex2D(_MaskTex, ((i.uv - 0.5) * 0.2) + 0.5);
    58.                     fixed4 original3 = original - original2;
    59.  
    60.                     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    61.  
    62.                     fixed grayscale = Luminance(original.rgb);
    63.  
    64.                     // Scale the Mask
    65.                     float Ratio = _ScreenParams.x / _ScreenParams.y;
    66.                     float2 MaskCenterPosition = float2(_MaskCenterPosition_X, _MaskCenterPosition_Y);
    67.                     float2 Scaled_uv = ((i.uv - MaskCenterPosition) * float2(Ratio, 1) / _MaskRadius) + 0.5;
    68.            
    69.                     float MaskValue = tex2D(_MaskTex, Scaled_uv).x;
    70.  
    71.                     half2 remap = half2 (grayscale + _RampOffset, 0.5f);
    72.  
    73.                     ////////////////////////////////////////////////////////////////////////////////////////
    74.                     fixed4 outputA = tex2D(_RampTex, remap) + original3;
    75.                     fixed4 outputB = tex2D(_RampTexB, remap);
    76.                     ////////////////////////////////////////////////////////////////////////////////////////
    77.  
    78.                     outputA.a = original.a;
    79.  
    80.                     // Mask between Original and the Output
    81.                     return  lerp(outputB, outputA, MaskValue);
    82.  
    83.                     }
    84.                     //========================================================================================
    85.  
    86.                     ENDCG
    87.             }
    88.         ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    89.     }
    90.  
    91.  
    92.     Fallback off
    93.  
    94. }