RenderKit / embree

Embree ray tracing kernels repository.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rtcSetGeometryIntersectFunction does not call it's intersect function

mmomentum opened this issue · comments

This is probably just something I'm doing wrong with Embree, but i'm not really sure what the cause of it is.

I run the following two functions (DBG is a debug function):

rtcSetGeometryIntersectFunction(geometry,
	[](const RTCIntersectFunctionNArguments* args)
	{
		DBG("Calling the setGeometryIntersectFunction()'s internal function.");

		Sphere* const spheres = static_cast<Sphere*>(args->geometryUserPtr);
		const Sphere& sphere = spheres[args->primID];
		RTCRayHit& ray = *reinterpret_cast<RTCRayHit*>(args->rayhit);
		SphereIntersection(sphere, &ray);
	});

rtcSetGeometryBoundsFunction(geometry,
	[](const RTCBoundsFunctionArguments* args)
	{
		DBG("Calling the setGeometryBoundsFunction()'s internal function.");

		const Sphere& sphere = *static_cast<const Sphere*>(args->geometryUserPtr);
		RTCBounds& output_bounds = *args->bounds_o;
		SphereBounds(sphere, &output_bounds);
	},
	nullptr);

Everything else in the function is standard for dealing with custom user geometries, and I dont think that's what's relevant to my issue, but this is what returns in the console output when this code is run (at a higher level, it iterates through a function that runs these lines five times)


Calling the setGeometryBoundsFunction()'s internal function.
Calling the setGeometryBoundsFunction()'s internal function.
Calling the setGeometryBoundsFunction()'s internal function.
Calling the setGeometryBoundsFunction()'s internal function.
Calling the setGeometryBoundsFunction()'s internal function.

It never calls the intersection function.

Does anyone have any suggestions as to how to deal with this problem? Should I be defining some other function as well? I don't need any occlusion with this geometry, for instance, but maybe that has something to do with it?

The bounds function is called when the acceleration structure is build, thus during rtcCommit of the scene. The intersect callback will get used when you trace rays and hit the box of one of the user defined primitives. Maybe you do not trace rays yet? Or the bounds you calculate are wrong? Or your rays to not hit any of the calculated boxes.

It seems like the issue at hand is not that user intersections are not working (I've gotten them working on some occasions where the intersect function will call), but that running rtcCommitScene() with regular geometry seems to not be functioning properly.

I have a path tracer that checks if an intersection occurs with the scene and breaks if the intersection doesn't occur (by checking if the hit's geomID is not RTC_INVALID_GEOMETRY_ID, basically) and it seems like in some instances it works fine, but others it doesn't (and we're testing with the same code, same machine, same geometry, same everything).

Is there any way to see some kind of structured data that a RTCScene holds to help with potentially debugging this issue with breakpoints?

You cannot look into the internal BVH structure. I assume the bounds you calculate for the spheres are not correct. Maybe an image of the artifacts could help. The sphere intersect function seems to be called at least for some pixels?