Contents

Parallax Voxel Ray Marcher

Contents

Parallax Voxel Ray Marcher

Prepare:

In VS:

  • posWS
  • viewDirMS + camPosMS
  • dot(ViewDirWS, cubeNormalWS)?

In PS:

several function here:

  1. finding start point

c++

start findStartPoint() {
    // ray theory
    interPoint = startPos + t * dir;
    t = (interPoint - startPos) / dir;

    // aabb detestation theory
    // the cube x,y,z coord are in [0-1]
    t1 = (0.0 - startPos.x) / dir.x;
    t2 = (1.0 - startPos.x) / dir.x;
    ..
    t5 = (0.0 - startPos.z) / dir.z;
    t6 = (1.0 - startPos.z) / dir.z;

    // 最后一个进去volume才算整个完全进入
    tmin = max(max(min(t1, t2), min(t2, t3), min(t3, t4)));
    // 最早一个出去的就算已经出去了
    tmax = min(min(max(t1, t2), max(t2, t3), max(t3, t4)));

    // if camera is insi
}
  1. distance field + sphere tracing

make sure we won’t miss any hit,

this is an optimization for this project, because we still step on grid every time

  1. hit function

c++

hit fixed_step() {
    // get cur voxel id
    vec3 cur = vec3(posWS.x/voxelSize, ...);
    vec3 dir = normalize(viewDirMS);

    float stepX = dir.x > 0 ? 1 : -1;
    // same for stepY and stepZ

    // find the next voxel
    float next_voxel_x = (cur.x + stepX) * voxelSize;
    // same for next_voxel_y and z

    // compute tmaxX, Y and Z
    // 他们表示从当前的voxel pos到边界,要多少t

    // compute the deltaX, Y and Z
    // 他们按照当前的dir分量,走一个voxel size需要多少t

    for() {
        // follow the minimum tmax
        // every loop, step forward along the dir of minimum tmax
        // tmax += tDelta
    }
}
  1. cal normal

  2. why project to the back side of the cube?

to avoid the situation like when we are inside the volume, if we project to the front face, then nothing will be rendered if we are inside the volume.