RenderKit / ospray

An Open, Scalable, Portable, Ray Tracing Based Rendering Engine for High-Fidelity Visualization
http://ospray.org
Apache License 2.0
982 stars 178 forks source link

Orthographic camera & clipping geometry behaviour #520

Closed NadirRoGue closed 2 years ago

NadirRoGue commented 2 years ago

Hello, I have been testing clipping geometry with orthographic camera on our application. I found a strange behaviour when using a clipping plane that is completely perpendicular to the orthrographic camera view.

diff --git a/apps/common/ospray_testing/builders/ClippingGeometries.cpp b/apps/common/ospray_testing/builders/ClippingGeometries.cpp
index 0c0cf52e1..93b3b0fca 100644
--- a/apps/common/ospray_testing/builders/ClippingGeometries.cpp
+++ b/apps/common/ospray_testing/builders/ClippingGeometries.cpp
@@ -195,7 +195,7 @@ cpp::World ClippingGeometries::buildWorld() const
     geometry.commit();
     cPos = vec3f(-.3f, 0.f, -.3f);
   } else if (geomType == "plane") {
-    std::vector<vec4f> coefficients = {vec4f(1.0f, 1.0f, 1.0f, 0.0f)};
+    std::vector<vec4f> coefficients = {vec4f(1.0f, 0.0f, 0.0f, 0.0f)};
     geometry.setParam("plane.coefficients", cpp::CopiedData(coefficients));
     geometry.commit();
     cPos = vec3f(-.3f, .2f, -.3f);
@@ -219,7 +219,7 @@ cpp::World ClippingGeometries::buildWorld() const
   // Create clipping instance with model that has inverted normals
   {
     cpp::GeometricModel model(geometry);
-    model.setParam("invertNormals", true);
+    //model.setParam("invertNormals", true);
     model.commit();

     cpp::Group group;
diff --git a/apps/ospExamples/GLFWOSPRayWindow.cpp b/apps/ospExamples/GLFWOSPRayWindow.cpp
index d1923d61e..fa4f8303e 100644
--- a/apps/ospExamples/GLFWOSPRayWindow.cpp
+++ b/apps/ospExamples/GLFWOSPRayWindow.cpp
@@ -283,7 +283,8 @@ void GLFWOSPRayWindow::reshape(const vec2i &newWindowSize)
 void GLFWOSPRayWindow::updateCamera()
 {
   camera.setParam("aspect", windowSize.x / float(windowSize.y));
-  camera.setParam("stereoMode", cameraStereoMode);
+  //camera.setParam("stereoMode", cameraStereoMode);
+  camera.setParam("height", 10.f);
   const auto xfm = arcballCamera->transform();
   if (rendererType == OSPRayRendererType::PATHTRACER && cameraMotionBlur) {
     camera.removeParam("transform");
diff --git a/apps/ospExamples/GLFWOSPRayWindow.h b/apps/ospExamples/GLFWOSPRayWindow.h
index 0c13fbd25..035c11ccb 100644
--- a/apps/ospExamples/GLFWOSPRayWindow.h
+++ b/apps/ospExamples/GLFWOSPRayWindow.h
@@ -85,7 +85,7 @@ class GLFWOSPRayWindow
   cpp::Renderer rendererAO{"ao"};
   cpp::Renderer rendererDBG{"debug"};
   cpp::Renderer *renderer{nullptr};
-  cpp::Camera camera{"perspective"};
+  cpp::Camera camera{"orthographic"};
   cpp::World world;
   cpp::Light sunSky{"sunSky"};
   cpp::FrameBuffer framebuffer;

By commenting and un-commenting the model.setParam("invertNormals", true); line, I can achieve both behaviours, as showcased in the following screenshots.

Furthermore, the clipping is not "symetrical". I would expect the second one (with inverted normals) to be the opposite clipping of the one without inverted normals, however, it seems to be clipped twice.

Am I setting something wrong or may this be a bug? If its the expected behaviour, how can I achieve clipping with orthographical camera when the planes are perpendicular to the view direction?

Kind regards.

NadirRoGue commented 2 years ago

I forgot to add that with perspective camera, the clipping behaves as expected, though.

johguenther commented 2 years ago

Thanks for reporting, this was a not-handled corner case (which however is rather common when using the orthographic camera). The fix is now in devel and will be part of the next release.

NadirRoGue commented 2 years ago

Thanks for the quick reply and support on this!.