1#include <catch2/catch_test_macros.hpp>
3#include <Engine/Data/BlinnPhongMaterial.hpp>
4#include <Engine/Data/LambertianMaterial.hpp>
5#include <Engine/Data/PlainMaterial.hpp>
6#include <Engine/Data/VolumetricMaterial.hpp>
7#include <Engine/RadiumEngine.hpp>
9#include <Headless/CLIViewer.hpp>
10#ifdef HEADLESS_HAS_EGL
11# include <Headless/OpenGLContext/EglOpenGLContext.hpp>
13# include <Headless/OpenGLContext/GlfwOpenGLContext.hpp>
16#include "../unittestUtils.hpp"
18using namespace Ra::Headless;
21struct PrintThemAll :
public PrintAllHelper<RenderParameters::BindableTypes> {};
23TEST_CASE(
"Engine/Data/Materials",
"[unittests][Engine][Engine/Data][Materials]" ) {
26 glbinding::Version glVersion { 4, 4 };
27#ifdef HEADLESS_HAS_EGL
28 CLIViewer viewer { std::make_unique<EglOpenGLContext>( glVersion ) };
30 CLIViewer viewer { std::make_unique<GlfwOpenGLContext>( glVersion ) };
32 const char* testName =
"Materials testing";
33 auto code = viewer.init( 1, &testName );
35 SECTION(
"Blinn-Phong material" ) {
36 LOG( Ra::Core::Utils::logINFO ) <<
"Testing Blinn-Phong material";
41 REQUIRE( bp.getAlpha() == 1.0 );
42 REQUIRE( !bp.isColoredByVertexAttrib() );
44 bp.setColoredByVertexAttrib(
true );
45 REQUIRE( bp.isColoredByVertexAttrib() ==
true );
48 auto& bpParameters = bp.getParameters();
50 bpParameters.visit( PrintThemAll {} );
52 REQUIRE( bpParameters.existsVariable<
bool>(
"material.hasPerVertexKd" ) );
53 REQUIRE( bpParameters.existsVariable<Scalar>(
"material.alpha" ) );
55 auto& pvc = bpParameters.getVariable<
bool>(
"material.hasPerVertexKd" );
56 REQUIRE( pvc == bp.isColoredByVertexAttrib() );
58 auto& alp = bpParameters.getVariable<Scalar>(
"material.alpha" );
59 REQUIRE( alp == bp.getAlpha() );
62 bpParameters.setVariable(
"material.hasPerVertexKd", !pvc );
63 bpParameters.setVariable(
"material.alpha", 0.5_ra );
64 REQUIRE( pvc != bp.isColoredByVertexAttrib() );
65 REQUIRE( alp != bp.getAlpha() );
68 bp.updateFromParameters();
69 REQUIRE( pvc == bp.isColoredByVertexAttrib() );
70 REQUIRE( alp == bp.getAlpha() );
71 LOG( Ra::Core::Utils::logINFO ) <<
"Blinn-Phong material tested.\n";
74 SECTION(
"Lambertian material" ) {
75 LOG( Ra::Core::Utils::logINFO ) <<
"Testing Lambertian material";
79 REQUIRE( !mat.isColoredByVertexAttrib() );
81 mat.setColoredByVertexAttrib(
true );
82 REQUIRE( mat.isColoredByVertexAttrib() );
85 auto& matParameters = mat.getParameters();
87 REQUIRE( matParameters.existsVariable<
bool>(
"material.perVertexColor" ) );
88 auto& pvc = matParameters.getVariable<
bool>(
"material.perVertexColor" );
89 REQUIRE( pvc == mat.isColoredByVertexAttrib() );
92 matParameters.setVariable(
"material.perVertexColor", !pvc );
93 REQUIRE( pvc != mat.isColoredByVertexAttrib() );
96 mat.updateFromParameters();
97 REQUIRE( pvc == mat.isColoredByVertexAttrib() );
98 LOG( Ra::Core::Utils::logINFO ) <<
"Lambertian material tested.\n";
101 SECTION(
"Plain material" ) {
102 LOG( Ra::Core::Utils::logINFO ) <<
"Testing Plain material";
103 REQUIRE( code == 0 );
106 REQUIRE( !mat.isColoredByVertexAttrib() );
108 mat.setColoredByVertexAttrib(
true );
109 REQUIRE( mat.isColoredByVertexAttrib() );
112 auto& matParameters = mat.getParameters();
114 REQUIRE( matParameters.existsVariable<
bool>(
"material.perVertexColor" ) );
115 auto& pvc = matParameters.getVariable<
bool>(
"material.perVertexColor" );
116 REQUIRE( pvc == mat.isColoredByVertexAttrib() );
119 matParameters.setVariable(
"material.perVertexColor", !pvc );
120 REQUIRE( pvc != mat.isColoredByVertexAttrib() );
123 mat.updateFromParameters();
124 REQUIRE( pvc == mat.isColoredByVertexAttrib() );
125 LOG( Ra::Core::Utils::logINFO ) <<
"Plain material tested.\n";
128 SECTION(
"Volumetric material" ) {
129 LOG( Ra::Core::Utils::logINFO ) <<
"Testing Volumetric material";
130 REQUIRE( code == 0 );
136 { gl::GL_CLAMP_TO_EDGE,
137 gl::GL_CLAMP_TO_EDGE,
138 gl::GL_CLAMP_TO_EDGE,
141 { gl::GL_TEXTURE_3D, 1, 1, 1, gl::GL_RED, gl::GL_RED, gl::GL_FLOAT,
false, d } } };
143 mat.setTexture( &density );
145 REQUIRE( mat.m_g == 0_ra );
148 auto& matParameters = mat.getParameters();
149 REQUIRE( matParameters.existsVariable<Scalar>(
"material.g" ) );
151 auto& g = matParameters.getVariable<Scalar>(
"material.g" );
152 REQUIRE( g == 0_ra );
155 matParameters.setVariable(
"material.g", 0.5_ra );
156 REQUIRE( g != mat.m_g );
159 mat.updateFromParameters();
160 REQUIRE( g == mat.m_g );
161 LOG( Ra::Core::Utils::logINFO ) <<
"Volumetric material tested.\n";
164 SECTION(
"Metadata verification" ) {
166 auto bpMetadata = bp.getParametersMetadata();
167 REQUIRE( bpMetadata.contains(
"material.tex.ns" ) );
168 REQUIRE( bpMetadata[
"material.tex.ns"].contains(
"type" ) );
169 REQUIRE( bpMetadata[
"material.tex.ns"][
"type"] ==
"texture" );
172 auto lmMetadata = lm.getParametersMetadata();
173 REQUIRE( lmMetadata.contains(
"material.tex.color" ) );
174 REQUIRE( lmMetadata[
"material.tex.color"].contains(
"type" ) );
175 REQUIRE( lmMetadata[
"material.tex.color"][
"type"] ==
"texture" );
178 auto pmMetadata = pm.getParametersMetadata();
179 REQUIRE( pmMetadata.contains(
"material.tex.color" ) );
180 REQUIRE( pmMetadata[
"material.tex.color"].contains(
"type" ) );
181 REQUIRE( pmMetadata[
"material.tex.color"][
"type"] ==
"texture" );
184 auto vmMetadata = vm.getParametersMetadata();
185 REQUIRE( vmMetadata.contains(
"material.sigma_a" ) );
186 REQUIRE( vmMetadata[
"material.sigma_a"].contains(
"type" ) );
187 REQUIRE( vmMetadata[
"material.sigma_a"][
"type"] ==
"array" );
189 nlohmann::json destination;
191 REQUIRE( destination.empty() );
Implementation of the Lambertian Material BSDF.
static void loadMetaData(const std::string &basename, nlohmann::json &destination)
Load the ParameterSet description.
Represent a Texture of the engine.
void initializeNow()
Generate the GPU representation of the texture right now. Need an active OpenGL context.
(GPU) Data representation, along with manager
Types, list of types as Ra::Core::Utils::TypeList< ... >