Refer to vertex color when importing with UniUnlit

This commit is contained in:
hirose
2019-12-16 21:07:25 +09:00
parent c842e577c4
commit db666f2b1d
5 changed files with 18 additions and 10 deletions

View File

@@ -170,10 +170,7 @@ namespace UniGLTF
var materialImporter = new MaterialImporter(shaderStore, null);
{
var material = materialImporter.CreateMaterial(0, new glTFMaterial
{
});
var material = materialImporter.CreateMaterial(0, new glTFMaterial { }, false);
Assert.AreEqual("Standard", material.shader.name);
}
}

View File

@@ -625,13 +625,13 @@ namespace UniGLTF
{
if (GLTF.materials == null || !GLTF.materials.Any())
{
AddMaterial(MaterialImporter.CreateMaterial(0, null));
AddMaterial(MaterialImporter.CreateMaterial(0, null, false));
}
else
{
for (int i = 0; i < GLTF.materials.Count; ++i)
{
AddMaterial(MaterialImporter.CreateMaterial(i, GLTF.materials[i]));
AddMaterial(MaterialImporter.CreateMaterial(i, GLTF.materials[i], GLTF.MaterialHasVertexColor(i)));
}
}
}

View File

@@ -10,7 +10,7 @@ namespace UniGLTF
{
public interface IMaterialImporter
{
Material CreateMaterial(int i, glTFMaterial src);
Material CreateMaterial(int i, glTFMaterial src, bool hasVertexColor);
}
public class MaterialImporter : IMaterialImporter
@@ -64,7 +64,7 @@ namespace UniGLTF
/// _SrcBlend
/// _DstBlend
/// _ZWrite
public virtual Material CreateMaterial(int i, glTFMaterial x)
public virtual Material CreateMaterial(int i, glTFMaterial x, bool hasVertexColor)
{
var shader = m_shaderStore.GetShader(x);
//Debug.LogFormat("[{0}]{1}", i, shader.name);
@@ -134,6 +134,12 @@ namespace UniGLTF
UniUnlit.Utils.SetCullMode(material, UniUnlit.UniUnlitCullMode.Back);
}
// VColor
if (hasVertexColor)
{
UniUnlit.Utils.SetVColBlendMode(material, UniUnlit.UniUnlitVertexColorBlendOp.Multiply);
}
UniUnlit.Utils.ValidateProperties(material, true);
return material;

View File

@@ -59,6 +59,11 @@ namespace UniGLTF.UniUnlit
material.SetInt(PropNameCullMode, (int) mode);
}
public static void SetVColBlendMode(Material material, UniUnlitVertexColorBlendOp mode)
{
material.SetInt(PropNameVColBlendMode, (int)mode);
}
public static UniUnlitRenderMode GetRenderMode(Material material)
{
return (UniUnlitRenderMode)material.GetInt(PropNameBlendMode);

View File

@@ -26,7 +26,7 @@ namespace VRM
"VRM/UnlitTransparentZWrite",
};
public override Material CreateMaterial(int i, glTFMaterial src)
public override Material CreateMaterial(int i, glTFMaterial src, bool hasVertexColor)
{
if(i==0 && m_materials.Count == 0)
{
@@ -50,7 +50,7 @@ namespace VRM
{
Debug.LogWarningFormat("unknown shader {0}.", shaderName);
}
return base.CreateMaterial(i, src);
return base.CreateMaterial(i, src, hasVertexColor);
}
//