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

Diffuse + Specular + normal map + Alpha cutout ?

Discussion in 'Shaders' started by LaurynasLubys, Jul 24, 2014.

  1. LaurynasLubys

    LaurynasLubys

    Joined:
    Mar 7, 2012
    Posts:
    80
    Hello, I need to use three textures on one house model.
    Diffuse which includes alpha map,
    Bump normal map,
    And specular map.

    I see similar in shaders of unity transparent>cutout>bumped specular, but it does not consist entry for specular texture. (it makes whole house shiny).

    Is it possible in unity ?
     

    Attached Files:

  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    It seems that shader actually uses the alpha in the diffuse texture for both the gloss and the cutout. Not very useful. Something like this should work, but I didn't test it:

    Code (csharp):
    1.  
    2. Shader "Transparent/Cutout/Bumped Specular Split" {
    3. Properties {
    4.    _Color ("Main Color", Color) = (1,1,1,1)
    5.    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
    6.    _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    7.    _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
    8.    _BumpMap ("Normalmap", 2D) = "bump" {}
    9.    _GlossMap ("Glossmap", 2D) = "black" {}
    10.    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    11. }
    12.  
    13. SubShader {
    14.    Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    15.    LOD 400
    16.    
    17. CGPROGRAM
    18. #pragma surface surf BlinnPhong alphatest:_Cutoff
    19. #pragma exclude_renderers flash
    20.  
    21. sampler2D _MainTex;
    22. sampler2D _BumpMap;
    23. sampler2D _GlossMap;
    24. fixed4 _Color;
    25. half _Shininess;
    26.  
    27. struct Input {
    28.    float2 uv_MainTex;
    29.    float2 uv_BumpMap;
    30. };
    31.  
    32. void surf (Input IN, inout SurfaceOutput o) {
    33.    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    34.    o.Albedo = tex.rgb * _Color.rgb;
    35.    o.Gloss = tex2D(_GlossMap, IN.uv_MainTex).a;
    36.    o.Alpha = tex.a * _Color.a;
    37.    o.Specular = _Shininess;
    38.    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    39. }
    40. ENDCG
    41. }
    42.  
    43. FallBack "Transparent/Cutout/VertexLit"
    44. }
    45.  
    The idea is that the gloss is stored in the alpha of the glossmap.
     
    LaurynasLubys likes this.