Z-sorting error

first of all, i salute you all for the first time. here at three melons we got the pro version about 2 weeks ago, and i must say, having worked with both 3dgamestudio and torque, unity is a bliss to make games with. and i know it’s not easy, congratulations!

so, now to the question itself:

i’m making a tech demo of a fps but instead of guns, it’s a paint hose, shooting a stream of red paint. i’ve managed to get something pretty close to that with a mesh particle emitter and a lot of particles and a nice shader. when the particles hit something, i kill the particle and put a little plane with splat imge on that place, so you can actually “paint” (don’t ask about performance, i still don’t even want to think about that…)
i have just a big level with a ground plane and a wall in front of the player, for him to paint on. the problem is, i shoot and paint the wall, and a lot of splat planes are placed stuck to the wall. but, whenever any of the particles are behind the wall (e.g. if i shoot over it) the whole particle system is rendered behind the splat planes. i’ve had a similar problem in other engines (though not with particles) and the solution was to apply a special zsorting shader.

so, any ideas on this? is this a known issue? did it make sense at all?
if needed (or if anybody is just curious), i can upload the demo so you can see the problem.

any suggestions welcome!

joaquin@threemelons

You probably want to make the splat plane shader not be in the transparent renderqueue but instead in the geometry render queue. Thus it will always render before the particles and the partilces will be culled by the z-buffer.

Another suggestion though, dont use splat planes.
Paint directly into the textures.

The procedural example project here: www.otee.dk/examples
has some code for painting with brushes.

There are a couple of real world issues with the technique:

  • You need unique uv maps for the texture that is used to paint upon. So its going to be best to have 2 UV sets for each mesh. The secondary one you always uuse for painted textures.
  • Since it is uniquely textured, you will end up with pretty big textures. The trick is to create the textures on demand, the first time when you want to paint one mesh.

One way to do this would be to have a shader that simply multiplies two textures. By default there is no texture using the secondary UV coordinate. When you hit the surface for the first time, you allocate a new texture, make it completely white and then paint into it. Then assign the new texture to the material.

There is a tradeoff between splat planes and painting textures. Spat planes you create lot of extra geometry, especially if you never want to fade them out.
With painting you need high resolution unique textures, but the big advantage is that you can paint several layers of paint with different colors on top of each other without any extra performance cost.

excellent! your suggestion actually seems to be what i was looking for, i’ll definitely start looking into that.
but for the meantime, exactly how do i place the plane shader in the geometry render queue?

thanks a lot!

Just remove the “Queue” Tag from the shader. If you’re not using some custom shader, then grab the source of builtin shaders from here, put the one you want to use into your project and remove the tag from there (also possibly change the name).