예제 #1
0
    void Start()
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();
        Scene scene = new Scene(true);

        bvhScene = new BVHScene(scene.triangles, scene.vertices);
        Debug.Log("bvhScene.triangles.Count = " + bvhScene.triangles.Count);

        Debug.Log(" ================================ ");

        var bvhData = new CPU_BVHData(bvhScene);

        CPU_SBVHBuilder.Build(bvhData);

        Debug.Log("bvhData.triangles.Count = " + bvhData.triIndices.Count);
        Debug.Log(" ================================ ");
        // debug gpu bvh
        GPU_BVHData gpuData = new GPU_BVHData().Generate(bvhData);

        Debug.Log("gpuData.nodes.Count = " + gpuData.nodes.Count);
        Debug.Log("gpuData.woopTris.Count = " + gpuData.woopTris.Count);
        Debug.Log("gpuData.triIndices.Count = " + gpuData.triIndices.Count);


        root = bvhData.root;
        sw.Stop();
        string log = "Build successfully, time: " + sw.ElapsedMilliseconds + " ms";

        Debug.Log(log);
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        var tracer = target as TracerBehaviour;

        bool pressGenerateBVH = GUILayout.Button("Rebuild BVH", GUILayout.ExpandWidth(true));

        if (pressGenerateBVH)
        {
            var scene    = new Scene(true);
            var bvhScene = new BVHScene(scene.triangles, scene.vertices);
            var cpuBVH   = new CPU_BVHData(bvhScene);
            CPU_SBVHBuilder.Build(cpuBVH);

            SaveBVH(tracer, cpuBVH);
        }

        //bool pressTest = GUILayout.Button("Log Test", GUILayout.ExpandWidth(true));
        //if (pressTest)
        //{
        //    Debug.Log(tracer.gpuBVH.nodes.Count);
        //    Debug.Log(tracer.gpuBVH.nodes[1]);
        //}

        DrawProperty("useCachedBVH");
        DrawProperty("spps");
        DrawProperty("tracingShader");
        DrawProperty("skyboxTex");
        DrawProperty("sun");

        serializedObject.ApplyModifiedProperties();
    }
예제 #3
0
    // Start is called before the first frame update
    void Start()
    {
        if (gpuBVH == null)
        {
            Debug.Log("No cached BVH data found, building BVH now.");
            _theScene = new Scene(true);
            var bvhScene = new BVHScene(_theScene.triangles, _theScene.vertices);
            var cpuBVH   = new CPU_BVHData(bvhScene);
            CPU_SBVHBuilder.Build(cpuBVH);
            gpuBVH = new GPU_BVHData().Generate(cpuBVH);
        }
        else
        {
            _theScene = new Scene(true);
            Debug.Log("Using cached BVH data.");
        }

        // bind texture2darray
        var diffuseTexLen = _theScene.diffuseTextures.Count;

        if (_theScene.diffuseTextures.Count > 0)
        {
            var tex = _theScene.diffuseTextures[0];
            _diffuseTextures = new Texture2DArray(tex.width, tex.height, diffuseTexLen, tex.format, true);

            for (int i = 0; i < diffuseTexLen; i++)
            {
                Graphics.CopyTexture(_theScene.diffuseTextures[i], 0, _diffuseTextures, i);
            }
        }

        // bvh
        CreateComputeBuffer(ref _nodesBuffer, gpuBVH.nodes, 16);
        CreateComputeBuffer(ref _woopTrisBuffer, gpuBVH.woopTris, 16);
        CreateComputeBuffer(ref _triIndicesBuffer, gpuBVH.triIndices, 4);

        // per vertex
        CreateComputeBuffer(ref _verticesBuffer, _theScene.vertices, 12);
        CreateComputeBuffer(ref _normalsBuffer, _theScene.normals, 12);
        CreateComputeBuffer(ref _uv0sBuffer, _theScene.uv0s, 8);

        // per triangle
        CreateComputeBuffer(ref _trianglesBuffer, _theScene.triangles, 12);
        CreateComputeBuffer(ref _materialsBuffer, _theScene.materials, 144);
        CreateComputeBuffer(ref _matIdxBuffer, _theScene.matIndices, 4);
    }
예제 #4
0
    public static void Build(CPU_BVHData bvhData)
    {
        var builder = new CPU_SBVHBuilder(bvhData);

        builder.Build();
    }