Lens flare not showing up in game window using Universal Render Pipeline URP (2019.3)

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.

Lens flares aren’t supported in Universal Render Pipeline.

In the Features Comparison Page , you can see that both “Lens Flare” and “Flare Layer” are marked as “Not Supported”

Description of “Not Supported” is as follows.

If a feature is marked as Not supported, it’s because Unity is not planning to support it in any release.

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.

Enable Post Processing on your Camera and URP Renderer guys.

Lens Flare aren’t not supported in HDRP also :frowning:
https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@7.1/manual/Feature-Comparison.html

If you enable YourRenderPipelineAsset > Quality > HDR it’ll work.

@noahrt

select camera - (from menu ) component - rendering - flare layer

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);
    }
}