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

0024350: TKOpenGl - non-physical materials are ignored by GLSL program manager

GLSL and Ray Tracing - take into account non-physical materials.
Move Ray Tracing test cases to v3d/raytrace grid.
This commit is contained in:
kgv 2013-11-13 21:44:24 +04:00 committed by bugmaster
parent f85399e5df
commit 64c759f898
11 changed files with 123 additions and 45 deletions

View File

@ -45,7 +45,7 @@ namespace
};
// =======================================================================
// function : OpenGl_Material
// function : OpenGl_RaytraceMaterial
// purpose : Creates new default material
// =======================================================================
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial()
@ -59,7 +59,7 @@ OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial()
{ }
// =======================================================================
// function : OpenGl_Material
// function : OpenGl_RaytraceMaterial
// purpose : Creates new material with specified properties
// =======================================================================
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
@ -77,7 +77,7 @@ OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbie
}
// =======================================================================
// function : OpenGl_Material
// function : OpenGl_RaytraceMaterial
// purpose : Creates new material with specified properties
// =======================================================================
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
@ -97,7 +97,7 @@ OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbie
}
// =======================================================================
// function : OpenGl_Material
// function : OpenGl_RaytraceMaterial
// purpose : Creates new material with specified properties
// =======================================================================
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,

View File

@ -612,6 +612,7 @@ static void PushAspectFace (const Handle(OpenGl_Context)& theCtx,
theProgram->GetStateLocation (OpenGl_OCCT_DISTINGUISH_MODE),
theAspect->DistinguishingMode());
const float aDefSpecCol[4] = {1.0f, 1.0f, 1.0f, 1.0f};
OpenGl_Vec4 aParams[5];
for (Standard_Integer anIndex = 0; anIndex < 2; ++anIndex)
{
@ -624,22 +625,27 @@ static void PushAspectFace (const Handle(OpenGl_Context)& theCtx,
}
const OPENGL_SURF_PROP& aProps = (anIndex == 0) ? theAspect->IntFront() : theAspect->IntBack();
const OpenGl_Vec4 anEmission (aProps.emscol.rgb[0] * aProps.emsv,
aProps.emscol.rgb[1] * aProps.emsv,
aProps.emscol.rgb[2] * aProps.emsv,
aProps.emscol.rgb[3] * aProps.emsv);
const OpenGl_Vec4 anAmbient (aProps.ambcol.rgb[0] * aProps.amb,
aProps.ambcol.rgb[1] * aProps.amb,
aProps.ambcol.rgb[2] * aProps.amb,
aProps.ambcol.rgb[3] * aProps.amb);
const OpenGl_Vec4 aDiffuse (aProps.difcol.rgb[0] * aProps.diff,
aProps.difcol.rgb[1] * aProps.diff,
aProps.difcol.rgb[2] * aProps.diff,
aProps.difcol.rgb[3] * aProps.diff);
const OpenGl_Vec4 aSpecular (aProps.speccol.rgb[0] * aProps.spec,
aProps.speccol.rgb[1] * aProps.spec,
aProps.speccol.rgb[2] * aProps.spec,
aProps.speccol.rgb[3] * aProps.spec);
const float* aSrcEms = aProps.isphysic ? aProps.emscol.rgb : aProps.matcol.rgb;
const OpenGl_Vec4 anEmission (aSrcEms[0] * aProps.emsv,
aSrcEms[1] * aProps.emsv,
aSrcEms[2] * aProps.emsv,
1.0f);
const float* aSrcAmb = aProps.isphysic ? aProps.ambcol.rgb : aProps.matcol.rgb;
const OpenGl_Vec4 anAmbient (aSrcAmb[0] * aProps.amb,
aSrcAmb[1] * aProps.amb,
aSrcAmb[2] * aProps.amb,
1.0f);
const float* aSrcDif = aProps.isphysic ? aProps.difcol.rgb : aProps.matcol.rgb;
const OpenGl_Vec4 aDiffuse (aSrcDif[0] * aProps.diff,
aSrcDif[1] * aProps.diff,
aSrcDif[2] * aProps.diff,
1.0f);
const float* aSrcSpe = aProps.isphysic ? aProps.speccol.rgb : aDefSpecCol;
const OpenGl_Vec4 aSpecular (aSrcSpe[0] * aProps.spec,
aSrcSpe[1] * aProps.spec,
aSrcSpe[2] * aProps.spec,
1.0f);
aParams[0] = anEmission;
aParams[1] = anAmbient;
aParams[2] = aDiffuse;

View File

@ -321,27 +321,33 @@ Standard_Boolean OpenGl_Workspace::CheckRaytraceStructure (const OpenGl_Structur
// function : CreateMaterial
// purpose : Creates ray-tracing material properties
// =======================================================================
void CreateMaterial (const OPENGL_SURF_PROP& theProp, OpenGl_RaytraceMaterial& theMaterial)
void CreateMaterial (const OPENGL_SURF_PROP& theProp,
OpenGl_RaytraceMaterial& theMaterial)
{
theMaterial.Ambient = OpenGl_RTVec4f (theProp.ambcol.rgb[0] * theProp.amb,
theProp.ambcol.rgb[1] * theProp.amb,
theProp.ambcol.rgb[2] * theProp.amb,
1.f);
const float* aSrcAmb = theProp.isphysic ? theProp.ambcol.rgb : theProp.matcol.rgb;
theMaterial.Ambient = OpenGl_RTVec4f (aSrcAmb[0] * theProp.amb,
aSrcAmb[1] * theProp.amb,
aSrcAmb[2] * theProp.amb,
1.0f);
theMaterial.Diffuse = OpenGl_RTVec4f (theProp.difcol.rgb[0] * theProp.diff,
theProp.difcol.rgb[1] * theProp.diff,
theProp.difcol.rgb[2] * theProp.diff,
1.f);
const float* aSrcDif = theProp.isphysic ? theProp.difcol.rgb : theProp.matcol.rgb;
theMaterial.Diffuse = OpenGl_RTVec4f (aSrcDif[0] * theProp.diff,
aSrcDif[1] * theProp.diff,
aSrcDif[2] * theProp.diff,
1.0f);
theMaterial.Specular = OpenGl_RTVec4f (theProp.speccol.rgb[0] * theProp.spec,
theProp.speccol.rgb[1] * theProp.spec,
theProp.speccol.rgb[2] * theProp.spec,
const float aDefSpecCol[4] = {1.0f, 1.0f, 1.0f, 1.0f};
const float* aSrcSpe = theProp.isphysic ? theProp.speccol.rgb : aDefSpecCol;
theMaterial.Specular = OpenGl_RTVec4f (aSrcSpe[0] * theProp.spec,
aSrcSpe[1] * theProp.spec,
aSrcSpe[2] * theProp.spec,
theProp.shine);
theMaterial.Emission = OpenGl_RTVec4f (theProp.emscol.rgb[0] * theProp.emsv,
theProp.emscol.rgb[1] * theProp.emsv,
theProp.emscol.rgb[2] * theProp.emsv,
1.f);
const float* aSrcEms = theProp.isphysic ? theProp.emscol.rgb : theProp.matcol.rgb;
theMaterial.Emission = OpenGl_RTVec4f (aSrcEms[0] * theProp.emsv,
aSrcEms[1] * theProp.emsv,
aSrcEms[2] * theProp.emsv,
1.0f);
// Note: Here we use sub-linear transparency function
// to produce realistic-looking transparency effect

View File

@ -4122,11 +4122,11 @@ static int VReadPixel (Draw_Interpretor& theDI,
{
if (aBufferType == Graphic3d_BT_RGBA)
{
theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha << "\n";
theDI << Quantity_Color::StringName (aColor.Name()) << " " << anAlpha;
}
else
{
theDI << Quantity_Color::StringName (aColor.Name()) << "\n";
theDI << Quantity_Color::StringName (aColor.Name());
}
}
else
@ -4138,22 +4138,22 @@ static int VReadPixel (Draw_Interpretor& theDI,
{
if (toShowHls)
{
theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation() << "\n";
theDI << aColor.Hue() << " " << aColor.Light() << " " << aColor.Saturation();
}
else
{
theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << "\n";
theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue();
}
break;
}
case Graphic3d_BT_RGBA:
{
theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha << "\n";
theDI << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " " << anAlpha;
break;
}
case Graphic3d_BT_Depth:
{
theDI << aColor.Red() << "\n";
theDI << aColor.Red();
break;
}
}

View File

@ -1,5 +1,4 @@
FAILED /\bFaulty\b/ bad shape
IGNORE /^Error [23]d = [\d.-]+/ debug output of blend command
SKIPPED /Error: unsupported locale specification/ locale is unavailable on tested system
SKIPPED /OCCT was compiled without OpenCL support!/
OK /Relative error of mass computation/ message from vprops

View File

@ -15,5 +15,5 @@ vfit
vlight clear
set color [vreadpixel 100 100 rgb]
set black "0 0 0\n"
set black "0 0 0"
if {[string equal $color $black] != 1} {error "Lights do not seems to be cleared!"}

View File

@ -0,0 +1,32 @@
puts "========"
puts "Per-pixel lighting using GLSL program (Phong shading), check plastic material"
puts "========"
# create box
box b 1 2 3
# draw box
vinit View1
vclear
vsetdispmode 1
vaxo
vdisplay b
vsetmaterial b PLASTIC
vsetcolor b GREEN
vfit
vrotate 0.2 0.0 0.0
# take snapshot with fixed pipeline
vdump $::imagedir/${::casename}_OFF.png
set aColorL [vreadpixel 150 250 rgb name]
set aColorR [vreadpixel 250 250 rgb name]
if { "$aColorL" != "GREEN3" || "$aColorR" != "GREEN4" } {
puts "Error: wrong color (fixed pipeline)!"
}
vshaderprog b phong
set aColorL [vreadpixel 150 250 rgb name]
set aColorR [vreadpixel 250 250 rgb name]
if { "$aColorL" != "GREEN3" || "$aColorR" != "GREEN4" } {
puts "Error: wrong color (Phong shader)!"
}

View File

@ -11,3 +11,4 @@
011 wire_solid
012 voxel
013 glsl
014 raytrace

View File

@ -1,2 +1,3 @@
FAILED /\bFaulty\b/ error
SKIPPED /OCCT was compiled without OpenCL support!/
SKIPPED /OpenCL device info is unavailable!/

View File

@ -0,0 +1,33 @@
puts "========"
puts "Ray Tracing - check lighting on Plastic material"
puts "========"
# create box
box b 1 2 3
# draw box
vinit View1
vclear
vsetdispmode 1
vaxo
vdisplay b
vsetmaterial b PLASTIC
vsetcolor b GREEN
vfit
vrotate 0.2 0.0 0.0
# take snapshot with fixed pipeline
vdump $::imagedir/${::casename}_OFF.png
set aColorL [vreadpixel 150 250 rgb name]
set aColorR [vreadpixel 250 250 rgb name]
if { "$aColorL" != "GREEN3" || "$aColorR" != "GREEN4" } {
puts "Error: wrong color (fixed pipeline)!"
}
vraytrace 1
vclinfo
set aColorL [vreadpixel 150 250 rgb name]
set aColorR [vreadpixel 250 250 rgb name]
#if { "$aColorL" != "GREEN3" || "$aColorR" != "GREEN4" } {
# puts "Error: wrong color (Ray Tracing)!"
#}