I have looked at your update for the 24th of July. You have to make sure
when the normals are computed the right primitive is being evaluated, also
in some cases the surface normal needs to be flipped. Notice that in
rt_boolweave() there is a pt_inflip and pt_outflip parameter. Then in the
ANSI C code the RT_HIT_NORMAL() macro is used to determine the actual
surface normal, i.e.:
https://svn.code.sf.net/p/brlcad/code/brlcad/trunk/include/rt/hit.h
/**
* Compute normal into (_hitp)->hit_normal.
*
* Set flip-flag accordingly depending on boolean logic, as one hit
* may be shared between multiple partitions with different flip
* status.
*
* Example: box.r = box.s - sph.s; sph.r = sph.s
*
* Return the post-boolean normal into caller-provided _normal vector.
*/
#define RT_HIT_NORMAL(_normal, _hitp, _stp, _unused, _flipflag) { \
RT_CK_HIT(_hitp); \
RT_CK_SOLTAB(_stp); \
RT_CK_FUNCTAB((_stp)->st_meth); \
{ \
void *_n = (void *)_normal; \
if ((_stp)->st_meth->ft_norm) { \
(_stp)->st_meth->ft_norm(_hitp, _stp, (_hitp)->hit_rayp); \
} \
if (_n != NULL) { \
int _f = (int)_flipflag; \
if (_f) { \
VREVERSE((fastf_t *)_normal, (_hitp)->hit_normal); \
} else { \
VMOVE((fastf_t *)_normal, (_hitp)->hit_normal); \
} \
} \
} \
}
Where:
/** @brief Reverse the direction of 3D vector `b' and store it in `a'. */
#define VREVERSE(a, b) do { \
(a)[X] = -(b)[X]; \
(a)[Y] = -(b)[Y]; \
(a)[Z] = -(b)[Z]; \
} while (0)
/** @brief Transfer 3D vector at `b' to vector at `a'. */
#define VMOVE(a, b) do { \
(a)[X] = (b)[X]; \
(a)[Y] = (b)[Y]; \
(a)[Z] = (b)[Z]; \
} while (0)
It is called like this in src/liboptical/shade.c:
/* Get surface normal for hit point */
RT_HIT_NORMAL(swp->sw_hit.hit_normal, &(swp->sw_hit),
pp->pt_inseg->seg_stp, &(ap->a_ray), pp->pt_inflip);
On Tue, Jul 25, 2017 at 12:33 AM, Vasco Alexandre da Silva Costa <
vasco.co...@gmail.com> wrote:
> On Sat, Jul 22, 2017 at 2:59 PM, Marco Domingues <
> marcodomingue...@gmail.com> wrote:
>
>> Well, the ‘rt -z1 -l5’ command takes 8,103 seconds for the havoc.g scene
>> when rendering with the GPU, and this same scene renders in 0,558 seconds
>> when using the ANSI C code. Despite that, when I comment the call to the
>> ‘build_regiontable’ function, the OpenCl code only takes 0,14 seconds. So
>> the process of building the regiontable, evaluating partitions and
>> resolving overlaps is causing a major bottleneck for this scene.
>>
>> The operators.g scene takes 0,027 seconds when using the ‘rt -z1 -l5’
>> command, and 0,054 when using the ‘rt’ command.
>>
>
> So I looked at your code and yes the major bottleneck seems to be the
> build_regiontable() function. The ANSI C code precomputes the list of
> regions each solid is in before starting the boolean evaluation, around the
> time it parses and optimizes the boolean tree, this is stored in
> stp->st_regions. It means this is precomputed once, instead of being
> computed for every partition like what you're doing on your code. This
> should be the main cause for the slowdown.
>
> Regards,
>
> --
> Vasco Alexandre da Silva Costa
> PhD in Computer Engineering (Computer Graphics)
> Instituto Superior Técnico/University of Lisbon, Portugal
>
--
Vasco Alexandre da Silva Costa
PhD in Computer Engineering (Computer Graphics)
Instituto Superior Técnico/University of Lisbon, Portugal
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Developer mailing list
brlcad-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-devel