#ifndef CUSTOM_LIGHTING_INCLUDED
#define CUSTOM_LIGHTING_INCLUDED
void CalculateMainLight_float(float3 WorldPos, out float3 Direction, out float3 Color
,out half DistanceAtten, out half ShadowAtten)
{
#if SHADERGRAPH_PREVIEW
Direction = float3(0.5, 0.5, 0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
#if SHADOWS_SCREEN
half4 clipPos = TransformWorldToHClip(WorldPos);
half4 shadowCoord = ComputeScreenPos(clipPos);
#else
half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
Light mainLight = GetMainLight(shadowCoord);
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
ShadowAtten = mainLight.shadowAttenuation;
#endif
}
void AddAdditionalLights_float(float Smoothness, float3 WorldPosition, float3 WorldNormal, float3 Worldview,
float MainDiffuse, float MainSpecular, float3 MainColor,
out float Diffuse, out float Specular, out float3 Color)
{
Diffuse = MainDiffuse;
Specular = MainSpecular;
Color = MainColor * (MainDiffuse + MainSpecular);
#ifndef SHADOWGRAPH_PREVIEW
int pixelLightCount = GetAdditionalLightsCount();
for (int i=0; i < pixelLightCount; ++i)
{
Light light = GetAdditionalLight(i, WorldPosition);
half NdotL = saturate(dot(WorldNormal, light.direction));
half atten = light.distanceAttenuation * light.shadowAttenuation;
half thisDiffuse = atten * NdotL;
half thisSpecular = LightingSpecular(thisDiffuse, light.direction, WorldNormal, Worldview, 1, Smoothness);
Diffuse += thisDiffuse;
Specular += thisSpecular;
Color += light.color * (thisDiffuse + thisSpecular);
}
#endif
half total = Diffuse + Specular;
Color = total <= 0 ? MainColor : Color / total;
}
#endif
==================================================
This is the code i was mimicking for toon shader tutoral. When you watch AddAdditionalLights function you would find the method ‘GetAdditionalLightsCount()’ in it. After I wrote this and tried to apply it to custom function node in shader graph. However the node says that GetAdditionalLightsCount method is undefined identifier which means it doesn’t know what the method is. As I know, GetAdditionalLightsCount is a built-in function that can be used without any special custom definition of it. Idk why my Unity cannot define this function and how to solve this problem. Can anybody help me solve this?
By the way, My unity version is currently 2022.3.5f1. Thank you
