最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to ignore light source on main camera in urp? - Stack Overflow

programmeradmin2浏览0评论

I want to make night vision camera like in outlast. And I need spot light only for this camera to light environment only through camera. In project that use built-in render pipeline I simply used this script

public class IgnoreNightVisionLight : MonoBehaviour
{
    [SerializeField] private Light limelight;

    private void OnPreCull()
    {
        limelight.enabled = false;
    }
    private void OnPreRender()
    {
        limelight.enabled = false;
    }
    private void OnPostRender()
    {
        limelight.enabled = true;
    }
}

and MainCamera was ignoring light source from night vision camera successfully. But in URP project I think render is working other way so this script is not working anymore. I also tried just set special layer to light source and ignore it in culling mask of MainCamera but this also doesn't work. I also didn't find any solution in google so I don't know how can i fix this. If there are any other simple ways to create night vision camera that will light environment only for itself it'll be nice to get this

I want to make night vision camera like in outlast. And I need spot light only for this camera to light environment only through camera. In project that use built-in render pipeline I simply used this script

public class IgnoreNightVisionLight : MonoBehaviour
{
    [SerializeField] private Light limelight;

    private void OnPreCull()
    {
        limelight.enabled = false;
    }
    private void OnPreRender()
    {
        limelight.enabled = false;
    }
    private void OnPostRender()
    {
        limelight.enabled = true;
    }
}

and MainCamera was ignoring light source from night vision camera successfully. But in URP project I think render is working other way so this script is not working anymore. I also tried just set special layer to light source and ignore it in culling mask of MainCamera but this also doesn't work. I also didn't find any solution in google so I don't know how can i fix this. If there are any other simple ways to create night vision camera that will light environment only for itself it'll be nice to get this

Share Improve this question edited Nov 18, 2024 at 14:19 derHugo 91.4k9 gold badges91 silver badges135 bronze badges asked Nov 16, 2024 at 23:52 WasTabonWasTabon 1431 gold badge1 silver badge7 bronze badges 7
  • can you ignore it by layer? – BugFinder Commented Nov 16, 2024 at 23:53
  • It is not working. As i know, rendering light does not working as rendering 3d objects, so even if I trying to ignore this by layer it is not working. But if I do the same thing for 3d objects - camera will ignore that – WasTabon Commented Nov 16, 2024 at 23:59
  • hmm, that seems dumb. Mind you, urp and lighting is a forbidden subject in this house so, i have other issues with it.. Id have expedcted the layer to work – BugFinder Commented Nov 17, 2024 at 1:34
  • Do you mean just giving a separate layer to the light source and then removing that layer from the list in the camera component's culling mask? If yes, that doesn't work, neither in URP nor in Built-in; I've tried everything I could. I can send screenshots as proof. – WasTabon Commented Nov 17, 2024 at 1:44
  • 1 TBH I wasnt planning on hunting through the bowels of youtube trying to find it, but I have seen something where they had like torches and those torches werent rendered on all cameras, but with that info, I would have as much chance of finding it as you do – BugFinder Commented Nov 17, 2024 at 13:36
 |  Show 2 more comments

1 Answer 1

Reset to default 1

Not tested but I guess from this thread you can go through RenderPipelineManager and do something like

public class CameraLight : MonoBehaviour
{
    [SerializeField] private Camera _camera;
    [SerializeField] private Light _light;
    
    void OnEnable()
    {
        RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
        RenderPipelineManager.endCameraRendering += OnEndCameraRendering;
    }
    
    void OnDisable()
    {
        RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
        RenderPipelineManager.endCameraRendering -= OnEndCameraRendering;
    }
    
    void OnBeginCameraRendering(ScriptableRenderContext context, Camera cam)
    {
        if (cam == _camera)
        {
            _light.enabled = false;
        }
    }
    
    void OnEndCameraRendering(ScriptableRenderContext context, Camera cam)
    {
        if (cam == _camera)
        {
            _light.enabled = true;
        }
    }
}
发布评论

评论列表(0)

  1. 暂无评论