// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "UsayaLib/3D/Rim/Additive" {
    Properties {
        _Color ("Color", Color) = (1, 1, 1, 1)
        _RimEffect ("Rim effect", Range(0, 1)) = 0
    }
    SubShader {
        Tags {
            "Queue"="Transparent"
            "RenderType"="Transparent"
        }

        Pass {
            Blend One One
            Cull Off
            ZWrite Off

            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct v2f {
                float4 pos : SV_POSITION;
                float3 normal : NORMAL;
                float3 viewDir : TEXCOORD1;
            };

            v2f vert(appdata_full v){
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                o.normal = UnityObjectToWorldNormal(v.normal);
                o.viewDir = normalize(ObjSpaceViewDir(v.vertex));
                return o;
            }

            fixed4 _Color;
            fixed _RimEffect;

            fixed4 frag(v2f i) : COLOR {
                float val = 1 - abs(dot(i.viewDir, i.normal)) * _RimEffect;
                return _Color * _Color.a * val * val;
            }

            ENDCG
        }
    }
    FallBack "Diffuse"
}