Version: Unity 6 (6000.0)
Language : English
Custom lighting in URP
Render additional lights in a shader in URP

Introduction to custom lighting in URP

Implementing a custom lighting function or model gives you more control over the visual style and performance of your application.

For example, a simpler, cartoon style rendering can be significantly faster than realistic physically-based rendering, and can have a unique appealing look.

A good example of a custom lighting implementation is the cockpit scene in the URP 3D Sample project.

Unity provides several ways of implementing custom lighting using HLSL, shaderA program that runs on the GPU. More info
See in Glossary
graph custom function nodes, or through URP source code modification.

HLSL shaders and shader graph shaders

Custom HLSL shaders provide you with a wide range of features and flexibility to implement custom lighting functions. You have full control over render passes, input and output variables, attributes, and internal shader functions.

Pre-built Shader Graph nodes let you use common shader functions, but provide few options for modifying their behavior. Shader Graph also provides custom function nodes that let you inject custom HLSL code inside a node.

You can find examples of custom function nodes in URP 3D Sample project, and in Shader Graph Feature Examples.

Limitations of custom function nodes

Custom function nodes let you insert your code into the vertex shaderA program that runs on each vertex of a 3D model when the model is being rendered. More info
See in Glossary
function or the fragment shader function. These functions correspond to the Vertex and Fragment shader stages in Shader Graph, or to the functions vert(Attributes IN) and frag(Varyings IN) in an HLSL shader.

A custom function node does not provide the following functionality:

  • Change or add attributes in the input and output structures (often defined as struct Attributes and struct Varyings in shader code). For example, this means that you can’t add an extra custom option to the Fragment or Vertex shader stages.

  • Define extra shader passes.

  • Define extra render state commands such as ColorMask.

If your shader requires any of the features above, consider writing a ShaderLabUnity’s language for defining the structure of Shader objects. More info
See in Glossary
shader.

Methods for using different types of light

Techniques for implementing custom lighting vary depending on which types of lights your custom effects require.

To use the main light, use the GetMainLight shader function. For more information, refer to Use lighting in a custom URP shader.

The Forward and Forward+ rendering paths handle extra directional lights and additional lights differently. The Forward+ rendering pathThe technique that a render pipeline uses to render graphics. Choosing a different rendering path affects how lighting and shading are calculated. Some rendering paths are more suited to different platforms and hardware than others. More info
See in Glossary
doesn’t have a limit on real-time lights per GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
, so the GetAdditionalLightsCount method always returns 0. For information on how to write a rendering loop that uses additional lights in Forward and Forward+ rendering paths, refer to Render additional lights in a shader in URP.

Additional resources

Custom lighting in URP
Render additional lights in a shader in URP