Radium Engine  1.5.0
PlainMaterial.cpp
1 #include <Engine/Data/PlainMaterial.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 
15 static const std::string materialName { "Plain" };
16 
17 nlohmann::json PlainMaterial::s_parametersMetadata = {};
18 
19 PlainMaterial::PlainMaterial( const std::string& instanceName ) :
20  SimpleMaterial( instanceName, materialName, Material::MaterialAspect::MAT_OPAQUE ) {}
21 
23 
25  // Get the Radium Resource location on the filesystem
26  auto resourcesRootDir { RadiumEngine::getInstance()->getResourcesDir() };
27  auto shaderProgramManager = RadiumEngine::getInstance()->getShaderProgramManager();
28 
29  shaderProgramManager->addNamedString( "/Plain.glsl",
30  resourcesRootDir + "Shaders/Materials/Plain/Plain.glsl" );
31  // registering re-usable shaders
33  "Plain",
34  resourcesRootDir + "Shaders/Materials/Plain/Plain.vert.glsl",
35  resourcesRootDir + "Shaders/Materials/Plain/Plain.frag.glsl" );
36 
38 
39  Data::ShaderConfiguration zprepassconfig(
40  "ZprepassPlain",
41  resourcesRootDir + "Shaders/Materials/Plain/Plain.vert.glsl",
42  resourcesRootDir + "Shaders/Materials/Plain/PlainZPrepass.frag.glsl" );
44 
45  // Registering technique
46  Rendering::EngineRenderTechniques::registerDefaultTechnique(
47  materialName, []( Rendering::RenderTechnique& rt, bool ) {
48  // Lighting pass
49  auto lightpass = Data::ShaderConfigurationFactory::getConfiguration( "Plain" );
50  rt.setConfiguration( *lightpass, Rendering::DefaultRenderingPasses::LIGHTING_OPAQUE );
51  // Z prepass
52  auto zprepass = Data::ShaderConfigurationFactory::getConfiguration( "ZprepassPlain" );
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( "Plain" );
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 
70 nlohmann::json PlainMaterial::getParametersMetadata() const {
71  return s_parametersMetadata;
72 }
73 
74 } // namespace Data
75 } // namespace Engine
76 } // namespace Ra
nlohmann::json getParametersMetadata() const override
PlainMaterial(const std::string &instanceName)
void updateFromParameters() override
Update the attributes of the ShaderParameterProvider to their actual values stored in the renderParam...
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