Portals icon indicating copy to clipboard operation
Portals copied to clipboard

Conversion to HDRP

Open mirata opened this issue 4 years ago • 12 comments

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.

mirata avatar Mar 16 '20 10:03 mirata

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

JimmyCushnie avatar Mar 16 '20 10:03 JimmyCushnie

So I got this working.

You need to:

  • Turn off the post-processing on both the portal cameras under the custom settings and then

  • In PortalTravelers change line 56 from foreach (var mat in renderer.materials) to foreach (var mat in renderer.sharedMaterials).

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

jmsether avatar May 06 '20 19:05 jmsether

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.

jeffries7 avatar Sep 04 '20 15:09 jeffries7

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 avatar Sep 19 '20 01:09 joaoachando

@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!

joaoachando avatar Sep 20 '20 18:09 joaoachando

@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

ghost avatar Oct 30 '20 19:10 ghost

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?)."

jwk88 avatar Feb 17 '21 17:02 jwk88

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

jmsether avatar Feb 18 '21 01:02 jmsether

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?

Flameshot avatar May 10 '21 22:05 Flameshot

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
  2. 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/

luty4ng avatar Nov 05 '21 12:11 luty4ng

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

Rallix avatar Dec 20 '21 21:12 Rallix

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
  2. 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

FusionAura avatar May 15 '23 02:05 FusionAura