Raycast with Cycles

Hi,

I hosted Cycles in my application and trying to generate normal maps using cycles. Blender’s code is my reference.

In Blender’s bake_api.c, there is a method

static bool cast_ray_highpoly(BVHTreeFromMesh *treeData,
                              TriTessFace *triangle_low,
                              TriTessFace *triangles[],
                              BakePixel *pixel_array_low,
                              BakePixel *pixel_array,
                              const float mat_low[4][4],
                              BakeHighPolyData *highpoly,
                              const float co[3],
                              const float dir[3],
                              const int pixel_id,
                              const int tot_highpoly)

It shoots a ray from low-poly face to high-poly. Blender has its own data-structure to represent the BVH tree.

I can replicate blender’s BVHTreeFromMesh and its population logic. But, BVH is a heavy data-structure and constructing it is a very expensive thing. Every mesh in Cycles already has its BVH, I would like to do ray-cast with Cycles using Cycles BVH.

Can you please give some clue how to do it?

Thanks in advance.

1 Like