myIndices->NbElements = 0;
}
- Graphic3d_Attribute anAttribs[4];
+ Graphic3d_Attribute anAttribs[5];
Standard_Integer aNbAttribs = 0;
anAttribs[aNbAttribs].Id = Graphic3d_TOA_POS;
anAttribs[aNbAttribs].DataType = Graphic3d_TOD_VEC3;
}
}
+ //! Change the vertex color back in the array.
+ //! @param[in] theIndex node index within [1, VertexNumberAllocated()] range
+ //! @param[in] theColor node color
+ void SetVertexColorBack (const Standard_Integer theIndex, const Quantity_Color& theColor)
+ {
+ SetVertexColorBack (theIndex, theColor.Red(), theColor.Green(), theColor.Blue());
+ }
+
+ //! Change the vertex color back in the array.
+ //! @param[in] theIndex node index within [1, VertexNumberAllocated()] range
+ //! @param[in] theR red color value within [0, 1] range
+ //! @param[in] theG green color value within [0, 1] range
+ //! @param[in] theB blue color value within [0, 1] range
+ void SetVertexColorBack (const Standard_Integer theIndex, const Standard_Real theR, const Standard_Real theG, const Standard_Real theB)
+ {
+ Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
+ if (myColDataBack != NULL)
+ {
+ Graphic3d_Vec4ub* aColorPtr = reinterpret_cast<Graphic3d_Vec4ub* >(myColDataBack + myColStrideBack * ((Standard_Size)theIndex - 1));
+ aColorPtr->SetValues (Standard_Byte(theR * 255.0),
+ Standard_Byte(theG * 255.0),
+ Standard_Byte(theB * 255.0), 255);
+ }
+ myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
+ }
+
+ //! Change the vertex color back in the array.
+ //! @param[in] theIndex node index within [1, VertexNumberAllocated()] range
+ //! @param[in] theColor node RGBA color values within [0, 255] range
+ void SetVertexColorBack (const Standard_Integer theIndex,
+ const Graphic3d_Vec4ub& theColor)
+ {
+ Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
+ if (myColDataBack != NULL)
+ {
+ Graphic3d_Vec4ub* aColorPtr = reinterpret_cast<Graphic3d_Vec4ub* >(myColDataBack + myColStrideBack * ((Standard_Size)theIndex - 1));
+ (*aColorPtr) = theColor;
+ }
+ myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
+ }
+
+ //! Change the vertex color back in the array.
+ //! @code
+ //! theColor32 = Alpha << 24 + Blue << 16 + Green << 8 + Red
+ //! @endcode
+ //! @param[in] theIndex node index within [1, VertexNumberAllocated()] range
+ //! @param[in] theColor32 packed RGBA color values
+ void SetVertexColorBack (const Standard_Integer theIndex, const Standard_Integer theColor32)
+ {
+ Standard_OutOfRange_Raise_if(theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
+ if (myColDataBack != NULL)
+ {
+ *reinterpret_cast<Standard_Integer* >(myColDataBack + myColStrideBack * ((Standard_Size)theIndex - 1)) = theColor32;
+ }
+ }
+
//! Change the vertex normal in the array.
//! @param[in] theIndex node index within [1, VertexNumberAllocated()] range
//! @param[in] theNormal normalized surface normal
EOL" vec3 aMatSpecular = occMaterial_Specular(theIsFront);"
EOL" vec4 aColor = vec4(Ambient * aMatAmbient + Diffuse * aMatDiffuse.rgb + Specular * aMatSpecular, aMatDiffuse.a);"
+ (theHasVertColor ?
- EOL" aColor *= getVertColor();" : "")
+ EOL" aColor *= getVertColor(theIsFront);" : "")
+ (theHasTexColor ?
EOL"#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)"
EOL" aColor *= occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w);"
EOL" in bool theIsFront)"
EOL"{"
EOL" DirectLighting = vec3(0.0);"
- EOL" BaseColor = occMaterialBaseColor(theIsFront, TexCoord.st / TexCoord.w)" + (theHasVertColor ? " * getVertColor()" : "") + ";"
+ EOL" BaseColor = occMaterialBaseColor(theIsFront, TexCoord.st / TexCoord.w)" + (theHasVertColor ? " * getVertColor(theIsFront)" : "") + ";"
+ EOL" Emission = occMaterialEmission(theIsFront, TexCoord.st / TexCoord.w);"
EOL" Metallic = occMaterialMetallic(theIsFront, TexCoord.st / TexCoord.w);"
EOL" NormalizedRoughness = occMaterialRoughness(theIsFront, TexCoord.st / TexCoord.w);"
{
aProgramSrc->SetTextureSetBits (Graphic3d_TextureSetBits_BaseColor);
aUniforms.Append (Graphic3d_ShaderObject::ShaderVariable ("sampler2D occSamplerBaseColor", Graphic3d_TOS_VERTEX));
- aSrcVertColor = EOL"vec4 getVertColor(void) { return occTexture2D (occSamplerBaseColor, occTexCoord.xy); }";
+ aSrcVertColor = EOL"vec4 getVertColor(in bool theIsFront) { return occTexture2D (occSamplerBaseColor, occTexCoord.xy); }";
}
}
else
if ((theBits & Graphic3d_ShaderFlags_VertColor) != 0)
{
- aSrcVertColor = EOL"vec4 getVertColor(void) { return gl_FrontFacing ? VertColor : VertColorBack; }";
+ aSrcVertColor = EOL"vec4 getVertColor(in bool theIsFront) { return theIsFront ? occVertColor : occVertColorBack; }";
}
int aNbClipPlanes = 0;
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 VertColor", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain += EOL" VertColor = occTexture2D (occSamplerBaseColor, occTexCoord.xy);";
- aSrcFragGetVertColor = EOL"vec4 getVertColor(void) { return VertColor; }";
+ aSrcFragGetVertColor = EOL"vec4 getVertColor(in bool theIsFront) { return VertColor; }";
}
}
else
aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("vec4 VertColorBack", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
aSrcVertExtraMain += EOL" VertColor = occVertColor;";
aSrcVertExtraMain += EOL" VertColorBack = occVertColorBack;";
- aSrcFragGetVertColor = EOL"vec4 getVertColor(void) { return gl_FrontFacing ? VertColor : VertColorBack; }";
+ aSrcFragGetVertColor = EOL"vec4 getVertColor (in bool theIsFront) { return theIsFront ? VertColor : VertColorBack; }";
}
int aNbClipPlanes = 0;
Graphic3d_Attribute aGragientAttribInfo[] =
{
{ Graphic3d_TOA_POS, Graphic3d_TOD_VEC2 },
- { Graphic3d_TOA_COLOR, Graphic3d_TOD_VEC3 },
- { Graphic3d_TOA_COLOR_BACK, Graphic3d_TOD_VEC3 }
+ { Graphic3d_TOA_COLOR, Graphic3d_TOD_VEC3 }
};
if (!myAttribs->Init (4, aGragientAttribInfo, 2))
anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColor;
}
+ // vertex has a color back
+ if (CheckInputCommand("cb", theDesc, anArgIndex, 3, anArgsCount))
+ {
+ anArrayFlags = anArrayFlags | Graphic3d_ArrayFlags_VertexColorBack;
+ }
+
// vertex has a texel
if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
{
theDesc->Value (anArgIndex - 1).RealValue());
myPArray->SetVertexColor (aVertIndex, aCol.r(), aCol.g(), aCol.b());
}
+ if (CheckInputCommand("cb", theDesc, anArgIndex, 3, anArgsCount))
+ {
+ const Graphic3d_Vec3d aColBack (theDesc->Value(anArgIndex - 3).RealValue(),
+ theDesc->Value(anArgIndex - 2).RealValue(),
+ theDesc->Value(anArgIndex - 1).RealValue());
+ myPArray->SetVertexColorBack (aVertIndex, aColBack.r(), aColBack.g(), aColBack.b());
+ }
if (CheckInputCommand ("t", theDesc, anArgIndex, 2, anArgsCount))
{
const Graphic3d_Vec2 aTex ((float )theDesc->Value (anArgIndex - 2).RealValue(),
vdrawparray name TypeOfArray={points|segments|polylines|triangles
|trianglefans|trianglestrips|quads|quadstrips|polygons}
[-deinterleaved|-mutable]
- [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [texel={'t' tx ty}]]
+ [vertex={'v' x y z [normal={'n' nx ny nz}] [color={'c' r g b}] [colorBack={'cb' r g b}] [texel={'t' tx ty}]]
[bound= {'b' nbVertices [bound_color={'c' r g b}]]
[edge= {'e' vertexId]
[-shape shapeName] [-patch]
{{0.5 0.0 0.0} {0.0 0.0 0.5} {0.0 0.5 0.0}}
{{0.5 0.5 0.0} {0.0 0.5 0.5} {0.5 0.0 0.5}}
}
+set aColorsBack {
+ {{1.0 0.0 0.0} {0.0 1.0 0.0} {1.0 0.0 0.0}}
+ {{0.0 1.0 0.0} {1.0 0.0 0.0} {0.0 1.0 0.0}}
+ {{0.0 0.0 1.0} {1.0 0.0 0.0} {0.0 0.0 1.0}}
+ {{1.0 1.0 1.0} {1.0 0.0 0.0} {1.0 1.0 1.0}}
+}
set aNormals {
{ 0 0 -1}
{ 1 1 1}
set aTris ""
for {set t $theFrom} {$t <= $theTo} {incr t} {
for {set n 0} {$n < 3} {incr n} {
- set aVert [lindex $::aVerts $t]
- set aCol [lindex $::aColors $t]
- set aNorm [lindex $::aNormals $t]
+ set aVert [lindex $::aVerts $t]
+ set aCol [lindex $::aColors $t]
+ set aColBack [lindex $::aColorsBack $t]
+ set aNorm [lindex $::aNormals $t]
set aTris "$aTris v [lindex $aVert $n] n $aNorm"
- if { $theColors == 1 } { set aTris "$aTris c [lindex $aCol $n]" }
+ if { $theColors == 1 } { set aTris "$aTris c [lindex $aCol $n] cb [lindex $aColBack $n]" }
}
}
return $aTris