darkfall / MagicaVoxelUnity

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

Not working in Unity 5.5 #6

Open baturinsky opened 7 years ago

baturinsky commented 7 years ago

Probably, because of shaders. FlatColor shader looks like solid black, when I change to StandardVertexTransp it looks similar to normal, but looks like it have z-order of faces wrong

http://i.imgur.com/oWkxVLC.png

Suggested fixes:

1. use tex coords instead of color:

//in cycle
var texCoords = new Vector2(cidx / 255f, 0.5f);

uv.Add(texCoords);
uv.Add(texCoords);
uv.Add(texCoords);
uv.Add(texCoords);

...

uv.Add(texCoords);

And use standard shader and a palette png that MagicaVoxel generates when exports obj.

  1. Fix StandartVertexTransp shader by changing

void vert (inout appdata_full v, out Input o)

to

void vert (inout appdata_full v, out v2f o)

(i.e. do not lose vertex position along the way)

Result is still looks pretty meh, because unshaded

I have also found this shaders that seems to do the trick

Shader "Vertex Color Lit" {
    Properties{
        _MainTex("Base (RGB)", 2D) = "white" {}
    }
        SubShader{
        Pass{
        Lighting On
        ColorMaterial AmbientAndDiffuse
        SetTexture[_MainTex]{
        combine texture * primary DOUBLE
    }
    }
    }
}
barraudf commented 7 years ago

Hey!

I haven't work on Unity for a good amount of time, I didn't notice this project was not wokring on newer version of Unity anymore.

If I had to do it again, I'd pick UV mapping over Vertex Color too, simply because using it is working with Unity default standard shader (unlike vertex color)

barraudf commented 6 years ago

Hey!

I don't know if you are still using this project, but it has been updated to work with newer versions of Unity (tested on Unity 2017.2) and is working with standard shader