Search Unity

How do I use\implement light maps in a custom realtime reflection shader for mobile?

Discussion in 'Shaders' started by MP-ul, Apr 13, 2017.

  1. MP-ul

    MP-ul

    Joined:
    Jan 25, 2014
    Posts:
    230
    Hey there is there someone who can help me with this shader? i want to make an reflectiv material
    Something like this but for static objects that have lightmaps .

    here is the shader that i have:

    Shader "Mobile/PlanarReflection"
    {
    Properties
    {
    _MainAlpha("MainAlpha", Range(0, 1)) = 1
    _ReflectionAlpha("ReflectionAlpha", Range(0, 1)) = 1
    _MainTex ("MainTex (RGBA)", 2D) = ""
    [HideInInspector]_ReflectionTex ("ReflectionTex", 2D) = "white" { TexGen ObjectLinear }
    }


    Subshader
    {

    CGPROGRAM
    #pragma surface surf Lambert

    float _MainAlpha;
    float _ReflectionAlpha;
    sampler2D _MainTex;
    sampler2D _ReflectionTex;

    struct Input
    {
    float2 uv_MainTex;
    float4 screenPos;
    };

    void surf(Input IN, inout SurfaceOutput o)
    {

    fixed4 main_Tex = tex2D(_MainTex, IN.uv_MainTex);

    o.Albedo = main_Tex.rgb * _MainAlpha;

    o.Emission = tex2D(_ReflectionTex, IN.screenPos.xy / IN.screenPos.w).rgb * _ReflectionAlpha * main_Tex.a;

    }
    ENDCG
    }

    Fallback "Diffuse"

    }
     
  2. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    314
    this is a surface shader, it already supports lightmaps. Lower your _ReflectionAlpha value and you should be able to see if if it's correctly baked.
     
  3. MP-ul

    MP-ul

    Joined:
    Jan 25, 2014
    Posts:
    230
    Hmm indeed it does but the reflection not is not showing on the mobile build o_O
     
  4. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874