RenderKit / ospray

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

Sphere light and pathtracer assertion failure #313

Closed karjonas closed 5 years ago

karjonas commented 5 years ago

Hi,

It seems like the pathtracer and sphere light does not get along together. If I add a sphere light and load a model using ospExampleViewer and the pathtracer renderer I get the following assertion failure:

jkarlsso@bbd-g5y5rg2 ~/W/o/build_debug> env LD_LIBRARY_PATH=/home/jkarlsso/.local/lib/ ./ospExampleViewer /home/jkarlsso/Downloads/bunny.obj -r pathtracer
attempting file import: /home/jkarlsso/Downloads/bunny.obj
loading... /home/jkarlsso/Downloads/bunny.obj
default load...
importDefaultExtensions "/home/jkarlsso/Downloads/bunny.obj"
single file import
... found 4968 triangles and 0 quads.
...adding found triangle & quad groups to the scene...
...finished import!
loaded
ospExampleViewer: /home/jkarlsso/Work/embree/kernels/bvh/bvh_intersector_hybrid.cpp:162: static void embree::sse42::BVHNIntersectorKHybrid<N, K, types, robust, PrimitiveIntersectorK, single>::intersect(embree::vint<K>*, embree::Accel::Intersectors*, embree::RayHitK<K>&, embree::IntersectContext*) [with int N = 4; int K = 4; int types = 1; bool robust = false; PrimitiveIntersectorK = embree::sse42::ArrayIntersectorK_1<4, embree::sse42::InstanceIntersectorK<4> >; bool single = false]: Assertion `all(valid, ray.valid())' failed.
fish: “env LD_LIBRARY_PATH=/home/jkarl…” terminated by signal SIGABRT (Abort)

I am using OSPRay v1.8.4 and embree v3.5.2.

Best regards, Jonas

johguenther commented 5 years ago

How do you add the sphere light (hardcoded in the viewer?)? With unusual position or radius? The assertion in Embree hints that invalid rays are generated (for example NaNs in origin, direction or distance).

karjonas commented 5 years ago

Okay. I add this at OSPApp.cpp:654:

            auto &sphere = lights.createChild("sphere", "PointLight");
            sphere["color"] = vec3f(1.f, 1.f, 1.f);
            sphere["position"] = vec3f(10, 10, 10);
            sphere["radius"] = 5.f;
            sphere["intensity"] = 1.25f;

I encountered the issue from outside of OSPRay to begin with though, but this is the simplest way to reproduce it.

johguenther commented 5 years ago

Thanks for the information; I have a fix (will be in the next release):

diff --git a/ospray/lights/PointLight.ispc b/ospray/lights/PointLight.ispc
@@ -62,7 +62,7 @@ Light_SampleRes PointLight_sample(const uniform Light* uniform super,
       res.dir = frame(res.dir) * localDir;
       res.pdf = uniformSampleConePDF(cosTheta);
       const float c = localDir.z;
-      res.dist = c*res.dist - sqrt(sqr(self->radius) - (1.f - c*c) * dist2);
+      res.dist = c*res.dist - sqrt_safe(sqr(self->radius) - (1.f - c*c) * dist2);
       // TODO scale radiance by actual distance
     } else { // inside sphere
       const vec3f localDir = cosineSampleHemisphere(s);
karjonas commented 5 years ago

Cool, thanks for the fix!