opengl 光线步进夹紧坐标产生奇怪的拉伸伪影

kcugc4gi  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(126)

我正尝试使用光线行进渲染球体网格。SDF函数如下所示:

float sq_layer(vec3 p, vec3 bounding_box_min, vec3 bounding_box_max)
{
         float cell_size = 4.0 / 16.0;
         vec3 p0 = clamp(p.xyz, bounding_box_min, bounding_box_max);
         p0 = mod(p0, cell_size) - cell_size * 0.5f;
         float d_pt = sphereSDF(vec3(p0.x, p0.y, p0.z), 0.05f)
         return d_pt;
}

但我得到了这样的东西:

为了获得更多的相关性,我试着稍微修改了代码:

float sq_layer(vec3 p, vec3 bounding_box_min, vec3 bounding_box_max)
{
         vec3 cell_size = (bounding_box_max - bounding_box_min)  / 4.0;
         vec3 p0 = clamp(p.xyz, bounding_box_min, bounding_box_max);
         p0 = mod(p0, cell_size) - cell_size * 0.5f;
         float d_pt = boxSDF(p0, cell_size * 0.35);
         return d_pt;
}

我仍然得到,

uwopmtnx

uwopmtnx1#

以这种方式钳制坐标会导致sdf返回一个非常接近曲面的恒定距离,因此会耗尽迭代次数,从而产生您所看到的伪影。

而不是钳制你想做一个交叉与框sdf你的边界框的大小:

float sq_layer(vec3 p, vec3 bounding_box_min, vec3 bounding_box_max)
{
         float cell_size = 4.0 / 16.0;
         vec3 p0 = mod(p, cell_size) - cell_size * 0.5f;
         float d_pt = sphereSDF(p0, 0.05f);

         // the following is just a simplified box sdf
         vec3 bb_extents = (bounding_box_max - bounding_box_min) * .5; 
         vec3 bb_center = bounding_box_min + bb_extents;
         vec3 bb_p = max(abs(p-bb_center)-bb_extents,0.);
         float d_bb = max(max(bb_p.x,bb_p.y),bb_p.z);

         // intersect "sphere-field" with bounding box
         return max(d_pt,d_bb);
}

相关问题