1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0032201: Visualization, TKOpenGl - unify Phong/PBR material properties getters

Graphic3d_ShaderManager::stdComputeLighting() - implementation has been adjusted
for better consistency between PBR / non-PBR.

OpenGl_Material definition has been modified to join Front/Back pair into a single uniform variable.
Common material definition now occupies 4x2 vec4 instead of 5x2 vec4.

Getters of Common material properties within Declarations.glsl
have been renamed to match PBR material syntax (e.g. take IsFront flag as function argument).
Auxliary macros (like occTextureColor()) has been renamed (like occMaterialBaseColor())
and adjusted to return material property directly instead of taking it as argument.
This commit is contained in:
kgv 2021-03-05 17:26:47 +03:00 committed by bugmaster
parent a604968547
commit 941f6cae55
23 changed files with 245 additions and 273 deletions

View File

@ -2211,8 +2211,13 @@ BRep and Binary BRep Shape formats (only in case of triangulation-only Faces, wi
Versions of formats have been changed (11 for BinOCAF, 10 for XmlOCAF, 4 for BRep Shape and 3 for Binary BRep Shape). Versions of formats have been changed (11 for BinOCAF, 10 for XmlOCAF, 4 for BRep Shape and 3 for Binary BRep Shape).
Files written with the new version will not be readable by applications of old versions. Files written with the new version will not be readable by applications of old versions.
@subsection upgrade_occt760_poly Changes in *Poly* package and *Poly_Triangulation* class: @subsection upgrade_occt760_poly Changes in *Poly* package and *Poly_Triangulation* class
*Poly_Triangulation* does no more provide access to internal array structures: methods Nodes(), ChangeNode(), Triangles(), ChangeTriangle(), UVNodes(), ChangeUVNode(), Normals() have been removed. *Poly_Triangulation* does no more provide access to internal array structures: methods Nodes(), ChangeNode(), Triangles(), ChangeTriangle(), UVNodes(), ChangeUVNode(), Normals() have been removed.
Methods of *Poly_Triangulation* for accessing individual nodal properties / triangles by index and implementing copy semantics should be used instead. Methods of *Poly_Triangulation* for accessing individual nodal properties / triangles by index and implementing copy semantics should be used instead.
The same is applicable to *Poly_PolygonOnTriangulation* interface. The same is applicable to *Poly_PolygonOnTriangulation* interface.
@subsection upgrade_occt760_glsl Custom GLSL programs
Accessors to standard materials have been modified within *Declarations.glsl* (*occFrontMaterial_Diffuse()* -> *occMaterial_Diffuse(bool)* and similar).
Applications defining custom GLSL programs should take into account syntax changes.

View File

@ -118,7 +118,7 @@ const char THE_FUNC_directionalLightFirst[] =
EOL" float aSpecl = 0.0;" EOL" float aSpecl = 0.0;"
EOL" if (aNdotL > 0.0)" EOL" if (aNdotL > 0.0)"
EOL" {" EOL" {"
EOL" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());" EOL" aSpecl = pow (aNdotH, occMaterial_Shininess(theIsFront));"
EOL" }" EOL" }"
EOL EOL
EOL" Diffuse += occLight_Diffuse(0) * aNdotL * theShadow;" EOL" Diffuse += occLight_Diffuse(0) * aNdotL * theShadow;"
@ -1154,7 +1154,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
const Handle(Graphic3d_LightSet)& theLights, const Handle(Graphic3d_LightSet)& theLights,
Standard_Boolean theHasVertColor, Standard_Boolean theHasVertColor,
Standard_Boolean theIsPBR, Standard_Boolean theIsPBR,
Standard_Boolean theHasEmissive, Standard_Boolean theHasTexColor,
Standard_Integer theNbShadowMaps) const Standard_Integer theNbShadowMaps) const
{ {
TCollection_AsciiString aLightsFunc, aLightsLoop; TCollection_AsciiString aLightsFunc, aLightsLoop;
@ -1296,11 +1296,11 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
} }
} }
TCollection_AsciiString aGetMatAmbient = "theIsFront ? occFrontMaterial_Ambient() : occBackMaterial_Ambient();"; TCollection_AsciiString aGetMatAmbient = "occMaterial_Ambient(theIsFront);";
TCollection_AsciiString aGetMatDiffuse = "theIsFront ? occFrontMaterial_Diffuse() : occBackMaterial_Diffuse();"; TCollection_AsciiString aGetMatDiffuse = "occMaterial_Diffuse(theIsFront);";
if (theHasVertColor) if (theHasVertColor)
{ {
aGetMatAmbient = "getVertColor();"; aGetMatAmbient = "getVertColor().rgb;";
aGetMatDiffuse = "getVertColor();"; aGetMatDiffuse = "getVertColor();";
} }
@ -1321,15 +1321,18 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
EOL" Specular = vec3 (0.0);" EOL" Specular = vec3 (0.0);"
EOL" vec3 aPoint = thePoint.xyz / thePoint.w;" EOL" vec3 aPoint = thePoint.xyz / thePoint.w;"
+ aLightsLoop + aLightsLoop
+ EOL" vec4 aMatAmbient = " + aGetMatAmbient + EOL" vec3 aMatAmbient = " + aGetMatAmbient
+ EOL" vec4 aMatDiffuse = " + aGetMatDiffuse + EOL" vec4 aMatDiffuse = " + aGetMatDiffuse
+ EOL" vec4 aMatSpecular = theIsFront ? occFrontMaterial_Specular() : occBackMaterial_Specular();" + EOL" vec3 aMatSpecular = occMaterial_Specular(theIsFront);"
EOL" vec3 aColor = Ambient * aMatAmbient.rgb + Diffuse * aMatDiffuse.rgb + Specular * aMatSpecular.rgb;" EOL" vec4 aColor = vec4(Ambient * aMatAmbient + Diffuse * aMatDiffuse.rgb + Specular * aMatSpecular, aMatDiffuse.a);"
EOL" occTextureOcclusion(aColor, TexCoord.st);" + (theHasTexColor ?
+ (theHasEmissive EOL"#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)"
? EOL" vec4 aMatEmission = theIsFront ? occFrontMaterial_Emission() : occBackMaterial_Emission();" EOL" aColor *= occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w);"
EOL" aColor += aMatEmission.rgb;" : "") EOL"#endif" : "")
+ EOL" return vec4 (aColor, aMatDiffuse.a);" + EOL" occMaterialOcclusion(aColor.rgb, TexCoord.st / TexCoord.w);"
EOL" vec3 aMatEmission = occMaterialEmission(theIsFront, TexCoord.st / TexCoord.w);"
EOL" aColor.rgb += aMatEmission.rgb;"
EOL" return aColor;"
EOL"}"; EOL"}";
} }
else else
@ -1345,10 +1348,10 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
EOL" in bool theIsFront)" EOL" in bool theIsFront)"
EOL"{" EOL"{"
EOL" DirectLighting = vec3(0.0);" EOL" DirectLighting = vec3(0.0);"
EOL" BaseColor = " + (theHasVertColor ? "getVertColor();" : "occTextureColor(occPBRMaterial_Color (theIsFront), TexCoord.st / TexCoord.w);") EOL" BaseColor = " + (theHasVertColor ? "getVertColor();" : "occMaterialBaseColor(theIsFront, TexCoord.st / TexCoord.w);")
+ EOL" Emission = occTextureEmissive(occPBRMaterial_Emission (theIsFront), TexCoord.st / TexCoord.w);" + EOL" Emission = occMaterialEmission(theIsFront, TexCoord.st / TexCoord.w);"
EOL" Metallic = occTextureMetallic(occPBRMaterial_Metallic (theIsFront), TexCoord.st / TexCoord.w);" EOL" Metallic = occMaterialMetallic(theIsFront, TexCoord.st / TexCoord.w);"
EOL" NormalizedRoughness = occTextureRoughness(occPBRMaterial_NormalizedRoughness (theIsFront), TexCoord.st / TexCoord.w);" EOL" NormalizedRoughness = occMaterialRoughness(theIsFront, TexCoord.st / TexCoord.w);"
EOL" Roughness = occRoughness (NormalizedRoughness);" EOL" Roughness = occRoughness (NormalizedRoughness);"
EOL" IOR = occPBRMaterial_IOR (theIsFront);" EOL" IOR = occPBRMaterial_IOR (theIsFront);"
EOL" vec3 aPoint = thePoint.xyz / thePoint.w;" EOL" vec3 aPoint = thePoint.xyz / thePoint.w;"
@ -1365,7 +1368,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
EOL" anIndirectLightingDiff *= occDiffIBLMap (theNormal).rgb;" EOL" anIndirectLightingDiff *= occDiffIBLMap (theNormal).rgb;"
EOL" aColor += occLightAmbient.rgb * (anIndirectLightingDiff + anIndirectLightingSpec);" EOL" aColor += occLightAmbient.rgb * (anIndirectLightingDiff + anIndirectLightingSpec);"
EOL" aColor += Emission;" EOL" aColor += Emission;"
EOL" occTextureOcclusion(aColor, TexCoord.st / TexCoord.w);" EOL" occMaterialOcclusion(aColor, TexCoord.st / TexCoord.w);"
EOL" return vec4 (aColor, mix(1.0, BaseColor.a, aRefractionCoeff.x));" EOL" return vec4 (aColor, mix(1.0, BaseColor.a, aRefractionCoeff.x));"
EOL"}"; EOL"}";
} }
@ -1383,7 +1386,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramGouraud (c
TCollection_AsciiString aSrcFrag, aSrcFragExtraMain; TCollection_AsciiString aSrcFrag, aSrcFragExtraMain;
TCollection_AsciiString aSrcFragGetColor = EOL"vec4 getColor(void) { return gl_FrontFacing ? FrontColor : BackColor; }"; TCollection_AsciiString aSrcFragGetColor = EOL"vec4 getColor(void) { return gl_FrontFacing ? FrontColor : BackColor; }";
Graphic3d_ShaderObject::ShaderVariableList aUniforms, aStageInOuts; Graphic3d_ShaderObject::ShaderVariableList aUniforms, aStageInOuts;
bool toUseTexColor = false;
if ((theBits & Graphic3d_ShaderFlags_IsPoint) != 0) if ((theBits & Graphic3d_ShaderFlags_IsPoint) != 0)
{ {
if (mySetPointSize) if (mySetPointSize)
@ -1409,6 +1412,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramGouraud (c
{ {
if ((theBits & Graphic3d_ShaderFlags_TextureRGB) != 0) if ((theBits & Graphic3d_ShaderFlags_TextureRGB) != 0)
{ {
toUseTexColor = true;
aProgramSrc->SetTextureSetBits (Graphic3d_TextureSetBits_BaseColor); aProgramSrc->SetTextureSetBits (Graphic3d_TextureSetBits_BaseColor);
aUniforms .Append (Graphic3d_ShaderObject::ShaderVariable ("sampler2D occSamplerBaseColor", Graphic3d_TOS_FRAGMENT)); aUniforms .Append (Graphic3d_ShaderObject::ShaderVariable ("sampler2D occSamplerBaseColor", Graphic3d_TOS_FRAGMENT));
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 TexCoord", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT)); aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 TexCoord", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
@ -1472,7 +1476,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramGouraud (c
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 BackColor", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT)); aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 BackColor", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
Standard_Integer aNbLights = 0; Standard_Integer aNbLights = 0;
const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, theLights, !aSrcVertColor.IsEmpty(), false, true, 0); const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, theLights, !aSrcVertColor.IsEmpty(), false, toUseTexColor, 0);
aSrcVert = TCollection_AsciiString() aSrcVert = TCollection_AsciiString()
+ THE_FUNC_transformNormal_view + THE_FUNC_transformNormal_view
+ EOL + EOL
@ -1533,6 +1537,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramPhong (con
"computeLighting (normalize (Normal), normalize (View), " + aPosition + ", gl_FrontFacing)"; "computeLighting (normalize (Normal), normalize (View), " + aPosition + ", gl_FrontFacing)";
const bool isFlatNormal = theIsFlatNormal && myHasFlatShading; const bool isFlatNormal = theIsFlatNormal && myHasFlatShading;
const char* aDFdxSignReversion = myToReverseDFdxSign ? "-" : ""; const char* aDFdxSignReversion = myToReverseDFdxSign ? "-" : "";
bool toUseTexColor = false;
if (isFlatNormal != theIsFlatNormal) if (isFlatNormal != theIsFlatNormal)
{ {
Message::SendWarning ("Warning: flat shading requires OpenGL ES 3.0+ or GL_OES_standard_derivatives extension"); Message::SendWarning ("Warning: flat shading requires OpenGL ES 3.0+ or GL_OES_standard_derivatives extension");
@ -1577,25 +1582,13 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramPhong (con
{ {
if ((theBits & Graphic3d_ShaderFlags_TextureRGB) != 0) if ((theBits & Graphic3d_ShaderFlags_TextureRGB) != 0)
{ {
toUseTexColor = true;
aUniforms .Append (Graphic3d_ShaderObject::ShaderVariable ("sampler2D occSamplerBaseColor", Graphic3d_TOS_FRAGMENT)); aUniforms .Append (Graphic3d_ShaderObject::ShaderVariable ("sampler2D occSamplerBaseColor", Graphic3d_TOS_FRAGMENT));
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 TexCoord", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT)); aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 TexCoord", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain += THE_VARY_TexCoord_Trsf; aSrcVertExtraMain += THE_VARY_TexCoord_Trsf;
Standard_Integer aTextureBits = Graphic3d_TextureSetBits_BaseColor | Graphic3d_TextureSetBits_Occlusion | Graphic3d_TextureSetBits_Emissive; Standard_Integer aTextureBits = Graphic3d_TextureSetBits_BaseColor | Graphic3d_TextureSetBits_Occlusion | Graphic3d_TextureSetBits_Emissive;
if (!theIsPBR) if (theIsPBR)
{
aSrcFragGetColor = TCollection_AsciiString() +
EOL"vec4 getColor(void)"
EOL"{"
EOL" vec2 aTexUV = TexCoord.st / TexCoord.w;"
EOL" vec4 aColor = " + aPhongCompLight + ";"
EOL" aColor *= occTexture2D(occSamplerBaseColor, aTexUV);"
EOL" vec3 anEmission = occTextureEmissive((gl_FrontFacing ? occFrontMaterial_Emission() : occBackMaterial_Emission()).rgb, aTexUV);"
EOL" aColor.rgb += anEmission;"
EOL" return aColor;"
EOL"}";
}
else
{ {
aTextureBits |= Graphic3d_TextureSetBits_MetallicRoughness; aTextureBits |= Graphic3d_TextureSetBits_MetallicRoughness;
} }
@ -1736,10 +1729,8 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramPhong (con
: EOL"#define getFinalColor getColor"; : EOL"#define getFinalColor getColor";
Standard_Integer aNbLights = 0; Standard_Integer aNbLights = 0;
const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, theLights, !aSrcFragGetVertColor.IsEmpty(), theIsPBR, const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, theLights, !aSrcFragGetVertColor.IsEmpty(),
(theBits & Graphic3d_ShaderFlags_TextureRGB) == 0 theIsPBR, toUseTexColor, theNbShadowMaps);
|| (theBits & Graphic3d_ShaderFlags_IsPoint) != 0,
theNbShadowMaps);
aSrcFrag += TCollection_AsciiString() aSrcFrag += TCollection_AsciiString()
+ EOL + EOL
+ aSrcFragGetVertColor + aSrcFragGetVertColor

View File

@ -197,13 +197,13 @@ protected:
//! @param theLights [in] light sources list //! @param theLights [in] light sources list
//! @param theHasVertColor [in] flag to use getVertColor() instead of Ambient and Diffuse components of active material //! @param theHasVertColor [in] flag to use getVertColor() instead of Ambient and Diffuse components of active material
//! @param theIsPBR [in] flag to activate PBR pipeline //! @param theIsPBR [in] flag to activate PBR pipeline
//! @param theHasEmissive [in] flag to include emissive //! @param theHasTexColor [in] flag to include color texturing
//! @param theNbShadowMaps [in] flag to include shadow map //! @param theNbShadowMaps [in] flag to include shadow map
Standard_EXPORT TCollection_AsciiString stdComputeLighting (Standard_Integer& theNbLights, Standard_EXPORT TCollection_AsciiString stdComputeLighting (Standard_Integer& theNbLights,
const Handle(Graphic3d_LightSet)& theLights, const Handle(Graphic3d_LightSet)& theLights,
Standard_Boolean theHasVertColor, Standard_Boolean theHasVertColor,
Standard_Boolean theIsPBR, Standard_Boolean theIsPBR,
Standard_Boolean theHasEmissive, Standard_Boolean theHasTexColor,
Standard_Integer theNbShadowMaps) const; Standard_Integer theNbShadowMaps) const;
protected: protected:

View File

@ -2417,32 +2417,22 @@ void OpenGl_Context::SetShadingMaterial (const OpenGl_Aspects* theAspect,
? anAspect->BackInteriorColor() ? anAspect->BackInteriorColor()
: aFrontIntColor; : aFrontIntColor;
myMatFront.Init (*this, aMatFrontSrc, aFrontIntColor); myMaterial.Init (*this, aMatFrontSrc, aFrontIntColor, aMatBackSrc, aBackIntColor);
if (toDistinguish)
{
myMatBack.Init (*this, aMatBackSrc, aBackIntColor);
}
else
{
myMatBack = myMatFront;
}
if (!theHighlight.IsNull() if (!theHighlight.IsNull()
&& theHighlight->BasicFillAreaAspect().IsNull()) && theHighlight->BasicFillAreaAspect().IsNull())
{ {
myMatFront.SetColor (theHighlight->ColorRGBA()); myMaterial.SetColor (theHighlight->ColorRGBA().GetRGB());
myMatBack .SetColor (theHighlight->ColorRGBA()); myMaterial.SetColor (theHighlight->ColorRGBA().GetRGB());
} }
Standard_ShortReal anAlphaFront = 1.0f; float anAlphaFront = 1.0f, anAlphaBack = 1.0f;
Standard_ShortReal anAlphaBack = 1.0f;
if (CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack)) if (CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack))
{ {
myMatFront.Common.Diffuse.a() = anAlphaFront; myMaterial.Common[0].Diffuse.a() = anAlphaFront;
myMatBack .Common.Diffuse.a() = anAlphaBack; myMaterial.Common[1].Diffuse.a() = anAlphaBack;
myMatFront.Pbr.BaseColor.a() = anAlphaFront; myMaterial.Pbr[0].BaseColor.a() = anAlphaFront;
myMatBack .Pbr.BaseColor.a() = anAlphaBack; myMaterial.Pbr[1].BaseColor.a() = anAlphaBack;
} }
// do not update material properties in case of zero reflection mode, // do not update material properties in case of zero reflection mode,
@ -2468,8 +2458,7 @@ void OpenGl_Context::SetShadingMaterial (const OpenGl_Aspects* theAspect,
return; return;
} }
} }
else if (myMatFront == aMatState.FrontMaterial() else if (myMaterial.IsEqual (aMatState.Material())
&& myMatBack == aMatState.BackMaterial()
&& toDistinguish == aMatState.ToDistinguish() && toDistinguish == aMatState.ToDistinguish()
&& toMapTexture == aMatState.ToMapTexture() && toMapTexture == aMatState.ToMapTexture()
&& anAlphaCutoff == aMatState.AlphaCutoff()) && anAlphaCutoff == aMatState.AlphaCutoff())
@ -2477,7 +2466,7 @@ void OpenGl_Context::SetShadingMaterial (const OpenGl_Aspects* theAspect,
return; return;
} }
myShaderManager->UpdateMaterialStateTo (myMatFront, myMatBack, anAlphaCutoff, toDistinguish, toMapTexture); myShaderManager->UpdateMaterialStateTo (myMaterial, anAlphaCutoff, toDistinguish, toMapTexture);
} }
// ======================================================================= // =======================================================================

View File

@ -1249,8 +1249,7 @@ private: //! @name fields tracking current state
Standard_ShortReal myLineFeather; //!< line feater width in pixels Standard_ShortReal myLineFeather; //!< line feater width in pixels
Standard_ShortReal myRenderScale; //!< scaling factor for rendering resolution Standard_ShortReal myRenderScale; //!< scaling factor for rendering resolution
Standard_ShortReal myRenderScaleInv; //!< scaling factor for rendering resolution (inverted value) Standard_ShortReal myRenderScaleInv; //!< scaling factor for rendering resolution (inverted value)
OpenGl_Material myMatFront; //!< current front material state (cached to reduce GL context updates) OpenGl_Material myMaterial; //!< current front/back material state (cached to reduce GL context updates)
OpenGl_Material myMatBack; //!< current back material state
private: private:

View File

@ -25,24 +25,24 @@ class OpenGl_Context;
struct OpenGl_MaterialCommon struct OpenGl_MaterialCommon
{ {
OpenGl_Vec4 Ambient; //!< ambient reflection coefficient OpenGl_Vec4 Diffuse; //!< diffuse RGB coefficients + alpha
OpenGl_Vec4 Diffuse; //!< diffuse reflection coefficient OpenGl_Vec4 Emission; //!< material RGB emission
OpenGl_Vec4 Specular; //!< glossy reflection coefficient OpenGl_Vec4 SpecularShininess; //!< glossy RGB coefficients + shininess
OpenGl_Vec4 Emission; //!< material emission OpenGl_Vec4 Ambient; //!< ambient RGB coefficients
OpenGl_Vec4 Params; //!< extra packed parameters
float Shine() const { return Params.x(); } float Shine() const { return SpecularShininess.a(); }
float& ChangeShine() { return Params.x(); } float& ChangeShine() { return SpecularShininess.a(); }
float Transparency() const { return Params.y(); }
float& ChangeTransparency() { return Params.y(); }
//! Empty constructor. //! Empty constructor.
OpenGl_MaterialCommon() : Ambient (1.0f), Diffuse (1.0f), Specular (1.0f), Emission (1.0f), Params (1.0f, 0.0f, 0.0f, 0.0f) {} OpenGl_MaterialCommon() : Diffuse (1.0f), Emission (1.0f), SpecularShininess (1.0f, 1.0f, 1.0f, 0.0f), Ambient (1.0f) {}
//! Returns packed (serialized) representation of material properties //! Set material color.
const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); } void SetColor (const OpenGl_Vec3& theColor)
static Standard_Integer NbOfVec4() { return 5; } {
// apply the same formula as in Graphic3d_MaterialAspect::SetColor()
Ambient.SetValues (theColor * 0.25f, Ambient.a());
Diffuse.SetValues (theColor, Diffuse.a());
}
}; };
@ -63,31 +63,35 @@ struct OpenGl_MaterialPBR
//! Empty constructor. //! Empty constructor.
OpenGl_MaterialPBR() : BaseColor (1.0f), EmissionIOR (1.0f), Params (1.0f, 1.0f, 1.0f, 1.0f) {} OpenGl_MaterialPBR() : BaseColor (1.0f), EmissionIOR (1.0f), Params (1.0f, 1.0f, 1.0f, 1.0f) {}
//! Returns packed (serialized) representation of material properties //! Set material color.
const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); } void SetColor (const OpenGl_Vec3& theColor)
static Standard_Integer NbOfVec4() { return 3; } {
BaseColor.SetValues (theColor, BaseColor.a());
}
}; };
//! OpenGL material definition //! OpenGL material definition
struct OpenGl_Material struct OpenGl_Material
{ {
OpenGl_MaterialCommon Common; OpenGl_MaterialCommon Common[2];
OpenGl_MaterialPBR Pbr; OpenGl_MaterialPBR Pbr[2];
//! Set material color. //! Set material color.
void SetColor (const OpenGl_Vec4& theColor) void SetColor (const OpenGl_Vec3& theColor)
{ {
// apply the same formula as in Graphic3d_MaterialAspect::SetColor() Common[0].SetColor (theColor);
Common.Ambient.SetValues (theColor.rgb() * 0.25f, Common.Ambient.a()); Common[1].SetColor (theColor);
Common.Diffuse.SetValues (theColor.rgb(), Common.Diffuse.a()); Pbr[0].SetColor (theColor);
Pbr .BaseColor.SetValues (theColor.rgb(), Pbr.BaseColor.a()); Pbr[1].SetColor (theColor);
} }
//! Initialize material //! Initialize material
void Init (const OpenGl_Context& theCtx, void Init (const OpenGl_Context& theCtx,
const Graphic3d_MaterialAspect& theProp, const Graphic3d_MaterialAspect& theFront,
const Quantity_Color& theInteriorColor); const Quantity_Color& theFrontColor,
const Graphic3d_MaterialAspect& theBack,
const Quantity_Color& theBackColor);
//! Check this material for equality with another material (without tolerance!). //! Check this material for equality with another material (without tolerance!).
bool IsEqual (const OpenGl_Material& theOther) const bool IsEqual (const OpenGl_Material& theOther) const
@ -103,6 +107,22 @@ struct OpenGl_Material
bool operator!= (const OpenGl_Material& theOther) { return !IsEqual (theOther); } bool operator!= (const OpenGl_Material& theOther) { return !IsEqual (theOther); }
bool operator!= (const OpenGl_Material& theOther) const { return !IsEqual (theOther); } bool operator!= (const OpenGl_Material& theOther) const { return !IsEqual (theOther); }
//! Returns packed (serialized) representation of common material properties
const OpenGl_Vec4* PackedCommon() const { return reinterpret_cast<const OpenGl_Vec4*> (Common); }
static Standard_Integer NbOfVec4Common() { return 4 * 2; }
//! Returns packed (serialized) representation of PBR material properties
const OpenGl_Vec4* PackedPbr() const { return reinterpret_cast<const OpenGl_Vec4*> (Pbr); }
static Standard_Integer NbOfVec4Pbr() { return 3 * 2; }
private:
//! Initialize material
void init (const OpenGl_Context& theCtx,
const Graphic3d_MaterialAspect& theMat,
const Quantity_Color& theColor,
const Standard_Integer theIndex);
}; };
//! Material flag //! Material flag

View File

@ -28,24 +28,19 @@ public:
OpenGl_MaterialState() : myAlphaCutoff (0.5f), myToDistinguish (false), myToMapTexture (false) {} OpenGl_MaterialState() : myAlphaCutoff (0.5f), myToDistinguish (false), myToMapTexture (false) {}
//! Sets new material aspect. //! Sets new material aspect.
void Set (const OpenGl_Material& theFrontMat, void Set (const OpenGl_Material& theMat,
const OpenGl_Material& theBackMat,
const float theAlphaCutoff, const float theAlphaCutoff,
const bool theToDistinguish, const bool theToDistinguish,
const bool theToMapTexture) const bool theToMapTexture)
{ {
myMatFront = theFrontMat; myMaterial = theMat;
myMatBack = theBackMat;
myAlphaCutoff = theAlphaCutoff; myAlphaCutoff = theAlphaCutoff;
myToDistinguish = theToDistinguish; myToDistinguish = theToDistinguish;
myToMapTexture = theToMapTexture; myToMapTexture = theToMapTexture;
} }
//! Return front material. //! Return front material.
const OpenGl_Material& FrontMaterial() const { return myMatFront; } const OpenGl_Material& Material() const { return myMaterial; }
//! Return back material.
const OpenGl_Material& BackMaterial() const { return myMatBack; }
//! Alpha cutoff value. //! Alpha cutoff value.
float AlphaCutoff() const { return myAlphaCutoff; } float AlphaCutoff() const { return myAlphaCutoff; }
@ -61,8 +56,7 @@ public:
private: private:
OpenGl_Material myMatFront; //!< front material OpenGl_Material myMaterial; //!< material
OpenGl_Material myMatBack; //!< back material
float myAlphaCutoff; //!< alpha cutoff value float myAlphaCutoff; //!< alpha cutoff value
bool myToDistinguish; //!< distinguish front/back flag bool myToDistinguish; //!< distinguish front/back flag
bool myToMapTexture; //!< flag for mapping a texture bool myToMapTexture; //!< flag for mapping a texture

View File

@ -908,8 +908,7 @@ void OpenGl_ShaderManager::pushClippingState (const Handle(OpenGl_ShaderProgram)
// ======================================================================= // =======================================================================
void OpenGl_ShaderManager::pushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const void OpenGl_ShaderManager::pushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{ {
const OpenGl_Material& aFrontMat = myMaterialState.FrontMaterial(); const OpenGl_Material& aMat = myMaterialState.Material();
const OpenGl_Material& aBackMat = myMaterialState.BackMaterial();
theProgram->UpdateState (OpenGl_MATERIAL_STATE, myMaterialState.Index()); theProgram->UpdateState (OpenGl_MATERIAL_STATE, myMaterialState.Index());
if (theProgram == myFfpProgram) if (theProgram == myFfpProgram)
{ {
@ -930,18 +929,22 @@ void OpenGl_ShaderManager::pushMaterialState (const Handle(OpenGl_ShaderProgram)
} }
const GLenum aFrontFace = myMaterialState.ToDistinguish() ? GL_FRONT : GL_FRONT_AND_BACK; const GLenum aFrontFace = myMaterialState.ToDistinguish() ? GL_FRONT : GL_FRONT_AND_BACK;
myContext->core11->glMaterialfv(aFrontFace, GL_AMBIENT, aFrontMat.Common.Ambient.GetData()); const OpenGl_MaterialCommon& aFrontMat = aMat.Common[0];
myContext->core11->glMaterialfv(aFrontFace, GL_DIFFUSE, aFrontMat.Common.Diffuse.GetData()); const OpenGl_MaterialCommon& aBackMat = aMat.Common[1];
myContext->core11->glMaterialfv(aFrontFace, GL_SPECULAR, aFrontMat.Common.Specular.GetData()); const Graphic3d_Vec4 aSpec4 (aFrontMat.SpecularShininess.rgb(), 1.0f);
myContext->core11->glMaterialfv(aFrontFace, GL_EMISSION, aFrontMat.Common.Emission.GetData()); myContext->core11->glMaterialfv(aFrontFace, GL_AMBIENT, aFrontMat.Ambient.GetData());
myContext->core11->glMaterialf (aFrontFace, GL_SHININESS, aFrontMat.Common.Shine()); myContext->core11->glMaterialfv(aFrontFace, GL_DIFFUSE, aFrontMat.Diffuse.GetData());
myContext->core11->glMaterialfv(aFrontFace, GL_SPECULAR, aSpec4.GetData());
myContext->core11->glMaterialfv(aFrontFace, GL_EMISSION, aFrontMat.Emission.GetData());
myContext->core11->glMaterialf (aFrontFace, GL_SHININESS, aFrontMat.Shine());
if (myMaterialState.ToDistinguish()) if (myMaterialState.ToDistinguish())
{ {
myContext->core11->glMaterialfv(GL_BACK, GL_AMBIENT, aBackMat.Common.Ambient.GetData()); const Graphic3d_Vec4 aSpec4Back (aBackMat.SpecularShininess.rgb(), 1.0f);
myContext->core11->glMaterialfv(GL_BACK, GL_DIFFUSE, aBackMat.Common.Diffuse.GetData()); myContext->core11->glMaterialfv(GL_BACK, GL_AMBIENT, aBackMat.Ambient.GetData());
myContext->core11->glMaterialfv(GL_BACK, GL_SPECULAR, aBackMat.Common.Specular.GetData()); myContext->core11->glMaterialfv(GL_BACK, GL_DIFFUSE, aBackMat.Diffuse.GetData());
myContext->core11->glMaterialfv(GL_BACK, GL_EMISSION, aBackMat.Common.Emission.GetData()); myContext->core11->glMaterialfv(GL_BACK, GL_SPECULAR, aSpec4Back.GetData());
myContext->core11->glMaterialf (GL_BACK, GL_SHININESS, aBackMat.Common.Shine()); myContext->core11->glMaterialfv(GL_BACK, GL_EMISSION, aBackMat.Emission.GetData());
myContext->core11->glMaterialf (GL_BACK, GL_SHININESS, aBackMat.Shine());
} }
#endif #endif
return; return;
@ -957,25 +960,13 @@ void OpenGl_ShaderManager::pushMaterialState (const Handle(OpenGl_ShaderProgram)
theProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE), theProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE),
myMaterialState.ToDistinguish() ? 1 : 0); myMaterialState.ToDistinguish() ? 1 : 0);
if (const OpenGl_ShaderUniformLocation& aLocPbrFront = theProgram->GetStateLocation (OpenGl_OCCT_PBR_FRONT_MATERIAL)) if (const OpenGl_ShaderUniformLocation& aLocPbrFront = theProgram->GetStateLocation (OpenGl_OCCT_PBR_MATERIAL))
{ {
theProgram->SetUniform (myContext, aLocPbrFront, OpenGl_MaterialPBR::NbOfVec4(), theProgram->SetUniform (myContext, aLocPbrFront, OpenGl_Material::NbOfVec4Pbr(), aMat.PackedPbr());
aFrontMat.Pbr.Packed());
} }
if (const OpenGl_ShaderUniformLocation aLocPbrBack = theProgram->GetStateLocation (OpenGl_OCCT_PBR_BACK_MATERIAL)) if (const OpenGl_ShaderUniformLocation& aLocFront = theProgram->GetStateLocation (OpenGl_OCCT_COMMON_MATERIAL))
{ {
theProgram->SetUniform (myContext, aLocPbrBack, OpenGl_MaterialPBR::NbOfVec4(), theProgram->SetUniform (myContext, aLocFront, OpenGl_Material::NbOfVec4Common(), aMat.PackedCommon());
aBackMat.Pbr.Packed());
}
if (const OpenGl_ShaderUniformLocation aLocFront = theProgram->GetStateLocation (OpenGl_OCCT_COMMON_FRONT_MATERIAL))
{
theProgram->SetUniform (myContext, aLocFront, OpenGl_MaterialCommon::NbOfVec4(),
aFrontMat.Common.Packed());
}
if (const OpenGl_ShaderUniformLocation aLocBack = theProgram->GetStateLocation (OpenGl_OCCT_COMMON_BACK_MATERIAL))
{
theProgram->SetUniform (myContext, aLocBack, OpenGl_MaterialCommon::NbOfVec4(),
aBackMat.Common.Packed());
} }
} }

View File

@ -373,13 +373,12 @@ public:
const OpenGl_MaterialState& MaterialState() const { return myMaterialState; } const OpenGl_MaterialState& MaterialState() const { return myMaterialState; }
//! Updates state of material. //! Updates state of material.
void UpdateMaterialStateTo (const OpenGl_Material& theFrontMat, void UpdateMaterialStateTo (const OpenGl_Material& theMat,
const OpenGl_Material& theBackMat,
const float theAlphaCutoff, const float theAlphaCutoff,
const bool theToDistinguish, const bool theToDistinguish,
const bool theToMapTexture) const bool theToMapTexture)
{ {
myMaterialState.Set (theFrontMat, theBackMat, theAlphaCutoff, theToDistinguish, theToMapTexture); myMaterialState.Set (theMat, theAlphaCutoff, theToDistinguish, theToMapTexture);
myMaterialState.Update(); myMaterialState.Update();
} }

View File

@ -70,10 +70,8 @@ Standard_CString OpenGl_ShaderProgram::PredefinedKeywords[] =
"occTextureEnable", // OpenGl_OCCT_TEXTURE_ENABLE "occTextureEnable", // OpenGl_OCCT_TEXTURE_ENABLE
"occDistinguishingMode", // OpenGl_OCCT_DISTINGUISH_MODE "occDistinguishingMode", // OpenGl_OCCT_DISTINGUISH_MODE
"occPbrFrontMaterial", // OpenGl_OCCT_PBR_FRONT_MATERIAL "occPbrMaterial", // OpenGl_OCCT_PBR_MATERIAL
"occPbrBackMaterial", // OpenGl_OCCT_PBR_BACK_MATERIAL "occCommonMaterial", // OpenGl_OCCT_COMMON_MATERIAL
"occFrontMaterial", // OpenGl_OCCT_COMMON_FRONT_MATERIAL
"occBackMaterial", // OpenGl_OCCT_COMMON_BACK_MATERIAL
"occAlphaCutoff", // OpenGl_OCCT_ALPHA_CUTOFF "occAlphaCutoff", // OpenGl_OCCT_ALPHA_CUTOFF
"occColor", // OpenGl_OCCT_COLOR "occColor", // OpenGl_OCCT_COLOR

View File

@ -66,10 +66,8 @@ enum OpenGl_StateVariable
// Material state // Material state
OpenGl_OCCT_TEXTURE_ENABLE, OpenGl_OCCT_TEXTURE_ENABLE,
OpenGl_OCCT_DISTINGUISH_MODE, OpenGl_OCCT_DISTINGUISH_MODE,
OpenGl_OCCT_PBR_FRONT_MATERIAL, OpenGl_OCCT_PBR_MATERIAL,
OpenGl_OCCT_PBR_BACK_MATERIAL, OpenGl_OCCT_COMMON_MATERIAL,
OpenGl_OCCT_COMMON_FRONT_MATERIAL,
OpenGl_OCCT_COMMON_BACK_MATERIAL,
OpenGl_OCCT_ALPHA_CUTOFF, OpenGl_OCCT_ALPHA_CUTOFF,
OpenGl_OCCT_COLOR, OpenGl_OCCT_COLOR,

View File

@ -54,45 +54,67 @@ namespace
// purpose : // purpose :
// ======================================================================= // =======================================================================
void OpenGl_Material::Init (const OpenGl_Context& theCtx, void OpenGl_Material::Init (const OpenGl_Context& theCtx,
const Graphic3d_MaterialAspect& theMat, const Graphic3d_MaterialAspect& theFront,
const Quantity_Color& theInteriorColor) const Quantity_Color& theFrontColor,
const Graphic3d_MaterialAspect& theBack,
const Quantity_Color& theBackColor)
{ {
Common.ChangeShine() = 128.0f * theMat.Shininess(); init (theCtx, theFront, theFrontColor, 0);
Common.ChangeTransparency() = theMat.Alpha(); if (&theFront != &theBack)
{
init (theCtx, theBack, theBackColor, 1);
}
else
{
Common[1] = Common[0];
Pbr[1] = Pbr[0];
}
}
Pbr.ChangeMetallic() = theMat.PBRMaterial().Metallic(); // =======================================================================
Pbr.ChangeRoughness() = theMat.PBRMaterial().NormalizedRoughness(); // function : init
Pbr.EmissionIOR = Graphic3d_Vec4 (theMat.PBRMaterial().Emission(), theMat.PBRMaterial().IOR()); // purpose :
// =======================================================================
void OpenGl_Material::init (const OpenGl_Context& theCtx,
const Graphic3d_MaterialAspect& theMat,
const Quantity_Color& theInteriorColor,
const Standard_Integer theIndex)
{
OpenGl_MaterialCommon& aCommon = Common[theIndex];
OpenGl_MaterialPBR& aPbr = Pbr[theIndex];
aPbr.ChangeMetallic() = theMat.PBRMaterial().Metallic();
aPbr.ChangeRoughness() = theMat.PBRMaterial().NormalizedRoughness();
aPbr.EmissionIOR = Graphic3d_Vec4 (theMat.PBRMaterial().Emission(), theMat.PBRMaterial().IOR());
const OpenGl_Vec3& aSrcAmb = theMat.AmbientColor(); const OpenGl_Vec3& aSrcAmb = theMat.AmbientColor();
const OpenGl_Vec3& aSrcDif = theMat.DiffuseColor(); const OpenGl_Vec3& aSrcDif = theMat.DiffuseColor();
const OpenGl_Vec3& aSrcSpe = theMat.SpecularColor(); const OpenGl_Vec3& aSrcSpe = theMat.SpecularColor();
const OpenGl_Vec3& aSrcEms = theMat.EmissiveColor(); const OpenGl_Vec3& aSrcEms = theMat.EmissiveColor();
Common.Specular.SetValues (aSrcSpe, 1.0f); // interior color is ignored for Specular aCommon.SpecularShininess.SetValues (aSrcSpe,128.0f * theMat.Shininess()); // interior color is ignored for Specular
switch (theMat.MaterialType()) switch (theMat.MaterialType())
{ {
case Graphic3d_MATERIAL_ASPECT: case Graphic3d_MATERIAL_ASPECT:
{ {
Common.Ambient .SetValues (aSrcAmb * theInteriorColor, 1.0f); aCommon.Diffuse .SetValues (aSrcDif * theInteriorColor, theMat.Alpha());
Common.Diffuse .SetValues (aSrcDif * theInteriorColor, 1.0f); aCommon.Ambient .SetValues (aSrcAmb * theInteriorColor, 1.0f);
Common.Emission.SetValues (aSrcEms * theInteriorColor, 1.0f); aCommon.Emission.SetValues (aSrcEms * theInteriorColor, 1.0f);
Pbr .BaseColor.SetValues (theInteriorColor, theMat.Alpha()); aPbr .BaseColor.SetValues (theInteriorColor, theMat.Alpha());
break; break;
} }
case Graphic3d_MATERIAL_PHYSIC: case Graphic3d_MATERIAL_PHYSIC:
{ {
Common.Ambient .SetValues (aSrcAmb, 1.0f); aCommon.Diffuse .SetValues (aSrcDif, theMat.Alpha());
Common.Diffuse .SetValues (aSrcDif, 1.0f); aCommon.Ambient .SetValues (aSrcAmb, 1.0f);
Common.Emission.SetValues (aSrcEms, 1.0f); aCommon.Emission.SetValues (aSrcEms, 1.0f);
Pbr.BaseColor = theMat.PBRMaterial().Color(); aPbr.BaseColor = theMat.PBRMaterial().Color();
break; break;
} }
} }
Common.Ambient = theCtx.Vec4FromQuantityColor (Common.Ambient); aCommon.Diffuse = theCtx.Vec4FromQuantityColor (aCommon.Diffuse);
Common.Diffuse = theCtx.Vec4FromQuantityColor (Common.Diffuse); aCommon.Ambient = theCtx.Vec4FromQuantityColor (aCommon.Ambient);
Common.Specular = theCtx.Vec4FromQuantityColor (Common.Specular); aCommon.SpecularShininess = theCtx.Vec4FromQuantityColor (aCommon.SpecularShininess);
Common.Emission = theCtx.Vec4FromQuantityColor (Common.Emission); aCommon.Emission = theCtx.Vec4FromQuantityColor (aCommon.Emission);
} }
// ======================================================================= // =======================================================================

View File

@ -203,22 +203,15 @@ float occPBRMaterial_Metallic(in bool theIsFront); //!< Metallic coefficient
float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient
vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material
float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction
#define occMaterial_Emission occPBRMaterial_Emission
#define occMaterial_Color occPBRMaterial_Color
#else #else
// Front material properties accessors vec4 occMaterial_Diffuse(in bool theIsFront); //!< Diffuse reflection
vec4 occFrontMaterial_Emission(void); //!< Emission color vec3 occMaterial_Specular(in bool theIsFront); //!< Specular reflection
vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection float occMaterial_Shininess(in bool theIsFront); //!< Specular exponent
vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection vec3 occMaterial_Ambient(in bool theIsFront); //!< Ambient reflection
vec4 occFrontMaterial_Specular(void); //!< Specular reflection vec3 occMaterial_Emission(in bool theIsFront); //!< Emission color
float occFrontMaterial_Shininess(void); //!< Specular exponent #define occMaterial_Color occMaterial_Diffuse
float occFrontMaterial_Transparency(void); //!< Transparency coefficient
// Back material properties accessors
vec4 occBackMaterial_Emission(void); //!< Emission color
vec4 occBackMaterial_Ambient(void); //!< Ambient reflection
vec4 occBackMaterial_Diffuse(void); //!< Diffuse reflection
vec4 occBackMaterial_Specular(void); //!< Specular reflection
float occBackMaterial_Shininess(void); //!< Specular exponent
float occBackMaterial_Transparency(void); //!< Transparency coefficient
#endif #endif
#ifdef THE_HAS_DEFAULT_SAMPLER #ifdef THE_HAS_DEFAULT_SAMPLER
@ -227,24 +220,24 @@ float occBackMaterial_Transparency(void); //!< Transparency coefficient
uniform sampler2D occSampler0; //!< current active sampler; uniform sampler2D occSampler0; //!< current active sampler;
#endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing #endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
#if defined(THE_HAS_TEXTURE_COLOR) #if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)
#define occTextureColor(theMatColor, theTexCoord) (theMatColor * occTexture2D(occSamplerBaseColor, theTexCoord)) #define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord))
#else #else
#define occTextureColor(theMatColor, theTexCoord) theMatColor #define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront)
#endif #endif
#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER) #if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerOcclusion; //!< R occlusion texture sampler uniform sampler2D occSamplerOcclusion; //!< R occlusion texture sampler
#define occTextureOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r; #define occMaterialOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;
#else #else
#define occTextureOcclusion(theColor, theTexCoord) #define occMaterialOcclusion(theColor, theTexCoord)
#endif #endif
#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER) #if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerEmissive; //!< RGB emissive texture sampler uniform sampler2D occSamplerEmissive; //!< RGB emissive texture sampler
#define occTextureEmissive(theMatEmis, theTexCoord) (theMatEmis * occTexture2D(occSamplerEmissive, theTexCoord).rgb) #define occMaterialEmission(theIsFront, theTexCoord) (occMaterial_Emission(theIsFront) * occTexture2D(occSamplerEmissive, theTexCoord).rgb)
#else #else
#define occTextureEmissive(theMatEmis, theTexCoord) theMatEmis #define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront)
#endif #endif
#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER) #if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)
@ -256,11 +249,11 @@ uniform sampler2D occSamplerNormal; //!< XYZ normal texture sampler with W=
#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER) #if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler
#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g) #define occMaterialRoughness(theIsFront, theTexCoord) (occPBRMaterial_NormalizedRoughness(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)
#define occTextureMetallic(theMet, theTexCoord) (theMet * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b) #define occMaterialMetallic(theIsFront, theTexCoord) (occPBRMaterial_Metallic(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)
#else #else
#define occTextureRoughness(theRoug, theTexCoord) theRoug #define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront)
#define occTextureMetallic(theMet, theTexCoord) theMet #define occMaterialMetallic(theIsFront, theTexCoord) occPBRMaterial_Metallic(theIsFront)
#endif #endif
uniform vec4 occColor; //!< color value (in case of disabled lighting) uniform vec4 occColor; //!< color value (in case of disabled lighting)

View File

@ -94,33 +94,23 @@ vec3 occDiffIBLMap (in vec3 theNormal)
// front and back material properties accessors // front and back material properties accessors
#if defined(THE_IS_PBR) #if defined(THE_IS_PBR)
uniform vec4 occPbrFrontMaterial[3]; uniform vec4 occPbrMaterial[3 * 2];
uniform vec4 occPbrBackMaterial[3];
#define MIN_ROUGHNESS 0.01 #define MIN_ROUGHNESS 0.01
float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; } float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }
vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[0] : occPbrBackMaterial[0]; } vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrMaterial[0] : occPbrMaterial[3]; }
vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].rgb : occPbrBackMaterial[1].rgb; } vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].rgb : occPbrMaterial[4].rgb; }
float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].w : occPbrBackMaterial[1].w; } float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].w : occPbrMaterial[4].w; }
float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].b : occPbrBackMaterial[2].b; } float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].b : occPbrMaterial[5].b; }
float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].g : occPbrBackMaterial[2].g; } float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].g : occPbrMaterial[5].g; }
#else #else
uniform vec4 occFrontMaterial[5]; uniform vec4 occCommonMaterial[4 * 2];
uniform vec4 occBackMaterial[5];
vec4 occFrontMaterial_Ambient(void) { return occFrontMaterial[0]; } vec4 occMaterial_Diffuse(in bool theIsFront) { return theIsFront ? occCommonMaterial[0] : occCommonMaterial[4]; }
vec4 occFrontMaterial_Diffuse(void) { return occFrontMaterial[1]; } vec3 occMaterial_Emission(in bool theIsFront) { return theIsFront ? occCommonMaterial[1].rgb : occCommonMaterial[5].rgb; }
vec4 occFrontMaterial_Specular(void) { return occFrontMaterial[2]; } vec3 occMaterial_Specular(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].rgb : occCommonMaterial[6].rgb; }
vec4 occFrontMaterial_Emission(void) { return occFrontMaterial[3]; } float occMaterial_Shininess(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].a : occCommonMaterial[6].a; }
float occFrontMaterial_Shininess(void) { return occFrontMaterial[4].x; } vec3 occMaterial_Ambient(in bool theIsFront) { return theIsFront ? occCommonMaterial[3].rgb : occCommonMaterial[7].rgb; }
float occFrontMaterial_Transparency(void) { return occFrontMaterial[4].y; }
vec4 occBackMaterial_Ambient(void) { return occBackMaterial[0]; }
vec4 occBackMaterial_Diffuse(void) { return occBackMaterial[1]; }
vec4 occBackMaterial_Specular(void) { return occBackMaterial[2]; }
vec4 occBackMaterial_Emission(void) { return occBackMaterial[3]; }
float occBackMaterial_Shininess(void) { return occBackMaterial[4].x; }
float occBackMaterial_Transparency(void) { return occBackMaterial[4].y; }
#endif #endif
// 2D texture coordinates transformation // 2D texture coordinates transformation

View File

@ -21,7 +21,7 @@ void occDirectionalLight (in int theId,
float aSpecl = 0.0; float aSpecl = 0.0;
if (aNdotL > 0.0) if (aNdotL > 0.0)
{ {
aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess()); aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));
} }
Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow; Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;

View File

@ -28,7 +28,7 @@ void occPointLight (in int theId,
float aSpecl = 0.0; float aSpecl = 0.0;
if (aNdotL > 0.0) if (aNdotL > 0.0)
{ {
aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess()); aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));
} }
Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten; Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;

View File

@ -50,7 +50,7 @@ void pointLight (in int theId,
float aSpecl = 0.0; float aSpecl = 0.0;
if (aNdotL > 0.0) if (aNdotL > 0.0)
{ {
aSpecl = pow (aNdotH, gl_FrontFacing ? occFrontMaterial_Shininess() : occBackMaterial_Shininess()); aSpecl = pow (aNdotH, occMaterial_Shininess (gl_FrontFacing));
} }
Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten; Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;
@ -101,7 +101,7 @@ void spotLight (in int theId,
float aSpecl = 0.0; float aSpecl = 0.0;
if (aNdotL > 0.0) if (aNdotL > 0.0)
{ {
aSpecl = pow (aNdotH, gl_FrontFacing ? occFrontMaterial_Shininess() : occBackMaterial_Shininess()); aSpecl = pow (aNdotH, occMaterial_Shininess (gl_FrontFacing));
} }
Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten; Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;
@ -128,7 +128,7 @@ void directionalLight (in int theId,
float aSpecl = 0.0; float aSpecl = 0.0;
if (aNdotL > 0.0) if (aNdotL > 0.0)
{ {
aSpecl = pow (aNdotH, gl_FrontFacing ? occFrontMaterial_Shininess() : occBackMaterial_Shininess()); aSpecl = pow (aNdotH, occMaterial_Shininess (gl_FrontFacing));
} }
Diffuse += occLight_Diffuse (theId).rgb * aNdotL; Diffuse += occLight_Diffuse (theId).rgb * aNdotL;
@ -162,15 +162,15 @@ vec4 computeLighting (in vec3 theNormal,
} }
} }
vec4 aMaterialAmbient = gl_FrontFacing ? occFrontMaterial_Ambient() : occBackMaterial_Ambient(); vec3 aMatAmbient = occMaterial_Ambient (gl_FrontFacing);
vec4 aMaterialDiffuse = gl_FrontFacing ? occFrontMaterial_Diffuse() : occBackMaterial_Diffuse(); vec4 aMatDiffuse = occMaterial_Diffuse (gl_FrontFacing);
vec4 aMaterialSpecular = gl_FrontFacing ? occFrontMaterial_Specular() : occBackMaterial_Specular(); vec3 aMatSpecular = occMaterial_Specular(gl_FrontFacing);
vec4 aMaterialEmission = gl_FrontFacing ? occFrontMaterial_Emission() : occBackMaterial_Emission(); vec3 aMatEmission = occMaterial_Emission(gl_FrontFacing);
vec3 aColor = Ambient * aMaterialAmbient.rgb vec3 aColor = Ambient * aMatAmbient.rgb
+ Diffuse * aMaterialDiffuse.rgb + Diffuse * aMatDiffuse.rgb
+ Specular * aMaterialSpecular.rgb + Specular * aMatSpecular.rgb
+ aMaterialEmission.rgb; + aMatEmission.rgb;
return vec4 (aColor, aMaterialDiffuse.a); return vec4 (aColor, aMatDiffuse.a);
} }
//! Entry point to the Fragment Shader //! Entry point to the Fragment Shader

View File

@ -43,7 +43,7 @@ void occSpotLight (in int theId,
float aSpecl = 0.0; float aSpecl = 0.0;
if (aNdotL > 0.0) if (aNdotL > 0.0)
{ {
aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess()); aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));
} }
Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten; Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;

View File

@ -97,33 +97,23 @@ static const char Shaders_DeclarationsImpl_glsl[] =
"\n" "\n"
"// front and back material properties accessors\n" "// front and back material properties accessors\n"
"#if defined(THE_IS_PBR)\n" "#if defined(THE_IS_PBR)\n"
"uniform vec4 occPbrFrontMaterial[3];\n" "uniform vec4 occPbrMaterial[3 * 2];\n"
"uniform vec4 occPbrBackMaterial[3];\n"
"\n" "\n"
"#define MIN_ROUGHNESS 0.01\n" "#define MIN_ROUGHNESS 0.01\n"
"float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }\n" "float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }\n"
"vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[0] : occPbrBackMaterial[0]; }\n" "vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrMaterial[0] : occPbrMaterial[3]; }\n"
"vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].rgb : occPbrBackMaterial[1].rgb; }\n" "vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].rgb : occPbrMaterial[4].rgb; }\n"
"float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].w : occPbrBackMaterial[1].w; }\n" "float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].w : occPbrMaterial[4].w; }\n"
"float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].b : occPbrBackMaterial[2].b; }\n" "float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].b : occPbrMaterial[5].b; }\n"
"float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].g : occPbrBackMaterial[2].g; }\n" "float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].g : occPbrMaterial[5].g; }\n"
"#else\n" "#else\n"
"uniform vec4 occFrontMaterial[5];\n" "uniform vec4 occCommonMaterial[4 * 2];\n"
"uniform vec4 occBackMaterial[5];\n"
"\n" "\n"
"vec4 occFrontMaterial_Ambient(void) { return occFrontMaterial[0]; }\n" "vec4 occMaterial_Diffuse(in bool theIsFront) { return theIsFront ? occCommonMaterial[0] : occCommonMaterial[4]; }\n"
"vec4 occFrontMaterial_Diffuse(void) { return occFrontMaterial[1]; }\n" "vec3 occMaterial_Emission(in bool theIsFront) { return theIsFront ? occCommonMaterial[1].rgb : occCommonMaterial[5].rgb; }\n"
"vec4 occFrontMaterial_Specular(void) { return occFrontMaterial[2]; }\n" "vec3 occMaterial_Specular(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].rgb : occCommonMaterial[6].rgb; }\n"
"vec4 occFrontMaterial_Emission(void) { return occFrontMaterial[3]; }\n" "float occMaterial_Shininess(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].a : occCommonMaterial[6].a; }\n"
"float occFrontMaterial_Shininess(void) { return occFrontMaterial[4].x; }\n" "vec3 occMaterial_Ambient(in bool theIsFront) { return theIsFront ? occCommonMaterial[3].rgb : occCommonMaterial[7].rgb; }\n"
"float occFrontMaterial_Transparency(void) { return occFrontMaterial[4].y; }\n"
"\n"
"vec4 occBackMaterial_Ambient(void) { return occBackMaterial[0]; }\n"
"vec4 occBackMaterial_Diffuse(void) { return occBackMaterial[1]; }\n"
"vec4 occBackMaterial_Specular(void) { return occBackMaterial[2]; }\n"
"vec4 occBackMaterial_Emission(void) { return occBackMaterial[3]; }\n"
"float occBackMaterial_Shininess(void) { return occBackMaterial[4].x; }\n"
"float occBackMaterial_Transparency(void) { return occBackMaterial[4].y; }\n"
"#endif\n" "#endif\n"
"\n" "\n"
"// 2D texture coordinates transformation\n" "// 2D texture coordinates transformation\n"

View File

@ -206,22 +206,15 @@ static const char Shaders_Declarations_glsl[] =
"float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient\n" "float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient\n"
"vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material\n" "vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material\n"
"float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction\n" "float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction\n"
"#define occMaterial_Emission occPBRMaterial_Emission\n"
"#define occMaterial_Color occPBRMaterial_Color\n"
"#else\n" "#else\n"
"// Front material properties accessors\n" "vec4 occMaterial_Diffuse(in bool theIsFront); //!< Diffuse reflection\n"
"vec4 occFrontMaterial_Emission(void); //!< Emission color\n" "vec3 occMaterial_Specular(in bool theIsFront); //!< Specular reflection\n"
"vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection\n" "float occMaterial_Shininess(in bool theIsFront); //!< Specular exponent\n"
"vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection\n" "vec3 occMaterial_Ambient(in bool theIsFront); //!< Ambient reflection\n"
"vec4 occFrontMaterial_Specular(void); //!< Specular reflection\n" "vec3 occMaterial_Emission(in bool theIsFront); //!< Emission color\n"
"float occFrontMaterial_Shininess(void); //!< Specular exponent\n" "#define occMaterial_Color occMaterial_Diffuse\n"
"float occFrontMaterial_Transparency(void); //!< Transparency coefficient\n"
"\n"
"// Back material properties accessors\n"
"vec4 occBackMaterial_Emission(void); //!< Emission color\n"
"vec4 occBackMaterial_Ambient(void); //!< Ambient reflection\n"
"vec4 occBackMaterial_Diffuse(void); //!< Diffuse reflection\n"
"vec4 occBackMaterial_Specular(void); //!< Specular reflection\n"
"float occBackMaterial_Shininess(void); //!< Specular exponent\n"
"float occBackMaterial_Transparency(void); //!< Transparency coefficient\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#ifdef THE_HAS_DEFAULT_SAMPLER\n" "#ifdef THE_HAS_DEFAULT_SAMPLER\n"
@ -230,24 +223,24 @@ static const char Shaders_Declarations_glsl[] =
"uniform sampler2D occSampler0; //!< current active sampler;\n" "uniform sampler2D occSampler0; //!< current active sampler;\n"
"#endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing\n" "#endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing\n"
"\n" "\n"
"#if defined(THE_HAS_TEXTURE_COLOR)\n" "#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)\n"
"#define occTextureColor(theMatColor, theTexCoord) (theMatColor * occTexture2D(occSamplerBaseColor, theTexCoord))\n" "#define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord))\n"
"#else\n" "#else\n"
"#define occTextureColor(theMatColor, theTexCoord) theMatColor\n" "#define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront)\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)\n" "#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerOcclusion; //!< R occlusion texture sampler\n" "uniform sampler2D occSamplerOcclusion; //!< R occlusion texture sampler\n"
"#define occTextureOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;\n" "#define occMaterialOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;\n"
"#else\n" "#else\n"
"#define occTextureOcclusion(theColor, theTexCoord)\n" "#define occMaterialOcclusion(theColor, theTexCoord)\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)\n" "#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerEmissive; //!< RGB emissive texture sampler\n" "uniform sampler2D occSamplerEmissive; //!< RGB emissive texture sampler\n"
"#define occTextureEmissive(theMatEmis, theTexCoord) (theMatEmis * occTexture2D(occSamplerEmissive, theTexCoord).rgb)\n" "#define occMaterialEmission(theIsFront, theTexCoord) (occMaterial_Emission(theIsFront) * occTexture2D(occSamplerEmissive, theTexCoord).rgb)\n"
"#else\n" "#else\n"
"#define occTextureEmissive(theMatEmis, theTexCoord) theMatEmis\n" "#define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront)\n"
"#endif\n" "#endif\n"
"\n" "\n"
"#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)\n" "#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)\n"
@ -259,11 +252,11 @@ static const char Shaders_Declarations_glsl[] =
"\n" "\n"
"#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)\n" "#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler\n" "uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler\n"
"#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)\n" "#define occMaterialRoughness(theIsFront, theTexCoord) (occPBRMaterial_NormalizedRoughness(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)\n"
"#define occTextureMetallic(theMet, theTexCoord) (theMet * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)\n" "#define occMaterialMetallic(theIsFront, theTexCoord) (occPBRMaterial_Metallic(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)\n"
"#else\n" "#else\n"
"#define occTextureRoughness(theRoug, theTexCoord) theRoug\n" "#define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront)\n"
"#define occTextureMetallic(theMet, theTexCoord) theMet\n" "#define occMaterialMetallic(theIsFront, theTexCoord) occPBRMaterial_Metallic(theIsFront)\n"
"#endif\n" "#endif\n"
"\n" "\n"
"uniform vec4 occColor; //!< color value (in case of disabled lighting)\n" "uniform vec4 occColor; //!< color value (in case of disabled lighting)\n"

View File

@ -24,7 +24,7 @@ static const char Shaders_PhongDirectionalLight_glsl[] =
" float aSpecl = 0.0;\n" " float aSpecl = 0.0;\n"
" if (aNdotL > 0.0)\n" " if (aNdotL > 0.0)\n"
" {\n" " {\n"
" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n" " aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));\n"
" }\n" " }\n"
"\n" "\n"
" Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;\n" " Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;\n"

View File

@ -31,7 +31,7 @@ static const char Shaders_PhongPointLight_glsl[] =
" float aSpecl = 0.0;\n" " float aSpecl = 0.0;\n"
" if (aNdotL > 0.0)\n" " if (aNdotL > 0.0)\n"
" {\n" " {\n"
" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n" " aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));\n"
" }\n" " }\n"
"\n" "\n"
" Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n" " Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n"

View File

@ -46,7 +46,7 @@ static const char Shaders_PhongSpotLight_glsl[] =
" float aSpecl = 0.0;\n" " float aSpecl = 0.0;\n"
" if (aNdotL > 0.0)\n" " if (aNdotL > 0.0)\n"
" {\n" " {\n"
" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n" " aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));\n"
" }\n" " }\n"
"\n" "\n"
" Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n" " Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n"