Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Editing Legacy Shaders/Lightmapped/Bumped Diffuse

Discussion in 'Shaders' started by bryandalo, May 21, 2018.

  1. bryandalo

    bryandalo

    Joined:
    Sep 20, 2013
    Posts:
    18
    Good day!

    I would like to know if it is possible to edit and add Transparency in Legacy Shaders/Lightmapped/Bumped Diffuse shader.
     
  2. Seyed_Morteza_Kamaly

    Seyed_Morteza_Kamaly

    Joined:
    Nov 18, 2015
    Posts:
    80
    Hi Try this:
    (Don't forget to set_LightMap and _MainTex because without them doesn't work)

    Code (CSharp):
    1.  
    2. Shader "Legacy Shaders/Lightmapped/Transparent Bumped Diffuse" {
    3. Properties {
    4. _Color ("Main Color", Color) = (1,1,1,1)
    5. _MainTex ("Base (RGB)", 2D) = "white" {}
    6. _BumpMap ("Normalmap", 2D) = "bump" {}
    7. _LightMap ("Lightmap (RGB)", 2D) = "black" {}
    8. _Alpha("Alpha",Range(0,1)) = 0.5
    9. }
    10. SubShader {
    11. LOD 300
    12. Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    13. Blend SrcAlpha OneMinusSrcAlpha
    14. CGPROGRAM
    15.  
    16. #pragma surface surf Lambert nodynlightmap alpha
    17. struct Input {
    18. float2 uv_MainTex;
    19. float2 uv_BumpMap;
    20. float2 uv2_LightMap;
    21. };
    22. sampler2D _MainTex;
    23. sampler2D _BumpMap;
    24. sampler2D _LightMap;
    25. fixed _Alpha;
    26. fixed4 _Color;
    27. void surf (Input IN, inout SurfaceOutput o)
    28. {
    29. o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color;
    30. half4 lm = tex2D (_LightMap, IN.uv2_LightMap);
    31. o.Emission = lm.rgb*o.Albedo.rgb;
    32. o.Alpha = lm.a * _Color.a*_Alpha;
    33. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    34. }
    35. ENDCG
    36. }
    37. FallBack "Legacy Shaders/Lightmapped/Diffuse"
    38. }
    39.  
    40.  
     
    Last edited: May 21, 2018
    bryandalo likes this.
  3. bryandalo

    bryandalo

    Joined:
    Sep 20, 2013
    Posts:
    18
    Thank you! Doesn't work as I want but I have the idea now. Thank you! :)
     
  4. bryandalo

    bryandalo

    Joined:
    Sep 20, 2013
    Posts:
    18
    Btw, do you know the best guide or tutorial that I can learn this more? I want to add cutoff in the shader too but asking someone to code for me is too much. I also really want to uderstand on how this things work :)
     
  5. Seyed_Morteza_Kamaly

    Seyed_Morteza_Kamaly

    Joined:
    Nov 18, 2015
    Posts:
    80
    Tutorial

    Just Add alphatest:_Cutoff after your #pragma

    Code (CSharp):
    1.  
    2. Shader "Legacy Shaders/Lightmapped/Transparent Bumped Diffuse" {
    3. Properties {
    4. _Color ("Main Color", Color) = (1,1,1,1)
    5. _MainTex ("Base (RGB)", 2D) = "white" {}
    6. _BumpMap ("Normalmap", 2D) = "bump" {}
    7. _LightMap ("Lightmap (RGB)", 2D) = "black" {}
    8. _Cutoff ("Cutoff Value", Range(0,1)) = 0.5
    9. }
    10. SubShader {
    11. LOD 300
    12. Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    13. Blend SrcAlpha OneMinusSrcAlpha
    14. CGPROGRAM
    15. #pragma surface surf Lambert nodynlightmap alphatest:_Cutoff
    16. struct Input {
    17. float2 uv_MainTex;
    18. float2 uv_BumpMap;
    19. float2 uv2_LightMap;
    20. };
    21. sampler2D _MainTex;
    22. sampler2D _BumpMap;
    23. sampler2D _LightMap;
    24. fixed4 _Color;
    25. void surf (Input IN, inout SurfaceOutput o)
    26. {
    27. fixed3 Maintex = tex2D (_MainTex, IN.uv_MainTex).rgb;
    28. o.Albedo = Maintex * _Color;
    29. half4 lm = tex2D (_LightMap, IN.uv2_LightMap);
    30. o.Emission = lm.rgb*o.Albedo.rgb;
    31. o.Alpha = lm.a * _Color.a * Maintex.g;
    32. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    33. }
    34. ENDCG
    35. }
    36. FallBack "Legacy Shaders/Lightmapped/Diffuse"
    37. }