@alexandral_unity
Since no documentation was written by Unity, and I’ve been frying my brain with trial and error for the last week.
I would like to know how to make this shader code work with the Universal RP.
No matter what #includes I add or remove, how many #ifdefs I tried I keep getting identifier undeclared
errors.
The furthest I got is by surrounding only the function bodies with:
#ifdef UNIVERSAL_LIGHTING_INCLUDED
....
#endif
Because doing it globally makes my function names undeclared, and then initialize my out vars before, which is even more stupid.
But then I would get this weird: Shader error in 'Unlit Master': 'GetAdditionalLight': no matching 2 parameter function
And yet one more undeclared identifier 'WorldPos'
Complete code:
half3 Lambert_half(half3 N, half3 color, half3 direction, half distAtten, half shadowAtten) // Could use LightingLambert directly from calling site instead
{
#ifdef UNIVERSAL_LIGHTING_INCLUDED
half3 attenColor = color * distAtten * shadowAtten;
half NdotL = saturate(dot(N, direction));
return NdotL * attenColor;
#endif
}
half3 BlinnPhong_half(half3 N, half3 V, half3 color, half3 direction, half3 specColor, half smoothness)
{
#ifdef UNIVERSAL_LIGHTING_INCLUDED
smoothness = exp2(10 * smoothness + 1);
N = normalize(N);
V = SafeNormalize(V);
half3 Out = LightingSpecular(color, direction, N, V, half4(specColor, 0), smoothness);
return Out;
#endif
}
void DiffSpec_half(half3 N, half3 V, half3 WorlPos, half3 SpecColor, half Smoothness, out half3 Diffuse, out half3 Specular)
{
Diffuse = 0;
Specular = 0;
#ifdef UNIVERSAL_LIGHTING_INCLUDED
half3 diffuseColor = 0;
half3 specularColor = 0;
Light l = GetMainLight(); // GET MAIN LIGHT
int pixelLightCount = GetAdditionalLightsCount();
diffuseColor += Lambert_half(N, l.color, l.direction, l.distanceAttenuation, l.shadowAttenuation);
specularColor += BlinnPhong_half(N, V, l.color, l.direction, SpecColor, Smoothness);
for (int i = 0; i < pixelLightCount; ++i)
{
Light light = GetAdditionalLight(i, WorldPos); // GET ADDT LIGHTS
diffuseColor += Lambert_half(N, light.color, light.direction, light.distanceAttenuation, light.shadowAttenuation);
specularColor += BlinnPhong_half(N, V, light.color, light.direction, SpecColor, Smoothness);
}
Diffuse = diffuseColor;
Specular = specularColor;
#endif
}
I also would like to know how to get vertex data and view data and matrices from shader code.
And of cource proper documentation from the responsible team and opening issues section in the GitHur repo.