Radium Engine  1.5.20
Loading...
Searching...
No Matches
BlinnPhongMaterial.hpp
1#pragma once
2
3#include <Engine/RaEngine.hpp>
4
5#include <Core/Utils/Color.hpp>
6#include <Engine/Data/Material.hpp>
7#include <Engine/Data/Texture.hpp>
8
9#include <string>
10
11namespace Ra {
12namespace Core {
13namespace Asset {
14class MaterialData;
15}
16} // namespace Core
17
18namespace Engine {
19
20namespace Data {
21class ShaderProgram;
22
24namespace TextureSemantics {
26enum class BlinnPhongMaterial { TEX_DIFFUSE, TEX_SPECULAR, TEX_NORMAL, TEX_SHININESS, TEX_ALPHA };
27} // namespace TextureSemantics
29
36class RA_ENGINE_API BlinnPhongMaterial final
37 : public Material,
39 public MaterialTextureSet<TextureSemantics::BlinnPhongMaterial>
40{
41 friend class BlinnPhongMaterialConverter;
42
43 public:
45
50 explicit BlinnPhongMaterial( const std::string& instanceName );
51
52 void updateGL() override;
53 void updateFromParameters() override;
54 bool isTransparent() const override;
55
61 static void registerMaterial();
62
67 static void unregisterMaterial();
68
69 inline nlohmann::json getParametersMetadata() const override { return s_parametersMetadata; }
70
71 inline void setColoredByVertexAttrib( bool state ) override;
72
73 inline bool isColoredByVertexAttrib() const override { return m_perVertexColor; }
74
75 inline void setDiffuseColor( Core::Utils::Color c );
76 inline void setSpecularColor( Core::Utils::Color c );
77 inline void setSpecularExponent( Scalar n );
78 inline void setRenderAsSplat( bool state );
79
80 inline const Core::Utils::Color& getDiffuseColor() { return m_kd; }
81 inline const Core::Utils::Color& getSpecularColor() { return m_ks; }
82 inline Scalar getSpecularExponent() { return m_ns; }
83 inline bool isRenderAsSplat() { return m_renderAsSplat; }
84 inline void setAlpha( Scalar a );
85 inline Scalar getAlpha() { return m_alpha; }
86
87 private:
88 Core::Utils::Color m_kd { 0.7, 0.7, 0.7, 1.0 };
89 Core::Utils::Color m_ks { 0.3, 0.3, 0.3, 1.0 };
90 Scalar m_ns { 64.0 };
91 Scalar m_alpha { 1.0 };
92 bool m_perVertexColor { false };
93 bool m_renderAsSplat { false };
94 static nlohmann::json s_parametersMetadata;
95
98 void updateRenderingParameters();
99};
100
104class RA_ENGINE_API BlinnPhongMaterialConverter final
105{
106 public:
107 BlinnPhongMaterialConverter() = default;
109
110 Material* operator()( const Ra::Core::Asset::MaterialData* toconvert );
111};
112
114 if ( state != m_perVertexColor ) {
115 m_perVertexColor = state;
116 needUpdate();
117 }
118}
119
120inline void BlinnPhongMaterial::setSpecularExponent( Scalar n ) {
121 m_ns = n;
122 needUpdate();
123}
124
125inline void BlinnPhongMaterial::setSpecularColor( Core::Utils::Color c ) {
126 m_ks = std::move( c );
127 needUpdate();
128}
129
130inline void BlinnPhongMaterial::setDiffuseColor( Core::Utils::Color c ) {
131 m_kd = std::move( c );
132 needUpdate();
133}
134
135inline void BlinnPhongMaterial::setRenderAsSplat( bool state ) {
136 if ( state != m_renderAsSplat ) {
137 m_renderAsSplat = state;
138 needUpdate();
139 }
140}
141
142inline void BlinnPhongMaterial::setAlpha( Scalar a ) {
143 m_alpha = a;
144 needUpdate();
145}
146
147} // namespace Data
148} // namespace Engine
149} // namespace Ra
represent material data loaded by a file loader. Material data must be identified by a unique name....
bool isColoredByVertexAttrib() const override
Indicates if the material takes the VERTEX_COLOR attribute into account.
void setColoredByVertexAttrib(bool state) override
Makes the Material take its base color from the VERTEX_COLOR attribute of the rendered geometry.
nlohmann::json getParametersMetadata() const override
Get a json containing metadata about the parameters.
Base class to manage a set of textures indexed by semantic (enum).
Base class for materials.
Definition Material.hpp:24
void needUpdate()
Mark the Material as needing update before the next OpenGL call.
Definition Material.hpp:98
Interface to define metadata (constraints, description, ...) for the editing of parameter set.
T move(T... args)
BlinnPhongMaterial
BlinnPhongMaterial's textures.
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3