#occlude near clip

1 messages · Page 1 of 1 (latest)

velvet forum
#

How can I make the areas where meshes are cut off by the near plane of a camera be hidden? Ideally, I would be able to have my meshes be filled with blackness, that's the kind of effect I'm looking for.

peak canopy
#

ChatGPT says:

velvet forum
#

@peak canopy I appreciate the thought but please see above

#

If it doesn't work I can't ask for any help about it 🤷‍♀️

#

and with a code that complex I rather doubt it will

#

That aside, my partner would kill me for using any ai-generated code anyway

peak canopy
#

think of ai as the ice-breaker: it doesn't get you far but it gets you started. none of the code above is complicated but it's daunting to jump into it when none of its components are familiar. just jump into it and learn as you go

fallow haven
harsh wasp
#

I'm sure Amey!? is capable of asking ChatGPT herself if she wants to. She's asking here because she wants to tap into the knowledge of other humans. 🙂

#

(Also, screenshots of code are not very helpful!)

#

Sidenote that I'm reasonably sure ChatGPT is wrong anyway.

#
  1. Nothing will be nearer than the near plane.
#
  1. Only a few pixels will be at the near plane.
#

You may want to try a second material pass with a front-culling unshaded black material, if it is things intersecting the near plane you want to show the insides of as black.

#

It would be more tricky to show the silhouette of things which are wholly in front of the near plane, if that's what you mean.

craggy depot
#

Thanks for providing a useful explanation haunty

velvet forum
#

I want to not only have the opposite side of the clipped mesh be black, I also want to not see the face of other meshes that intersect that one

#

drawing a black clip-shaped blob over the clip would be ideal

harsh wasp
#

Is the camera orthographic?

velvet forum
#

I want that bit of floor to also be hidden

harsh wasp
#

Is that because of z-fighting? You might have to move the bottom of the vending machine up fractionally.

velvet forum
harsh wasp
#

Unfortunately, I don't believe anything can tell the front of the vending machine is missing.

#

But the inside bottom of the vending machine might be able to do something.

velvet forum
#

Understood 🫡

velvet forum
harsh wasp
#

Easy on the face of it.

#

But the floor wins at random.

#

Annoyingly, this would be easy to fix in Unity. gdcry

velvet forum
harsh wasp
#

What I'd like to do is offset the inside pixels towards the camera slightly, so they'll win.

velvet forum
#

Oh, as for why I even want to do this
I want geometry that players can stand on to intersect the near plane and have a solid color at the intersection to make it obvious what is and isn’t “floor”

harsh wasp
#

I would do that by just modifying DEPTH in the shader, but I can't just modify it - if it is set it has to be calculated from the start.

#
shader_type spatial;
render_mode cull_front, unshaded, world_vertex_coords;

void vertex() {
  VERTEX += 0.0001 * CAMERA_DIRECTION_WORLD;
}

void fragment() {
  ALBEDO = vec3(0);
}
#

This is working for me, as a second material pass shader.

#

Slightly moves the mesh towards the camera, which will usually move it past anything it is intersecting.

#

If it you move it too far, though...

velvet forum
#

Interesting! I’m going to have to mess with this a bit when I get back to my workstation gdpixelangel