Hi all.
In fist time, no, I don’t have experience with shaders at all. 
I’m trying to convert MirrorReflection2 to surface shader (Same script and modified shader)
I’m pretty sure the problem is not script, because it works, with bad projection (so it´s a problem with my noob shader coding…)
The shader:
Shader "Surface/MirrorRef" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_ReflectionTex ("Reflection", 2D) = "black" { TexGen ObjectLinear }
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _ReflectionTex;
float4x4 _ProjMatrix; // Set by MirrorReflection.cs script
struct Input {
float2 uv_MainTex;
float4 screenPos;
};
void surf (Input IN, inout SurfaceOutput o) {
// half4 c = tex2D (_MainTex, IN.uv_MainTex);
// float2 uvref = IN.screenPos.xy / IN.screenPos.w;
o.Albedo = tex2Dproj( _ReflectionTex, mul(_ProjMatrix, IN.screenPos)); // Here is the wrong projection...
// o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Anyone can help??
Can you give any more detail about what exactly is going wrong with the projection?
It´s solved, but thanks!
The script is MirrorReflection2, you can find it in the wiki, and here is the modified shader (NOT SURFACE SHADER FOR NOW, BUT WORKS ON Unity 3. If anyone can convert and post… welcome
)
Shader:
Shader "FX/MirrorReflection" {
Properties {
_MainTex ("Main texture", 2D) = "" {}
_ReflectionTex ("Internal Reflection", 2D) = "" {}
}
// -----------------------------------------------------------
// Fragment program cards
Subshader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#define HAS_REFLECTION 1
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f {
float4 pos : SV_POSITION;
#if defined(HAS_REFLECTION) || defined(HAS_REFRACTION)
float4 ref : TEXCOORD0;
float3 viewDir : TEXCOORD3;
#else
float2 bumpuv0 : TEXCOORD0;
float2 bumpuv1 : TEXCOORD1;
float3 viewDir : TEXCOORD2;
#endif
};
v2f vert(appdata v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
// object space view direction (will normalize per pixel)
o.viewDir.xzy = ObjSpaceViewDir(v.vertex);
o.ref = ComputeScreenPos(o.pos);
return o;
}
sampler2D _ReflectionTex;
half4 frag( v2f i ) : COLOR
{
i.viewDir = normalize(i.viewDir);
float4 uv1 = i.ref; uv1.xy;
half4 refl = tex2Dproj( _ReflectionTex, UNITY_PROJ_COORD(uv1) );
// final color is between refracted and reflected based on fresnel
half4 color;
color.rgb = refl.rgb;
color.a = refl.a;
return color;
}
ENDCG
}
}
}