#Rendering objects occluded, without rendering it's occluder?

1 messages · Page 1 of 1 (latest)

copper lily
#

Rendering camera stack/processing pass question for URP.

I have a low resolution render texture (pictured).
I want to put units onto that terrain, but at a completely different pixel depth. I can't just render them with the terrain because they are at the same tiny pixel size.

My thought/idea is to render them to a different render texture or to some kind of buffer then overlay that buffer into the low res terrain texture.
The problem is however I still want the units occluded by geometry, but I don't want that geometry to show up.

Is there some way to get a buffer/pass of just the units, but also have those units be occluded by geometry that is not being rendered into the pass?

#

Here is a photoshop example of what I am trying to describe/accomplish

  • Units at a different pixel depth to the terrain, occluded by the terrain.
    But how do I render the units, AND occlude them by the terrain, without also rendering the terrain? Because I can't render the terrain at full rez, it won't have the size/pixelated look.
#

if I render the units at the actual scale 1:1 with the terrain, they are little 2x2 blobs, which is why I want them at a better resolution

harsh wren
#

In theory you'd render a depth texture of the terrain camera's perspective, upscale it with nearest neighbor, then clip the characters' alpha using the depth texture in their fragment shader against their depth/position, or in a separate pass alternatively

copper lily
#

hmm okay, cull them using the low res render's depth texture.
I was originally going to use a second camera at a higher resolution to have something higher res to clip with, but I wasnt sure how to remove the terrain from that high res render

#

i just had the thought I could override the terrain material to be some color like black while doing that, but I also have black on my units so that wouldnt work
and I couldnt use some color like magenta, because transparency with particle effects (which I also plan to render at higher res) wouldnt play nice with that UnityChanThink

harsh wren
#

As long as you pass the depth texture of the first camera to the second so it can use it when rendering the units

#

Hard to keep the pixelation otherwise

copper lily
#

I was going to use two cameras, one high res and one low res, and composite after
but Im not experienced enough how to do that 'right', so what im trying to "solve" is that I dont know how to get the version with the unit being occluded, but without the terrain, as in render JUST the terrain's occlusion

harsh wren
#

That's probably possible too, but do you want to though
Wouldn't get the pixelation that way and might not be as efficient

#

An empty pass can be used to clear any transparent materials behind the geometry
But then you'd be rendering everything twice in max resolution with a lot of overdraw just for that

copper lily
#

Yeah I hadnt considered upscaling the pixel and using that as the occlusion, that sounds like its probably the better method.
I'm going to need to cull a lot of things using that upscaled depth buffer which I am not sure how to do, I am probably going to have to write a custom shader for every single thing I want to add to the scene won't I? one that samples this render texture and uses it to cull off parts of the high res art that I want to composite with the low res terrain

#

The "easiest" answer would be to ditch the low res terrain entirely, but then I lose the look I was going for, which is a last resort, so I dont want to do that if it can be helped

harsh wren
#

Yes
At least one shader for any non-terrain objects
Or at least a subgraph for the culling which you can re-use for every shader that needs to be different somehow

copper lily
#

Okay, I will start by trying to just upscale nearest neighbour my low res terrain to 1080p or whatever the true screen res is.

Then Ill try to sample that and use it to clip out parts of the units.
I am using URP and shadergraph but I am guessing I will have to actually WRITE an HLSL/CGCode shader to be able to do things like culling/clipping in the fragment portion using the nearest neighbour upscale, sampling the depth and doing a stencil mask write/dont write based on the value of the depth buffer probably?

I have no idea how to do either of those things but they're actionable bites to start to google into

harsh wren
copper lily
#

Here is my low res terrain render texture

harsh wren
#

Because the bits that would be occluded by terrain are invisible, you can render the units right on top of the terrain camera's render without worrying about the negative space because it's all transparent

copper lily
#

whoops, and some of my desktop

#

I am using the depth for some post processing already so I know this texture does have the depth inside of it

harsh wren
#

I'd anticipate the tricky parts to be making sure the fragment depth and the depth texture depth are actually the same kind of depth
And that the depth texture is upscaled correctly, as it can really mess up the results if it's distorted which happens easily if the nearest neighbor scaling isn't perfect
Maybe you can test it with simple bilinear scaling but that'll distort the results too as blurriness will result in "ramps" in depth between disconnected areas

harsh wren
copper lily
#

Different kinds of depth 👀 UnityChanThink

#

I wrote this a while ago so I have to re-familiarize myself with render textures, but this is how I was using the depth before

harsh wren
#

Telling camera A that it needs to output its depth texture for camera B to use in shaders by the time B is rendering is probably not hard, but I don't know what the process is

#

Also disclaimer I wouldn't be surprised if my theory has some errors or overlooked things
I've only made shaders in this vicinity, not this exact thing

copper lily
#

All good, this gives me something to go off of to start with

#

I didnt evne know there were different kinds of depth so that cyan link will help

harsh wren
#

I do know it's a real technique though
Disco Elysium uses a pre-rendered background with pre-rendered depth textures so the 3D characters can be occluded by and clip into it
The digital artbook if you can find it somewhere includes some technical details

#

But probably not many relevant ones since they didn't have to generate the depth at runtime, nor upscale it

#

But it's a real thing anyway

copper lily
#

Oh cool, I had no idea 👀 If you asked me I would have guessed Disco was fully 3D

#

Ill see if I can find those pages of the artbook

copper lily
#

Im still working on this but not having much luck

#

im currently trying to force the URP Render Pipeline to draw a render texture as a full screen render pass to just blit my entire screen with one render texture

#

XY problem what im REALLY trying to do is figure out ANY way to combine low res and high res elements and still use the depth buffer to mask out things that should be masked out

#

I was trying to render the terrain to get its actual depth buffer written, then render texture as the full entire screen, then render the objects after that while sampling the depth buffer

#

but so far I can't get the render texture to render to the entire screen

#

or to anything or anywhere

#

scratch that had a breakthrough

#

im not using the low res texture as my clipping buffer

#

im using the actual geometry

#

====
how it is currently achieved is:

  • low res camera renders only Terrain
  • high res camera has a giant quad of the output of that Terrain only low res image
    then the URP renderer feature has an Render Objects render pass draw in the scene objects, occluded by the real geometry, overtop of that quad glued to the camera
copper lily
#

unfortunately the high res stuff overlaps the pixel outlines with this method, which I think is unavoidable

#

the outline doesnt exist anywhere in 3D space, it has no depth since its a render trick, so I can't possibly sample against it to mask out units

#

I think probably the issue will be less noticable later when I change the game pixel scale

harsh wren
#

I feel like that should be doable
If working with just one camera getting the depth texture is just a checkbox

copper lily
#

depth texture is ON for my camera

#

but I have no way to access and use that data

#

I had to use two cameras and I couldnt find any way around using two cameras

#

when I render the high res units Im also using the high res terrain as my depth buffer here

#

which required two cameras

#

but there's a huge flaw with this method

#

look how much the units jitter when the camera pans

#

because the low res terrain is a render texture on a plane its perpetually behind by 1 frame

#

which produces very significant jitter, not sure yet how to resolve this

#

im not even 100% sure what the source of the jitter is, it could be the render texture, it could be other parts of the pipeline

harsh wren
#

I wish I knew more about the render pipeline background stuff like this

copper lily
#

me too UnityChanThink

#

jitter is definitely caused by the low res terrain being delayed behind the actual scene

#

turning it off and just showing the actual high res terrain, no jitter

#

im guessing the two cameras and the render textures are not in sync with eachother so one can be frames behind the other

#

In a perfect world, this would be the sollution:

#

(as far as I understand)

#

one single render pipeline, which renders everything at high res

#

and renderer features which blit the terrain in a render pass and downscale it and then perform those two shader passes on that, and then composting it all together

#

right now I have two entirely separate render pipelines, one of which produces a render texture that the other high res one shows on a plane

#

which is stupid and bad, but I don't know how to achieve the result without doing that, I'm not knowledgeable enough

#

and its not looking as good as I hoped right :/
proof of concept but not game ready, not production ready performance

copper lily
#

to dig me out of the grave I made for myself

#

i'm a dangerous person, I know enough to dream big, but dont know enough to not do a bunch of stupid things that are horribly the wrong way to get the result im trying to achieve

#

removing the upscale pass and just sampling the low res texture on my render texture plane

#

seems to reduce the jitter

#

I was only doing the upscale because I was trying to composite it together but since im just slapping it on a plane with point sampling I don't need to do that part

harsh wren
copper lily
#

yeah, nose to the grind stone looking through tutorials and doccumentation

#

or just keep winging it and hope someone else can fix it later /s

harsh wren
copper lily
#

Yeah the more you do it the better you get at it, can only grow by trying to do stuff I couldn't previously do

#

its looking pretty good for what it is right now, still lots of small ways I can improve it