Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.27
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RawShaderMaterial.cpp
1#include <Engine/Data/MaterialConverters.hpp>
2#include <Engine/Data/RawShaderMaterial.hpp>
3#include <Engine/Data/ShaderConfigFactory.hpp>
4#include <Engine/Rendering/RenderTechnique.hpp>
5#include <cstddef>
6#include <optional>
7
8namespace Ra {
9namespace Engine {
10namespace Data {
11
13 const std::string& instanceName,
16 Material( instanceName, instanceName, Material::MaterialAspect::MAT_OPAQUE ),
17 m_shaders { shaders },
18 m_paramProvider { std::move( paramProvider ) } {
19 m_materialKey = computeKey();
20 setMaterialName( m_materialKey );
22}
23
24RawShaderMaterial::~RawShaderMaterial() {
25 Rendering::EngineRenderTechniques::removeDefaultTechnique( m_materialKey );
26}
27
28std::string RawShaderMaterial::computeKey() {
29 // Hash the shader source to obtain identification keys
30 auto content = std::to_string( std::size_t( this ) );
31 for ( const auto& p : m_shaders ) {
32 content += p.second;
33 content += std::to_string( std::size_t( this ) );
34 }
35 return std::to_string( std::hash<std::string> {}( content ) );
36}
37
39 // Generate configuration using the given glsl source.
40 // The configuration key/name is the hash of shader sources
41 // The same configuration will be used as z-prepass config and opaque pass config.
42 Data::ShaderConfiguration myConfig { m_materialKey };
43 for ( const auto& p : m_shaders ) {
44 myConfig.addShaderSource( p.first, p.second );
45 }
47 // Register the technique builder for the custom material
48 // For now, as we can't change the material name, always use the key of the initial
49 // configuration
50 auto materialKey { m_materialKey };
51
52 Rendering::EngineRenderTechniques::registerDefaultTechnique(
53 materialKey, [materialKey]( Rendering::RenderTechnique& rt, bool ) {
54 // Configure the technique to render this object using forward Renderer or any
55 // compatible one Main pass (Mandatory) : BlinnPhong
58 // Z prepass use the same config
60 } );
61}
62
64 // Defining the material converter
65 EngineMaterialConverters::registerMaterialConverter( "Ra::Engine::Data::RawShaderMaterial",
67}
68
70 EngineMaterialConverters::removeMaterialConverter( "Ra::Engine::Data::RawShaderMaterial" );
71}
72
74 // update the state of the parameter provider
75 m_paramProvider->updateGL();
76}
77
82 Rendering::EngineRenderTechniques::removeDefaultTechnique( m_materialKey );
83 m_shaders = shaders;
84 if ( paramProvider ) { m_paramProvider = std::move( paramProvider ); }
85 m_materialKey = computeKey();
86 setMaterialName( m_materialKey );
88}
89} // namespace Data
90} // namespace Engine
91} // namespace Ra
Base class for materials.
Definition Material.hpp:24
void setMaterialName(std::string newName)
Change the material name.
Definition Material.hpp:115
MaterialAspect
Identifies the type of the material.
Definition Material.hpp:31
void updateShaders(const std::vector< std::pair< Data::ShaderType, std::string > > &shaders, std::shared_ptr< Data::ShaderParameterProvider > paramProvider=nullptr)
RawShaderMaterial(const std::string &instanceName, const std::vector< std::pair< Data::ShaderType, std::string > > &shaders, std::shared_ptr< Data::ShaderParameterProvider > paramProvider)
void setConfiguration(const Data::ShaderConfiguration &newConfig, Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
T move(T... args)
bool removeMaterialConverter(const std::string &name)
bool registerMaterialConverter(const std::string &name, ConverterFunction converter)
void addConfiguration(const ShaderConfiguration &config)
Core::Utils::optional< ShaderConfiguration > getConfiguration(const std::string &name)
bool removeConfiguration(const std::string &configName)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4
STL namespace.
T to_string(T... args)