mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-01 17:36:21 +03:00
Add test for back vertex color
This commit is contained in:
parent
c1d8d32346
commit
cb760284e8
@ -150,7 +150,7 @@ void Graphic3d_ArrayOfPrimitives::init (Graphic3d_TypeOfPrimitiveArray theType,
|
||||
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;
|
||||
|
@ -381,6 +381,62 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
//! 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
|
||||
|
@ -1327,7 +1327,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
|
||||
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);"
|
||||
@ -1351,7 +1351,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
|
||||
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);"
|
||||
@ -1408,7 +1408,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramGouraud (c
|
||||
{
|
||||
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
|
||||
@ -1432,7 +1432,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramGouraud (c
|
||||
|
||||
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;
|
||||
@ -1583,7 +1583,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramPhong (con
|
||||
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
|
||||
@ -1622,7 +1622,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getStdProgramPhong (con
|
||||
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;
|
||||
|
@ -201,8 +201,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
|
||||
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))
|
||||
|
@ -3432,6 +3432,12 @@ Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimTyp
|
||||
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))
|
||||
{
|
||||
@ -3557,6 +3563,13 @@ Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimTyp
|
||||
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(),
|
||||
@ -7051,7 +7064,7 @@ Use vtop to see projected HLR shape.
|
||||
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]
|
||||
|
@ -15,6 +15,12 @@ set aColors {
|
||||
{{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}
|
||||
@ -26,11 +32,12 @@ proc genTris {theFrom theTo theColors} {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user