Search Unity

MirrorReflections with bump as surface shader?

Discussion in 'Shaders' started by Steva, Jun 17, 2011.

  1. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    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:
    Code (csharp):
    1.  
    2. void surf (Input IN, inout SurfaceOutput o) {
    3.     fixed4 tex = tex2D (_MainTex, IN.uv_MainTex);
    4.     fixed2 screenUV = IN.screenPos.xy / IN.screenPos.w;
    5.    
    6.     o.Albedo = tex.rgb;
    7.     o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
    8.     o.Emission = tex2D (_ReflectionTex, screenUV) *tex.a *_Color.a;
    9.    
    10. }
    11.  
    unfortunately the bump doesn't affect reflections (eg. shadowed area are flat mirrors)
    any ideas? thanks :)
     
    ZiadJ likes this.
  2. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    bump? i just can't get the bump to work with emissions :(
     
  3. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    here's what it looks like with cubemaps vs my mirrorReflection shader
     

    Attached Files:

  4. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    nevermind i got it...
     
  5. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    if anyone's interested, heres my shader:

    Code (csharp):
    1.  
    2. Shader "FX/Mirror Reflection" {
    3.     Properties {
    4.         _Color ("Main Color", Color) = (1,1,1,1)
    5.         _MainTex ("Base (RGB)", 2D) = "white" {}
    6.         _BumpMap ("Normalmap", 2D) = "bump" {}
    7.        
    8.         _ReflAmount ("Reflection amount", float) = 0.5
    9.         _ReflDistort ("Reflection distort", float) = 0.25
    10.         _ReflectionTex ("Reflection", 2D) = "white" { TexGen ObjectLinear }
    11.     }
    12.    
    13.     SubShader {
    14.         Tags { "RenderType" = "Opaque" }
    15.         CGPROGRAM
    16.         #pragma surface surf Lambert
    17.         //#pragma surface surf BlinnPhong
    18.        
    19.         struct Input {
    20.             float2 uv_MainTex;
    21.             float2 uv_BumpMap;
    22.             float4 screenPos;
    23.         }; 
    24.        
    25.         uniform fixed4 _Color;
    26.         uniform sampler2D _MainTex;
    27.         uniform sampler2D _BumpMap;
    28.         uniform float _ReflAmount;
    29.         uniform float _ReflDistort;
    30.         uniform sampler2D _ReflectionTex;
    31.        
    32.         void surf (Input IN, inout SurfaceOutput o) {
    33.            
    34.             fixed4 tex = tex2D (_MainTex, IN.uv_MainTex);
    35.             fixed3 nor = UnpackNormal (tex2D(_BumpMap, IN.uv_BumpMap));
    36.            
    37.             fixed2 screenUV = (IN.screenPos.xy) / (IN.screenPos.w);
    38.             screenUV.xy += nor *_ReflDistort;
    39.            
    40.             fixed4 refl = tex2D (_ReflectionTex, screenUV);
    41.            
    42.             o.Albedo = tex.rgb *_Color.rgb;
    43.             o.Normal = nor.rgb;
    44.             o.Emission = refl *_ReflAmount *tex.a;
    45.             o.Specular = _Color.a;
    46.             o.Gloss = tex.a;
    47.             o.Alpha = tex.a;
    48.            
    49.         }
    50.         ENDCG
    51.     }
    52.    
    53.     FallBack "Diffuse"
    54. }
    55.  
     
    modanhan and ZiadJ like this.
  6. tony77

    tony77

    Joined:
    Nov 4, 2010
    Posts:
    13
    Hello, I am also I of Padua in Italy, have you tried strumpy shader editor to achieve this effect?
     
  7. GizmoBradwell

    GizmoBradwell

    Joined:
    Dec 27, 2010
    Posts:
    67
    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 :)
     
  8. Steva

    Steva

    Joined:
    Sep 9, 2010
    Posts:
    60
    No because i find it easier to code directly in surface shader/CG..

    Glad to be of help :)
     
  9. Shan

    Shan

    Joined:
    Sep 22, 2012
    Posts:
    1
    Hi Steva..u know what..this what i looking for....gracias my friend... :)
     
  10. ZiadJ

    ZiadJ

    Joined:
    Sep 3, 2011
    Posts:
    62
    Thanks for sharing Steva but will this work with MirrorReflection3 in Unity5?