1#include <Core/Asset/BlinnPhongMaterialData.hpp>
2#include <Engine/Data/BlinnPhongMaterial.hpp>
3#include <Engine/Data/MaterialConverters.hpp>
4#include <Engine/Data/ShaderConfigFactory.hpp>
5#include <Engine/Data/ShaderProgramManager.hpp>
6#include <Engine/Data/TextureManager.hpp>
7#include <Engine/RadiumEngine.hpp>
8#include <Engine/Rendering/RenderTechnique.hpp>
15static const std::string materialName {
"BlinnPhong" };
17nlohmann::json BlinnPhongMaterial::s_parametersMetadata = {};
22void BlinnPhongMaterial::updateRenderingParameters() {
24 auto& renderParameters = getParameters();
25 renderParameters.setVariable(
"material.kd", m_kd );
26 renderParameters.setVariable(
"material.hasPerVertexKd", m_perVertexColor );
27 renderParameters.setVariable(
"material.renderAsSplat", m_renderAsSplat );
28 renderParameters.setVariable(
"material.ks", m_ks );
29 renderParameters.setVariable(
"material.ns", m_ns );
30 renderParameters.setVariable(
"material.alpha",
std::min( m_alpha, m_kd[3] ) );
32 if ( tex !=
nullptr ) { renderParameters.setTexture(
"material.tex.kd", tex ); }
33 renderParameters.setVariable(
"material.tex.hasKd", tex !=
nullptr );
34 tex =
getTexture( BlinnPhongMaterial::TextureSemantic::TEX_SPECULAR );
35 if ( tex !=
nullptr ) { renderParameters.setTexture(
"material.tex.ks", tex ); }
36 renderParameters.setVariable(
"material.tex.hasKs", tex !=
nullptr );
37 tex =
getTexture( BlinnPhongMaterial::TextureSemantic::TEX_NORMAL );
38 if ( tex !=
nullptr ) { renderParameters.setTexture(
"material.tex.normal", tex ); }
39 renderParameters.setVariable(
"material.tex.hasNormal", tex !=
nullptr );
40 tex =
getTexture( BlinnPhongMaterial::TextureSemantic::TEX_SHININESS );
41 if ( tex !=
nullptr ) { renderParameters.setTexture(
"material.tex.ns", tex ); }
42 renderParameters.setVariable(
"material.tex.hasNs", tex !=
nullptr );
43 tex =
getTexture( BlinnPhongMaterial::TextureSemantic::TEX_ALPHA );
44 if ( tex !=
nullptr ) { renderParameters.setTexture(
"material.tex.alpha", tex ); }
45 renderParameters.setVariable(
"material.tex.hasAlpha", tex !=
nullptr );
51 updateRenderingParameters();
56 auto& renderParameters = getParameters();
58 m_perVertexColor = renderParameters.getVariable<
bool>(
"material.hasPerVertexKd" );
59 m_renderAsSplat = renderParameters.getVariable<
bool>(
"material.renderAsSplat" );
61 m_ns = renderParameters.getVariable<Scalar>(
"material.ns" );
62 m_alpha = renderParameters.getVariable<Scalar>(
"material.alpha" );
71 auto resourcesRootDir { RadiumEngine::getInstance()->getResourcesDir() };
72 auto shaderProgramManager = RadiumEngine::getInstance()->getShaderProgramManager();
79 shaderProgramManager->addNamedString(
80 "/BlinnPhong.glsl", resourcesRootDir +
"Shaders/Materials/BlinnPhong/BlinnPhong.glsl" );
84 resourcesRootDir +
"Shaders/Materials/BlinnPhong/BlinnPhong.vert.glsl",
85 resourcesRootDir +
"Shaders/Materials/BlinnPhong/BlinnPhong.frag.glsl" );
90 resourcesRootDir +
"Shaders/Materials/BlinnPhong/BlinnPhong.vert.glsl",
91 resourcesRootDir +
"Shaders/Materials/BlinnPhong/BlinnPhongZPrepass.frag.glsl" );
96 resourcesRootDir +
"Shaders/Materials/BlinnPhong/BlinnPhong.vert.glsl",
97 resourcesRootDir +
"Shaders/Materials/BlinnPhong/LitOITBlinnPhong.frag.glsl" );
101 Rendering::EngineRenderTechniques::registerDefaultTechnique(
116 auto transparentpass =
129 Rendering::EngineRenderTechniques::removeDefaultTechnique( materialName );
137 auto source =
static_cast<const Ra::Core::Asset::BlinnPhongMaterialData*
>( toconvert );
139 if ( source->hasDiffuse() ) result->m_kd = source->m_diffuse;
140 if ( source->hasSpecular() ) result->m_ks = source->m_specular;
141 if ( source->hasShininess() ) result->m_ns = source->m_shininess;
142 if ( source->hasOpacity() ) result->m_alpha = source->m_opacity;
144 data.sampler.
wrapS = GL_REPEAT;
145 data.sampler.
wrapT = GL_REPEAT;
146 data.sampler.
minFilter = GL_LINEAR_MIPMAP_LINEAR;
147 auto texManager = RadiumEngine::getInstance()->getTextureManager();
148 if ( source->hasDiffuseTexture() ) {
149 data.name =
"diffuse";
150 data.image = texManager->loadTextureImage( source->m_texDiffuse,
true );
151 result->addTexture( BlinnPhongMaterial::TextureSemantic::TEX_DIFFUSE, data );
153 if ( source->hasSpecularTexture() ) {
154 data.name =
"specular";
155 data.image = texManager->loadTextureImage( source->m_texSpecular,
true );
156 result->addTexture( BlinnPhongMaterial::TextureSemantic::TEX_SPECULAR, data );
158 if ( source->hasShininessTexture() ) {
159 data.name =
"shininess";
160 data.image = texManager->loadTextureImage( source->m_texShininess,
false );
161 result->addTexture( BlinnPhongMaterial::TextureSemantic::TEX_SHININESS, data );
164 if ( source->hasOpacityTexture() ) {
165 data.name =
"opacity";
166 data.image = texManager->loadTextureImage( source->m_texOpacity,
false );
167 result->addTexture( BlinnPhongMaterial::TextureSemantic::TEX_ALPHA, data );
169 if ( source->hasNormalTexture() ) {
170 data.name =
"normal";
171 data.image = texManager->loadTextureImage( source->m_texNormal,
false );
172 result->addTexture( BlinnPhongMaterial::TextureSemantic::TEX_NORMAL, data );
virtual const std::string & getName() const
Acces to the name of the asset.
represent material data loaded by a file loader. Material data must be identified by a unique name....
static void registerMaterial()
BlinnPhongMaterial(const std::string &instanceName)
Construct a named BlinnPhongMaterial.
bool isTransparent() const override
void updateFromParameters() override
Update the attributes of the ShaderParameterProvider to their actual values stored in the renderParam...
static void unregisterMaterial()
void updateGL() override
Update the OpenGL states used by the ShaderParameterProvider.
Texture * getTexture(const TextureSemantics::BlinnPhongMaterial &semantic) const
Base class for materials.
bool isDirty()
Return dirty state.
void setClean()
Set dirty state to false.
MaterialAspect
Identifies the type of the material.
virtual bool isTransparent() const
static void loadMetaData(const std::string &basename, nlohmann::json &destination)
Load the ParameterSet description.
Represent a Texture of the engine.
void setConfiguration(const Data::ShaderConfiguration &newConfig, Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
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)
hepler function to manage enum as underlying types in VariableSet
GLenum wrapT
OpenGL wrap mode in the t direction.
GLenum minFilter
OpenGL minification filter ( GL_LINEAR or GL_NEAREST or GL_XXX_MIPMAP_YYY )
GLenum wrapS
OpenGL wrap mode in the s direction.
Describes the sampler and image of a texture.