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

How to: Shader with diffuse map + reflection + lightmap

Discussion in 'Shaders' started by pradmegs, Mar 8, 2011.

  1. pradmegs

    pradmegs

    Joined:
    Mar 7, 2011
    Posts:
    2
    I am a newbie. Is it possible to write a shader to show Diffuse Map + Reflection (cube) + Lightmap or Self Illumination that uses texcoords1 instead of 0

    I have models with texture UV in texcoord0 and lightmap UV in texcoord1

    Is there a possibility to use Self Illumination shader, but to apply the map in texcoords1?

    Also how is it possible to write multipass material.

    Thanks in advance for replies!

    this is what i have done so far... I am a newbie remember, and have very little exposure in scripting.
    Code (csharp):
    1. Shader "Lightmap_Refl" {
    2.    Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    5.     _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
    6.     _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
    7.     _Illum ("Illumin (A)", 2D) = "white" {}
    8. }
    9. SubShader {
    10.  
    11.  
    12. Name "PradShades"
    13.    
    14.     Tags { "RenderType"="Opaque" }
    15.    
    16. CGPROGRAM
    17. #pragma surface surf Lambert
    18.  
    19. sampler2D _MainTex;
    20. samplerCUBE _Cube;
    21. sampler2D _Illum;
    22.  
    23. fixed4 _Color;
    24. fixed4 _ReflectColor;
    25.  
    26. struct Input {
    27.     float2 uv_MainTex;
    28.     float3 worldRefl;
    29. };
    30.  
    31. void surf (Input IN, inout SurfaceOutput o) {
    32.     fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    33.     fixed4 c = tex * _Color;
    34.     o.Albedo = c.rgb;
    35.    
    36.     fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
    37.     reflcol *= tex.a;
    38.     o.Emission = reflcol.rgb * _ReflectColor.rgb;
    39.     o.Alpha = reflcol.a * _ReflectColor.a;
    40.    
    41.        
    42. }
    43. ENDCG
    44.  
    45.  
    46.     }
    47.  
    48.  
    49. }
     
  2. pradmegs

    pradmegs

    Joined:
    Mar 7, 2011
    Posts:
    2
    ok! I made some progress today. This shader can have texture + lightmap + reflection!!

    Code (csharp):
    1. Shader "Megsmap_Refl" {
    2.    Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    5.     _MainTex ("Texture", 2D) = "white" {}
    6.     _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
    7.    
    8.     _Illum ("Lightmap", 2D) = "white" { LightmapMode }
    9. }
    10. SubShader {
    11.  
    12. Pass {
    13.  
    14.  
    15.    
    16.    
    17.         BindChannels {
    18.                     Bind "Vertex", vertex
    19.                     Bind "texcoord", texcoord0
    20.                     Bind "texcoord1", texcoord1
    21.                         }
    22.    
    23.     SetTexture [_MainTex] {
    24.         constantColor [_Color]
    25.         Combine texture * constant
    26.        
    27.     }
    28.     SetTexture [_Illum] {
    29.    
    30.          Combine texture * previous
    31.     }
    32. }
    33.  
    34. Pass {
    35. Blend One One
    36.  
    37.  
    38.     SetTexture [_Cube] {
    39.    
    40.         constantColor [_ReflectColor]
    41.         Combine  texture * constant
    42.    
    43.                
    44.                
    45.        
    46.    
    47.                                 }
    48.  
    49.  
    50.     }
    51.  
    52.  
    53. }
    54. }
     
  3. cpt NOVA

    cpt NOVA

    Joined:
    Mar 15, 2012
    Posts:
    9
    Thanks. It is very usefull. What about Lightmapped reflective bumped specular?
     
  4. cpt NOVA

    cpt NOVA

    Joined:
    Mar 15, 2012
    Posts:
    9
    It's not working with specular map in alpha channel of diffuse texture.
     
  5. snaker

    snaker

    Joined:
    Feb 25, 2012
    Posts:
    11
    Hi,pradmegs
    could tell me where can i use this shader ?
     
  6. snaker

    snaker

    Joined:
    Feb 25, 2012
    Posts:
    11
    Hi,pradmegs
    could you tell me where can i use this shader?
     
  7. GeorgeRigato

    GeorgeRigato

    Joined:
    Jul 5, 2012
    Posts:
    58
    This shader helped A LOT.

    Thanks for posting it.

    I don't know nothing about programming shaders. Willing to start on it, but if anyone can suggest on how to improve this code could save me a little work.

    Thanks.
     
  8. kondrup

    kondrup

    Joined:
    Apr 23, 2009
    Posts:
    205
    Thanks, was looking for this shader :)