How do I see my player when camera is blocked by some other mesh?

In my game I want to be able to see the player even when something gets in the way of the camera.

This article explains two common approaches:

1. Render the occluded player. The author says, “Here, we use the ZTest Greater syntax to specify that this material should only be drawn if it is occluded by other geometry.”

2. Dithering on camera clipped geometry. The author says, “In the shader’s vertex function, we calculate the amount of dithering applied to the object using its world space distance from the camera.
So then we can smoothly fade out the dithering the closer the camera approaches the occluding object.”

So, I’d like to try 1 and 2 to see what works better for my game. The question is how do I go about each in BJS? Is there equivalent “z test greater”? Or anything already written in BJS for handling this sort of camera occlusion case already? That’d be great, haha :sweat_smile:

Edit: ooo, this looks relevant:

I would like to see such an elegant solution. I believe a mesh may have some readable ‘isOccluded’ property?

Yes indeed, isOccluded should get me started for 1). For 2) I am guessing maybe I have to put a custom material on everything I want to be “dithered”?

Not sure what u mean dithered? Like fading an object away if the camera is in it? I think that is where you need a shader for a fancy transparency effect. (Which again I will be happy to see ;p

I had a mind to dial in a camera radius collision/return but this is spicy as well.

Not sure what u mean dithered? Like fading an object away if the camera is in it?

Yeah, pretty much. I’m sure you’d know dithering if you saw it. It’s basically fake transparency. Commonly seen in older 2d games back when transparency was not feasible. It is still useful today for a cheap transparent effect .

1 Like

We ended up basically going for approach #2.

We did it by modifying ammojs raycast to return all meshes between camera and player and then making those meshes slightly transparent.

Hi guyz, sorry to butt-in… but I was thinkin’.

Using a combination of precise followCamera.minZ and followCam follow-distance, could a “nothing allowed to be rendered between player and camera” operation… be created?

You mentioned AmmoJS physics engine, so maybe you have a mesh parented-to cam, or vice-versa… and if you have collision-testing active on that mesh… the “minZ method” won’t work so well. Collide could STILL happen even when occluded mesh is minZ frustum-clipped. (I think. Maybe. Not sure.)

I’m not sure I have ever tested a physics impostor of a non-active mesh, or a partially-minZ-clipped mesh. I’m too scared. Example: Player walks past tree. Tree disappears via .minZ clip, but inbound bullet physics-hits tree that player just passed (part of game intensity). Is physics still active on frustum-clipped mesh? hmm.

Anyway, I don’t mean to accidentally simplify someone’s mesh.visibility or custom shading fun. This is a fun area of experimentation… I’m interested in every method tried, weird or not. I guess someone needs to build a playground that we all can fill with various elixers of dementation. :smiley:

A zig-zagging box character… banging its way thru a giant array (landscape) of telephone poles… with a followCam trying its best to tag-along? hmm.

Hey mr137… got a few moments to tell how the physics are involved? Is the camera physics-active (via impostor on mesh parented to cam or similar)? Physics on player… no concerns. Physics on the followCamera drone? That might require an invisible telephone pole detector/radar. heh.

Physics on camera is weird, anyway. Probably only used for drone pilot training app. :wink: All in all, I’m glad you found a solve, guys.

Hi wingut,

Yeah I did experiment with changing camera min-z to clip the meshes between camera and player at certain times but I found it clipped altogether too much of my scene. Additionally, I didn’t really want the occluding meshes to be completely invisible, just see-through, so I wanted them to be either dithered or somewhat transparent.

The camera is just a normal arc rotate camera that has its target set to the player.

The game is a completely physics-based game, so seeing as all meshes were already in an efficient structure in ammojs, it seemed reasonable enough to do the raycast in ammojs to figure out which meshes in particular were occluding my player then set a transparent material on them.

This was my only question about a raycast, is do you cast just the one from the center or maybe one from each edge of the frustrum? For the desirable visual effect?

Camera tracks the player pretty tightly in my game, so casting from camera center to player seems to give a good visual effect for me.

1 Like