Portals
Portals copied to clipboard
Conversion to HDRP
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.
- 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.
- The portal shader looks slightly too dark. I have no idea why this is occuring in HDRP.
- 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.
It would be helpful for you to publish your fork with the changes you've made so far.
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.
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.
I commented on the other issue but I think it applies to this one aswell: https://github.com/SebLague/Portals/issues/8#issuecomment-695125411
@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 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
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?)."
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
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?
This work for me in URP:
- Use
RenderPipelineManager.beginCameraRendering
as the alternative ofOnPreCull
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);
}
}
- Use
UniversalRenderPipeline.RenderSingleCamera(context, portalCam)
instead ofportalCam.Render()
in Portal.cs - 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 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
}
}
This work for me in URP:
- Use
RenderPipelineManager.beginCameraRendering
as the alternative ofOnPreCull
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); } }
- Use
UniversalRenderPipeline.RenderSingleCamera(context, portalCam)
instead ofportalCam.Render()
in Portal.cs- 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