-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
色プロパティのシリアライズ・デシリアライズ時に色空間をコードで明示 #933
Conversation
var color = src.pbrMetallicRoughness.baseColorFactor; | ||
param.Colors.Add("_Color", (new Color(color[0], color[1], color[2], color[3])).gamma); | ||
param.Colors.Add("_Color", | ||
src.pbrMetallicRoughness.baseColorFactor.ToColor4(ColorSpace.Linear, ColorSpace.sRGB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glTF の定義として baseColorFactor
は Linear 空間の色である。
また、Unity の Standard Shader の _Color
プロパティは sRGB 空間の色である。
その変換を明示。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glTF Import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -38,7 +38,7 @@ static void Export_Color(Material m, TextureExporter textureManager, glTFMateria | |||
{ | |||
if (m.HasProperty("_Color")) | |||
{ | |||
material.pbrMetallicRoughness.baseColorFactor = m.color.linear.ToArray(); | |||
material.pbrMetallicRoughness.baseColorFactor = m.GetColor("_Color").ToFloat4(ColorSpace.sRGB, ColorSpace.Linear); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
glTF Export
@@ -160,7 +161,8 @@ public static glTF_VRM_Material CreateFromMaterial(Material m, TextureExporter t | |||
{ | |||
case ShaderPropertyType.Color: | |||
{ | |||
var value = m.GetColor(kv.Key).ToArray(); | |||
// No color conversion. Because color property is serialized to raw float array. | |||
var value = m.GetColor(kv.Key).ToFloat4(ColorSpace.Linear, ColorSpace.Linear); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VRM0.x Export
@@ -23,14 +24,14 @@ public override glTFMaterial ExportMaterial(Material m, TextureExporter textureE | |||
|
|||
pbrMetallicRoughness = new glTFPbrMetallicRoughness | |||
{ | |||
baseColorFactor = def.Color.LitColor.ToArray(), | |||
baseColorFactor = def.Color.LitColor.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VRM10 Export
material.SetColor(MToon.Utils.PropColor, m.pbrMetallicRoughness.baseColorFactor.ToColor4()); | ||
if (mtoon.ShadeColorFactor != null) material.SetColor(MToon.Utils.PropShadeColor, mtoon.ShadeColorFactor.ToColor3()); | ||
material.SetColor(MToon.Utils.PropColor, m.pbrMetallicRoughness.baseColorFactor | ||
.ToColor4(UniGLTF.ColorSpace.Linear, UniGLTF.ColorSpace.sRGB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VRM10 Import
@@ -315,7 +305,7 @@ public static void Migrate(glTF gltf, JsonNode json) | |||
var dst = new VRMC_materials_mtoon(); | |||
|
|||
// Color | |||
gltfMaterial.pbrMetallicRoughness.baseColorFactor = mtoon.Definition.Color.LitColor.ToFloat4(); | |||
gltfMaterial.pbrMetallicRoughness.baseColorFactor = mtoon.Definition.Color.LitColor.ToFloat4(ColorSpace.sRGB, ColorSpace.Linear); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migrate VRM0.x to VRM10
} | ||
|
||
private static Color ConvertColorSpace(this Color srcColor, ColorSpace srcColorSpace, ColorSpace dstColorSpace) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 x 2 = 4 pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よさそう
var color = src.pbrMetallicRoughness.baseColorFactor; | ||
param.Colors.Add("_Color", (new Color(color[0], color[1], color[2], color[3])).gamma); | ||
param.Colors.Add("_Color", | ||
src.pbrMetallicRoughness.baseColorFactor.ToColor4(ColorSpace.Linear, ColorSpace.sRGB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -153,7 +152,9 @@ public static bool TryCreateParam(GltfParser parser, int i, out MaterialImportPa | |||
|
|||
if (src.emissiveFactor != null && src.emissiveFactor.Length == 3) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
float[]
とUnityEngine.Color
間の変換において色空間を明示しないと変換できないようにした。