private void RunBoundsPhase(Mesh mesh, out Vector3 minBounds, out Vector3 maxBounds) { int[] meshBounds = new int[6]; BoundsBuffer.SetData(meshBounds); MeshSampleComputeShader.Dispatch(ComputeBoundsKernel, Mathf.CeilToInt(mesh.triangles.Length / 64f), 1, 1); BoundsBuffer.GetData(meshBounds); const float packingMultiplier = 1000f; minBounds = new Vector3(meshBounds[0] / packingMultiplier, meshBounds[1] / packingMultiplier, meshBounds[2] / packingMultiplier); maxBounds = new Vector3(meshBounds[3] / packingMultiplier, meshBounds[4] / packingMultiplier, meshBounds[5] / packingMultiplier); minBounds -= m_padding * Vector3.one; maxBounds += m_padding * Vector3.one; }
/// <summary> /// Note: I chose to use buffers instead of writing to texture 3ds directly on the GPU because for some reason it's /// stupidly complicated to write to a texture3d on the gpu and then get that data back to the cpu for serialization. /// </summary> private void RunSamplePhase(bool hasUVs, out float[] samples, out float[] packedUVs, Vector3 minBounds, Vector3 maxBounds) { MeshSampleComputeShader.SetVector(Properties.MinBounds_Vector3, minBounds); MeshSampleComputeShader.SetVector(Properties.MaxBounds_Vector3, maxBounds); int threadGroups = Mathf.CeilToInt(m_size / 8f); MeshSampleComputeShader.Dispatch(GetTextureWholeKernel, threadGroups, threadGroups, threadGroups); SamplesBuffer.GetData(m_samples); samples = m_samples; if (hasUVs) { PackedUVsBuffer.GetData(m_packedUVs); packedUVs = m_packedUVs; } else { packedUVs = null; } }