create new specular shader

hi all!
i’ve just a question:
if I click Assets->Create->Shader->Standard Surface Shader it creates a simply metallic shader, but if I wish a simple specular shader, how can I do?
thanks

There’s no easy “make standard specular shader”, and there’s zero documentation on this anywhere I know of, so it can be kind of annoying, but it’s mostly straight forward.

Any place in that default standard surface shader that says “Standard” make it say “StandardSpecular”. So for example:
#pragma surface surf Standard fullforwardshadows

#pragma surface surf *StandardSpecular* fullforwardshadows

void surf (Input IN, inout SurfaceOutputStandard o) {

void surf (Input IN, inout *SurfaceOutputStandardSpecular* o) {

Then replace the _Metallic("", Float), half _Metallic;, and o.Metallic = _Metallic;, with a _SpecularColor("", Color), fixed3 _SpecularColor;, and o.Specular = _SpecularColor;.

edit: changed _SpecColor to _SpecularColor because, even though Unity uses _SpecColor in all of their StandardSpecular and legacy shaders, they also define it in their surface shader .cginc files for legacy shaders rather than in the shader file itself. Yay… Could use _SpecColor and just not define it in this shader, but it’s ugly and confusing.

Shader "Custom/StandardSpecularSurfaceShader" {
    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _SpecularColor("Specular", Color) = (0.2,0.2,0.2)
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
    
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf StandardSpecular fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input {
            float2 uv_MainTex;
        };

        half _Glossiness;
        fixed3 _SpecularColor;
        fixed4 _Color;

        void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
            // Albedo comes from a texture tinted by color
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            // Specular from specular color
            o.Specular = _SpecularColor;
            // Smoothness come from slider variable
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
            o.Emission = half3(1,0,0);
        }
        ENDCG
    }
    FallBack "Diffuse"
}
2 Likes

thankyou very much!

@bgolus
when you use a Unity Standard Specular shader, the energy conservation law drives the rendered result…and I think that this depends on the lighting model of the shader. Is it correct?

If yes, with the instructions you posted, the energy conservation law of the PBR shader is kept? Or it needs to be explicitally expressed in the new shader with all the logic behind?

Thanks in advance.

The Standard, Standard Specular, and surface shaders using either lighting function run through the same shader functions. In other words there shouldn’t be anything you need to do to make a surface shader using the Standard Specular energy conserving.