URP Materials & Lighting
The Universal Render Pipeline (URP) is Unity's scalable renderer, from phones to PCs and consoles. A new Unity 6 project from the Universal 3D template already uses it. Its look comes from three things: materials (how surfaces respond to light), lights, and global illumination (light bouncing around, usually baked).
Materials and the URP Lit shader
A material is an asset that pairs a shader with values. Most opaque 3D surfaces use Universal Render Pipeline/Lit, a physically based shader:
| Property | Shader name | Meaning |
|---|---|---|
| Base Map / colour | _BaseMap, _BaseColor |
albedo: the surface colour without lighting |
| Metallic / Smoothness | _Metallic, _Smoothness |
metal vs non-metal; rough vs glossy |
| Normal Map | _BumpMap |
fake small surface detail |
| Emission | _EmissionColor |
self-lit glow (feeds Bloom when HDR is on) |
| Surface Type | Opaque / Transparent | transparency costs more and sorts differently |
Simple Lit and Unlit are cheaper variants for mobile and stylized games.
Changing materials from code
using UnityEngine;
public class DamageTint : MonoBehaviour
{
static readonly int BaseColor = Shader.PropertyToID("_BaseColor"); // look the id up once
[SerializeField] Renderer target;
Material instance;
void Awake()
{
instance = target.material; // .material CLONES the material for this renderer (you must destroy it)
// target.sharedMaterial // the asset itself: changing it changes every object using it
}
public void Tint(Color c) => instance.SetColor(BaseColor, c);
void OnDestroy() => Destroy(instance); // clones are not cleaned up automatically
}Note: In the built-in pipeline the main colour was
_Color/material.color; URP Lit uses_BaseColor.MaterialPropertyBlock(per-renderer overrides without cloning) still works, but in URP it makes the renderer incompatible with the SRP Batcher, which is usually the bigger performance win. See Profiler, Frame Debugger & Batching.
Lights
| Light | Use |
|---|---|
| Directional | the sun or moon: parallel rays, one main light with shadows |
| Point | bulbs, torches: radiates in all directions, falls off with distance |
| Spot | flashlights, street lamps: a cone |
| Area (baked only in URP) | soft light from windows or panels |
Each light has a Mode: Realtime (computed every frame, can move), Baked (precomputed into lightmaps, free at runtime, can't change) and Mixed (baked indirect light plus realtime direct light and shadows). URP has Forward, Forward+ and Deferred rendering paths. Forward+ removes the classic per-object limit on the number of realtime lights.
What a light does to a surface, at its simplest, is Lambert's law: brightness is proportional to the cosine of the angle between the surface normal and the light direction, and a point light's intensity falls off with the inverse square of the distance. The model computes that, then converts the result to the 8-bit sRGB value a monitor receives (Unity projects work in linear colour space by default and convert at the end):
using System;
double intensity = 4.0; // point light intensity
double albedo = 0.8; // light grey surface
Console.WriteLine("dist | angle | linear | sRGB byte");
foreach (var (dist, angleDeg) in new[] { (1.0, 0.0), (1.0, 60.0), (2.0, 0.0), (2.0, 60.0), (4.0, 0.0), (1.0, 95.0) })
{
double nDotL = Math.Max(0, Math.Cos(angleDeg * Math.PI / 180)); // facing away = 0
double attenuation = 1 / (dist * dist); // inverse square
double linear = Math.Min(1, albedo * intensity * nDotL * attenuation); // clamp: no HDR here
Console.WriteLine(quot;{dist,4:F1} | {angleDeg,3:F0} deg | {linear,6:F3} | {ToSrgbByte(linear),4}");
}
static int ToSrgbByte(double linear)
{
double s = linear <= 0.0031308 ? 12.92 * linear : 1.055 * Math.Pow(linear, 1 / 2.4) - 0.055;
return (int)Math.Round(Math.Clamp(s, 0, 1) * 255);
}dist | angle | linear | sRGB byte
1.0 | 0 deg | 1.000 | 255
1.0 | 60 deg | 1.000 | 255
2.0 | 0 deg | 0.800 | 231
2.0 | 60 deg | 0.400 | 170
4.0 | 0 deg | 0.200 | 124
1.0 | 95 deg | 0.000 | 0
Doubling the distance quarters the light, yet the 0.2 linear value still displays as byte 124 of 255, about half brightness: monitors and eyes are non-linear. That's why lighting math happens in linear space, and why textures holding colour are marked sRGB in their import settings while data textures (normal maps, masks) are not. The first two rows also show clipping: values above 1 need HDR and tonemapping (URP's post-processing) to keep detail.
Baked lighting and probes
Realtime lights are expensive and don't bounce. For static scenery, bake:
- Mark non-moving objects Static (at least Contribute GI) in the Inspector's top-right drop-down.
- Set lights to Baked or Mixed.
- Open Window > Rendering > Lighting, create a Lighting Settings asset, and click Generate Lighting.
- Moving objects can't use lightmaps. They receive baked light from Light Probes (placed in a Light Probe Group, or the Adaptive Probe Volumes system in Unity 6) and reflections from Reflection Probes.
Lightmaps take memory and build time: lower the lightmap resolution for large, low-detail areas, and bake on a fast machine or with the GPU lightmapper.
Post-processing
URP post-processing uses Volumes: add GameObject > Volume > Global Volume, create a profile, and add overrides such as Bloom, Tonemapping (ACES or Neutral), Color Adjustments and Vignette. Enable Post Processing on the camera. Local volumes with a collider change the look in specific areas (a cave gets darker and bluer).
Test yourself
What does renderer.material return the first time you access it?
- The shared material asset
- A new per-renderer copy of the material, which you should destroy later
- null
- A MaterialPropertyBlock
Which property sets the main colour of a URP Lit material?
_Color_BaseColor_MainColor_Albedo
How do moving characters receive baked lighting?
- Lightmaps
- Light Probes
- They can't
- Area lights