Skip to content

Commit c853148

Browse files
committed
Fixed visible egdes between node borders in iso surface rendering
1 parent 644a6be commit c853148

File tree

1 file changed

+68
-40
lines changed

1 file changed

+68
-40
lines changed

lib/isaac/isaac_kernel.hpp

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,7 @@ struct merge_source_iterator
295295
typename TStepLength,
296296
typename TScale,
297297
typename TFirst,
298-
typename TLast,
299-
typename TStartNormal,
300-
typename TEndNormal
298+
typename TStartNormal
301299
>
302300
ISAAC_HOST_DEVICE_INLINE void operator()(
303301
const NR& nr,
@@ -313,9 +311,7 @@ struct merge_source_iterator
313311
const TStepLength& stepLength,
314312
const TScale& scale,
315313
const TFirst& first,
316-
const TLast& last,
317-
const TStartNormal& start_normal,
318-
const TEndNormal& end_normal
314+
const TStartNormal& start_normal
319315
) const
320316
{
321317
if ( mpl::at_c< TFilter, NR::value >::type::value )
@@ -388,12 +384,6 @@ struct merge_source_iterator
388384
gradient.y = start_normal.y;
389385
gradient.z = start_normal.z;
390386
}
391-
if (last)
392-
{
393-
gradient.x = end_normal.x;
394-
gradient.y = end_normal.y;
395-
gradient.z = end_normal.z;
396-
}
397387
isaac_float l = sqrt(
398388
gradient.x * gradient.x +
399389
gradient.y * gradient.y +
@@ -547,10 +537,11 @@ template <
547537
isaac_float3 local_size_f[ISAAC_VECTOR_ELEM];
548538
isaac_float3 count_end[ISAAC_VECTOR_ELEM];
549539
isaac_float3 start_normal[ISAAC_VECTOR_ELEM];
550-
isaac_float3 end_normal[ISAAC_VECTOR_ELEM];
540+
bool global_front[ISAAC_VECTOR_ELEM];
551541

552542
ISAAC_ELEM_ITERATE(e)
553543
{
544+
global_front[e] = false;
554545
pixel_f[e].x = isaac_float( pixel[e].x )/(isaac_float)framebuffer_size.x*isaac_float(2)-isaac_float(1);
555546
pixel_f[e].y = isaac_float( pixel[e].y )/(isaac_float)framebuffer_size.y*isaac_float(2)-isaac_float(1);
556547

@@ -631,21 +622,65 @@ template <
631622

632623
//calc intersection of all three super planes and save in [count_start.x ; count_end.x]
633624
float max_start = ISAAC_MAX( ISAAC_MAX( count_start[e].x, count_start[e].y ), count_start[e].z );
634-
if (count_start[e].x == max_start)
635-
start_normal[e] = {-1,0,0};
636-
if (count_start[e].y == max_start)
637-
start_normal[e] = {0,-1,0};
638-
if (count_start[e].z == max_start)
639-
start_normal[e] = {0,0,-1};
625+
if (ceil(count_start[e].x) == ceil(max_start))
626+
{
627+
if (step_vec[e].x>0.0f)
628+
{
629+
if (isaac_size_d[0].position.value.x == 0)
630+
{
631+
global_front[e] = true;
632+
start_normal[e] = { 1.0f,0,0};
633+
}
634+
}
635+
else
636+
{
637+
if (isaac_size_d[0].position.value.x == isaac_size_d[0].global_size.value.x - isaac_size_d[0].local_size.value.x)
638+
{
639+
global_front[e] = true;
640+
start_normal[e] = {-1.0f,0,0};
641+
}
642+
}
643+
}
644+
if (ceil(count_start[e].y) == ceil(max_start))
645+
{
646+
if (step_vec[e].y>0.0f)
647+
{
648+
if (isaac_size_d[0].position.value.y == 0)
649+
{
650+
global_front[e] = true;
651+
start_normal[e] = {0, 1.0f,0};
652+
}
653+
}
654+
else
655+
{
656+
if (isaac_size_d[0].position.value.y == isaac_size_d[0].global_size.value.y - isaac_size_d[0].local_size.value.y)
657+
{
658+
global_front[e] = true;
659+
start_normal[e] = {0,-1.0f,0};
660+
}
661+
}
662+
}
663+
if (ceil(count_start[e].z) == ceil(max_start))
664+
{
665+
if (step_vec[e].z>0.0f)
666+
{
667+
if (isaac_size_d[0].position.value.z == 0)
668+
{
669+
global_front[e] = true;
670+
start_normal[e] = {0,0, 1.0f};
671+
}
672+
}
673+
else
674+
{
675+
if (isaac_size_d[0].position.value.z == isaac_size_d[0].global_size.value.z- isaac_size_d[0].local_size.value.z)
676+
{
677+
global_front[e] = true;
678+
start_normal[e] = {0,0,-1.0f};
679+
}
680+
}
681+
}
640682
count_start[e].x = max_start;
641-
float min_end = ISAAC_MIN( ISAAC_MIN( count_end[e].x, count_end[e].y ), count_end[e].z );
642-
if (count_end[e].x == min_end)
643-
end_normal[e] = {-1,0,0};
644-
if (count_end[e].y == min_end)
645-
end_normal[e] = {0,-1,0};
646-
if (count_end[e].z == min_end)
647-
end_normal[e] = {0,0,-1};
648-
count_end[e].x = min_end;
683+
count_end[e].x = ISAAC_MIN( ISAAC_MIN( count_end[e].x, count_end[e].y ), count_end[e].z );
649684
if ( count_start[e].x > count_end[e].x)
650685
{
651686
if (!finish[e])
@@ -664,8 +699,8 @@ template <
664699

665700
ISAAC_ELEM_ITERATE(e)
666701
{
667-
first[e] = isaac_int( floor(count_start[e].x) );
668-
last[e] = isaac_int( ceil(count_end[e].x) );
702+
first[e] = isaac_int( ceil(count_start[e].x) );
703+
last[e] = isaac_int( floor(count_end[e].x) );
669704

670705
//Moving last and first until their points are valid
671706
pos[e] = start[e] + step_vec[e] * isaac_float(last[e]);
@@ -715,9 +750,10 @@ template <
715750
ISAAC_SET_COLOR( pixels[pixel[e].x + pixel[e].y * framebuffer_size.x], color[e] )
716751
finish[e] = true;
717752
}
718-
if ( first[e] < intersection_step[e] )
753+
if ( first[e] <= ceil( intersection_step[e] ) )
719754
{
720755
first[e] = ceil( intersection_step[e] );
756+
global_front[e] = true;
721757
start_normal[e].x = clipping[e].elem[i].normal.x;
722758
start_normal[e].y = clipping[e].elem[i].normal.y;
723759
start_normal[e].z = clipping[e].elem[i].normal.z;
@@ -732,12 +768,7 @@ template <
732768
finish[e] = true;
733769
}
734770
if ( last[e] > intersection_step[e] )
735-
{
736771
last[e] = floor( intersection_step[e] );
737-
end_normal[e].x = clipping[e].elem[i].normal.x;
738-
end_normal[e].y = clipping[e].elem[i].normal.y;
739-
end_normal[e].z = clipping[e].elem[i].normal.z;
740-
}
741772
}
742773
}
743774
}
@@ -766,8 +797,7 @@ template <
766797
value[e].z = 0;
767798
value[e].w = 0;
768799
result[e] = 0;
769-
bool firstRound = (i == first[e]);
770-
bool lastRound = (i == last[e]);
800+
bool firstRound = (global_front[e] && i == first[e]);
771801
isaac_for_each_with_mpl_params
772802
(
773803
sources,
@@ -789,9 +819,7 @@ template <
789819
step,
790820
scale,
791821
firstRound,
792-
lastRound,
793-
start_normal[e],
794-
end_normal[e]
822+
start_normal[e]
795823
);
796824
/*if ( mpl::size< TSourceList >::type::value > 1)
797825
value = value / isaac_float( mpl::size< TSourceList >::type::value );*/

0 commit comments

Comments
 (0)