setting the z buffer

I want an object to set the z buffer value to the far clip plane for pixels that are visible.

things have been rendered in the scene, and I want a window into another scene, based on a geometric object I render between the two scenes.

Has anybody got any idea how to write a specific value to the depth buffer?

Yeah, just use a shader with ColorMask 0 in it. I’m on my iPhone presently so it’s not easy to get you links. Let me know after some searching if you need more help than that.

Thanks for taking the time Jessy

I got the basics, it’s setting the pixel values to far clip that I’m not sure about.

It needs to clip against the objects already rendered in it’s real z space, but to write far into the z buffer if it passes the z test…

so if I’m in an inverted cube, and I render the object intersecting with the cube faces, I want it to put the z to the far clip value, where I would see it if it was rendered normally.

I’m sorry. I did read what you said about pushing the depth back, but I guess I disregarded it after you said WHY you were trying to do it. I don’t actually know how to set the depth to the far clip plane; you can use Offset, but that’s not good for setting to a discrete value like you want. Can you explain why you need to do what you say you want to do? From the info you’ve given so far, it sounds like you just need to render a scene with one camera, then use a ColorMask 0 mesh, and then render other geometry, like some of us have done around here for portal systems.

It is a portal system.

Rendering with ColorMask 0 allows you to write triangles to the z buffer, I see that.

I want to render the closest room first, then portal, then room behind portal, I’m unsure but to use ColorMask 0 you have to have rendered the objects behind the portal before you mask the z-buffer, is that correct?

You can use ColorMask 0 wherever you like, but yes, the system that I’ve had success with renders the room past the portal first. It is indeed highly inefficient, particularly because Unity does not allow you to work with the stencil buffer.

What I might recommend for you, if you really want to optimize and try what you’re talking about, is to use two shaders for the portal. The portal itself could ZTest LEqual as normal, but you’d modify its vertices to be on the far clip plane every frame. A border around the portal could be pushed to the near clip plane, with an optional ZTest Always. I never tried the former part, but I was never able to get success in all cases with the latter, so I gave up. Maybe you’re smarter than I am and would be able to make it work better. :wink:

Yes, and if you do succeed let us know.
By the way, users have asked for access to stencil buffer since 2006, but the Unity Gods have not deemed it worthy to bestow us with one.