adding normal map to a realtime reflective material

Helloo,

i find this tutorial that explains how to make a shader/script to add realtime reflections to flat surfaces.

http://wiki.unity3d.com/index.php/SurfaceReflection

i’m trying to do a wood floor, anyone knows how to add normal map and specular map and maybe a falloff to this shader?

I’ve never made a script for a shader, and i don’t know how to start…

Shader - SurfaceReflection.shader

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
        {
            SetTexture[_ReflectionTex] { constantColor(0,0,0, [_ReflectionAlpha]) matrix [_ProjMatrix] combine texture * previous, constant} 
        }
        Pass
        {
            SetTexture[_MainTex] { constantColor(0,0,0, [_MainAlpha]) combine texture * primary, texture * constant}
        }
    }
 
    //Fallback: just main texture
    Subshader
    {
        Pass
        {
            SetTexture [_MainTex] { combine texture }
        }
    }
}

Thanks!!!

The shader you have is a fixed function shader, which means you can’t add a normal map. You will need to re-write the shader as a vertex/fragment (or surface) shader in order to support a normal map.

thanks!! im looking how to do it :slight_smile:

for certain types of cg shader, you can use ddx and ddy functions to measure the neighbour pixel values, and that gives you 3 points every time from which to construct a normal vector for each pixel, i.e. a normal map using cg’s ddx ddy function. in dx11 there is a slight more advanced version of ddx ddy.