I just want to use Lens Flare in my game, but sometimes is so difficult to do simple things in unity. I imported Unity Standard Assets (Effects) that comes with lens flare. I tried everything and the Lens flare only show in Scene view, not in Game view why? I’m using URP, This works in URP?
Everything I tried
My camera has the flare layer turned on
My camera has a flare layer.
The lens flare is positioned in front of the camera and not show up.
The lens flare is marked as directional in a light gameobject that is the sun of scene
Also tested lens flare not attached to a light, just attached in a empty game object
The lens flare has directional unchecked, also tested with directional checked.
Every object is on default layer
The lens flare is set to ignore nothing
The camera’s far plane is 1000
The flare is show up perfectly in Scene view
There are no colliders between camera
The flare has a texture imported from standard asset and is bright enough
The flare has a correct fade speed that shows the flare quickly
There is no setup options for flare in Universal Render Pipeline, not even in Player, and Quality tab in preferences.
I’ve tried to attach the flare to a point light. There is no Flare setting in point light.
I’m not using VR, is just a simple camera.
Tried using physical camera and normal camera.
Tried to enable and disable post processes from URP
Tried to enable and disable “Use Fog” in Flare asset.
I’m starting to think that flares simply doesn’t work in URP.
Solved! It’s the Occlusion Remap in the Lens Flare settings, it’s glitched and doesn’t do what it’s supposed to do. You need to set it at 1 in order for your lens flare to work properly.
EDIT: Now the occlusion doesn’t work. With this I understood that it acts as if there was an object occluding the lens flare at the center of the camera.
Here is a quick and dirty occlusion script for anyone having issues with the built-in occluder. You put it on the same gameobject that you have the LensFlareComponentSRP on.
using UnityEngine;
using UnityEngine.Rendering;
[RequireComponent(typeof(LensFlareComponentSRP))]
public class LensFlareOcclusion : MonoBehaviour
{
public bool useOcclusion = false;
[Header("Occlusion Settings")]
[Range(0f, 5f)] public float occlusionSpeed = 1f; // Speed of intensity change when occluded or revealed
public float occlusionDistance = 1000f;
public LayerMask occlusionLayerMask;
private float occludedIntensity = 0f; // Intensity when occluded
private float targetIntensity; // Target intensity that we want to reach
private float originalIntensity; // To restore the original intensity
private LensFlareComponentSRP lensFlare;
private void Start()
{
lensFlare = GetComponent<LensFlareComponentSRP>();
originalIntensity = lensFlare.intensity;
targetIntensity = originalIntensity;
}
private void Update()
{
if (useOcclusion)
{
Vector3 origin = Camera.main.transform.position;
Vector3 direction = transform.forward;
Vector3 targetPosition = origin - direction * occlusionDistance;
RaycastHit hit;
bool isOccluded = Physics.Linecast(origin, targetPosition, out hit, occlusionLayerMask);
targetIntensity = isOccluded ? occludedIntensity : originalIntensity;
}
else
{
targetIntensity = originalIntensity;
}
// Lerp the intensity
lensFlare.intensity = Mathf.Lerp(lensFlare.intensity, targetIntensity, Time.deltaTime * occlusionSpeed);
}
}