Hi,
I’m trying to modify the builtin bumped specular shader to support an Ambient Occlusion map.
I usually extract the AO map using Filter Forge software.
It is a black and white map where it is darkest when there is the shadow and brightest when there is only light.
The shader code so far is as follows, please pay attention to the line with the comment:
Shader "Bumped Specular Ambient Occlusion" {
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)", 2D) = "white" {}
_GlossTex ("Gloss (A)",2D) = "white" {}
_AOTex ("Ambient Occlusion", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 400
CGPROGRAM
#pragma surface surf BlinnPhong
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _GlossTex;
sampler2D _AOTex;
fixed4 _Color;
half _Shininess;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float2 uv_GlossTex;
float2 uv__AOTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
fixed4 gloss = tex2D(_GlossTex, IN.uv_GlossTex);
fixed4 aocclusion = tex2D(_AOTex, IN.uv__AOTex);
The Interesting Line -->
o.Albedo = tex.rgb * aocclusion.a * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = gloss.a * _Color.a;
o.Specular = _Shininess;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
FallBack "Specular"
}
This shader causes my material to appear very dark and almost not possible to lit in the scene.
My question is that how can I modify this shader to properly support the AO map?
Note: that the infamous SSAO does not take the texture normals and bumps into consideration while this map does.