Radium Engine  1.5.0
LambertianMaterial.cpp
1 #include <Engine/Data/LambertianMaterial.hpp>
2 
3 #include <Engine/Data/ShaderConfigFactory.hpp>
4 #include <Engine/Data/ShaderProgramManager.hpp>
5 #include <Engine/Data/TextureManager.hpp>
6 #include <Engine/RadiumEngine.hpp>
7 #include <Engine/Rendering/RenderTechnique.hpp>
8 
9 #include <fstream>
10 
11 namespace Ra {
12 namespace Engine {
13 namespace Data {
14 static const std::string materialName { "Lambertian" };
15 
16 nlohmann::json LambertianMaterial::s_parametersMetadata = {};
17 
18 LambertianMaterial::LambertianMaterial( const std::string& instanceName ) :
19  SimpleMaterial( instanceName, materialName, Material::MaterialAspect::MAT_OPAQUE ) {}
20 
22 
24  // Get the Radium Resource location on the filesystem
25  auto resourcesRootDir { RadiumEngine::getInstance()->getResourcesDir() };
26  auto shaderProgramManager = RadiumEngine::getInstance()->getShaderProgramManager();
27 
28  shaderProgramManager->addNamedString(
29  "/Lambertian.glsl", resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.glsl" );
30  // registering re-usable shaders
32  "Lambertian",
33  resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.vert.glsl",
34  resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.frag.glsl" );
35 
37 
38  Data::ShaderConfiguration zprepassconfig(
39  "ZprepassLambertian",
40  resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.vert.glsl",
41  resourcesRootDir + "Shaders/Materials/Lambertian/LambertianZPrepass.frag.glsl" );
43 
44  // Registering technique
45  Rendering::EngineRenderTechniques::registerDefaultTechnique(
46  materialName, []( Rendering::RenderTechnique& rt, bool ) {
47  // Lighting pass
48  auto lightpass = Data::ShaderConfigurationFactory::getConfiguration( "Lambertian" );
49  rt.setConfiguration( *lightpass, Rendering::DefaultRenderingPasses::LIGHTING_OPAQUE );
50  // Z prepass
51  auto zprepass =
53  rt.setConfiguration( *zprepass, Rendering::DefaultRenderingPasses::Z_PREPASS );
54  } );
55 
56  // Registering parameters metadata
57  SimpleMaterial::loadMetaData( s_parametersMetadata );
58 }
59 
61  Rendering::EngineRenderTechniques::removeDefaultTechnique( materialName );
62 }
63 
65  auto& renderParameters = getParameters();
66  m_color = renderParameters.getParameter<Core::Utils::Color>( "material.color" );
67  m_perVertexColor = renderParameters.getParameter<bool>( "material.perVertexColor" );
68 }
69 
71  return s_parametersMetadata;
72 }
73 
74 } // namespace Data
75 } // namespace Engine
76 } // namespace Ra
LambertianMaterial(const std::string &instanceName)
void updateFromParameters() override
Update the attributes of the ShaderParameterProvider to their actual values stored in the renderParam...
nlohmann::json getParametersMetadata() const override
static void loadMetaData(nlohmann::json &destination)
Load the material parameter description.
Core::Utils::Color m_color
The base color of the material.
void setConfiguration(const Data::ShaderConfiguration &newConfig, Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
void addConfiguration(const ShaderConfiguration &config)
Core::Utils::optional< ShaderConfiguration > getConfiguration(const std::string &name)
Definition: Cage.cpp:3