From 64c759f8983d25fb44228bce8100f2b86433b86d Mon Sep 17 00:00:00 2001 From: kgv Date: Wed, 13 Nov 2013 21:44:24 +0400 Subject: [PATCH] 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. --- src/OpenGl/OpenGl_SceneGeometry.cxx | 8 ++-- src/OpenGl/OpenGl_ShaderManager.cxx | 38 ++++++++++-------- src/OpenGl/OpenGl_Workspace_Raytrace.cxx | 42 +++++++++++--------- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 12 +++--- tests/bugs/parse.rules | 1 - tests/v3d/glsl/light_off | 2 +- tests/v3d/glsl/phong_plastic | 32 +++++++++++++++ tests/v3d/grids.list | 1 + tests/v3d/parse.rules | 3 +- tests/{bugs/vis => v3d/raytrace}/bug24130 | 0 tests/v3d/raytrace/plastic | 33 +++++++++++++++ 11 files changed, 125 insertions(+), 47 deletions(-) create mode 100644 tests/v3d/glsl/phong_plastic rename tests/{bugs/vis => v3d/raytrace}/bug24130 (100%) create mode 100644 tests/v3d/raytrace/plastic diff --git a/src/OpenGl/OpenGl_SceneGeometry.cxx b/src/OpenGl/OpenGl_SceneGeometry.cxx index 5184e8dba9..472687e155 100644 --- a/src/OpenGl/OpenGl_SceneGeometry.cxx +++ b/src/OpenGl/OpenGl_SceneGeometry.cxx @@ -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, diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index 4092769818..3c50e2e9a0 100644 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -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; diff --git a/src/OpenGl/OpenGl_Workspace_Raytrace.cxx b/src/OpenGl/OpenGl_Workspace_Raytrace.cxx index 6a181fc796..192b21e341 100644 --- a/src/OpenGl/OpenGl_Workspace_Raytrace.cxx +++ b/src/OpenGl/OpenGl_Workspace_Raytrace.cxx @@ -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); - - theMaterial.Diffuse = OpenGl_RTVec4f (theProp.difcol.rgb[0] * theProp.diff, - theProp.difcol.rgb[1] * theProp.diff, - theProp.difcol.rgb[2] * theProp.diff, - 1.f); - - theMaterial.Specular = OpenGl_RTVec4f (theProp.speccol.rgb[0] * theProp.spec, - theProp.speccol.rgb[1] * theProp.spec, - theProp.speccol.rgb[2] * theProp.spec, + 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); + + 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); + + 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 diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 519f3436d8..9bb9c7e24f 100755 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -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; } } diff --git a/tests/bugs/parse.rules b/tests/bugs/parse.rules index 466a2c0b25..eab3eb5026 100755 --- a/tests/bugs/parse.rules +++ b/tests/bugs/parse.rules @@ -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 diff --git a/tests/v3d/glsl/light_off b/tests/v3d/glsl/light_off index 8a9c9f771f..e5a2c6b0e5 100644 --- a/tests/v3d/glsl/light_off +++ b/tests/v3d/glsl/light_off @@ -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!"} diff --git a/tests/v3d/glsl/phong_plastic b/tests/v3d/glsl/phong_plastic new file mode 100644 index 0000000000..c03aef2c8e --- /dev/null +++ b/tests/v3d/glsl/phong_plastic @@ -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)!" +} diff --git a/tests/v3d/grids.list b/tests/v3d/grids.list index 626997505d..972d658298 100644 --- a/tests/v3d/grids.list +++ b/tests/v3d/grids.list @@ -11,3 +11,4 @@ 011 wire_solid 012 voxel 013 glsl +014 raytrace diff --git a/tests/v3d/parse.rules b/tests/v3d/parse.rules index b1d8fe84df..4546f28fdf 100644 --- a/tests/v3d/parse.rules +++ b/tests/v3d/parse.rules @@ -1,2 +1,3 @@ FAILED /\bFaulty\b/ error - +SKIPPED /OCCT was compiled without OpenCL support!/ +SKIPPED /OpenCL device info is unavailable!/ diff --git a/tests/bugs/vis/bug24130 b/tests/v3d/raytrace/bug24130 similarity index 100% rename from tests/bugs/vis/bug24130 rename to tests/v3d/raytrace/bug24130 diff --git a/tests/v3d/raytrace/plastic b/tests/v3d/raytrace/plastic new file mode 100644 index 0000000000..54c08d004b --- /dev/null +++ b/tests/v3d/raytrace/plastic @@ -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)!" +#} -- 2.20.1