Radium Engine  1.5.20
Loading...
Searching...
No Matches
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
11namespace Ra {
12namespace Engine {
13namespace Data {
14static const std::string materialName { "Lambertian" };
15
16nlohmann::json LambertianMaterial::s_parametersMetadata = {};
17
19 SimpleMaterial( instanceName, materialName, Material::MaterialAspect::MAT_OPAQUE ) {}
20
22 // Get the Radium Resource location on the filesystem
23 auto resourcesRootDir { RadiumEngine::getInstance()->getResourcesDir() };
24 auto shaderProgramManager = RadiumEngine::getInstance()->getShaderProgramManager();
25
26 shaderProgramManager->addNamedString(
27 "/Lambertian.glsl", resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.glsl" );
28 // registering re-usable shaders
30 "Lambertian",
31 resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.vert.glsl",
32 resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.frag.glsl" );
33
35
36 Data::ShaderConfiguration zprepassconfig(
37 "ZprepassLambertian",
38 resourcesRootDir + "Shaders/Materials/Lambertian/Lambertian.vert.glsl",
39 resourcesRootDir + "Shaders/Materials/Lambertian/LambertianZPrepass.frag.glsl" );
41
42 // Registering technique
43 Rendering::EngineRenderTechniques::registerDefaultTechnique(
44 materialName, []( Rendering::RenderTechnique& rt, bool ) {
45 // Lighting pass
46 auto lightpass = Data::ShaderConfigurationFactory::getConfiguration( "Lambertian" );
48 // Z prepass
49 auto zprepass =
52 } );
53
54 // Registering parameters metadata
55 SimpleMaterial::loadMetaData( s_parametersMetadata );
56}
57
59 Rendering::EngineRenderTechniques::removeDefaultTechnique( materialName );
60}
61
63 auto& renderParameters = getParameters();
64 setColor( renderParameters.getVariable<Core::Utils::Color>( "material.color" ) );
65 setColoredByVertexAttrib( renderParameters.getVariable<bool>( "material.perVertexColor" ) );
66}
67
69 return s_parametersMetadata;
70}
71
72} // namespace Data
73} // namespace Engine
74} // namespace Ra
LambertianMaterial(const std::string &instanceName)
Construct a named Lambertian material.
void updateFromParameters() override
Update the attributes of the ShaderParameterProvider to their actual values stored in the renderParam...
static void unregisterMaterial()
Remove the material from the material library.
nlohmann::json getParametersMetadata() const override
Get a json containing metadata about the parameters.
static void registerMaterial()
Register the material in the material library.
Base class for materials.
Definition Material.hpp:24
MaterialAspect
Identifies the type of the material.
Definition Material.hpp:31
Base implementation for simple, monocolored, materials.
static void loadMetaData(nlohmann::json &destination)
Load the material parameter description.
void setColoredByVertexAttrib(bool state) override
Makes the Material take its base color from the VERTEX_COLOR attribute of the rendered geometry.
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)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3