#Make character visible only behind walls?

1 messages · Page 1 of 1 (latest)

vocal leaf
#

I have a shader I created with rendering layers that makes my character visible whenever they get occluded by any mesh. The issue is, I want this effect only to happen behind walls. What's the easiest way to go about this in URP?

cursive violet
#

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

vocal leaf
cursive violet
#

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

vocal leaf
#

yeah, that makes sense. So you suggest putting the walls on their own layer?

cursive violet
#

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

vocal leaf
#

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

cursive violet
cursive violet
vocal leaf
#

thats pretty much exactly what Im doing in that link

#

so you're saying this is more complicated than Im thinking it is, hah

cursive violet
#

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

▶ Play video
#

Well, alpha clips it ;p

vocal leaf
#

If I dont want an alpha to clip it and I want specifically a character outline, does this apply?

cursive violet
#

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

vocal leaf
#

oof, yeah this is a bit over my head currently

cursive violet
#

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

vocal leaf
#

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

cursive violet
#

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

vocal leaf
#

ok how would I go about that?

cursive violet
#

Walls need to be on their own layer

vocal leaf
#

so I can keep my current setup, I just need a few more things added then

#

(that would be ideal)

vocal leaf
cursive violet
#

Rendering layer. Just playing around with some ideas without stencils

#

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?

vocal leaf
#

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

cursive violet
#

Try that then

#

otherwise each case works fine

vocal leaf
#

Ok lemme try

cursive violet
#

The opposite though may be a little tricky

#

as in full occlude if behind both

#

Actually another edge case

vocal leaf
#

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

cursive violet
#

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

vocal leaf
#

Yeah Opaque Layer Mask is set to Mixed currently with those layers unchecked

#

And Transparent Layer Mask is set to Everything

cursive violet
#

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

vocal leaf
#

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

cursive violet
#

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

vocal leaf
#

Ok so I have them on the correct layers then

cursive violet
#

previously they were called light layers but just renamed them to rendering layers

vocal leaf
#

My Walls, Player and PlayerBehind layers are all under “Layers”

cursive violet
vocal leaf
#

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

cursive violet
#

Yeah, same layers as how you do the raycasting

vocal leaf
#

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

cursive violet
#

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

vocal leaf
#

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

https://www.youtube.com/watch?v=GAh225QNpm0

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

▶ Play video
cursive violet
#

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

vocal leaf
#

How would I check?

vocal leaf
#

am I missing anything?

cursive violet
#

Seems fine to me

#

And you set the filtering to Nothing right

vocal leaf
#

should Opaque be set to Nothing?

cursive violet
#

Well, only the layers you're overriding should be unset

#

could just set it to nothing for the sake of debugging

vocal leaf
#

yeah I set it to Nothing and still didnt work...hmm

cursive violet
#

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

vocal leaf
cursive violet
#

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

vocal leaf
#

tried messing with Depth Test and nothing worked...I also tried disabling Stencil and nothing worked either

#

Im a bit baffled

cursive violet
#

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

vocal leaf
#

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.

cursive violet
#

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