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.
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.
-@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.
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.
+
+@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.
EOL" float aSpecl = 0.0;"
EOL" if (aNdotL > 0.0)"
EOL" {"
- EOL" aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());"
+ EOL" aSpecl = pow (aNdotH, occMaterial_Shininess(theIsFront));"
EOL" }"
EOL
EOL" Diffuse += occLight_Diffuse(0) * aNdotL * theShadow;"
const Handle(Graphic3d_LightSet)& theLights,
Standard_Boolean theHasVertColor,
Standard_Boolean theIsPBR,
- Standard_Boolean theHasEmissive,
+ Standard_Boolean theHasTexColor,
Standard_Integer theNbShadowMaps) const
{
TCollection_AsciiString aLightsFunc, aLightsLoop;
}
}
- TCollection_AsciiString aGetMatAmbient = "theIsFront ? occFrontMaterial_Ambient() : occBackMaterial_Ambient();";
- TCollection_AsciiString aGetMatDiffuse = "theIsFront ? occFrontMaterial_Diffuse() : occBackMaterial_Diffuse();";
+ TCollection_AsciiString aGetMatAmbient = "occMaterial_Ambient(theIsFront);";
+ TCollection_AsciiString aGetMatDiffuse = "occMaterial_Diffuse(theIsFront);";
if (theHasVertColor)
{
- aGetMatAmbient = "getVertColor();";
+ aGetMatAmbient = "getVertColor().rgb;";
aGetMatDiffuse = "getVertColor();";
}
EOL" Specular = vec3 (0.0);"
EOL" vec3 aPoint = thePoint.xyz / thePoint.w;"
+ aLightsLoop
- + EOL" vec4 aMatAmbient = " + aGetMatAmbient
+ + EOL" vec3 aMatAmbient = " + aGetMatAmbient
+ EOL" vec4 aMatDiffuse = " + aGetMatDiffuse
- + EOL" vec4 aMatSpecular = theIsFront ? occFrontMaterial_Specular() : occBackMaterial_Specular();"
- EOL" vec3 aColor = Ambient * aMatAmbient.rgb + Diffuse * aMatDiffuse.rgb + Specular * aMatSpecular.rgb;"
- EOL" occTextureOcclusion(aColor, TexCoord.st);"
- + (theHasEmissive
- ? EOL" vec4 aMatEmission = theIsFront ? occFrontMaterial_Emission() : occBackMaterial_Emission();"
- EOL" aColor += aMatEmission.rgb;" : "")
- + EOL" return vec4 (aColor, aMatDiffuse.a);"
+ + EOL" vec3 aMatSpecular = occMaterial_Specular(theIsFront);"
+ EOL" vec4 aColor = vec4(Ambient * aMatAmbient + Diffuse * aMatDiffuse.rgb + Specular * aMatSpecular, aMatDiffuse.a);"
+ + (theHasTexColor ?
+ EOL"#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)"
+ EOL" aColor *= occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w);"
+ EOL"#endif" : "")
+ + 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"}";
}
else
EOL" in bool theIsFront)"
EOL"{"
EOL" DirectLighting = vec3(0.0);"
- EOL" BaseColor = " + (theHasVertColor ? "getVertColor();" : "occTextureColor(occPBRMaterial_Color (theIsFront), TexCoord.st / TexCoord.w);")
- + EOL" Emission = occTextureEmissive(occPBRMaterial_Emission (theIsFront), TexCoord.st / TexCoord.w);"
- EOL" Metallic = occTextureMetallic(occPBRMaterial_Metallic (theIsFront), TexCoord.st / TexCoord.w);"
- EOL" NormalizedRoughness = occTextureRoughness(occPBRMaterial_NormalizedRoughness (theIsFront), TexCoord.st / TexCoord.w);"
+ EOL" BaseColor = " + (theHasVertColor ? "getVertColor();" : "occMaterialBaseColor(theIsFront, TexCoord.st / TexCoord.w);")
+ + EOL" Emission = occMaterialEmission(theIsFront, TexCoord.st / TexCoord.w);"
+ EOL" Metallic = occMaterialMetallic(theIsFront, TexCoord.st / TexCoord.w);"
+ EOL" NormalizedRoughness = occMaterialRoughness(theIsFront, TexCoord.st / TexCoord.w);"
EOL" Roughness = occRoughness (NormalizedRoughness);"
EOL" IOR = occPBRMaterial_IOR (theIsFront);"
EOL" vec3 aPoint = thePoint.xyz / thePoint.w;"
EOL" anIndirectLightingDiff *= occDiffIBLMap (theNormal).rgb;"
EOL" aColor += occLightAmbient.rgb * (anIndirectLightingDiff + anIndirectLightingSpec);"
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"}";
}
TCollection_AsciiString aSrcFrag, aSrcFragExtraMain;
TCollection_AsciiString aSrcFragGetColor = EOL"vec4 getColor(void) { return gl_FrontFacing ? FrontColor : BackColor; }";
Graphic3d_ShaderObject::ShaderVariableList aUniforms, aStageInOuts;
-
+ bool toUseTexColor = false;
if ((theBits & Graphic3d_ShaderFlags_IsPoint) != 0)
{
if (mySetPointSize)
{
if ((theBits & Graphic3d_ShaderFlags_TextureRGB) != 0)
{
+ toUseTexColor = true;
aProgramSrc->SetTextureSetBits (Graphic3d_TextureSetBits_BaseColor);
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 BackColor", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
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()
+ THE_FUNC_transformNormal_view
+ EOL
"computeLighting (normalize (Normal), normalize (View), " + aPosition + ", gl_FrontFacing)";
const bool isFlatNormal = theIsFlatNormal && myHasFlatShading;
const char* aDFdxSignReversion = myToReverseDFdxSign ? "-" : "";
+ bool toUseTexColor = false;
if (isFlatNormal != theIsFlatNormal)
{
Message::SendWarning ("Warning: flat shading requires OpenGL ES 3.0+ or GL_OES_standard_derivatives extension");
{
if ((theBits & Graphic3d_ShaderFlags_TextureRGB) != 0)
{
+ toUseTexColor = true;
aUniforms .Append (Graphic3d_ShaderObject::ShaderVariable ("sampler2D occSamplerBaseColor", Graphic3d_TOS_FRAGMENT));
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 TexCoord", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain += THE_VARY_TexCoord_Trsf;
Standard_Integer aTextureBits = Graphic3d_TextureSetBits_BaseColor | Graphic3d_TextureSetBits_Occlusion | Graphic3d_TextureSetBits_Emissive;
- 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
+ if (theIsPBR)
{
aTextureBits |= Graphic3d_TextureSetBits_MetallicRoughness;
}
: EOL"#define getFinalColor getColor";
Standard_Integer aNbLights = 0;
- const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, theLights, !aSrcFragGetVertColor.IsEmpty(), theIsPBR,
- (theBits & Graphic3d_ShaderFlags_TextureRGB) == 0
- || (theBits & Graphic3d_ShaderFlags_IsPoint) != 0,
- theNbShadowMaps);
+ const TCollection_AsciiString aLights = stdComputeLighting (aNbLights, theLights, !aSrcFragGetVertColor.IsEmpty(),
+ theIsPBR, toUseTexColor, theNbShadowMaps);
aSrcFrag += TCollection_AsciiString()
+ EOL
+ aSrcFragGetVertColor
//! @param theLights [in] light sources list
//! @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 theHasEmissive [in] flag to include emissive
+ //! @param theHasTexColor [in] flag to include color texturing
//! @param theNbShadowMaps [in] flag to include shadow map
Standard_EXPORT TCollection_AsciiString stdComputeLighting (Standard_Integer& theNbLights,
const Handle(Graphic3d_LightSet)& theLights,
Standard_Boolean theHasVertColor,
Standard_Boolean theIsPBR,
- Standard_Boolean theHasEmissive,
+ Standard_Boolean theHasTexColor,
Standard_Integer theNbShadowMaps) const;
protected:
? anAspect->BackInteriorColor()
: aFrontIntColor;
- myMatFront.Init (*this, aMatFrontSrc, aFrontIntColor);
- if (toDistinguish)
- {
- myMatBack.Init (*this, aMatBackSrc, aBackIntColor);
- }
- else
- {
- myMatBack = myMatFront;
- }
-
+ myMaterial.Init (*this, aMatFrontSrc, aFrontIntColor, aMatBackSrc, aBackIntColor);
if (!theHighlight.IsNull()
&& theHighlight->BasicFillAreaAspect().IsNull())
{
- myMatFront.SetColor (theHighlight->ColorRGBA());
- myMatBack .SetColor (theHighlight->ColorRGBA());
+ myMaterial.SetColor (theHighlight->ColorRGBA().GetRGB());
+ myMaterial.SetColor (theHighlight->ColorRGBA().GetRGB());
}
- Standard_ShortReal anAlphaFront = 1.0f;
- Standard_ShortReal anAlphaBack = 1.0f;
+ float anAlphaFront = 1.0f, anAlphaBack = 1.0f;
if (CheckIsTransparent (theAspect, theHighlight, anAlphaFront, anAlphaBack))
{
- myMatFront.Common.Diffuse.a() = anAlphaFront;
- myMatBack .Common.Diffuse.a() = anAlphaBack;
+ myMaterial.Common[0].Diffuse.a() = anAlphaFront;
+ myMaterial.Common[1].Diffuse.a() = anAlphaBack;
- myMatFront.Pbr.BaseColor.a() = anAlphaFront;
- myMatBack .Pbr.BaseColor.a() = anAlphaBack;
+ myMaterial.Pbr[0].BaseColor.a() = anAlphaFront;
+ myMaterial.Pbr[1].BaseColor.a() = anAlphaBack;
}
// do not update material properties in case of zero reflection mode,
return;
}
}
- else if (myMatFront == aMatState.FrontMaterial()
- && myMatBack == aMatState.BackMaterial()
+ else if (myMaterial.IsEqual (aMatState.Material())
&& toDistinguish == aMatState.ToDistinguish()
&& toMapTexture == aMatState.ToMapTexture()
&& anAlphaCutoff == aMatState.AlphaCutoff())
return;
}
- myShaderManager->UpdateMaterialStateTo (myMatFront, myMatBack, anAlphaCutoff, toDistinguish, toMapTexture);
+ myShaderManager->UpdateMaterialStateTo (myMaterial, anAlphaCutoff, toDistinguish, toMapTexture);
}
// =======================================================================
Standard_ShortReal myLineFeather; //!< line feater width in pixels
Standard_ShortReal myRenderScale; //!< scaling factor for rendering resolution
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 myMatBack; //!< current back material state
+ OpenGl_Material myMaterial; //!< current front/back material state (cached to reduce GL context updates)
private:
struct OpenGl_MaterialCommon
{
- OpenGl_Vec4 Ambient; //!< ambient reflection coefficient
- OpenGl_Vec4 Diffuse; //!< diffuse reflection coefficient
- OpenGl_Vec4 Specular; //!< glossy reflection coefficient
- OpenGl_Vec4 Emission; //!< material emission
- OpenGl_Vec4 Params; //!< extra packed parameters
+ OpenGl_Vec4 Diffuse; //!< diffuse RGB coefficients + alpha
+ OpenGl_Vec4 Emission; //!< material RGB emission
+ OpenGl_Vec4 SpecularShininess; //!< glossy RGB coefficients + shininess
+ OpenGl_Vec4 Ambient; //!< ambient RGB coefficients
- float Shine() const { return Params.x(); }
- float& ChangeShine() { return Params.x(); }
-
- float Transparency() const { return Params.y(); }
- float& ChangeTransparency() { return Params.y(); }
+ float Shine() const { return SpecularShininess.a(); }
+ float& ChangeShine() { return SpecularShininess.a(); }
//! 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
- const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
- static Standard_Integer NbOfVec4() { return 5; }
+ //! Set material color.
+ void SetColor (const OpenGl_Vec3& theColor)
+ {
+ // apply the same formula as in Graphic3d_MaterialAspect::SetColor()
+ Ambient.SetValues (theColor * 0.25f, Ambient.a());
+ Diffuse.SetValues (theColor, Diffuse.a());
+ }
};
//! Empty constructor.
OpenGl_MaterialPBR() : BaseColor (1.0f), EmissionIOR (1.0f), Params (1.0f, 1.0f, 1.0f, 1.0f) {}
- //! Returns packed (serialized) representation of material properties
- const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
- static Standard_Integer NbOfVec4() { return 3; }
+ //! Set material color.
+ void SetColor (const OpenGl_Vec3& theColor)
+ {
+ BaseColor.SetValues (theColor, BaseColor.a());
+ }
};
//! OpenGL material definition
struct OpenGl_Material
{
- OpenGl_MaterialCommon Common;
- OpenGl_MaterialPBR Pbr;
+ OpenGl_MaterialCommon Common[2];
+ OpenGl_MaterialPBR Pbr[2];
//! 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.Ambient.SetValues (theColor.rgb() * 0.25f, Common.Ambient.a());
- Common.Diffuse.SetValues (theColor.rgb(), Common.Diffuse.a());
- Pbr .BaseColor.SetValues (theColor.rgb(), Pbr.BaseColor.a());
+ Common[0].SetColor (theColor);
+ Common[1].SetColor (theColor);
+ Pbr[0].SetColor (theColor);
+ Pbr[1].SetColor (theColor);
}
//! Initialize material
void Init (const OpenGl_Context& theCtx,
- const Graphic3d_MaterialAspect& theProp,
- const Quantity_Color& theInteriorColor);
+ const Graphic3d_MaterialAspect& theFront,
+ const Quantity_Color& theFrontColor,
+ const Graphic3d_MaterialAspect& theBack,
+ const Quantity_Color& theBackColor);
//! Check this material for equality with another material (without tolerance!).
bool IsEqual (const OpenGl_Material& theOther) const
bool operator!= (const OpenGl_Material& theOther) { 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
OpenGl_MaterialState() : myAlphaCutoff (0.5f), myToDistinguish (false), myToMapTexture (false) {}
//! Sets new material aspect.
- void Set (const OpenGl_Material& theFrontMat,
- const OpenGl_Material& theBackMat,
+ void Set (const OpenGl_Material& theMat,
const float theAlphaCutoff,
const bool theToDistinguish,
const bool theToMapTexture)
{
- myMatFront = theFrontMat;
- myMatBack = theBackMat;
+ myMaterial = theMat;
myAlphaCutoff = theAlphaCutoff;
myToDistinguish = theToDistinguish;
myToMapTexture = theToMapTexture;
}
//! Return front material.
- const OpenGl_Material& FrontMaterial() const { return myMatFront; }
-
- //! Return back material.
- const OpenGl_Material& BackMaterial() const { return myMatBack; }
+ const OpenGl_Material& Material() const { return myMaterial; }
//! Alpha cutoff value.
float AlphaCutoff() const { return myAlphaCutoff; }
private:
- OpenGl_Material myMatFront; //!< front material
- OpenGl_Material myMatBack; //!< back material
+ OpenGl_Material myMaterial; //!< material
float myAlphaCutoff; //!< alpha cutoff value
bool myToDistinguish; //!< distinguish front/back flag
bool myToMapTexture; //!< flag for mapping a texture
// =======================================================================
void OpenGl_ShaderManager::pushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const
{
- const OpenGl_Material& aFrontMat = myMaterialState.FrontMaterial();
- const OpenGl_Material& aBackMat = myMaterialState.BackMaterial();
+ const OpenGl_Material& aMat = myMaterialState.Material();
theProgram->UpdateState (OpenGl_MATERIAL_STATE, myMaterialState.Index());
if (theProgram == myFfpProgram)
{
}
const GLenum aFrontFace = myMaterialState.ToDistinguish() ? GL_FRONT : GL_FRONT_AND_BACK;
- myContext->core11->glMaterialfv(aFrontFace, GL_AMBIENT, aFrontMat.Common.Ambient.GetData());
- myContext->core11->glMaterialfv(aFrontFace, GL_DIFFUSE, aFrontMat.Common.Diffuse.GetData());
- myContext->core11->glMaterialfv(aFrontFace, GL_SPECULAR, aFrontMat.Common.Specular.GetData());
- myContext->core11->glMaterialfv(aFrontFace, GL_EMISSION, aFrontMat.Common.Emission.GetData());
- myContext->core11->glMaterialf (aFrontFace, GL_SHININESS, aFrontMat.Common.Shine());
+ const OpenGl_MaterialCommon& aFrontMat = aMat.Common[0];
+ const OpenGl_MaterialCommon& aBackMat = aMat.Common[1];
+ const Graphic3d_Vec4 aSpec4 (aFrontMat.SpecularShininess.rgb(), 1.0f);
+ myContext->core11->glMaterialfv(aFrontFace, GL_AMBIENT, aFrontMat.Ambient.GetData());
+ 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())
{
- myContext->core11->glMaterialfv(GL_BACK, GL_AMBIENT, aBackMat.Common.Ambient.GetData());
- myContext->core11->glMaterialfv(GL_BACK, GL_DIFFUSE, aBackMat.Common.Diffuse.GetData());
- myContext->core11->glMaterialfv(GL_BACK, GL_SPECULAR, aBackMat.Common.Specular.GetData());
- myContext->core11->glMaterialfv(GL_BACK, GL_EMISSION, aBackMat.Common.Emission.GetData());
- myContext->core11->glMaterialf (GL_BACK, GL_SHININESS, aBackMat.Common.Shine());
+ const Graphic3d_Vec4 aSpec4Back (aBackMat.SpecularShininess.rgb(), 1.0f);
+ myContext->core11->glMaterialfv(GL_BACK, GL_AMBIENT, aBackMat.Ambient.GetData());
+ myContext->core11->glMaterialfv(GL_BACK, GL_DIFFUSE, aBackMat.Diffuse.GetData());
+ myContext->core11->glMaterialfv(GL_BACK, GL_SPECULAR, aSpec4Back.GetData());
+ myContext->core11->glMaterialfv(GL_BACK, GL_EMISSION, aBackMat.Emission.GetData());
+ myContext->core11->glMaterialf (GL_BACK, GL_SHININESS, aBackMat.Shine());
}
#endif
return;
theProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE),
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(),
- aFrontMat.Pbr.Packed());
+ theProgram->SetUniform (myContext, aLocPbrFront, OpenGl_Material::NbOfVec4Pbr(), aMat.PackedPbr());
}
- 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(),
- 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());
+ theProgram->SetUniform (myContext, aLocFront, OpenGl_Material::NbOfVec4Common(), aMat.PackedCommon());
}
}
const OpenGl_MaterialState& MaterialState() const { return myMaterialState; }
//! Updates state of material.
- void UpdateMaterialStateTo (const OpenGl_Material& theFrontMat,
- const OpenGl_Material& theBackMat,
+ void UpdateMaterialStateTo (const OpenGl_Material& theMat,
const float theAlphaCutoff,
const bool theToDistinguish,
const bool theToMapTexture)
{
- myMaterialState.Set (theFrontMat, theBackMat, theAlphaCutoff, theToDistinguish, theToMapTexture);
+ myMaterialState.Set (theMat, theAlphaCutoff, theToDistinguish, theToMapTexture);
myMaterialState.Update();
}
"occTextureEnable", // OpenGl_OCCT_TEXTURE_ENABLE
"occDistinguishingMode", // OpenGl_OCCT_DISTINGUISH_MODE
- "occPbrFrontMaterial", // OpenGl_OCCT_PBR_FRONT_MATERIAL
- "occPbrBackMaterial", // OpenGl_OCCT_PBR_BACK_MATERIAL
- "occFrontMaterial", // OpenGl_OCCT_COMMON_FRONT_MATERIAL
- "occBackMaterial", // OpenGl_OCCT_COMMON_BACK_MATERIAL
+ "occPbrMaterial", // OpenGl_OCCT_PBR_MATERIAL
+ "occCommonMaterial", // OpenGl_OCCT_COMMON_MATERIAL
"occAlphaCutoff", // OpenGl_OCCT_ALPHA_CUTOFF
"occColor", // OpenGl_OCCT_COLOR
// Material state
OpenGl_OCCT_TEXTURE_ENABLE,
OpenGl_OCCT_DISTINGUISH_MODE,
- OpenGl_OCCT_PBR_FRONT_MATERIAL,
- OpenGl_OCCT_PBR_BACK_MATERIAL,
- OpenGl_OCCT_COMMON_FRONT_MATERIAL,
- OpenGl_OCCT_COMMON_BACK_MATERIAL,
+ OpenGl_OCCT_PBR_MATERIAL,
+ OpenGl_OCCT_COMMON_MATERIAL,
OpenGl_OCCT_ALPHA_CUTOFF,
OpenGl_OCCT_COLOR,
// purpose :
// =======================================================================
void OpenGl_Material::Init (const OpenGl_Context& theCtx,
- const Graphic3d_MaterialAspect& theMat,
- const Quantity_Color& theInteriorColor)
+ const Graphic3d_MaterialAspect& theFront,
+ const Quantity_Color& theFrontColor,
+ const Graphic3d_MaterialAspect& theBack,
+ const Quantity_Color& theBackColor)
{
- Common.ChangeShine() = 128.0f * theMat.Shininess();
- Common.ChangeTransparency() = theMat.Alpha();
+ init (theCtx, theFront, theFrontColor, 0);
+ 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();
- Pbr.EmissionIOR = Graphic3d_Vec4 (theMat.PBRMaterial().Emission(), theMat.PBRMaterial().IOR());
+// =======================================================================
+// function : init
+// 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& aSrcDif = theMat.DiffuseColor();
const OpenGl_Vec3& aSrcSpe = theMat.SpecularColor();
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())
{
case Graphic3d_MATERIAL_ASPECT:
{
- Common.Ambient .SetValues (aSrcAmb * theInteriorColor, 1.0f);
- Common.Diffuse .SetValues (aSrcDif * theInteriorColor, 1.0f);
- Common.Emission.SetValues (aSrcEms * theInteriorColor, 1.0f);
- Pbr .BaseColor.SetValues (theInteriorColor, theMat.Alpha());
+ aCommon.Diffuse .SetValues (aSrcDif * theInteriorColor, theMat.Alpha());
+ aCommon.Ambient .SetValues (aSrcAmb * theInteriorColor, 1.0f);
+ aCommon.Emission.SetValues (aSrcEms * theInteriorColor, 1.0f);
+ aPbr .BaseColor.SetValues (theInteriorColor, theMat.Alpha());
break;
}
case Graphic3d_MATERIAL_PHYSIC:
{
- Common.Ambient .SetValues (aSrcAmb, 1.0f);
- Common.Diffuse .SetValues (aSrcDif, 1.0f);
- Common.Emission.SetValues (aSrcEms, 1.0f);
- Pbr.BaseColor = theMat.PBRMaterial().Color();
+ aCommon.Diffuse .SetValues (aSrcDif, theMat.Alpha());
+ aCommon.Ambient .SetValues (aSrcAmb, 1.0f);
+ aCommon.Emission.SetValues (aSrcEms, 1.0f);
+ aPbr.BaseColor = theMat.PBRMaterial().Color();
break;
}
}
- Common.Ambient = theCtx.Vec4FromQuantityColor (Common.Ambient);
- Common.Diffuse = theCtx.Vec4FromQuantityColor (Common.Diffuse);
- Common.Specular = theCtx.Vec4FromQuantityColor (Common.Specular);
- Common.Emission = theCtx.Vec4FromQuantityColor (Common.Emission);
+ aCommon.Diffuse = theCtx.Vec4FromQuantityColor (aCommon.Diffuse);
+ aCommon.Ambient = theCtx.Vec4FromQuantityColor (aCommon.Ambient);
+ aCommon.SpecularShininess = theCtx.Vec4FromQuantityColor (aCommon.SpecularShininess);
+ aCommon.Emission = theCtx.Vec4FromQuantityColor (aCommon.Emission);
}
// =======================================================================
float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient
vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material
float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction
+#define occMaterial_Emission occPBRMaterial_Emission
+#define occMaterial_Color occPBRMaterial_Color
#else
-// Front material properties accessors
-vec4 occFrontMaterial_Emission(void); //!< Emission color
-vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection
-vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection
-vec4 occFrontMaterial_Specular(void); //!< Specular reflection
-float occFrontMaterial_Shininess(void); //!< Specular exponent
-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
+vec4 occMaterial_Diffuse(in bool theIsFront); //!< Diffuse reflection
+vec3 occMaterial_Specular(in bool theIsFront); //!< Specular reflection
+float occMaterial_Shininess(in bool theIsFront); //!< Specular exponent
+vec3 occMaterial_Ambient(in bool theIsFront); //!< Ambient reflection
+vec3 occMaterial_Emission(in bool theIsFront); //!< Emission color
+#define occMaterial_Color occMaterial_Diffuse
#endif
#ifdef THE_HAS_DEFAULT_SAMPLER
uniform sampler2D occSampler0; //!< current active sampler;
#endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
-#if defined(THE_HAS_TEXTURE_COLOR)
-#define occTextureColor(theMatColor, theTexCoord) (theMatColor * occTexture2D(occSamplerBaseColor, theTexCoord))
+#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)
+#define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord))
#else
-#define occTextureColor(theMatColor, theTexCoord) theMatColor
+#define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront)
#endif
#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)
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
-#define occTextureOcclusion(theColor, theTexCoord)
+#define occMaterialOcclusion(theColor, theTexCoord)
#endif
#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)
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
-#define occTextureEmissive(theMatEmis, theTexCoord) theMatEmis
+#define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront)
#endif
#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)
#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)
uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler
-#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)
-#define occTextureMetallic(theMet, theTexCoord) (theMet * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)
+#define occMaterialRoughness(theIsFront, theTexCoord) (occPBRMaterial_NormalizedRoughness(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)
+#define occMaterialMetallic(theIsFront, theTexCoord) (occPBRMaterial_Metallic(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)
#else
-#define occTextureRoughness(theRoug, theTexCoord) theRoug
-#define occTextureMetallic(theMet, theTexCoord) theMet
+#define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront)
+#define occMaterialMetallic(theIsFront, theTexCoord) occPBRMaterial_Metallic(theIsFront)
#endif
uniform vec4 occColor; //!< color value (in case of disabled lighting)
// front and back material properties accessors
#if defined(THE_IS_PBR)
-uniform vec4 occPbrFrontMaterial[3];
-uniform vec4 occPbrBackMaterial[3];
+uniform vec4 occPbrMaterial[3 * 2];
#define MIN_ROUGHNESS 0.01
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]; }
-vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].rgb : occPbrBackMaterial[1].rgb; }
-float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].w : occPbrBackMaterial[1].w; }
-float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].b : occPbrBackMaterial[2].b; }
-float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].g : occPbrBackMaterial[2].g; }
+vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrMaterial[0] : occPbrMaterial[3]; }
+vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].rgb : occPbrMaterial[4].rgb; }
+float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].w : occPbrMaterial[4].w; }
+float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].b : occPbrMaterial[5].b; }
+float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].g : occPbrMaterial[5].g; }
#else
-uniform vec4 occFrontMaterial[5];
-uniform vec4 occBackMaterial[5];
+uniform vec4 occCommonMaterial[4 * 2];
-vec4 occFrontMaterial_Ambient(void) { return occFrontMaterial[0]; }
-vec4 occFrontMaterial_Diffuse(void) { return occFrontMaterial[1]; }
-vec4 occFrontMaterial_Specular(void) { return occFrontMaterial[2]; }
-vec4 occFrontMaterial_Emission(void) { return occFrontMaterial[3]; }
-float occFrontMaterial_Shininess(void) { return occFrontMaterial[4].x; }
-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; }
+vec4 occMaterial_Diffuse(in bool theIsFront) { return theIsFront ? occCommonMaterial[0] : occCommonMaterial[4]; }
+vec3 occMaterial_Emission(in bool theIsFront) { return theIsFront ? occCommonMaterial[1].rgb : occCommonMaterial[5].rgb; }
+vec3 occMaterial_Specular(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].rgb : occCommonMaterial[6].rgb; }
+float occMaterial_Shininess(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].a : occCommonMaterial[6].a; }
+vec3 occMaterial_Ambient(in bool theIsFront) { return theIsFront ? occCommonMaterial[3].rgb : occCommonMaterial[7].rgb; }
#endif
// 2D texture coordinates transformation
float aSpecl = 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;
float aSpecl = 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;
float aSpecl = 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;
float aSpecl = 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;
float aSpecl = 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;
}
}
- vec4 aMaterialAmbient = gl_FrontFacing ? occFrontMaterial_Ambient() : occBackMaterial_Ambient();
- vec4 aMaterialDiffuse = gl_FrontFacing ? occFrontMaterial_Diffuse() : occBackMaterial_Diffuse();
- vec4 aMaterialSpecular = gl_FrontFacing ? occFrontMaterial_Specular() : occBackMaterial_Specular();
- vec4 aMaterialEmission = gl_FrontFacing ? occFrontMaterial_Emission() : occBackMaterial_Emission();
- vec3 aColor = Ambient * aMaterialAmbient.rgb
- + Diffuse * aMaterialDiffuse.rgb
- + Specular * aMaterialSpecular.rgb
- + aMaterialEmission.rgb;
- return vec4 (aColor, aMaterialDiffuse.a);
+ vec3 aMatAmbient = occMaterial_Ambient (gl_FrontFacing);
+ vec4 aMatDiffuse = occMaterial_Diffuse (gl_FrontFacing);
+ vec3 aMatSpecular = occMaterial_Specular(gl_FrontFacing);
+ vec3 aMatEmission = occMaterial_Emission(gl_FrontFacing);
+ vec3 aColor = Ambient * aMatAmbient.rgb
+ + Diffuse * aMatDiffuse.rgb
+ + Specular * aMatSpecular.rgb
+ + aMatEmission.rgb;
+ return vec4 (aColor, aMatDiffuse.a);
}
//! Entry point to the Fragment Shader
float aSpecl = 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;
"\n"
"// front and back material properties accessors\n"
"#if defined(THE_IS_PBR)\n"
- "uniform vec4 occPbrFrontMaterial[3];\n"
- "uniform vec4 occPbrBackMaterial[3];\n"
+ "uniform vec4 occPbrMaterial[3 * 2];\n"
"\n"
"#define MIN_ROUGHNESS 0.01\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"
- "vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].rgb : occPbrBackMaterial[1].rgb; }\n"
- "float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[1].w : occPbrBackMaterial[1].w; }\n"
- "float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].b : occPbrBackMaterial[2].b; }\n"
- "float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrFrontMaterial[2].g : occPbrBackMaterial[2].g; }\n"
+ "vec4 occPBRMaterial_Color(in bool theIsFront) { return theIsFront ? occPbrMaterial[0] : occPbrMaterial[3]; }\n"
+ "vec3 occPBRMaterial_Emission(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].rgb : occPbrMaterial[4].rgb; }\n"
+ "float occPBRMaterial_IOR(in bool theIsFront) { return theIsFront ? occPbrMaterial[1].w : occPbrMaterial[4].w; }\n"
+ "float occPBRMaterial_Metallic(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].b : occPbrMaterial[5].b; }\n"
+ "float occPBRMaterial_NormalizedRoughness(in bool theIsFront) { return theIsFront ? occPbrMaterial[2].g : occPbrMaterial[5].g; }\n"
"#else\n"
- "uniform vec4 occFrontMaterial[5];\n"
- "uniform vec4 occBackMaterial[5];\n"
+ "uniform vec4 occCommonMaterial[4 * 2];\n"
"\n"
- "vec4 occFrontMaterial_Ambient(void) { return occFrontMaterial[0]; }\n"
- "vec4 occFrontMaterial_Diffuse(void) { return occFrontMaterial[1]; }\n"
- "vec4 occFrontMaterial_Specular(void) { return occFrontMaterial[2]; }\n"
- "vec4 occFrontMaterial_Emission(void) { return occFrontMaterial[3]; }\n"
- "float occFrontMaterial_Shininess(void) { return occFrontMaterial[4].x; }\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"
+ "vec4 occMaterial_Diffuse(in bool theIsFront) { return theIsFront ? occCommonMaterial[0] : occCommonMaterial[4]; }\n"
+ "vec3 occMaterial_Emission(in bool theIsFront) { return theIsFront ? occCommonMaterial[1].rgb : occCommonMaterial[5].rgb; }\n"
+ "vec3 occMaterial_Specular(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].rgb : occCommonMaterial[6].rgb; }\n"
+ "float occMaterial_Shininess(in bool theIsFront) { return theIsFront ? occCommonMaterial[2].a : occCommonMaterial[6].a; }\n"
+ "vec3 occMaterial_Ambient(in bool theIsFront) { return theIsFront ? occCommonMaterial[3].rgb : occCommonMaterial[7].rgb; }\n"
"#endif\n"
"\n"
"// 2D texture coordinates transformation\n"
"float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient\n"
"vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material\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"
- "// Front material properties accessors\n"
- "vec4 occFrontMaterial_Emission(void); //!< Emission color\n"
- "vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection\n"
- "vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection\n"
- "vec4 occFrontMaterial_Specular(void); //!< Specular reflection\n"
- "float occFrontMaterial_Shininess(void); //!< Specular exponent\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"
+ "vec4 occMaterial_Diffuse(in bool theIsFront); //!< Diffuse reflection\n"
+ "vec3 occMaterial_Specular(in bool theIsFront); //!< Specular reflection\n"
+ "float occMaterial_Shininess(in bool theIsFront); //!< Specular exponent\n"
+ "vec3 occMaterial_Ambient(in bool theIsFront); //!< Ambient reflection\n"
+ "vec3 occMaterial_Emission(in bool theIsFront); //!< Emission color\n"
+ "#define occMaterial_Color occMaterial_Diffuse\n"
"#endif\n"
"\n"
"#ifdef THE_HAS_DEFAULT_SAMPLER\n"
"uniform sampler2D occSampler0; //!< current active sampler;\n"
"#endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing\n"
"\n"
- "#if defined(THE_HAS_TEXTURE_COLOR)\n"
- "#define occTextureColor(theMatColor, theTexCoord) (theMatColor * occTexture2D(occSamplerBaseColor, theTexCoord))\n"
+ "#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)\n"
+ "#define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord))\n"
"#else\n"
- "#define occTextureColor(theMatColor, theTexCoord) theMatColor\n"
+ "#define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront)\n"
"#endif\n"
"\n"
"#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)\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"
- "#define occTextureOcclusion(theColor, theTexCoord)\n"
+ "#define occMaterialOcclusion(theColor, theTexCoord)\n"
"#endif\n"
"\n"
"#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)\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"
- "#define occTextureEmissive(theMatEmis, theTexCoord) theMatEmis\n"
+ "#define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront)\n"
"#endif\n"
"\n"
"#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)\n"
"\n"
"#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)\n"
"uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler\n"
- "#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)\n"
- "#define occTextureMetallic(theMet, theTexCoord) (theMet * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)\n"
+ "#define occMaterialRoughness(theIsFront, theTexCoord) (occPBRMaterial_NormalizedRoughness(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)\n"
+ "#define occMaterialMetallic(theIsFront, theTexCoord) (occPBRMaterial_Metallic(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)\n"
"#else\n"
- "#define occTextureRoughness(theRoug, theTexCoord) theRoug\n"
- "#define occTextureMetallic(theMet, theTexCoord) theMet\n"
+ "#define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront)\n"
+ "#define occMaterialMetallic(theIsFront, theTexCoord) occPBRMaterial_Metallic(theIsFront)\n"
"#endif\n"
"\n"
"uniform vec4 occColor; //!< color value (in case of disabled lighting)\n"
" float aSpecl = 0.0;\n"
" if (aNdotL > 0.0)\n"
" {\n"
- " aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n"
+ " aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));\n"
" }\n"
"\n"
" Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;\n"
" float aSpecl = 0.0;\n"
" if (aNdotL > 0.0)\n"
" {\n"
- " aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n"
+ " aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));\n"
" }\n"
"\n"
" Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n"
" float aSpecl = 0.0;\n"
" if (aNdotL > 0.0)\n"
" {\n"
- " aSpecl = pow (aNdotH, theIsFront ? occFrontMaterial_Shininess() : occBackMaterial_Shininess());\n"
+ " aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));\n"
" }\n"
"\n"
" Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;\n"