Turn a Volume Transparent or Invisible

Mese posted this 19 September 2016

Hi, I'm doing a top-down orthographic game. When some objects go "under" a volume, I want that volume to be able to turn transparent. (Like when using "PicaVoxel PBR Transparent") What I'm trying is to swap the material at runtime, but the volume doesn't update.

The Workaround is to use "PicaVoxel PBR Transparent" and using the PicaVoxel Editor to turn transparent the top part of the Volume on Frame 2.. Voxel by Voxel. Later I switch from frame 1 to 2 and back via Scripting depending if there's an object that triggers the transparency under the Volume.

This is a pain in the butt to do... Is there any other way to turn transparent an object?

The best thing I think is: It would be amazing to have an Outline Shader working for PicaVoxel... (I have tried this option with several Shaders around the internet but they seems not to work correctly)

Any help will be appreciated.

Last edited 19 September 2016

Order By: Standard | Newest | Votes
Mese posted this 19 September 2016

Here's an example of what I'm doing currently: Transparency

GarethIW posted this 19 September 2016

I would do this in the same way that I would do it with non-voxel models: by adjusting the transparency via a shader parameter. You can use the Tint parameter of the PBR Transparent shader to do this:

  1. Create a duplicate of the PicaVoxel PBR Transparent material
  2. Assign it to the volume you want to fade out
  3. In script, use Material.SetColor() to adjust the alpha value of the Tint parameter on the material: https://docs.unity3d.com/ScriptReference/Material.SetColor.html
  4. I'd add a nice lerp to the change so it isn't instantaneous.


Mese posted this 19 September 2016

Hi Gareth, Thats actually a good Idea I didnt though about, Thank you...

But now I have another problem, with "PicaVoxel PBR Transparent" I just noticed this: enter image description here

Several faces of the Voxel are actually completely invisible when they aren't intended to be. In the transparent phase it seems "OK", but when turning solid I get this issue, at editor time and run time.

Thanks in advance.

GarethIW posted this 19 September 2016

Hmm yes, there is indeed a depth buffer issue with the transparent shader.

Try replacing the shader with this code: https://gist.github.com/GarethIW/b7ac200c6c4530a8b278b950576fcf35

Mese posted this 19 September 2016

Hi, Thanks! The Shader is throwing me an error on line 84: Cannot find "unity_ObjectToWorld") (I think its line 85 on github) I'm updating Unity since it can be related (and I needed to update anyway). Once I port and check everything I'll report it.

Mese posted this 19 September 2016

Ok, confirmed! after updating "unity_ObjectToWorld" line is valid and it works wonderfully!

Many Thanks Gareth!

I'm linking the script I created to turn buildings invisible: link

Here working:


now to fix that pesky pink box sprite!

Last edited 19 September 2016

Mese posted this 08 November 2016

Hi again Gareth,

I'm sorry to bother again, I'm back to modeling more things on MagicaVoxel, and I just experienced this with the Shader you gave me, earlier on this thread.

enter image description here

A transparent cube doesnt show what's behind it, it shows what's behind the entire object. I might be doing something wrong

Also, Is there a way to import transparency and emission from Magica Voxel?

Thanks in advance!

GarethIW posted this 08 November 2016

Yeah, that isn't a problem with the shader or PicaVoxel, but a limitation of transparency in 3D engines in general.

In order to render something transparent and still be able to see things behind it, you must render it last in the scene.

This means that you cannot have a voxel volume with selected voxels as semitransparent, because those voxels will be rendered at the same time as the rest of the (opaque) volume.

In order for your example to work, you will need to have a separate volume using the transparent shader which has only the voxels (for windows on a building I assume?) you need to be transparent in it.

The latest version of MagicaVoxel does export the materials, but not in a way that really translates to use in Unity so no, there is no support for them currently.

Mese posted this 09 November 2016

Oh! Ok, thanks for the explanation!

I'll try a different approach

Our 137 members have posted 527 times in 128 discussions