Special shader question. How to draw half an object with one shader and the other half with another?

I think this is the right question? Here’s the back story: I was playing a mod for a game called Garry’s Mod. One of the game mechanics involved producing resources such as oil. To produce the oil you’d put down an oil derrick and let it produce the oil. Your oil barrel spawns in front of the derrick and starts out in wireframe. As it gets produces it slowly fills with the actual real texture of the model. For example, if you’re oil barrel was 50% done producing, the top half would be wireframe and the bottom half would be the actual oil barrel texture.

How exactly would you do something like this in unity. I’m not sure how they did it in the source engine but if they did it with lua in there, I’m guessing there’s some way that its possible to do in unity.

You’d draw it twice, using different shaders. Probably just draw a different “wireframe” model for one of them, then a “bottom half” for the real, which covers the wireframe.

For the “real” part, skip the top using a shader parameter, maybe HT. The program would set it and the shader would say something like if(o.vert.y>HT) discard;. Since the shader can’t normally access the model coords, you’d have to copy it like in the “Custom data computed per-vertex” surf shader example. It’s not super-easy – you have to type some shader lines – but dosn’t use advanced math or anything.

You could also just use one shader, and the if(y>HT) test would put a grey texture on the unbuilt part (but would obviously be the same model.)