#Make character visible only behind walls?
1 messages · Page 1 of 1 (latest)
So you're checking depth and then drawing with an override material if the object is occluded via depth map, right?
The solution off my head here is that you're going to have to draw the wall layer objects into its own depth map to then compare against
Stencil masking can work too but you may run into cutting more geometry than you want
Yeah I know its something to do with putting the wall meshes on their own layer, but I have no idea how to go about this. I followed a tutorial to get the first part working and created my own custom shader, but when it comes to layers and depth it confuses me a bit.
Render Object layers just allows you to override some settings of the renderings for that specific layer, but when you're using the depth map here you're still comparing against the full depth map supplied by the main camera rendering
And the pixels of the depth map have no idea what layer each of them represent
yeah, that makes sense. So you suggest putting the walls on their own layer?
Depends, if you're using stencils then that would be the idea, but like I was saying you may end up with a situation where the stencils cull more than you want
The easiest solution here is you need some raycasting to specify what wall is occluding the player
This way you'd have a wall shader that accepts some texture or mask in the screen space to cull or color when told
Im using two Render Objects, one for hidden and one for visible and the shader is making my character have an outline behind objects.
for Hidden, Depth Test is set to Greater
https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@13.1/manual/renderer-features/how-to-custom-effect-render-objects.html
I'm assuming it's similar to this, but as I've mentioned you are comparing against a single depth map which has no idea what layer each of the pixels are on.
You'd have to chop up these maps if you only want specific information being populated
thats pretty much exactly what Im doing in that link
so you're saying this is more complicated than Im thinking it is, hah
https://www.youtube.com/watch?v=jidloC6gyf8
Danel here has a good solution, but instead of using a secondary material to show behind the wall he just culls it. Though, the idea is similar but instead of culling you'd draw instead. But the big take away here is he does raycasting to specify what wall is being culled
Many games need to make sure the focus is on the player or some other object, and walls are usually a hindrance. You could move the camera past the wall or render things over it.
In this tutorial, we'll just cut a hole in the wall instead. I've seen a wall cutout effect before in a handful of ways, so I'm going to take an alternative approach t...
Well, alpha clips it ;p
If I dont want an alpha to clip it and I want specifically a character outline, does this apply?
Ah, he does some distance calcs too it seems. But the c# code is more what I wanted to point out.
he raycasts the wall then edits global shader parameters, but I would instead change local parameters of the material
oof, yeah this is a bit over my head currently
Yeah, not finding a good video of the exact requirements I'm suggesting. Ultimately you do want to raycast, you do want to tell that material that your character is being occluded, and you do want some sort of information to give that material of the pixels to change depending where your character is.
But now that I think about it again, stencils may be fine assuming you want to draw and not a culling mask.
Yeah I think they would work fine and I think you can do it with render objects
yeah I basically just want what you posted in that first link, but only behind specified meshes (walls, in this case)
the issue is now this effect is happening behind everything including NPCs and other meshes, which I dont want
I think the idea is you'd continue using the depth map, but you also need to stencil test
if the player is occluded then we stencil test -> if the stencil test passes then we draw
ok how would I go about that?
Walls need to be on their own layer
so I can keep my current setup, I just need a few more things added then
(that would be ideal)
rendering layer, sorting layer or regular layer?
Rendering layer. Just playing around with some ideas without stencils
https://i.imgur.com/WTSU2QE.png
https://i.imgur.com/TvaS66q.png
https://i.imgur.com/SYZiz2z.png
So this is a depth only solution, but there's one problem with it where you'll still get a player cut-out if they are occluded by both a wall and other geometry
But if it's only occluded by either a wall OR geometry it works fine... but I think to fix this edge case you do need some stencil testing
Sorry that's behind render similar to what the page is doing
Yeah the reason for the edge case is it will always do the cutout as long as the player is behind the wall even if you do draw the other geometry later
Ok, how about this. What happens when both geometry and a wall occludes the player. What is expected?
Hmm, good point. Yeah the player would still be need to be seen behind the wall in that case
behind the wall and mesh. Like if a bookcase is up against a wall and the player goes behind, the expected result would be the player outline is seen behind the bookcase and the wall
Try that then
https://i.imgur.com/c9Fby54.png
Will be seen if a wall and other geometry occludes
otherwise each case works fine
Ok lemme try
The opposite though may be a little tricky
as in full occlude if behind both
Actually another edge case
Hmm, tried that and nothing seems to be working now.
I put my walls in the new walls layer. I added my shader/character material to the BehindRender section
double checked it was all the same as your setup and for some reason, not working
Make sure you're filtering out the layers at the top of the rendering asset
and we're using opaque here so make sure your materials are too
Basically filtering should be set to none if we're going to override it all
Yeah Opaque Layer Mask is set to Mixed currently with those layers unchecked
And Transparent Layer Mask is set to Everything
https://i.imgur.com/XdqO8Xe.png
https://i.imgur.com/qMobu5g.png
https://i.imgur.com/BSQuwEU.png
https://i.imgur.com/7ltHZ7N.png
Ok, that seems to meet the requirements. May be going about it a more convoluted way but it works.
Also there's an ordering to it so make sure from top to bottom they are placed
Make sure you're using the correct rendering asset too on the camera
Should these layers be under Rendering Layers or default?
I have 3 layer options - sorting layers, layers, and rendering layers. I’ve been putting them in just regular Layers
oh sorry so URP objects use the basic physical layers not the rendering layers if I said that
really it would be nice to use the rendering layers here, but unity doesn't want to provide specific layering for rendering these
rendering layers are specifically for light UVs and decals
Ok so I have them on the correct layers then
previously they were called light layers but just renamed them to rendering layers
My Walls, Player and PlayerBehind layers are all under “Layers”
I still refer to the basic layers as both the rendering and physical layers for the sake of URP objects and pipeline scripting
My player is under my “Player” layer. Walls in the Walls layer and nothing technically in the PlayerBehind layer except the material that gets used for the outline
Yeah, same layers as how you do the raycasting
Hmm yeah nothing is working. No idea why.
Nothing is working as in the player isn’t even rendering behind anything as if I’ve made no changes at all
Not sure what tutorial you were following, but the page I linked sets the premise for it all
I'd double check you're editing the right rendering asset and the camera is using it
I definitely am, its the one that was working before
this is the initial tutorial I was working with, but its since changed since now I changed all the rendering layers to what you suggested
In this Unity game development tutorial we're going to look at how we can use URP Renderer Features to create a silhouette of a character when they're hidden by an obstacle.
We'll start looking at how to remove the rendering of the character completely by assigning it to a layer and removing this layer from the renderer.
Then we'll add two ren...
Hmm, well other than suggesting using default unity shaders just in case your materials have some conflicts, I'm not doing anything out the ordinary here.
Unless there's some graphical API confliction here that's not liking the stencil ops
How would I check?
this is under my render asset
am I missing anything?
right now its
should Opaque be set to Nothing?
Well, only the layers you're overriding should be unset
could just set it to nothing for the sake of debugging
yeah I set it to Nothing and still didnt work...hmm
Play around witht he depth testing on the BehindRender here
Otherwise I'm stumped cause the logic seems fine so im going with some Unity problem
Heck, even without* the stenciling it should always render in front
Also, for testing purposes just use a unity lit material and set it opaque
oh, the shader I made is actually a Lit material. I didnt use the same one as in the video, I made my own.
SO behind Render here has depth test to always meaning it will always pass the depth test so it will always draw on top
So if you disable the stenciling here it should always render no matter what
tried messing with Depth Test and nothing worked...I also tried disabling Stencil and nothing worked either
Im a bit baffled
Yeah no idea then. That right there should always render over all opaques no matter what
the stenciling however does an extra check to see if there's a wall stencil value at the pixel location and if it doesnt then it discard the pixel
So I suggest try to get that render object only working
I'm using Unity 6 URP here btw, but I can't expect this having problems in earlier versions
Im using U6 as well.
Ok, ill try some things. Thank you a ton for the help. Ill let ya know if I get it figured out.
yeah the logic there looks correct and if the URP objects dont work then you could look into how to set it up in HLSL, but you kinda lose out on the shader graph if you choose to do that