Hi all. I’m just wondering if someone can advise me how to access the per-pixel diffuse luminance value for a shader? I have the following shader, using a forward-lit lighting model. I intend to limit scene lighting to a single directional source, which may make it easier to solve?
Here is my shader:
Shader "JRPG/GradientMap"
{
Properties
{
_MainTex ("Base (RGBA)", 2D) = "white" {}
_GradientMap ("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _GradientMap;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
float surfaceLum = 1;
float gradientVal = clamp(tex2D(_MainTex, IN.uv_MainTex).r * surfaceLum, 0, 1);
float gradientSel = tex2D(_MainTex, IN.uv_MainTex).g;
half4 c = tex2D(_GradientMap, float2(gradientVal, gradientSel));
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
What I’d like to do is substitute the line:
float surfaceLum = 1;
with:
float surfaceLum = perPixelDiffuseLuminanceValueSomehow;
I’m also hoping to eventually improve it to support multiple lights (in a Deferred model) and specularity. But I’m a bit boggle at shaders at the moment.