예제 #1
0
        private void CustomRender(ScriptableRenderContext context, HDCamera hd)
        {
            var cmd = CommandBufferPool.Get();

            void RenderPointCloud(CubemapFace face)
            {
                PointCloudManager.RenderLidar(context, cmd, hd, renderTarget.ColorHandle, renderTarget.DepthHandle, face);
            }

            RenderMarker.Begin();
            SensorPassRenderer.Render(context, cmd, hd, renderTarget, passId, Color.clear, RenderPointCloud);
            RenderMarker.End();

            ComputeMarker.Begin();
            var kernel = cs.FindKernel(Compensated ? "CubeComputeComp" : "CubeCompute");

            cmd.SetComputeTextureParam(cs, kernel, Properties.InputCubemapTexture, renderTarget.ColorHandle);
            cmd.SetComputeBufferParam(cs, kernel, Properties.Output, PointCloudBuffer);
            cmd.SetComputeBufferParam(cs, kernel, Properties.LatitudeAngles, LatitudeAnglesBuffer);
            cmd.SetComputeIntParam(cs, Properties.LaserCount, LaserCount);
            cmd.SetComputeIntParam(cs, Properties.MeasuresPerRotation, UsedMeasurementsPerRotation);
            cmd.SetComputeFloatParam(cs, Properties.AntialiasingThreshold, AntialiasingThreshold);
            cmd.SetComputeVectorParam(cs, Properties.Origin, SensorCamera.transform.position);
            cmd.SetComputeMatrixParam(cs, Properties.RotMatrix, Matrix4x4.Rotate(transform.rotation));
            cmd.SetComputeMatrixParam(cs, Properties.Transform, transform.worldToLocalMatrix);
            cmd.SetComputeVectorParam(cs, Properties.PackedVec, new Vector4(MaxDistance, DeltaLongitudeAngle, MinDistance, StartLongitudeOffset));
            cmd.DispatchCompute(cs, kernel, HDRPUtilities.GetGroupSize(UsedMeasurementsPerRotation, 8), HDRPUtilities.GetGroupSize(LaserCount, 8), 1);
            ComputeMarker.End();

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }
        private void OnSegmentationRender(ScriptableRenderContext context, HDCamera hdCamera)
        {
            var cmd = CommandBufferPool.Get();

            SensorPassRenderer.Render(context, cmd, hdCamera, renderTarget, passId, SimulatorManager.Instance.SkySegmentationColor);

            var clearKernel = cs.FindKernel("Clear");

            cmd.SetComputeVectorParam(cs, Properties.TexSize, new Vector4(Width, Height, 1f / Width, 1f / Height));
            cmd.SetComputeBufferParam(cs, clearKernel, Properties.MinX, minX);
            cmd.SetComputeBufferParam(cs, clearKernel, Properties.MaxX, maxX);
            cmd.SetComputeBufferParam(cs, clearKernel, Properties.MinY, minY);
            cmd.SetComputeBufferParam(cs, clearKernel, Properties.MaxY, maxY);
            cmd.DispatchCompute(cs, clearKernel, 4, 1, 1);

            var detectKernel = cs.FindKernel("Detect");

            cmd.SetComputeTextureParam(cs, detectKernel, Properties.Input, renderTarget.ColorHandle);
            cmd.SetComputeVectorParam(cs, Properties.TexSize, new Vector4(Width, Height, 1f / Width, 1f / Height));
            cmd.SetComputeBufferParam(cs, detectKernel, Properties.MinX, minX);
            cmd.SetComputeBufferParam(cs, detectKernel, Properties.MaxX, maxX);
            cmd.SetComputeBufferParam(cs, detectKernel, Properties.MinY, minY);
            cmd.SetComputeBufferParam(cs, detectKernel, Properties.MaxY, maxY);
            cmd.DispatchCompute(cs, detectKernel, HDRPUtilities.GetGroupSize(Width, 8), HDRPUtilities.GetGroupSize(Height, 8), 1);

            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }
예제 #3
0
        void CustomRender(ScriptableRenderContext context, HDCamera hd)
        {
            var cmd = CommandBufferPool.Get();

            SensorPassRenderer.Render(context, cmd, hd, renderTarget, passId, SimulatorManager.Instance.SkySegmentationColor);
            var kernel = computeUtils.FindKernel("FillAlphaXR");

            cmd.SetComputeTextureParam(computeUtils, kernel, Properties.Output, renderTarget.ColorHandle);
            cmd.SetComputeVectorParam(computeUtils, Properties.TexSize, new Vector4(Width, Height, 1f / Width, 1f / Height));
            cmd.DispatchCompute(computeUtils, kernel, HDRPUtilities.GetGroupSize(Width, 8), HDRPUtilities.GetGroupSize(Height, 8), 1);
            context.ExecuteCommandBuffer(cmd);
            cmd.Clear();
            CommandBufferPool.Release(cmd);
        }
        public static SignedDistanceFieldData Generate(GameObject obj, ComputeShader cs, Vector3Int resolution, Bounds bounds, float step)
        {
            var width  = resolution.x;
            var height = resolution.y;
            var depth  = resolution.z;

            var meshFilters = obj.GetComponentsInChildren <MeshFilter>();

            var voxelRes = new[] { width, height, depth };

            var resVoxels = new bool[width][][];

            for (var i = 0; i < width; ++i)
            {
                resVoxels[i] = new bool[height][];
                for (var j = 0; j < height; ++j)
                {
                    resVoxels[i][j] = new bool[depth];
                }
            }

            foreach (var meshFilter in meshFilters)
            {
                Voxelize(meshFilter, bounds, resolution, step, resVoxels);
            }

            var count     = width * height * depth;
            var bufferCpu = new float[count];

            for (var x = 0; x < width; ++x)
            {
                for (var z = 0; z < depth; ++z)
                {
                    var filled = false;

                    for (var y = height - 1; y >= 0; --y)
                    {
                        var full = resVoxels[x][y][z] || filled;
                        if (!filled && full)
                        {
                            filled = true;
                        }

                        var pos = TreeUtility.Flatten(x, y, z, voxelRes);
                        bufferCpu[pos] = full ? 1f : 0f;
                    }
                }
            }

            var buffer = new ComputeBuffer(count, sizeof(float));

            buffer.SetData(bufferCpu);

            var texture = new RenderTexture(width, height, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Default)
            {
                dimension         = TextureDimension.Tex3D,
                volumeDepth       = depth,
                enableRandomWrite = true,
                wrapMode          = TextureWrapMode.Clamp
            };

            texture.Create();

            var initializeKernel = cs.FindKernel("Initialize");

            cs.SetTexture(initializeKernel, "_Texture", texture);
            cs.SetBuffer(initializeKernel, "_VoxelBuffer", buffer);
            cs.SetVector("_TexSize", new Vector4(width, height, depth, 0f));
            cs.Dispatch(initializeKernel, HDRPUtilities.GetGroupSize(width, 8),
                        HDRPUtilities.GetGroupSize(height, 8), HDRPUtilities.GetGroupSize(depth, 8));

            buffer.Dispose();

            return(new SignedDistanceFieldData()
            {
                texture = texture,
                bounds = bounds,
                voxels = resVoxels,
                step = step
            });
        }