Search Unity

Question SRP lens flares broken with camera stacking

Discussion in 'Universal Render Pipeline' started by UltMate-Potato, May 18, 2022.

  1. UltMate-Potato

    UltMate-Potato

    Joined:
    Apr 11, 2021
    Posts:
    4
    im using mixed fov and camera stacking to stop weapon clipping but this shish happens where the lens flare is out of place . the reason the lens flare is out of place is that the weapon camera is the one rendering the lens flare but because it has a different fov from your main cam the lens flare gets out of place. even though lens flares count as post processing effects u *cant* disable them on specific cameras using volume layers on your cam and culling masks. the camera with post processing will be the one rendering it and you might say then enable post processing on the base camera but if you do that camera stacking breaks and your weapon wont receive post processing effects. i think unity should make it so we can choose what camera the lens flare appears on. but then there will be another problem of the lens flare appearing through your weapons because its in a separate camera. i have no idea what to do, HEEELLLLPPPPPP

     
    Thygrrr likes this.
  2. lgarczyn

    lgarczyn

    Joined:
    Nov 23, 2014
    Posts:
    68
    You can add this component to the lens flare, and set cameraTarget as the only camera that should render lens flares


    Code (CSharp):
    1.  
    2. namespace CameraUtils
    3. {
    4.   [RequireComponent(typeof(LensFlareComponentSRP))]
    5.   public class LensFlareController : MonoBehaviour
    6.   {
    7.     [SerializeField] Camera targetCamera;
    8.  
    9.     void OnCameraEnd(ScriptableRenderContext _, Camera currentCamera)
    10.     {
    11.       if (targetCamera == null || currentCamera == targetCamera) reqLensFlare.enabled = false;
    12.     }
    13.  
    14.     void OnCameraStart(ScriptableRenderContext _, Camera currentCamera)
    15.     {
    16.       if (targetCamera == null || currentCamera == targetCamera) reqLensFlare.enabled = true;
    17.     }
    18.  
    19.     void Awake()
    20.     {
    21.       RenderPipelineManager.beginCameraRendering += OnCameraStart;
    22.       RenderPipelineManager.endCameraRendering += OnCameraEnd;
    23.     }
    24.     void OnDestroy()
    25.     {
    26.       RenderPipelineManager.beginCameraRendering -= OnCameraStart;
    27.       RenderPipelineManager.endCameraRendering -= OnCameraEnd;
    28.     }
    29. }