Search Unity

Legacy lightmap shader doesnt give any specular highlight.

Discussion in 'Editor & General Support' started by kurylo3d, Nov 16, 2010.

  1. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    I tried creating a quick lightmap in beast.. i saved it out in photoshop and i brought it back in for use with a legacy lightmap bumped spec shader. The idea was to have a normal light in there interact with the scene to get some bump and specular highlights.

    Now the problem is no specular highlights exist in the lightmapped version! Check out the screenshots. Whats up with this. This worked in untiy 2. The normal maps work... just all specularity vanishes.

    Unity devs... this cant be on purpose... whats up.
     

    Attached Files:

    Last edited: Nov 16, 2010
  2. the_gnoblin

    the_gnoblin

    Joined:
    Jan 10, 2009
    Posts:
    722
    The built-in shader you're talking about looks like this:

    Code (csharp):
    1. Shader "Legacy Shaders/Lightmapped/Bumped Specular" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    5.         _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    6.         _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    7.         _BumpMap ("Normalmap", 2D) = "bump" {}
    8.         _LightMap ("Lightmap (RGB)", 2D) = "lightmap" { LightmapMode }
    9.     }
    10.     FallBack "Legacy Shaders/Lightmapped/Bumped Diffuse"
    11. }
    So, here's a fixed version I've made recently:

    Code (csharp):
    1. Shader "Legacy Shaders/Lightmapped/Gnoblin/BumpedSpec" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    5.     _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    6.     _MainTex ("Base (RGB)", 2D) = "white" {}
    7.     _BumpMap ("Normalmap", 2D) = "bump" {}
    8.     _LightMap ("Lightmap (RGB)", 2D) = "black" {}
    9. }
    10.  
    11. SubShader {
    12.     LOD 200
    13.     Tags { "RenderType" = "Opaque" }
    14. CGPROGRAM
    15. #pragma surface surf BlinnPhong
    16. struct Input {
    17.   float2 uv_MainTex;
    18.   float2 uv_BumpMap;
    19.   float2 uv2_LightMap;
    20. };
    21. sampler2D _MainTex;
    22. sampler2D _LightMap;
    23. sampler2D _BumpMap;
    24. float4 _Color;
    25. float _Shininess;
    26.  
    27. void surf (Input IN, inout SurfaceOutput o)
    28. {
    29.   half4 tex = tex2D (_MainTex, IN.uv_MainTex);
    30.   o.Albedo = tex.rgb * _Color;
    31.   half4 lm = tex2D (_LightMap, IN.uv2_LightMap);
    32.   o.Emission = lm.rgb*o.Albedo.rgb;
    33.   o.Gloss = tex.a;
    34.   o.Alpha = lm.a * _Color.a;
    35.   o.Specular = _Shininess;
    36.   o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    37. }
    38. ENDCG
    39. }
    40. FallBack "Legacy Shaders/Lightmapped/VertexLit"
    41. }
    42.  
     
  3. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Thank you so much! Worked like a charm.
     
  4. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    Thanks a million!! I was just about to make a post about it :)
     
  5. MANISH KUMAR

    MANISH KUMAR

    Joined:
    Nov 22, 2010
    Posts:
    57
    Can Anyone give me any alternate option of Legacy Shader.
     
  6. V!nc3r

    V!nc3r

    Joined:
    Sep 12, 2011
    Posts:
    2
    great job, thanks Gnoblin !
     
  7. Dark-_-Image

    Dark-_-Image

    Joined:
    May 6, 2011
    Posts:
    10
    Good job very helpfull for me
     
    Last edited: Oct 9, 2011
  8. nebulabox

    nebulabox

    Joined:
    Dec 25, 2010
    Posts:
    5
    Thanks Gnoblin! Very cool!
     
  9. Ingsoc75

    Ingsoc75

    Joined:
    Apr 14, 2011
    Posts:
    13
    How do I get this to work in Unity?
     
  10. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Save the text file with the ending .shader somewhere in your project tree. Then you should be able to select this shader in the shader tab.
     
  11. Ingsoc75

    Ingsoc75

    Joined:
    Apr 14, 2011
    Posts:
    13
    I copied it into Notepad, saved it out as " ".shader in my project folder. It shows up in the list in the Project area. When I select it it, the Inspector gives me a few errors at the bottom.

    I'm using the newest version of Unity 3.5.0f5 (Pro Trial).
     
  12. Ingsoc75

    Ingsoc75

    Joined:
    Apr 14, 2011
    Posts:
    13
    Got it. Thanks Tiles.
     
  13. tapiocaflash

    tapiocaflash

    Joined:
    Jun 19, 2012
    Posts:
    9
    Hi,

    Can someone verify that the script written by Gnoblin works in Unity3d 3.5 free? I got a really brightly-lit scene with no specularity when I tried. Didn't seem to work? Interested because it would be cool to retain some specularity when deploying a lightmapped scene to the mobile platform. Thanks.