Generate white vertex colours if missing

This commit is contained in:
ackwell 2024-01-17 23:25:20 +11:00 committed by Ottermandias
parent 107f6706d3
commit 2c5f22047a

View file

@ -394,10 +394,9 @@ public class VertexAttribute
return result;
}
public static VertexAttribute? Color(Accessors accessors)
public static VertexAttribute Color(Accessors accessors)
{
if (!accessors.TryGetValue("COLOR_0", out var accessor))
return null;
accessors.TryGetValue("COLOR_0", out var accessor);
var element = new MdlStructs.VertexElement()
{
@ -406,11 +405,12 @@ public class VertexAttribute
Usage = (byte)MdlFile.VertexUsage.Color,
};
var values = accessor.AsVector4Array();
// Some shaders rely on the presence of vertex colors to render - fall back to a pure white value if it's missing.
var values = accessor?.AsVector4Array();
return new VertexAttribute(
element,
index => BuildByteFloat4(values[index])
index => BuildByteFloat4(values?[index] ?? Vector4.One)
);
}