[Bf-cycles] ray/scene intersection with instancing
Mohamed Sakr
3dsakr at gmail.com
Wed Jun 1 07:47:52 CEST 2016
sorry Sergey, didn't mean to. "but the name PRIM_NONE is miss leading :) "
On Tue, May 31, 2016 at 8:47 PM, Sergey Sharybin <sergey.vfx at gmail.com>
wrote:
> Mohamed, please do not confuse guys around.
>
> PRIM_NONE on intersection would mean intersection happened outside of the
> instance (rad: intersection was found in scene level BVH). Proper check for
> intersection would be to either check scene_intersect() return value or to
> check prim != PRIM_NONE.
>
> On Tue, May 31, 2016 at 8:45 PM, Sergey Sharybin <sergey.vfx at gmail.com>
> wrote:
>
>> 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
>>
>
>
>
> --
> With best regards, Sergey Sharybin
>
> _______________________________________________
> Bf-cycles mailing list
> Bf-cycles at blender.org
> https://lists.blender.org/mailman/listinfo/bf-cycles
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-cycles/attachments/20160601/42bf48a7/attachment.htm
More information about the Bf-cycles
mailing list