darkfall / MagicaVoxelUnity

Unity3D plugin for MagicaVoxel's vox format.
MIT License
197 stars 34 forks source link

New feature : use a model as alpha mask #3

Closed barraudf closed 9 years ago

barraudf commented 9 years ago

I wanted my models to use transparency, and until MagicaVoxel support it, here is a workaround I have set up : on vox model loaging, another model can be loaded as an alpha mask.

How does it work?

Two models are loaded, one for color data and the other for alpha value :

alphamask1

  1. The main model in MagicaVoxel
  2. The alpha mask model in MagicaVoxel
  3. Final result in Unity

For the alpha mask model, color index is used as alpha value (the color itself doesn't matter at all), independently of the palette (index 1 means fully transparent and index 255 means fully opaque) :

alphamask2

ps : my shader is not very nice at the moment, but I'm totally new to this stuff and that's the best I could do. Plus I can't get your shader to work, everything is black.

darkfall commented 9 years ago

This is definitely a nice way to deal with transparency and even masking for animation purposes. When I was talking with @gltracy, he mentioned something similar but I just decided to wait for him to implement the layer feature. I'll merge this as soon as possible.