[Bf-cycles] ray/scene intersection with instancing

laurent.boiron at dunwich.fr laurent.boiron at dunwich.fr
Tue May 31 19:27:00 CEST 2016


Hi all,

I am working on path tracing kernel in cycles and I am facing a behavior 
of ray/scene intersection that I am not clearly understanding. Here is 
my problem:

For a given ray sent from the camera, I try to find the object 
intersected by the ray, the point of intersection ray/triangle in world 
space and his geometric normal.

My solution looks like that:

==============
bool hit = scene_intersect(kg, &ray, visibility, &isect, NULL, 0.0f, 
0.0f);
if( !hit ) return;

//get object ID (inspired from
int object = (isect.object == PRIM_NONE)? 
kernel_tex_fetch(__prim_object, isect.prim): isect.object;

int prim = kernel_tex_fetch(__prim_index, isect.prim);
float3 Ng,Pi;

//compute intersection point and geometrical normal (from 
kernel/geom/geom_triangle.h )
triangle_point_normal(kg, object, prim, isect.u, isect.v, &Pi, &Ng, 
&stub );
==============

It works fine EXCEPT in some cases when I have two objects sharing the 
same mesh. In this special case the object ID is the same for both 
object and coordinates of Pi are in object space. It happens only for 
those two objects, others give correct results.

So my question is:
How should I differentiate those two objects sharing the same mesh ? 
what is exactly the meaning of isect.object == PRIM_NONE  returned by 
scene_intersect function ? And how can I guess if ray intersects unique 
mesh or a mesh instance ?

Any enlightenment would be very appreciated.

Thanks,


Laurent


More information about the Bf-cycles mailing list