Rendering an object through its parent

Hi,
I have a situation where I need an object to render through (after) its parent, unless there’s an easier way to do this…

I have a “Furniture” object that could be any size or shape.
It has a child “Rune” object that is smaller than the Furniture and is positioned in the center of it.

I need the Rune object to be visible from all sides of the Furniture, like its a glowing symbol floating just in front of it, no matter which side you look from.

I figure one way to do this would be to make the Rune a billboard that always faces the camera and have it render through the Furniture object somehow.

I know you can make an object render after everything using multiple cameras, like the gun in a FPS, but the Rune must only render over the Furniture, not everything else that might be in the way.

Also if having the Rune a child of the Furniture hinders this process, that could probably be changed, it’s only a child so that it moves as the Furniture moves, I could do that manually.

2 Answers

2

Two choices I can think of:

  • A transparent shader that ignores depth on the rune
  • Put it on it’s own layer. Have two cameras, the first one renders everything except this layer. The second one has a higher depth than the first and is set to “Clear Depth Only” and renders just the rune’s layer.

But wouldn't both of those options cause the rune to render over the top of everything else in the scene? It has to only render over the top of its parent. All other objects have to still sort with it normally. E.g. I don't want it to show through walls.

Yes that is true. Hmmm. Only over its parent will be a problem - all shader solutions will have a hard job identifying that in the fragment part. You could render over any object of that type by having the sofa render with a shader that wrote a specific alpha value. You could make them part of the same mesh and use vertex colours in a second pass to render the rune and not the sofa. You could then have the rune texture as a separate material texture and use that.

I use that vertex color effect here to render the semi-transparent, reflective glass infront of the rest of the model even though the whole thing is Z writing. The first pass positions the glass offscreen.[9231-screen+shot+2013-03-23+at+13.47.24.png|9231]

I don't think that will solve it for me. There can be multiple Runes in one room so the player would notice if a Rune was rendering through other objects that also had Runes on them. They also cant be part of the same mesh since the player can place the Runes on any object they like.

I think that might be possible if you used three stages, which you could accomplish with either multiple camera or specify rendering order in the shaders.

Render Pass 1:
Clear Depth and render skybox as usual.
Render your Furniture and write to the Z buffer.

Render Pass 2:
Don’t clear.
Render your Runes, but with ZTest Always and ZWrite Off in the shader.

Render Pass 3:
Don’t clear.
Render everything else in the scene as usual, which should render in front of Furniture/Runes according to Z buffer like you want.

The only issue I can think of would be that the Runes would render in front of potentially other pieces of furniture that may be in front, not just the piece they are parented to. But depending on your layout, that might not be a problem?

Unfortunately it would be a problem. There can be multiple in one room, in fact that player can place these Runes on any furniture they like.

But can each item only have one? And what is it a mesh or a texture?

Each item can have more than one (up to 5). The Rune is a mesh, like a glowing floating 3D rune.

How close are the furniture items? This isn't an elegant solution, but if each furniture item is reasonably far apart, you could change the ZTest back to LEqual for the Rune shader and then specify an Offset value to try to force it in front of the furniture. With the right Offset, you might be able to get the Runes to render in front of it's furniture but not in front of nearby furniture.

So it strikes me you could merge the 3D rune into the mesh of the sofa using a combine and ensure all of it's vertex colours are set to something that a shader would use to render in a second pass and translate to off screen in a first pass. Now that will only work if they aren't moving relative to the sofa.