Home Unity

Shader Wanted: Diffuse, Normal, Spec, Emmission and Alpha

Hi folks,


I have no idea what I’m doing with shaders or tools like strumpy for that matter (And believe me I’ve tried) and I have created a character that I’m working on setting up as a 3rd person Player Character in Unity, that I need a specific type of shader for.



So… I was wondering if anyone has or can make me a Unity Shader that supports Diffuse maps, Normal maps, Spec maps, Emmision maps and Alpha channels/cutoff that I can please pilfer?


Cheers.


SW

Replies

  • electricsauce
    Options
    Offline / Send Message
    electricsauce polycounter lvl 11
    Try this out:

    alpha cutoff references the main texture alpha, emission is packed in the normal map alpha

    Shader "Custom/PC_ASlphaEmissive" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
    _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5

    _EmissionLM ("Emission (Lightmapper)", Float) = 0
    _EAmount ("Emission Amount", Float) = 0
    _EColor ("Emission Color", Color) = (1,1,1,1)
    }

    SubShader {
    Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    LOD 400

    CGPROGRAM
    #pragma surface surf BlinnPhong alphatest:_Cutoff
    #pragma exclude_renderers flash

    sampler2D _MainTex;
    sampler2D _BumpMap;
    fixed4 _Color;
    half _Shininess;

    float _EAmount;
    fixed4 _EColor;

    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    };

    void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    o.Albedo = tex * _Color;
    o.Emission = tex.rgb * tex2D(_BumpMap, IN.uv_BumpMap).a * _EAmount * _EColor;
    o.Gloss = tex.a;
    o.Alpha = tex.a * _Color.a;
    o.Specular = _Shininess;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    }
    ENDCG
    }

    FallBack "Transparent/Cutout/VertexLit"
    }
  • Shockwolf
    Options
    Offline / Send Message
    Cheers electricsauce,

    This is good, but ideally I need slots to place my specmap and emmisive map in too.

    Edit: Also placing a texture into the Alpha channel of the Normal map, does not seem to make any difference.

    Thanks.

    SW
  • Farfarer
    Options
    Offline / Send Message
    The normal map compression that Unity uses will wipe it's alpha channel (and it's blue channel). You shouldn't put anything in there you want to use unless you compress/decompress it yourself.
  • electricsauce
    Options
    Offline / Send Message
    electricsauce polycounter lvl 11
    Farfarer wrote: »
    The normal map compression that Unity uses will wipe it's alpha channel (and it's blue channel). You shouldn't put anything in there you want to use unless you compress/decompress it yourself.


    That's good to know. I guess we need at least one more texture lookup.
  • Shockwolf
    Options
    Offline / Send Message
    I've managed to wing an adaption of the above script, which impliments the emissive feature I'm after and it works nicely, but alas I cannot work out how to add in a Specmap feature to this without breaking it.



    Shader "Custom/PC_ASlphaEmissive" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
    _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
    _MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5

    _EmissionRange("_EmissionRange", Range(0,10) ) = 0.91
    _Emission("_Emission", 2D) = "black" {}
    }

    SubShader {
    Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    LOD 400

    CGPROGRAM
    #pragma surface surf BlinnPhong alphatest:_Cutoff
    #pragma exclude_renderers flash

    sampler2D _MainTex;
    sampler2D _BumpMap;
    fixed4 _Color;
    half _Shininess;

    float _EmissionRange;
    sampler2D _Emission;
    half3 Emission;

    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float2 uv_Emission;
    };

    void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    o.Albedo = tex * _Color;
    o.Emission = 0.0;
    o.Gloss = tex.a;
    o.Alpha = tex.a * _Color.a;
    o.Specular = _Shininess;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

    float4 Tex2D2=tex2D(_Emission,(IN.uv_Emission.xyxy).xy);
    float4 Multiply2=_EmissionRange.xxxx * Tex2D2;

    o.Emission = Multiply2;

    }
    ENDCG
    }

    FallBack "Transparent/Cutout/VertexLit"
    }
  • Shockwolf
    Options
    Offline / Send Message
    Further to this I found out its possible to place more than one material on a mesh with Unity. Just by simply increasing the "Size" of the materials under the mesh renderer inpsector, you can then add more materials and play around with the order until you get the desired result. So I added the Specmap material I needed over the other material and that pretty much solved it.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    Be aware that multi materials mean multiple draw calls
Sign In or Register to comment.