Hi,
I would like to show/hide parts of a mesh. As an example think of a building that is placed, which hides 90% of the structure on placement. Each time the building is being worked on, some percentage is revealed. How do I achieve something like this?
Best wishes.
There are a number of different possible solutions. If you are talking about a 3D object, then there is an additional hurdle to overcome. Meshes are one sided. Most shaders cull out back sides. So imagine you had a box with the top off. If you look down inside the box you won’t see the insides…you will see through the box. A typical solution is to modify the shader to turn the culling off. This will display both sides, but it will display both sides as lit from the front side. So you lighting may not look right.
Here are some ideas. Some are “in theory” since I’ve never written the specific code or used the specific concept.
- Use a mask
There are shaders that use a mask and a cutoff. You can create a mask to along with your textures. In the shader you change the cutoff to reveal more the building. This answer uses this method in 2D for a circular progress bar:
http://answers.unity3d.com/questions/14770/creating-a-circular-progressbar-timer.html
- Different materials
If you want your building to go up in stages, then you can define the different parts of your building to have different materials. Then at runtime, you modify the alpha of the main color for each material to expose different areas. This requires a shader that supports transparency and has a main color.
- Texture atlas and changing UV
This one is a bit more complex. It assumes you are using a texture atlas for mapping the texture onto the building. You can dynamically change the uv in the material to point to different parts of the atlas. Parts that have not be exposed, point to a part of the atlas that is clear. As they are exposed, uvs are changed to another part of the texture.
- Vertex colors
Using a shader that supports vertex colors and transparency, you can change the vertex colors in the material.
- Custom shader
You can write a shader based on a parameter only show part of the pixels (based on height for example).
- Direct manipulation of the texture.
You can directly modify the texture used in the material and alpha values.
I’m sure there are more ways.