Add complex test to MetallicRoughnessConverter

This commit is contained in:
Masataka SUMI
2021-05-27 22:45:21 +09:00
parent 9aee0b1ea3
commit 388a7fbc6e
2 changed files with 35 additions and 23 deletions

View File

@@ -49,15 +49,17 @@
fixed4 frag (v2f i) : SV_Target
{
half4 metallicRoughness = tex2D(_GltfMetallicRoughnessTexture, i.uv);
half metallic = metallicRoughness.b * _GltfMetallicFactor;
half roughness = metallicRoughness.g * _GltfRoughnessFactor;
half occlusion = tex2D(_GltfOcclusionTexture, i.uv).r;
half4 metallicRoughnessTex = tex2D(_GltfMetallicRoughnessTexture, i.uv);
half4 occlusionTex = tex2D(_GltfOcclusionTexture, i.uv);
half occlusion = occlusionTex.r; // R: glTF Occlusion
half roughness = metallicRoughnessTex.g * _GltfRoughnessFactor; // G: glTF Roughness
half metallic = metallicRoughnessTex.b * _GltfMetallicFactor; // B: glTF Metallic
fixed4 result;
result.r = metallic; // R: Unity Metallic
result.g = occlusion; // G: Unity Occlusion
result.b = 0; // B: Unity Heightmap (no use)
result.r = metallic; // R: Unity Metallic
result.g = occlusion; // G: Unity Occlusion
result.b = 0; // B: Unity Heightmap (no use)
result.a = 1.0 - roughness; // A: Unity Smoothness
return result;

View File

@@ -76,45 +76,55 @@ namespace VRMShaders
var roughnessFactor = 1.0f;
Assert.That(
ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
// r <- 255 : Same metallic (src.r)
// g <- 0 : (Unused)
// r <- 255 : metallic (metallicRoughness.b * metallicFactor)
// g <- 0 : occlusion (occlusion.r)
// b <- 0 : (Unused)
// a <- 0 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
// a <- 0 : smoothness (1.0 - (metallicRoughness.g * roughnessFactor))
Is.EqualTo(new Color32(255, 0, 0, 0)));
}
{
var roughnessFactor = 1.0f;
Assert.That(
ImportPixel(new Color32(255, 128, 255, 255), 1.0f, roughnessFactor, default),
// r <- 255 : Same metallic (src.r)
// g <- 0 : (Unused)
ImportPixel(new Color32(255, 127, 255, 255), 1.0f, roughnessFactor, default),
// r <- 255 : metallic (metallicRoughness.b * metallicFactor)
// g <- 0 : occlusion (occlusion.r)
// b <- 0 : (Unused)
// a <- 128 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
Is.EqualTo(new Color32(255, 0, 0, 127))); // smoothness 0.5 * src.a 1.0
// a <- 128 : smoothness (1.0 - (metallicRoughness.g * roughnessFactor))
Is.EqualTo(new Color32(255, 0, 0, 128))); // A:smoothness = 1.0 - (0.5 * 1.0) = 0.5
}
{
var roughnessFactor = 0.5f;
Assert.That(
ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
// r <- 255 : Same metallic (src.r)
// g <- 0 : (Unused)
ImportPixel(new Color32(255, 127, 255, 255), 1.0f, roughnessFactor, default),
// r <- 255 : metallic (metallicRoughness.b * metallicFactor)
// g <- 0 : occlusion (occlusion.r)
// b <- 0 : (Unused)
// a <- 74 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
Is.EqualTo(new Color32(255, 0, 0, 127)));
// a <- 191 : smoothness (1.0 - (metallicRoughness.g * roughnessFactor))
Is.EqualTo(new Color32(255, 0, 0, 191))); // A:smoothness = 1.0 - (0.5 * 0.5) = 0.75
}
{
var roughnessFactor = 0.0f;
Assert.That(
ImportPixel(new Color32(255, 255, 255, 255), 1.0f, roughnessFactor, default),
// r <- 255 : Same metallic (src.r)
// g <- 0 : (Unused)
// r <- 255 : metallic (metallicRoughness.b * metallicFactor)
// g <- 0 : occlusion (occlusion.r)
// b <- 0 : (Unused)
// a <- 255 : ((1 - sqrt(src.g(as float) * roughnessFactor)))(as uint8)
// a <- 255 : smoothness (1.0 - (metallicRoughness.g * roughnessFactor))
Is.EqualTo(new Color32(255, 0, 0, 255)));
}
{
Assert.That(
ImportPixel(new Color32(222, 200, 100, 255), 0.5f, 0.25f, new Color32(127, 0, 0, 0)),
// r <- 50 : metallic (metallicRoughness.b * metallicFactor)
// g <- 127 : occlusion (occlusion.r)
// b <- 0 : (Unused)
// a <- 205 : smoothness (1.0 - (metallicRoughness.g * roughnessFactor))
Is.EqualTo(new Color32(50, 127, 0, 205)));
}
}
[Test]