Hi, I’ve been learning about writing my own shaders, particularly from Kenneth Lemmers youtube tutorials which are great.
I currently have a fake BRDF shader with diffuse and normal map included. But I’m having trouble adding specular from the diffuse texture’s alpha.
I know how to do it using the BlinnPhong surface but unsure with the current code I have here. I’ve removed any lines that attempt to use specular in the hopes to hopefully prevent confusion.
Shader "Custom/PP_BRDF"
{
Properties
{
_ColorTint ("Colour Tint", Color) = (125,125,125,1)
_MainTex ("Albedo", 2D) = "white" {}
_BumpMap ("Normal Map", 2D) = "bump"{}
_Ramp2D ("BRDF Ramp", 2D) = "gray" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Ramp
#pragma target 3.0
float4 _ColorTint;
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _Ramp2D;
struct Input
{
float4 color : Color;
float2 uv_MainTex;
float2 uv_BumpMap;
};
half4 LightingRamp (SurfaceOutput s,half3 lightDir, half3 viewDir, half atten)
{
float NdotL = dot(s.Normal, lightDir);
float NdotE = dot(s.Normal, viewDir);
//Diffuse Wrap
float diff = (NdotL * 0.5) + 0.5;
float2 brdfUV = float2(NdotE, diff);
float3 BRDF = tex2D(_Ramp2D, brdfUV.xy).rgb;
float4 c;
c.rgb = BRDF;
c.a = s.Alpha;
return c;
}
void surf (Input IN, inout SurfaceOutput o)
{
half4 c = float4(0.5,0.5,0.5,1)/ tex2D (_MainTex, IN.uv_MainTex)/2;
IN.color = _ColorTint;
o.Albedo = tex2D(_MainTex, IN.uv_MainTex) * IN.color/c.rgb * 2;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
FallBack "Diffuse"
}