三维分形切片渲染方法的验证

问题描述 投票:1回答:1

Ray Casting Algorithm

MandelBulb Ray Casting Algorithm Python Example

因此,如果我理解正确的话,光线投射算法要求观察者位于3D分形的外部,在该点处,矢量从观察者朝向与矢量垂直的平面上的点并且与原点相交。

在我看来,这将严重限制分形的渲染视图,或者需要使用多个观察者位置对分形进行立体3D重建(这对我来说似乎很难)。另外,不能收集关于分形的内部结构的信息。

Other Algorithms

或者,直接体积渲染看起来足够直观,但计算上昂贵并且本身可能效率低下。使用诸如行进立方体之类的算法的间接体绘制也可能采用一些学习曲线。

在第二个链接的pdf中的某个地方,它讨论了切割平面视图,以便查看分形的切片。

Question:

为什么不使用切割平面作为渲染方法?

  • 1)使用改进的光线跟踪算法,假设我们将observer放在点Q处的原点(0, 0, 0)
  • 2)让我们然后从原点向yz点组合所跨越的入射平面发射光线,这些点组合正在切割分形。
  • 3)使用第一个链接中的算法计算到分形表面的距离。如果计算距离的x分量在切片平面的dx之内,那么yz坐标以及切片平面的x值被存储为x, y, z坐标。这些坐标现在代表x中特定切片的表面。
  • 4)让我们说切片平面在x方向上有一个自由度。通过以其自由度移动平面,我们可以接收给定切片的另一组x, y, z坐标。
  • 5)最终结果是由前面步骤中创建的点云生成的可计算表面。
  • 6)另外,可以改变切片平面的自由度以创建另一个点云,然后可以将其作为后处理的手段与之前的点进行验证。

请参见下图作为视觉辅助(球体代表MandelBulb)。

enter image description here

下面是我的Python代码到目前为止,改编自第一个链接。我成功地生成了点平面,并且能够获得从原点到平面上的点的方向。在距离估计函数中肯定存在一些根本性的缺陷,因为那就是一切都崩溃了,我得到总距离的nans

def get_plane_points(x, y_res=500, z_res=500, y_min=-10, y_max=10, z_min=-10, z_max=10):
    y = np.linspace(y_min, y_max, y_res)
    z = np.linspace(z_min, z_max, z_res)
    x, y, z = np.meshgrid(x, y, z)

    x, y, z = x.reshape(-1), y.reshape(-1) , z.reshape(-1)

    P = np.vstack((x, y, z)).T
    return P


def get_directions(P):
    v = np.array(P - 0)
    v = v/np.linalg.norm(v, axis=1)[:, np.newaxis]
    return v


@jit
def DistanceEstimator(positions, plane_loc, iterations, degree):
    m = positions.shape[0]

    x, y, z = np.zeros(m), np.zeros(m), np.zeros(m)
    x0, y0, z0 = positions[:, 0], positions[:, 1], positions[:, 2]

    dr = np.zeros(m) + 1
    r = np.zeros(m)

    theta = np.zeros(m)
    phi = np.zeros(m)
    zr = np.zeros(m)

    for _ in range(iterations):
        r = np.sqrt(x * x + y * y + z * z)

        dx = .01
        x_loc = plane_loc
        idx = (x < x_loc + dx) & (x > x_loc - dx)
        dr[idx] = np.power(r[idx], degree - 1) * degree * dr[idx] + 1.0

        theta[idx] = np.arctan2(np.sqrt(x[idx] * x[idx] + y[idx] * y[idx]), z[idx])
        phi[idx] = np.arctan2(y[idx], x[idx])

        zr[idx] = r[idx] ** degree
        theta[idx] = theta[idx] * degree
        phi[idx] = phi[idx] * degree

        x[idx] = zr[idx] * np.sin(theta[idx]) * np.cos(phi[idx]) + x0[idx]
        y[idx] = zr[idx] * np.sin(theta[idx]) * np.sin(phi[idx]) + y0[idx]
        z[idx] = zr[idx] * np.cos(theta[idx]) + z0[idx]

    return 0.5 * np.log(r) * r / dr


def trace(directions, plane_location, max_steps=50, iterations=50, degree=8):
    total_distance = np.zeros(directions.shape[0])
    keep_iterations = np.ones_like(total_distance)
    steps = np.zeros_like(total_distance)

    for _ in range(max_steps):
        positions = total_distance[:, np.newaxis] * directions
        distance = DistanceEstimator(positions, plane_location, iterations, degree)
        total_distance += distance * keep_iterations
        steps += keep_iterations

    # return 1 - (steps / max_steps) ** power
    return total_distance


def run():
    plane_location = 2
    plane_points = get_plane_points(x=plane_location)
    directions = get_directions(plane_points)
    distance = trace(directions, plane_location)

    return distance

我渴望听到有关这方面的想法以及我可能遇到的限制/问题。在此先感谢您的帮助!

python rendering point-clouds raycasting fractals
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.