SebLague / Portals

Portals in Unity
https://www.youtube.com/watch?v=cWpFZbjtSQg
MIT License
780 stars 170 forks source link

Conversion to HDRP #3

Open mirata opened 4 years ago

mirata commented 4 years ago

Hi Sebastian, love your work.

I tried converting your project to HDRP and noticed a number of issues with it. Thought you might like to know. If you solve them, I'd be keen to hear about it.

  1. The portals no longer appear. This seems to be because HDRP does not use the OnPreCull event in MainCamera. I tried using LateUpdate instead to fix it - I'm sure you know a better way.
  2. The portal shader looks slightly too dark. I have no idea why this is occuring in HDRP.
  3. There seems to be a graphical glitch when crossing the portal that was not there previously. This may be because of the change to LateUpdate.

I really enjoy watching your vids. Keep it up.

JimmyCushnie commented 4 years ago

It would be helpful for you to publish your fork with the changes you've made so far.

jmsether commented 4 years ago

So I got this working.

You need to:

As far as OnPreCall you can put a call to the render pipeline to call back before the frame starts. I also recommend using Brackeys precut shader as that one works well with HDRP. Still polishing up as there is a slight flicker when going through the portals. Not 100% seamless but That so far fixes the dark look and gets us 99% there. image

jeffries7 commented 4 years ago

Regarding getting this working on URP all the points above are required except that you need to enable post-processing on both portal cameras not disable it.

joaoachando commented 4 years ago

I commented on the other issue but I think it applies to this one aswell: https://github.com/SebLague/Portals/issues/8#issuecomment-695125411

joaoachando commented 4 years ago

@jmsether Do you have a link for the refered Brackeys precut shader, couldn't find that anywhere on the internet. Might just being blind xD, Any help appreciated!

ghost commented 3 years ago

@joaoachando you can find the shader you're looking for in the description of his video: https://www.youtube.com/watch?v=cuQao3hEKfs&t=89s

I summon you all: @jeffries7 @jmsether @mirata

I beg for your help guys... I'm on URP and basically as soon as the game starts, the portals get messed up; easier to show than it is to explain... -> https://drive.google.com/file/d/12XMdVidhfvOXO34zb5QXxUaYUfpEyrUx/view?usp=sharing

jwk88 commented 3 years ago

As far as OnPreCall you can put a call to the render pipeline to call back before the frame starts. I also recommend using Brackeys precut shader as that one works well with HDRP. Still polishing up as there is a slight flicker when going through the portals. Not 100% seamless but That so far fixes the dark look and gets us 99% there.

Could you elaborate on this part? I tried injecting the PrePortalRender, Render and PostPortalRender calls of the portals after the BeginFrameRendering or BeginCameraRendering pipeline callback, but I'm getting an error: "Recursive rendering is not supported in SRP (are you calling Camera.Render from within a render pipeline?)."

jmsether commented 3 years ago

It's been a while but I will dig up my old project and get the scripts I used there. It's mostly down to disabling the hdr effects on the portals cameras

Flameshot commented 3 years ago

Does anyone know where should I move what "OnPreCull" method cotains on a HDRP pipeline? I know I can use LateUpdate, but as far as I know it's better to call them in render pipeline you are using. So I saw there is RenderPipelineManager.beginCameraRendering but it seems it's not working. Any ideas?

luty4ng commented 2 years ago

This work for me in URP:

  1. Use RenderPipelineManager.beginCameraRendering as the alternative of OnPreCull as it doesn't support SRP.

    void Awake()
    {
        portals = FindObjectsOfType<Portal>();
        mainCam = GetComponent<Camera>();
        RenderPipelineManager.beginCameraRendering += RenderPortal;
    }
    
    private void OnDestroy()
    {
        RenderPipelineManager.beginCameraRendering -= RenderPortal;
    }
    
    private void RenderPortal(ScriptableRenderContext context, Camera camera)
    {
        for (int i = 0; i < portals.Length; i++)
        {
            portals[i].PrePortalRender(context);
        }
        for (int i = 0; i < portals.Length; i++)
        {
            portals[i].Render(context);
        }
        for (int i = 0; i < portals.Length; i++)
        {
            portals[i].PostPortalRender(context);
        }
    }
  2. Use UniversalRenderPipeline.RenderSingleCamera(context, portalCam) instead of portalCam.Render() in Portal.cs
  3. Enable post-processing for all portal camera

Some Reference: https://forum.unity.com/threads/onprecull-event-not-running.907634/ https://teodutra.com/unity/shaders/urp/graphics/2020/05/18/From-Built-in-to-URP/

Rallix commented 2 years ago

I also needed to change the screen texture from _MainTex to _BaseMap.


static readonly int MainTexture = Shader.PropertyToID("_BaseMap");

void CreateViewTexture () 
{
    if (viewTexture == null || viewTexture.width != Screen.width || viewTexture.height != Screen.height) 
    {
        if (viewTexture != null) viewTexture.Release();
        viewTexture = new RenderTexture(Screen.width, Screen.height, 0);        
        portalCam.targetTexture = viewTexture;  // the view from the portal camera to the view texture
        linkedPortal.screen.material.SetTexture(MainTexture, viewTexture); // display it
    }
}
FusionAura commented 1 year ago

This work for me in URP:

  1. Use RenderPipelineManager.beginCameraRendering as the alternative of OnPreCull as it doesn't support SRP.
void Awake()
    {
        portals = FindObjectsOfType<Portal>();
        mainCam = GetComponent<Camera>();
        RenderPipelineManager.beginCameraRendering += RenderPortal;
    }

    private void OnDestroy()
    {
        RenderPipelineManager.beginCameraRendering -= RenderPortal;
    }

    private void RenderPortal(ScriptableRenderContext context, Camera camera)
    {
        for (int i = 0; i < portals.Length; i++)
        {
            portals[i].PrePortalRender(context);
        }
        for (int i = 0; i < portals.Length; i++)
        {
            portals[i].Render(context);
        }
        for (int i = 0; i < portals.Length; i++)
        {
            portals[i].PostPortalRender(context);
        }
    }
  1. Use UniversalRenderPipeline.RenderSingleCamera(context, portalCam) instead of portalCam.Render() in Portal.cs
    1. Enable post-processing for all portal camera

Some Reference: https://forum.unity.com/threads/onprecull-event-not-running.907634/ https://teodutra.com/unity/shaders/urp/graphics/2020/05/18/From-Built-in-to-URP/

I originally had an issue where the Portal Camera's overwrote what the Main Camera rendered however I found the cause and potential fix in my case. I found that using an additional Overlay Camera with Camera Stacking to render my Weapons interfered with the above code.

The solution is to add a Render Object to the URP and get it to render the Weapons that are on their own layer. Once that's set up, the overlay camera is no longer needed. Source