I’m following a written explanation by someone who us creating a custom function. I’m working in 2020.3.8f1 in URP.
There was an error I ran into regarding an ‘undeclared identifier’ that got solved when changing #ifdef SHADERGRAPH_PREVIEW to #if defined(SHADERGRAPH_PREVIEW) .
In another custom function I’m just adding onto that but having the same issue with a #ifndef SHADERGRAPH_PREVIEW . Did #ifndef also get changed? I’ll post below this function and let me know if something else is getting buggy.
void AddAdditionalLights_float(float3 WorldPosition, float3 WorldNormal, float MainDiffuse, out float Diffuse) { //takes the world pos, world normal and main diffuse
Diffuse = MainDiffuse; //diffuse is mainlight diffuse
#ifndef SHADERGRAPH_PREVIEW //if shadergraph preview not defined
int pixelLightCount = GetAdditionalLightsCount(); //get the number of lights in scene
for (int i = 0; i < pixelLightCount; ++i) { //for each loop, starting at 0 through to total light count:
Light light = GetAdditionalLight(i, WorldPosition); //get additional light i (from the loop) at world pos
half NdotL = saturate(dot(WorldNormal, light.direction)); //clamps the dot product 0-1 between the world normal and light direction
half atten = light.distanceAttenuation * light.shadowAttenuation; //multiplies distance and shadow atten
half thisDiffuse = atten * NdotL; //diffuse is atten * NdotL
Diffuse += thisDiffuse; //adds this to the original diffuse
}
#endif
half total = Diffuse;
}
#endif