feat: add unity-aligned shader contract metadata

This commit is contained in:
2026-04-03 00:01:31 +08:00
parent b43d4048b8
commit 6636834b35
9 changed files with 484 additions and 0 deletions

View File

@@ -446,6 +446,39 @@ TEST(RenderMaterialUtility_Test, ResolvesBuiltinForwardMaterialContractFromCanon
EXPECT_EQ(ResolveBuiltinBaseColorTexture(&aliasMaterial), baseColorTexture);
}
TEST(RenderMaterialUtility_Test, ResolvesBuiltinForwardMaterialContractFromShaderSemanticMetadata) {
auto* shader = new Shader();
ShaderPropertyDesc colorProperty = {};
colorProperty.name = "TintColor";
colorProperty.displayName = "Tint";
colorProperty.type = ShaderPropertyType::Color;
colorProperty.semantic = "BaseColor";
shader->AddProperty(colorProperty);
ShaderPropertyDesc textureProperty = {};
textureProperty.name = "AlbedoMap";
textureProperty.displayName = "Albedo";
textureProperty.type = ShaderPropertyType::Texture2D;
textureProperty.semantic = "BaseColorTexture";
shader->AddProperty(textureProperty);
Material material;
material.SetShader(ResourceHandle<Shader>(shader));
material.SetFloat4("TintColor", Vector4(0.3f, 0.5f, 0.7f, 0.9f));
Texture* texture = new Texture();
IResource::ConstructParams textureParams = {};
textureParams.name = "SemanticTexture";
textureParams.path = "Textures/semantic_base_color.texture";
textureParams.guid = ResourceGUID::Generate(textureParams.path);
texture->Initialize(textureParams);
material.SetTexture("AlbedoMap", ResourceHandle<Texture>(texture));
EXPECT_EQ(ResolveBuiltinBaseColorFactor(&material), Vector4(0.3f, 0.5f, 0.7f, 0.9f));
EXPECT_EQ(ResolveBuiltinBaseColorTexture(&material), texture);
}
TEST(RenderMaterialUtility_Test, UsesOpacityOnlyWhenBaseColorFactorIsMissing) {
Material material;
material.SetFloat("opacity", 0.35f);