How to render only part of your object (or workarounds)

Hello,

Here is the picture:

a) There is a square (or cubioid for that matter) that has certain bounds. It is suppose to get suck trough the portal at the end of the level. How do i achieve that only the part of the cuboid, that is sticking out (“is still on this world”) is rendered?

No need for code or anything like that, just need rendering or some others established procedure tips.

Thank you.

9796-unityquestion.png

I know this could be easily done with DukeNukem engine as I know you can make hallways in same X/Y/Z and you don't see them workarounds: - you could do with: part by part stop rendering - you could do with: wider portal so the end of the mesh isn't through portal when the begin of it goes in good basic question thumbs up [1]: http://answers.unity3d.com/users/4275/vicenti.html

3 Answers

3

How about using the DepthMask shader to obscure the rendering of the part of the cuboid which isn’t visible any longer?

http://wiki.unity3d.com/index.php?title=DepthMask

You would render an area around the exit of the portal with a cube using that shader and then nothing would appear inside that volume.

I ended up using this. Not really sure weather it is more efficient than manipulating mesh (which is only viable because my object is so simple), but it is working fabulously and i have long lasting sympaty for shaders. Thank you for all the nice answers guys.

If you’re guaranteed to have only plaincolor cuboids entering portals straight-on (i.e. they don’t look funky when scaled), you can just scale them relative to how close they are to the portal.

Something like but probably not exactly:

transform.localScale.x = Mathf.Min(1.0, (portal.position.x - transform.position.x) / cuboidWidth );

Note that while the cuboid is touching the portal, it needs to move at half speed (to offset the visual effect of scaling). or double speed. my math brain does not remember which. probably half.

I have this exact procedure implemented as a filler atm. It does the work but you can clearly see the textures shrinking (even though object is small. As you said, plaincolor is needed here:))

My next suggestion would be to just alter the cuboid's mesh while it's within range of a portal. If ( 'back' of 'boid is on a different side of the portal than the 'front' ) move all front vertices to the portal's plane and adjust their UV values accordingly

Will definitely try this when i get home. I havent been manipulating mesh or UV in unity jet, sounds interesting.

First idea came up to my mind using a separate camera and playing with its normalized view port rectangles values.

I guess this could easily be done as i have static isometric camera and only one "portal" (when you complete the level). But how about a fully 3d game? Would i have to rotate all view ports? Manage all the cameras? What about the rendering times? Not to forget that i dont actually need anything rendered. Essentially i would be rendering much more to show less. Seems like an overkill and a lot of work. I have no real idea about this nor much knowledge about rendering etc..

Yeah it would be hard to manage that in a 3d game.You might need script that updates all cameras accordingly.But as you said it would require a lot of work. I wonder how Portals do that,Following and upvoting the topic :)