如何在保持顶点数不变的前提下过滤曲线避免渲染时线段重叠?
基于2D点序列的粗曲线渲染问题
我有一组2D点序列,通过四边形(quads)渲染为粗线条。这些四边形是通过沿法线方向将曲线围绕其中线挤压形成的。

该图展示了一个厚度变化的圆形渲染效果,颜色标识了填充曲线所使用的坐标系,这也解释了为何必须使用四边形。
只要曲线不是过粗或没有过于尖锐的拐角,渲染效果就很好。但如果曲线较粗或存在尖锐拐角,沿法线方向的线段会在曲线内侧发生重叠,需要一种可靠的方法避免此类相交问题。
我尝试过一种解决方案,在出现重叠时合并相邻顶点,代码如下:
if(normals_has_intersection) { // Collapse vertices into one auto const new_loc = midpoint(prev_loc, current_loc); auto const new_thickness = 0.5f*(prev_thickness + current_thickness); auto const saved_locations = ret.locations(); auto const prev_saved_loc = saved_locations.empty()? curve.front() : saved_locations.back(); saved_vertex = thick_curve::vertex{ .loc = new_loc, .normal = direction{(next_loc - prev_saved_loc).rot_right_angle_z_right()}, .thickness = new_thickness }; } else { // Keep current vertex saved_vertex = thick_curve::vertex{ .loc = current_loc, .normal = current_normal, .thickness = current_thickness }; } ret.data.push_back(saved_vertex.loc, saved_vertex.normal, saved_vertex.thickness); // Continue with next vertex
但该方案存在以下问题:
- 曲线的顶点数量会改变,而调用方要求保持顶点数不变。
- 由于已接受的点可能被修改后不再有效,算法需要反复运行直到没有顶点导致法线相交。
综上,需要实现的目标是:在保持顶点数量不变的前提下,结合各顶点的厚度,确保法线不会发生相交。
内容的提问来源于stack exchange,提问作者user877329
相关产品推荐
相关产品推荐

