Skip to content

Commit

Permalink
Added materials tests
Browse files Browse the repository at this point in the history
Signed-off-by: ahcorde <[email protected]>
  • Loading branch information
ahcorde committed Mar 8, 2022
1 parent f77cd78 commit 0f34f61
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 127 additions & 0 deletions test/usd/upAxisZ.usda
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,131 @@ def Scope "Looks"
token outputs:out
}
}

def Material "Material_textures"
{
token outputs:mdl:displacement.connect = </Looks/Material_36/Shader.outputs:out>
token outputs:mdl:surface.connect = </Looks/Material_36/Shader.outputs:out>
token outputs:mdl:volume.connect = </Looks/Material_36/Shader.outputs:out>

def Shader "Shader"
{
uniform token info:implementationSource = "sourceAsset"
uniform asset info:mdl:sourceAsset = @OmniPBR.mdl@
uniform token info:mdl:sourceAsset:subIdentifier = "OmniPBR"
color3f inputs:diffuse_color_constant = (1, 1, 1) (
customData = {
float3 default = (0.2, 0.2, 0.2)
dictionary range = {
float3 max = (100000, 100000, 100000)
float3 min = (0, 0, 0)
}
}
displayGroup = "Albedo"
displayName = "Base Color"
doc = "This is the base color"
)
asset inputs:diffuse_texture = @materials/textures/FANS_Albedo.png@ (
colorSpace = "auto"
customData = {
asset default = @@
}
displayGroup = "Albedo"
displayName = "Base Map"
)
color3f inputs:emissive_color = (0, 0, 0) (
customData = {
float3 default = (1, 0.1, 0.1)
dictionary range = {
float3 max = (100000, 100000, 100000)
float3 min = (0, 0, 0)
}
}
displayGroup = "Emissive"
displayName = "Emissive Color"
doc = "The emission color"
)
float inputs:emissive_intensity = 1 (
customData = {
int default = 40
dictionary range = {
int max = 100000
int min = 0
}
}
displayGroup = "Emissive"
displayName = "Emissive Intensity"
doc = "Intensity of the emission"
)
bool inputs:enable_emission = 1 (
customData = {
int default = 0
}
displayGroup = "Emissive"
displayName = "Enable Emissive"
doc = "Enables the emission of light from the material"
)
float inputs:metallic_constant = 0.5 (
customData = {
double default = 0.5
dictionary range = {
int max = 1
int min = 0
}
}
displayGroup = "Reflectivity"
displayName = "Metallic Amount"
doc = "Metallic Material"
)
asset inputs:metallic_texture = @materials/textures/FANS_Metalness.png@ (
colorSpace = "raw"
customData = {
asset default = @@
}
displayGroup = "Reflectivity"
displayName = "Metallic Map"
)
asset inputs:normalmap_texture = @materials/textures/FANS_Normal.png@ (
colorSpace = "raw"
customData = {
asset default = @@
}
displayGroup = "Normal"
displayName = "Normal Map"
)
float inputs:reflection_roughness_constant = 0.5 (
customData = {
double default = 0.5
dictionary range = {
int max = 1
int min = 0
}
}
displayGroup = "Reflectivity"
displayName = "Roughness Amount"
doc = "Higher roughness values lead to more blurry reflections"
)
bool inputs:reflection_roughness_texture_influence = 1 (
colorSpace = "raw"
customData = {
int default = 0
dictionary range = {
int max = 1
int min = 0
}
}
displayGroup = "Reflectivity"
displayName = "Roughness Map Influence"
)
asset inputs:reflectionroughness_texture = @materials/textures/FANS_Roughness.png@ (
colorSpace = "raw"
customData = {
asset default = @@
}
displayGroup = "RoughnessMap"
displayName = "RoughnessMap Map"
)
token outputs:out
}
}
}
62 changes: 62 additions & 0 deletions usd/src/usd_parser/USDData_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <gtest/gtest.h>

#include <ignition/common/Filesystem.hh>
#include <ignition/common/Util.hh>

#include <ignition/utilities/ExtraTestMacros.hh>

Expand All @@ -27,6 +28,9 @@
#include "test_config.h"
#include "test_utils.hh"

#include <sdf/Material.hh>
#include <sdf/Pbr.hh>

/////////////////////////////////////////////////
TEST(USDData, Constructor)
{
Expand All @@ -35,14 +39,68 @@ TEST(USDData, Constructor)
sdf::usd::UsdErrors errors = data.Init();
EXPECT_EQ(1u, errors.size());

// Add test/usd directory to find some resources
auto systemPaths = ignition::common::systemPaths();
systemPaths->AddFilePaths(sdf::testing::TestFile("usd"));

// Open a valid USD file
{
std::string filename = sdf::testing::TestFile("usd", "upAxisZ.usda");
sdf::usd::USDData usdData(filename);
EXPECT_EQ(0u, usdData.Init().size());
EXPECT_EQ(0u, usdData.ParseMaterials().size());

EXPECT_EQ(1u, usdData.AllReferences().size());
EXPECT_EQ(2u, usdData.Models().size());
EXPECT_EQ(7u, usdData.Materials().size());

auto materials = usdData.Materials();

auto material0 = materials["Material_0"];
EXPECT_EQ(ignition::math::Color(0.8, 0.8, 0.8), material0.Diffuse());
EXPECT_EQ(ignition::math::Color(0, 0, 0), material0.Emissive());

auto material1 = materials["Material_1"];
EXPECT_EQ(ignition::math::Color(1, 0, 0), material1.Diffuse());
EXPECT_EQ(ignition::math::Color(0, 0, 0), material1.Emissive());

auto material2 = materials["Material_2"];
EXPECT_EQ(ignition::math::Color(0, 1, 0), material2.Diffuse());
EXPECT_EQ(ignition::math::Color(0, 0, 0), material2.Emissive());

auto material3 = materials["Material_3"];
EXPECT_EQ(ignition::math::Color(0, 0, 1), material3.Diffuse());
EXPECT_EQ(ignition::math::Color(0, 0, 0), material3.Emissive());

auto material4 = materials["Material_4"];
EXPECT_EQ(ignition::math::Color(1, 1, 0), material4.Diffuse());
EXPECT_EQ(ignition::math::Color(0, 0, 0), material4.Emissive());

auto material5 = materials["Material_5"];
EXPECT_EQ(ignition::math::Color(1, 0, 1), material5.Diffuse());
EXPECT_EQ(ignition::math::Color(0, 0, 0), material5.Emissive());

auto materialTextures = materials["Material_textures"];
const auto * pbr = materialTextures.PbrMaterial();
ASSERT_TRUE(pbr);
const auto * workflow = pbr->Workflow(sdf::PbrWorkflowType::METAL);
ASSERT_TRUE(workflow);
EXPECT_EQ(ignition::math::Color(1, 1, 1), materialTextures.Diffuse());
EXPECT_EQ(
"materials/textures/FANS_Albedo.png",
workflow->AlbedoMap());
EXPECT_EQ(ignition::math::Color(0, 0, 0), materialTextures.Emissive());
EXPECT_DOUBLE_EQ(0.5, workflow->Metalness());
EXPECT_EQ(
"materials/textures/FANS_Metalness.png",
workflow->MetalnessMap());
EXPECT_DOUBLE_EQ(0.5, workflow->Roughness());
EXPECT_EQ(
"materials/textures/FANS_Roughness.png",
workflow->RoughnessMap());
EXPECT_EQ(
"materials/textures/FANS_Normal.png",
workflow->NormalMap());

// Find a path inside the stage
auto boxStage = usdData.FindStage("box");
Expand All @@ -54,6 +112,10 @@ TEST(USDData, Constructor)
auto invalidStage = usdData.FindStage("invalid");
EXPECT_EQ("", invalidStage.first);
EXPECT_EQ(nullptr, invalidStage.second);

// Remove copied materials
ignition::common::removeAll(
ignition::common::joinPaths(ignition::common::cwd(), "materials"));
}
}

Expand Down

0 comments on commit 0f34f61

Please sign in to comment.