mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +03:00
0032198: Visualization, TKOpenGl - per-vertex lighting ignores back/front material colors
Graphic3d_ShaderManager::stdComputeLighting() now multiplies vertex color by material color.
This commit is contained in:
parent
941f6cae55
commit
61a05a3658
@ -2221,3 +2221,11 @@ The same is applicable to *Poly_PolygonOnTriangulation* interface.
|
|||||||
|
|
||||||
Accessors to standard materials have been modified within *Declarations.glsl* (*occFrontMaterial_Diffuse()* -> *occMaterial_Diffuse(bool)* and similar).
|
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.
|
Applications defining custom GLSL programs should take into account syntax changes.
|
||||||
|
|
||||||
|
@subsection upgrade_occt760_noral_colors Nodal color modulation
|
||||||
|
|
||||||
|
Nodal color vertex attribute is now modulated in the same way as a color texture - color is multiplied by material coefficients (diffuse/ambient/specular in case of a common material definition).
|
||||||
|
Existing code defining nodal colors should be updated to:
|
||||||
|
- Use *Graphic3d_TOSM_UNLIT* shading model when lighting is not needed.
|
||||||
|
- Adjust diffuse/ambient material coefficients, which have been previously ignored.
|
||||||
|
- Remove code multiplying nodal colors, intended to compensate over-brightness due to addition of specular color from material definition, as specular component is now also modulated by a vertex color.
|
||||||
|
@ -133,7 +133,7 @@ void AIS_Triangulation::Compute (const Handle(PrsMgr_PresentationManager)& ,
|
|||||||
Handle(Graphic3d_Group) aGroup = thePrs->CurrentGroup();
|
Handle(Graphic3d_Group) aGroup = thePrs->CurrentGroup();
|
||||||
Handle(Graphic3d_AspectFillArea3d) anAspect = myDrawer->ShadingAspect()->Aspect();
|
Handle(Graphic3d_AspectFillArea3d) anAspect = myDrawer->ShadingAspect()->Aspect();
|
||||||
|
|
||||||
const Standard_Real anAmbient = 0.2;
|
const Standard_Real anAmbient = 1.0;
|
||||||
if (hasVNormals)
|
if (hasVNormals)
|
||||||
{
|
{
|
||||||
gp_Vec3f aNormal;
|
gp_Vec3f aNormal;
|
||||||
|
@ -1296,14 +1296,6 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TCollection_AsciiString aGetMatAmbient = "occMaterial_Ambient(theIsFront);";
|
|
||||||
TCollection_AsciiString aGetMatDiffuse = "occMaterial_Diffuse(theIsFront);";
|
|
||||||
if (theHasVertColor)
|
|
||||||
{
|
|
||||||
aGetMatAmbient = "getVertColor().rgb;";
|
|
||||||
aGetMatDiffuse = "getVertColor();";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!theIsPBR)
|
if (!theIsPBR)
|
||||||
{
|
{
|
||||||
return TCollection_AsciiString()
|
return TCollection_AsciiString()
|
||||||
@ -1321,10 +1313,12 @@ 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" vec3 aMatAmbient = " + aGetMatAmbient
|
+ EOL" vec3 aMatAmbient = occMaterial_Ambient(theIsFront);"
|
||||||
+ EOL" vec4 aMatDiffuse = " + aGetMatDiffuse
|
EOL" vec4 aMatDiffuse = occMaterial_Diffuse(theIsFront);"
|
||||||
+ EOL" vec3 aMatSpecular = occMaterial_Specular(theIsFront);"
|
EOL" vec3 aMatSpecular = occMaterial_Specular(theIsFront);"
|
||||||
EOL" vec4 aColor = vec4(Ambient * aMatAmbient + Diffuse * aMatDiffuse.rgb + Specular * aMatSpecular, aMatDiffuse.a);"
|
EOL" vec4 aColor = vec4(Ambient * aMatAmbient + Diffuse * aMatDiffuse.rgb + Specular * aMatSpecular, aMatDiffuse.a);"
|
||||||
|
+ (theHasVertColor ?
|
||||||
|
EOL" aColor *= getVertColor();" : "")
|
||||||
+ (theHasTexColor ?
|
+ (theHasTexColor ?
|
||||||
EOL"#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)"
|
EOL"#if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)"
|
||||||
EOL" aColor *= occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w);"
|
EOL" aColor *= occTexture2D(occSamplerBaseColor, TexCoord.st / TexCoord.w);"
|
||||||
@ -1348,7 +1342,7 @@ 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();" : "occMaterialBaseColor(theIsFront, TexCoord.st / TexCoord.w);")
|
EOL" BaseColor = occMaterialBaseColor(theIsFront, TexCoord.st / TexCoord.w)" + (theHasVertColor ? " * getVertColor()" : "") + ";"
|
||||||
+ EOL" Emission = occMaterialEmission(theIsFront, TexCoord.st / TexCoord.w);"
|
+ EOL" Emission = occMaterialEmission(theIsFront, TexCoord.st / TexCoord.w);"
|
||||||
EOL" Metallic = occMaterialMetallic(theIsFront, TexCoord.st / TexCoord.w);"
|
EOL" Metallic = occMaterialMetallic(theIsFront, TexCoord.st / TexCoord.w);"
|
||||||
EOL" NormalizedRoughness = occMaterialRoughness(theIsFront, TexCoord.st / TexCoord.w);"
|
EOL" NormalizedRoughness = occMaterialRoughness(theIsFront, TexCoord.st / TexCoord.w);"
|
||||||
|
@ -274,7 +274,7 @@ void MeshVS_NodalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& Prs,
|
|||||||
gp_Dir aDefNorm( 0., 0., 1. );
|
gp_Dir aDefNorm( 0., 0., 1. );
|
||||||
|
|
||||||
// Prepare for scaling the incoming colors
|
// Prepare for scaling the incoming colors
|
||||||
const Standard_Real anColorRatio = !IsReflect ? 0.44f : 0.5f;
|
const Standard_Real anColorRatio = 1.0;
|
||||||
|
|
||||||
for (it.Reset(); it.More(); it.Next())
|
for (it.Reset(); it.More(); it.Next())
|
||||||
{
|
{
|
||||||
@ -454,7 +454,7 @@ void MeshVS_NodalColorPrsBuilder::Build ( const Handle(Prs3d_Presentation)& Prs,
|
|||||||
// aStyle = (Aspect_InteriorStyle)aStyleInt;
|
// aStyle = (Aspect_InteriorStyle)aStyleInt;
|
||||||
|
|
||||||
anAsp = new Graphic3d_AspectFillArea3d (
|
anAsp = new Graphic3d_AspectFillArea3d (
|
||||||
Aspect_IS_SOLID, Quantity_NOC_GRAY, anEdgeColor,
|
Aspect_IS_SOLID, Quantity_NOC_WHITE, anEdgeColor,
|
||||||
anEdgeType, anEdgeWidth, aMaterial[ 0 ], aMaterial[ 1 ] );
|
anEdgeType, anEdgeWidth, aMaterial[ 0 ], aMaterial[ 1 ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3014,7 +3014,7 @@ static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const c
|
|||||||
aMat.SetSpecularColor(Quantity_Color (Graphic3d_Vec3 (0.50f)));
|
aMat.SetSpecularColor(Quantity_Color (Graphic3d_Vec3 (0.50f)));
|
||||||
Handle(Graphic3d_AspectFillArea3d) anAspect
|
Handle(Graphic3d_AspectFillArea3d) anAspect
|
||||||
= new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
|
= new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID,
|
||||||
Quantity_NOC_RED,
|
Quantity_NOC_WHITE,
|
||||||
Quantity_NOC_YELLOW,
|
Quantity_NOC_YELLOW,
|
||||||
Aspect_TOL_SOLID,
|
Aspect_TOL_SOLID,
|
||||||
1.0,
|
1.0,
|
||||||
@ -3438,6 +3438,17 @@ Standard_Boolean MyPArrayObject::Init (Graphic3d_TypeOfPrimitiveArray thePrimTyp
|
|||||||
if (myPArray.IsNull())
|
if (myPArray.IsNull())
|
||||||
{
|
{
|
||||||
myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
|
myPArray = Graphic3d_ArrayOfPrimitives::CreateArray (thePrimType, aVertexNum, aBoundNum, aEdgeNum, anArrayFlags);
|
||||||
|
if (myPArray->HasVertexColors())
|
||||||
|
{
|
||||||
|
myDrawer->SetupOwnShadingAspect();
|
||||||
|
Graphic3d_MaterialAspect aMat (Graphic3d_NameOfMaterial_Plastified);
|
||||||
|
aMat.SetSpecularColor (Quantity_NOC_BLACK);
|
||||||
|
aMat.SetEmissiveColor (Quantity_NOC_BLACK);
|
||||||
|
aMat.SetAmbientColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
|
||||||
|
aMat.SetDiffuseColor (Quantity_Color (Graphic3d_Vec3 (0.5f)));
|
||||||
|
myDrawer->ShadingAspect()->SetMaterial (aMat);
|
||||||
|
myDrawer->ShadingAspect()->SetColor (Quantity_NOC_WHITE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,6 @@ vdrawparray a triangles -deinterleaved -mutable v 10 0 0 {*}$c1 v 11 0 0
|
|||||||
vfit
|
vfit
|
||||||
vdump $imagedir/${casename}_1.png
|
vdump $imagedir/${casename}_1.png
|
||||||
vdrawparray a -patch triangles -deinterleaved -mutable v 10 0 0 {*}$c2 v 11 0 0 {*}$c2 v 11 1 0 {*}$c2 v 11 1 0 {*}$c1 v 10 1 0 {*}$c1 v 10 0 0 {*}$c1
|
vdrawparray a -patch triangles -deinterleaved -mutable v 10 0 0 {*}$c2 v 11 0 0 {*}$c2 v 11 1 0 {*}$c2 v 11 1 0 {*}$c1 v 10 1 0 {*}$c1 v 10 0 0 {*}$c1
|
||||||
if { [vreadpixel 200 150 rgb name] != "RED" } { puts "Error: array was not updated" }
|
if { [vreadpixel 200 150 rgb name] != "RED2" } { puts "Error: array was not updated" }
|
||||||
if { [vreadpixel 200 250 rgb name] != "BLUE" } { puts "Error: array was not updated" }
|
if { [vreadpixel 200 250 rgb name] != "BLUE2" } { puts "Error: array was not updated" }
|
||||||
vdump $imagedir/${casename}_2.png
|
vdump $imagedir/${casename}_2.png
|
||||||
|
76
tests/v3d/glsl/vert_color
Normal file
76
tests/v3d/glsl/vert_color
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
puts "============"
|
||||||
|
puts "0032198: Visualization, TKOpenGl - per-vertex lighting ignores back/front material colors"
|
||||||
|
puts "============"
|
||||||
|
puts ""
|
||||||
|
|
||||||
|
set aVerts {
|
||||||
|
{{0 55 0} { 0 75 0} {20 55 0}}
|
||||||
|
{{0 75 0} { 0 55 20} {20 55 0}}
|
||||||
|
{{0 55 0} { 0 55 20} { 0 75 0}}
|
||||||
|
{{0 55 0} {20 55 0} { 0 55 20}}
|
||||||
|
}
|
||||||
|
set aColors {
|
||||||
|
{{1.0 0.0 0.0} {0.0 1.0 0.0} {0.0 0.0 1.0}}
|
||||||
|
{{1.0 1.0 0.0} {1.0 1.0 1.0} {0.0 1.0 1.0}}
|
||||||
|
{{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 aNormals {
|
||||||
|
{ 0 0 -1}
|
||||||
|
{ 1 1 1}
|
||||||
|
{-1 0 0}
|
||||||
|
{ 0 -1 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 aTris "$aTris v [lindex $aVert $n] n $aNorm"
|
||||||
|
if { $theColors == 1 } { set aTris "$aTris c [lindex $aCol $n]" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aTris
|
||||||
|
}
|
||||||
|
|
||||||
|
set aTris1 [genTris 0 3 0]
|
||||||
|
set aTris1c [genTris 0 3 1]
|
||||||
|
set aTris2 [genTris 0 1 0]
|
||||||
|
set aTris2c [genTris 0 1 1]
|
||||||
|
|
||||||
|
pload MODELING VISUALIZATION
|
||||||
|
vclear
|
||||||
|
vinit View1
|
||||||
|
vviewparams -scale 10 -proj -0.3 -0.7 0.6 -up 0.013 0.65 0.75 -at 35.4 61.8 31.5
|
||||||
|
vdrawparray t1 triangles {*}$aTris1
|
||||||
|
vdrawparray t1c triangles {*}$aTris1c
|
||||||
|
vdrawparray t2 triangles {*}$aTris2
|
||||||
|
vdrawparray t2c triangles {*}$aTris2c
|
||||||
|
vdrawparray t3 triangles {*}$aTris2
|
||||||
|
vdrawparray t3c triangles {*}$aTris2c
|
||||||
|
vlocation t1 -location 0 0 0
|
||||||
|
vlocation t2 -location 30 0 0
|
||||||
|
vlocation t3 -location 60 0 0
|
||||||
|
vlocation t1c -location 0 0 30
|
||||||
|
vlocation t2c -location 30 0 30
|
||||||
|
vlocation t3c -location 60 0 30
|
||||||
|
vaspects t1 -color GREEN -backfaceColor RED
|
||||||
|
vaspects t2 -color GREEN -backfaceColor RED
|
||||||
|
vaspects t1c -color GREEN -backfaceColor RED
|
||||||
|
vaspects t2c -color GREEN -backfaceColor RED
|
||||||
|
vaspects t3 -color WHITE -backfaceColor WHITE
|
||||||
|
vaspects t3c -color WHITE -backfaceColor WHITE
|
||||||
|
|
||||||
|
vrenderparams -shadingModel VERT
|
||||||
|
vdump ${imagedir}/${casename}_vert.png
|
||||||
|
vrenderparams -shadingModel PHONG
|
||||||
|
vdump ${imagedir}/${casename}_phong.png
|
||||||
|
vrenderparams -shadingModel FLAT
|
||||||
|
vdump ${imagedir}/${casename}_flat.png
|
||||||
|
vrenderparams -shadingModel UNLIT
|
||||||
|
vdump ${imagedir}/${casename}_unlit.png
|
||||||
|
vrenderparams -shadingModel PBR
|
||||||
|
vdump ${imagedir}/${casename}_pbr.png
|
Loading…
x
Reference in New Issue
Block a user