Refraction

Unity3D/Shader 2020. 12. 23. 17:42
반응형

Shader "Custom/Refraction"
{
    Properties
    {
        _MainTex ("Main Tex", 2D) = "white" {}
        _RefStrength ("Reflection Strength", Range(0, 0.1)) = 0.05
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent"}

        zwrite off

        GrabPass {}
        
        CGPROGRAM
        #pragma surface surf _NoLight noambient alpha:fade

        sampler2D _MainTex;
        sampler2D _GrabTexture;
        float _RefStrength;

        struct Input
        {
            float4 color:COLOR;
            float4 screenPos;
            float2 uv_MainTex;
        };

        void surf (Input i, inout SurfaceOutput o)
        {
            float4 ref = tex2D(_MainTex, i.uv_MainTex);
            float3 screenUV = i.screenPos.rgb / i.screenPos.a;
            //o.Emission = float3(screenUV.xy, 0);
            o.Emission = tex2D(_GrabTexture, screenUV.xy + ref.x * _RefStrength);
        }

        float4 Lighting_NoLight (SurfaceOutput s, float3 lightDir, float atten){
            return float4(0, 0, 0, 1);
        }
        ENDCG
    }
    FallBack "Regacy Shaders/Transparent/Vertexlit"
}
반응형

'Unity3D > Shader' 카테고리의 다른 글

Dev Weeks: URP 셰이더 뜯어보기  (0) 2021.07.27
water  (0) 2020.12.23
Matcap  (0) 2020.12.23
흔들리는 풀  (0) 2020.12.23
Unity Unlit Shader (vertex & fragment shader)  (0) 2020.12.22
: