Fast Custom Lighting - Custom Lighting Models - Episode 14
In this video, I show how to create a custom lighting model that renders as fast as possible. This might work well for low power mobile phones or XR headsets that have weak GPUs or require high frame rates.
In order to render faster, this model does not support specular, reflections, metallic, screen space ambient occlusion, light cookies, etc. It leaves out features in favor of faster rendering.
Here's the code for the additional lights subgraph:
----------------------------------
Diffuse = MainDiffuse;
Color = MainColor * MainDiffuse;
#ifndef SHADERGRAPH_PREVIEW
uint pixelLightCount = GetAdditionalLightsCount();
#if USE_CLUSTER_LIGHT_LOOP
// for Foward+ LIGHT_LOOP_BEGIN macro uses inputData.normalizedScreenSpaceUV and inputData.positionWS
InputData inputData = (InputData)0;
inputData.normalizedScreenSpaceUV = ScreenPosition;
inputData.positionWS = WorldPosition;
#endif
LIGHT_LOOP_BEGIN(pixelLightCount)
// Convert the pixel light index to the light data index
#if !USE_CLUSTER_LIGHT_LOOP
lightIndex = GetPerObjectLightIndex(lightIndex);
#endif
Light light = GetAdditionalPerObjectLight(lightIndex, WorldPosition);
float NdotL = saturate(dot(WorldNormal, light.direction));
float thisDiffuse = light.distanceAttenuation * NdotL;
Diffuse += thisDiffuse;
Color += light.color * thisDiffuse;
LIGHT_LOOP_END
float total = Diffuse;
Color = total !!!!= 0 ? MainColor : Color / total;
#endif
----------------------------------
In the code above, please replace the !!!! with the less than sign on the second to last line. YouTube doesn't allow that symbol in video descriptions.
Here's last week's video on converting a scene to use custom lighting:
https://youtu.be/oXo7pN8YnAw
Shader Book Recommendations
https://www.bencloward.com/resources_books.shtml
------------------------------
Theme Music
Peace in the Circuitry - Glitch Hop
http://teknoaxe.com/Link_Code_3.php?q=1526
Background Music
Speo - The Little Things
https://www.youtube.com/watch?v=kvCYuyyLgC0
#UnrealEngine #shadergraph #Unity