Hi,
I was using the surface reflection example from the Unity Wiki: http://wiki.unity3d.com/index.php/SurfaceReflection
Everything was fine with Unity 4. Today I upgraded my project to Unity 5 and the shader does not seems to work anymore. The reflection is totally distorted and the main texture is not visible at all any more.
Well, I noticed that the MirrorReflection example from the Wiki, which SurfaceReflction is based on, got updated for Unity 5 and the first pass was replaced by CGCODE. If I use the CGCODE pass from that example the reflection is working fine again, but I’m failing to combine the reflection with my main texture from the SurfaceReflection example.Here is what I changed the SurfaceReflection example to:
Shader "FX/Surface Reflection"
{
Properties
{
_MainAlpha("MainAlpha", Range(0, 1)) = 1
_ReflectionAlpha("ReflectionAlpha", Range(0, 1)) = 1
_TintColor ("Tint Color (RGB)", Color) = (1,1,1)
_MainTex ("MainTex (RGBA)", 2D) = ""
_ReflectionTex ("ReflectionTex", 2D) = "white" { TexGen ObjectLinear }
}
//Two texture cards: full thing
Subshader
{
Tags {Queue = Transparent}
ZWrite Off
Colormask RGBA
Color [_TintColor]
Blend SrcAlpha OneMinusSrcAlpha
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 = mul (UNITY_MATRIX_MVP, 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
}
Pass
{
SetTexture[_MainTex] { constantColor(0,0,0, [_MainAlpha]) combine texture * primary, texture * constant}
}
}
}
Does anyone have an idea how to combine these two passes in a correct way soo the same effect as in the SurfaceReflection example is achieved? Thanks a lot in advance for any help!
-Axel