lundi 22 janvier 2018

Adding Alpha to my Refraction Shader in Unity

I'm new to shaders but I've been following some tutorials and I tried a LOT of things on this particular shader... to no avail.

I used the MirrorReflection4 (Link to the Shader) and I wanna add a alpha which I can control from outside because and also maybe to add a texture to tell the Reflection where on a plane it is allowed to make reflection.

Would be Awesome if somebody could help a amateur :)

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

Shader "FX/MirrorReflection"
{
        Properties
        {
        _MainTex("Base (RGB)", 2D) = "white" {}
        //_ReflectionAlpha("ReflectionAlpha", Range(0, 1)) = 0
        [HideInInspector] _ReflectionTex("", 2D) = "white" {}
        }
                SubShader
        {
                Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
                ZWrite Off
                Blend SrcAlpha OneMinusSrcAlpha
                LOD 1024

                Pass{
                CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
                struct v2f
        {
                float2 uv : TEXCOORD0;
                float4 refl : TEXCOORD1;
                float4 pos : SV_POSITION;
        };
        float4 _MainTex_ST;
        v2f vert(float4 pos : POSITION, float2 uv : TEXCOORD0)
        {
                v2f o;
                o.pos = UnityObjectToClipPos(pos);
                o.uv = TRANSFORM_TEX(uv, _MainTex);
                o.refl = ComputeScreenPos(o.pos);
                return o;
        }
        sampler2D _MainTex;
        sampler2D _ReflectionTex;
        fixed4 frag(v2f i) : SV_Target
        {
                fixed4 tex = tex2D(_MainTex, i.uv);
        fixed4 refl = tex2Dproj(_ReflectionTex, UNITY_PROJ_COORD(i.refl));
        return tex * refl;
        }
                ENDCG
        }
        }
}




Aucun commentaire:

Enregistrer un commentaire