[Bf-cycles] ray/scene intersection with instancing

Sergey Sharybin sergey.vfx at gmail.com
Tue May 31 20:45:29 CEST 2016


Hi,

triangle_point_normal() only uses object to get negative scale flag. So
what you have to do is to apply object inverse transform on Ng and P.

Without checking the code, something like this should work:

if(object != OBJECT_NONE) {
  Transform tfm = object_fetch_transform(kg, isect->object,
OBJECT_INVERSE_TRANSFORM);
  P = transform_point(&tfm, P);
  Ng = transform_direction(&tfm, Ng);
}

On Tue, May 31, 2016 at 7:27 PM, <laurent.boiron at dunwich.fr> wrote:

> 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
> _______________________________________________
> Bf-cycles mailing list
> Bf-cycles at blender.org
> https://lists.blender.org/mailman/listinfo/bf-cycles
>



-- 
With best regards, Sergey Sharybin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-cycles/attachments/20160531/77037063/attachment.htm 


More information about the Bf-cycles mailing list