Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion to HDRP #3

Open
mirata opened this issue Mar 16, 2020 · 13 comments
Open

Conversion to HDRP #3

mirata opened this issue Mar 16, 2020 · 13 comments

Comments

@mirata
Copy link

mirata commented Mar 16, 2020

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
Copy link

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

@jmsether
Copy link

jmsether commented May 6, 2020

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

@jeffries7
Copy link

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
Copy link

I commented on the other issue but I think it applies to this one aswell:
#8 (comment)

@joaoachando
Copy link

@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
Copy link

ghost commented Oct 30, 2020

@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
Copy link

jwk88 commented Feb 17, 2021

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
Copy link

jmsether commented Feb 18, 2021

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
Copy link

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
Copy link

luty4ng commented Nov 5, 2021

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/

@Rallix
Copy link

Rallix commented Dec 20, 2021

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
Copy link

FusionAura commented May 15, 2023

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

@RMXdotEXE
Copy link

I know this is super old, but I've been trying to get this work with HDRP too and am having the same issue of calling Camera.Render() within the render pipeline via RenderPipelineManager.beginCameraRendering.

I tried replacing Camera.Render() with a call to RenderPipeline.SubmitRenderRequest(portalCamera, request) but am now getting an error saying recursive calls aren't allowed either with Camera.Render() OR RenderPipeline.SubmitRenderRequest().

Seems like Unity has a bunch of issues with this stuff. I'm currently on Unity 6000.0.23f1. Has anyone made any developments either on this version or another one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests