Search Unity

Confused on doing voxelization

Discussion in 'General Graphics' started by zhutianlun810, Jun 10, 2019.

  1. zhutianlun810

    zhutianlun810

    Joined:
    Sep 17, 2017
    Posts:
    168
    Hello,

    I am planning to do GPU voxelization in Unity3D. I read many documents and the implementation of SEGI, and I have some questions on the voxelization step.

    I am following the tutorial from https://developer.nvidia.com/content/basics-gpu-voxelization . I feel I may misunderstand something. In figure 1, It is said "Orthogonal projection view frustum aligned to fit the voxel grid you will use to voxelize the scene". So I need to use a orthogonal camera whose view frustum is covering all objects in my scene? But My scene may be very large.

    I read the implementation in SEGI, the author creates a variable called:
    public float voxelSpaceSize = 25.0f;

    And then the orthogonal camera(voxelCameraGO) is set by these following parameters:

    Code (CSharp):
    1.         voxelCameraGO = new GameObject("SEGI_VOXEL_CAMERA");
    2.         voxelCameraGO.hideFlags = HideFlags.HideAndDontSave;
    3.  
    4.         voxelCamera = voxelCameraGO.AddComponent<Camera>();
    5.         voxelCamera.enabled = false;
    6.         voxelCamera.orthographic = true;
    7.         voxelCamera.orthographicSize = voxelSpaceSize * 0.5f;
    8.         voxelCamera.nearClipPlane = 0.0f;
    9.         voxelCamera.farClipPlane = voxelSpaceSize;
    10.         voxelCamera.depth = -2;
    11.         voxelCamera.renderingPath = RenderingPath.Forward;
    12.         voxelCamera.clearFlags = CameraClearFlags.Color;
    13.         voxelCamera.backgroundColor = Color.black;
    14.         voxelCamera.useOcclusionCulling = false;
    And then the author set the position of the orthogonal camera relative to the main camera:
    Code (CSharp):
    1.             float interval = voxelSpaceSize / 8.0f;                                                //The interval at which the voxel volume will be "locked" in world-space
    2.             Vector3 origin;
    3.             if (followTransform)
    4.             {
    5.                 origin = followTransform.position;
    6.             }
    7.             else
    8.             {
    9.                 origin = transform.position + transform.forward * voxelSpaceSize / 4.0f;
    10.             }
    11.             //Lock the voxel volume origin based on the interval
    12.             voxelSpaceOrigin = new Vector3(Mathf.Round(origin.x / interval) * interval, Mathf.Round(origin.y / interval) * interval, Mathf.Round(origin.z / interval) * interval);
    13. voxelCameraGO.transform.position = voxelSpaceOrigin - Vector3.forward * voxelSpaceSize * 0.5f;
    This script is attached to the main camera. So "origin = transform.position + transform.forward * voxelSpaceSize / 4.0f;" means the position of the orthogonal camera is relative to the main camera. I don't think the orthogonal camera can cover the whole scene.

    Or, what will happen if a vertex which is outside my orthogonal camera's view, is multiplied by UNITY_MATRIX_P?

    I feel I just have a blur understanding of how UNITY_MATRIX_P works...

    I really appreciate any help.