Add specular map to shader

Hi there,

I’m trying to figure out how to add a texture into my shader which uses the red channel for the specular level and the green channel for the specular polish/shininess. I would also want to the blue channel to be used for something…maybe emmissive mask, but that’s a whole other story.

If anyone can help out, or point me toward some hints, that would be super awesome.

Thanks!

simple compare differences with shader you point to

Shader "Unity Answers/Bumped Specular with own map" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
	_Shininess ("Shininess", Range (0.03, 1)) = 0.078125
	_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
	_BumpMap ("Normalmap", 2D) = "bump" {}
	_SpecMap ("Specular map", 2D) = "black" {}
}
SubShader { 
	Tags { "RenderType"="Opaque" }
	LOD 400
	
CGPROGRAM
#pragma surface surf BlinnPhong

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

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

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

FallBack "Specular"
}

Shader “Bumped Specular” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,1)
_SpecColor (“Specular Color”, Color) = (0.5, 0.5, 0.5, 1)
_Shininess (“Shininess”, Range (0.03, 1)) = 0.078125
_MainTex (“Base (RGB) Gloss (A)”, 2D) = “white” {}
_BumpMap (“Normalmap”, 2D) = “bump” {}
}
SubShader {
Tags { “RenderType”=“Opaque” }
LOD 400

CGPROGRAM
#pragma surface surf BlinnPhong


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

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.rgb * _Color.rgb;
	o.Gloss = tex.a;
	o.Alpha = tex.a * _Color.a;
	o.Specular = _Shininess;
	o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}

FallBack "Specular"
}

Hi ScroodgeM,

Did you try this with new Unity 5 shader.?

I think these two params are missing.

o.Gloss
o.Specular

  • Pratap Dafedar.