Steva
June 17, 2011, 3:19pm
1
I have successfully ported the wiki MirrorReflection2 shader from the wiki to a Surface shader, problem is i now want to add bump to the reflection… here’s what i have so far:
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D (_MainTex, IN.uv_MainTex);
fixed2 screenUV = IN.screenPos.xy / IN.screenPos.w;
o.Albedo = tex.rgb;
o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
o.Emission = tex2D (_ReflectionTex, screenUV) *tex.a *_Color.a;
}
unfortunately the bump doesn’t affect reflections (eg. shadowed area are flat mirrors)
any ideas? thanks
1 Like
Steva
June 20, 2011, 9:49am
2
bump? i just can’t get the bump to work with emissions
Steva
June 20, 2011, 12:07pm
3
here’s what it looks like with cubemaps vs my mirrorReflection shader
Steva
June 21, 2011, 4:32pm
5
if anyone’s interested, heres my shader:
Shader "FX/Mirror Reflection" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_ReflAmount ("Reflection amount", float) = 0.5
_ReflDistort ("Reflection distort", float) = 0.25
_ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear }
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
//#pragma surface surf BlinnPhong
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float4 screenPos;
};
uniform fixed4 _Color;
uniform sampler2D _MainTex;
uniform sampler2D _BumpMap;
uniform float _ReflAmount;
uniform float _ReflDistort;
uniform sampler2D _ReflectionTex;
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D (_MainTex, IN.uv_MainTex);
fixed3 nor = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
fixed2 screenUV = (IN.screenPos.xy) / (IN.screenPos.w);
screenUV.xy += nor *_ReflDistort;
fixed4 refl = tex2D (_ReflectionTex, screenUV);
o.Albedo = tex.rgb *_Color.rgb;
o.Normal = nor.rgb;
o.Emission = refl *_ReflAmount *tex.a;
o.Specular = _Color.a;
o.Gloss = tex.a;
o.Alpha = tex.a;
}
ENDCG
}
FallBack "Diffuse"
}
2 Likes
Hello, I am also I of Padua in Italy, have you tried strumpy shader editor to achieve this effect?
I’ve been crying out for a shader like this! Shiny floors, great. This has all the features one could hope for, that would take me half a year to work out how to do. THANKYOU
Steva
November 30, 2011, 5:53pm
8
No because i find it easier to code directly in surface shader/CG…
Glad to be of help
Shan
September 22, 2012, 8:17am
9
Hi Steva…u know what…this what i looking for…gracias my friend…
ZiadJ
August 11, 2015, 10:10pm
10
Thanks for sharing Steva but will this work with MirrorReflection3 in Unity5?