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 );