public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data)
        {
            float4x4 proj = GL.GetGPUProjectionMatrix(camera.cam.nonJitteredProjectionMatrix, false);
            float4x4 viewProj;

            if (camera.cam.orthographic)
            {
                OrthoCam cam = new OrthoCam
                {
                    forward  = camera.cam.transform.forward,
                    up       = camera.cam.transform.up,
                    right    = camera.cam.transform.right,
                    position = 0
                };
                cam.UpdateTRSMatrix();
                viewProj = mul(proj, cam.worldToCameraMatrix);
            }
            else
            {
                PerspCam cam = new PerspCam
                {
                    forward  = camera.cam.transform.forward,
                    up       = camera.cam.transform.up,
                    right    = camera.cam.transform.right,
                    position = 0
                };
                cam.UpdateTRSMatrix();
                viewProj = mul(proj, cam.worldToCameraMatrix);
            }
            CommandBuffer buffer = data.buffer;

            buffer.SetGlobalMatrix(_InvSkyVP, inverse(viewProj));
            buffer.SetRenderTarget(color: camera.targets.renderTargetIdentifier, depth: ShaderIDs._DepthBufferTexture);
            buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0);
        }
 public void Execute()
 {
     if (isOrtho)
     {
         OrthoCam cam = new OrthoCam
         {
             forward  = forward,
             up       = up,
             right    = right,
             position = 0
         };
         cam.UpdateTRSMatrix();
         viewProj = mul(proj, cam.worldToCameraMatrix);
     }
     else
     {
         PerspCam cam = new PerspCam
         {
             forward  = forward,
             up       = up,
             right    = right,
             position = 0
         };
         cam.UpdateTRSMatrix();
         viewProj = mul(proj, cam.worldToCameraMatrix);
     }
     invViewProj = inverse(viewProj);
 }
예제 #3
0
 public static void GetPerspFrustumPlanesWithCorner(ref PerspCam perspCam, float4 *planes, float3 *corners)
 {
     planes[0] = MathLib.GetPlane(corners[1], corners[0], perspCam.position);
     planes[1] = MathLib.GetPlane(corners[2], corners[3], perspCam.position);
     planes[2] = MathLib.GetPlane(corners[0], corners[2], perspCam.position);
     planes[3] = MathLib.GetPlane(corners[3], corners[1], perspCam.position);
     planes[4] = MathLib.GetPlane(perspCam.forward, perspCam.position + perspCam.forward * perspCam.farClipPlane);
     planes[5] = MathLib.GetPlane(-perspCam.forward, perspCam.position + perspCam.forward * perspCam.nearClipPlane);
 }
예제 #4
0
        private static void CalculateCubemapMatrix(float3 position, float farClipPlane, float nearClipPlane, out NativeList <float4x4> viewMatrices, out NativeList <float4x4> projMatrices)
        {
            viewMatrices = new NativeList <float4x4>(6, 6, Allocator.Temp);
            projMatrices = new NativeList <float4x4>(6, 6, Allocator.Temp);
            PerspCam cam = new PerspCam();

            cam.aspect        = 1;
            cam.farClipPlane  = farClipPlane;
            cam.nearClipPlane = nearClipPlane;
            cam.position      = position;
            cam.fov           = 90f;
            //Forward
            cam.right   = float3(1, 0, 0);
            cam.up      = float3(0, 1, 0);
            cam.forward = float3(0, 0, 1);
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            for (int i = 0; i < 6; ++i)
            {
                projMatrices[i] = cam.projectionMatrix;
            }
            viewMatrices[5] = cam.worldToCameraMatrix;
            //Back
            cam.right   = float3(-1, 0, 0);
            cam.up      = float3(0, 1, 0);
            cam.forward = float3(0, 0, -1);
            cam.UpdateTRSMatrix();

            viewMatrices[4] = cam.worldToCameraMatrix;
            //Up
            cam.right   = float3(-1, 0, 0);
            cam.up      = float3(0, 0, 1);
            cam.forward = float3(0, 1, 0);
            cam.UpdateTRSMatrix();
            viewMatrices[3] = cam.worldToCameraMatrix;
            //Down
            cam.right   = float3(-1, 0, 0);
            cam.up      = float3(0, 0, -1);
            cam.forward = float3(0, -1, 0);
            cam.UpdateTRSMatrix();
            viewMatrices[2] = cam.worldToCameraMatrix;
            //Right
            cam.up      = float3(0, 1, 0);
            cam.right   = float3(0, 0, -1);
            cam.forward = float3(1, 0, 0);
            cam.UpdateTRSMatrix();
            viewMatrices[1] = cam.worldToCameraMatrix;
            //Left
            cam.up      = float3(0, 1, 0);
            cam.right   = float3(0, 0, 1);
            cam.forward = float3(-1, 0, 0);
            cam.UpdateTRSMatrix();
            viewMatrices[0] = cam.worldToCameraMatrix;
        }
        private void BakeCubemap()
        {
            PerspCam persp = new PerspCam();

            persp.aspect        = 1;
            persp.farClipPlane  = considerRange;
            persp.nearClipPlane = 0.1f;
            persp.fov           = 90f;
            NativeList <float4x4> worldToCameras = new NativeList <float4x4>(6, 6, Allocator.TempJob);
            NativeList <float4x4> projection     = new NativeList <float4x4>(6, 6, Allocator.TempJob);

            GetMatrix(worldToCameras.unsafePtr, ref persp, transform.position);
            persp.UpdateProjectionMatrix();
            for (int i = 0; i < 6; ++i)
            {
                projection[i] = persp.projectionMatrix;
            }
            RenderTexture rt = new RenderTexture(new RenderTextureDescriptor
            {
                autoGenerateMips  = false,
                bindMS            = false,
                colorFormat       = RenderTextureFormat.ARGBHalf,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2DArray,
                enableRandomWrite = false,
                height            = 128,
                width             = 128,
                volumeDepth       = 6,
                msaaSamples       = 1,
                useMipMap         = true
            });

            rt.filterMode = FilterMode.Trilinear;
            rt.Create();
            RenderTexture tempRT = new RenderTexture(new RenderTextureDescriptor
            {
                autoGenerateMips  = false,
                bindMS            = false,
                colorFormat       = RenderTextureFormat.ARGBHalf,
                depthBufferBits   = 16,
                dimension         = TextureDimension.Tex2D,
                enableRandomWrite = false,
                height            = 128,
                width             = 128,
                volumeDepth       = 1,
                msaaSamples       = 1
            });

            cbuffer.Clear();
            cbuffer.SetGlobalTexture("_Cubemap", rt);
            cbuffer.GenerateMips(rt);
            RenderPipeline.AddRenderingMissionInEditor(worldToCameras, projection, targetCamera, rt, tempRT, cbuffer);
        }
예제 #6
0
        public static void GetFrustumPlanes(ref PerspCam perspCam, float4 *planes)
        {
            float3 *corners = stackalloc float3[4];

            GetFrustumCorner(ref perspCam, perspCam.farClipPlane, corners);
            planes[0] = MathLib.GetPlane(corners[1], corners[0], perspCam.position);
            planes[1] = MathLib.GetPlane(corners[2], corners[3], perspCam.position);
            planes[2] = MathLib.GetPlane(corners[0], corners[2], perspCam.position);
            planes[3] = MathLib.GetPlane(corners[3], corners[1], perspCam.position);
            planes[4] = MathLib.GetPlane(perspCam.forward, perspCam.position + perspCam.forward * perspCam.farClipPlane);
            planes[5] = MathLib.GetPlane(-perspCam.forward, perspCam.position + perspCam.forward * perspCam.nearClipPlane);
        }
예제 #7
0
        public static void GetFrustumCorner(ref PerspCam perspCam, float distance, float3 *corners)
        {
            float  fov         = Mathf.Deg2Rad * perspCam.fov * 0.5f;
            float  upLength    = distance * tan(fov);
            float  rightLength = upLength * perspCam.aspect;
            float3 farPoint    = perspCam.position + distance * perspCam.forward;
            float3 upVec       = upLength * perspCam.up;
            float3 rightVec    = rightLength * perspCam.right;

            corners[0] = farPoint - upVec - rightVec;
            corners[1] = farPoint - upVec + rightVec;
            corners[2] = farPoint + upVec - rightVec;
            corners[3] = farPoint + upVec + rightVec;
        }
        public override void FrameUpdate(PipelineCamera camera, ref PipelineCommandData data)
        {
            SkyboxMatrixData skyData = IPerCameraData.GetProperty(camera, () => new SkyboxMatrixData(), this);
            float4x4         proj    = GL.GetGPUProjectionMatrix(camera.cam.nonJitteredProjectionMatrix, false);
            float4x4         viewProj;

            if (camera.cam.orthographic)
            {
                OrthoCam cam = new OrthoCam
                {
                    forward  = camera.cam.transform.forward,
                    up       = camera.cam.transform.up,
                    right    = camera.cam.transform.right,
                    position = 0
                };
                cam.UpdateTRSMatrix();
                viewProj = mul(proj, cam.worldToCameraMatrix);
            }
            else
            {
                PerspCam cam = new PerspCam
                {
                    forward  = camera.cam.transform.forward,
                    up       = camera.cam.transform.up,
                    right    = camera.cam.transform.right,
                    position = 0
                };
                cam.UpdateTRSMatrix();
                viewProj = mul(proj, cam.worldToCameraMatrix);
            }
            CommandBuffer buffer = data.buffer;

            buffer.SetGlobalMatrix(_InvSkyVP, inverse(viewProj));
            buffer.SetGlobalMatrix(_LastSkyVP, skyData.lastVP);
            targets[0] = camera.targets.renderTargetIdentifier;
            targets[1] = camera.targets.motionVectorTexture;
            buffer.SetRenderTarget(colors: targets, depth: camera.targets.depthBuffer);
            buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, skyboxMaterial, 0, 0);
            skyData.lastVP = viewProj;
        }
 private static void GetMatrix(float4x4 *allmat, ref PerspCam persp, float3 position)
 {
     persp.position = position;
     //X
     persp.up      = float3(0, 1, 0);
     persp.right   = float3(0, 0, -1);
     persp.forward = float3(1, 0, 0);
     persp.UpdateTRSMatrix();
     allmat[1] = persp.worldToCameraMatrix;
     //-X
     persp.up      = float3(0, 1, 0);
     persp.right   = float3(0, 0, 1);
     persp.forward = float3(-1, 0, 0);
     persp.UpdateTRSMatrix();
     allmat[0] = persp.worldToCameraMatrix;
     //Y
     persp.right   = float3(-1, 0, 0);
     persp.up      = float3(0, 0, 1);
     persp.forward = float3(0, 1, 0);
     persp.UpdateTRSMatrix();
     allmat[2] = persp.worldToCameraMatrix;
     //-Y
     persp.right   = float3(-1, 0, 0);
     persp.up      = float3(0, 0, -1);
     persp.forward = float3(0, -1, 0);
     persp.UpdateTRSMatrix();
     allmat[3] = persp.worldToCameraMatrix;
     //Z
     persp.right   = float3(1, 0, 0);
     persp.up      = float3(0, 1, 0);
     persp.forward = float3(0, 0, 1);
     persp.UpdateTRSMatrix();
     allmat[5] = persp.worldToCameraMatrix;
     //-Z
     persp.right   = float3(-1, 0, 0);
     persp.up      = float3(0, 1, 0);
     persp.forward = float3(0, 0, -1);
     persp.UpdateTRSMatrix();
     allmat[4] = persp.worldToCameraMatrix;
 }
        private void BakeMap(int3 index, RenderTexture texArray, RenderTexture tempTex)
        {
            float3   left     = transform.position - transform.lossyScale * 0.5f;
            float3   right    = transform.position + transform.lossyScale * 0.5f;
            float3   position = lerp(left, right, ((float3)index + 0.5f) / probeCount);
            PerspCam persp    = new PerspCam();

            persp.aspect        = 1;
            persp.farClipPlane  = considerRange;
            persp.nearClipPlane = 0.1f;
            persp.fov           = 90f;
            NativeList <float4x4> worldToCameras = new NativeList <float4x4>(6, 6, Allocator.TempJob);
            NativeList <float4x4> projection     = new NativeList <float4x4>(6, 6, Allocator.TempJob);

            GetMatrix(worldToCameras.unsafePtr, ref persp, position);
            persp.UpdateProjectionMatrix();
            for (int i = 0; i < 6; ++i)
            {
                projection[i] = persp.projectionMatrix;
            }
            RenderPipeline.AddRenderingMissionInEditor(worldToCameras, projection, targetCamera, texArray, tempTex, cbuffer);
        }
예제 #11
0
        public static void GetFrustumCorner(ref PerspCam perspCam, float3 *corners)
        {
            float fov = tan(Mathf.Deg2Rad * perspCam.fov * 0.5f);

            void GetCorner(float dist, ref PerspCam persp)
            {
                float  upLength    = dist * (fov);
                float  rightLength = upLength * persp.aspect;
                float3 farPoint    = persp.position + dist * persp.forward;
                float3 upVec       = upLength * persp.up;
                float3 rightVec    = rightLength * persp.right;

                corners[0] = farPoint - upVec - rightVec;
                corners[1] = farPoint - upVec + rightVec;
                corners[2] = farPoint + upVec - rightVec;
                corners[3] = farPoint + upVec + rightVec;
                corners   += 4;
            }

            GetCorner(perspCam.nearClipPlane, ref perspCam);
            GetCorner(perspCam.farClipPlane, ref perspCam);
        }
        public override void DrawCubeMap(MPointLight lit, ref RenderClusterOptions opts, ref CubeCullingBuffer buffer, int offset)
        {
            CommandBuffer cb            = opts.command;
            ComputeShader shader        = opts.cullingShader;
            Material      depthMaterial = opts.proceduralMaterial;

            cb.SetComputeIntParam(shader, ShaderIDs._LightOffset, offset);
            ComputeShaderUtility.Dispatch(shader, cb, CubeFunction.RunFrustumCull, baseBuffer.clusterCount, 256);
            PerspCam cam = new PerspCam();

            cam.aspect        = 1;
            cam.farClipPlane  = lit.range;
            cam.nearClipPlane = 0.3f;
            cam.position      = lit.position;
            cam.fov           = 90f;
            Matrix4x4 vpMatrix;

            cb.SetGlobalVector(ShaderIDs._LightPos, new Vector4(lit.position.x, lit.position.y, lit.position.z, lit.range));
            cb.SetGlobalBuffer(ShaderIDs.verticesBuffer, baseBuffer.verticesBuffer);
            cb.SetGlobalBuffer(ShaderIDs.resultBuffer, baseBuffer.resultBuffer);
            //Forward
            cam.forward  = Vector3.forward;
            cam.up       = Vector3.down;
            cam.right    = Vector3.left;
            cam.position = lit.position;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeZ);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            offset = offset * 20;
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Back
            cam.forward = Vector3.back;
            cam.up      = Vector3.down;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveZ);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Up
            cam.forward = Vector3.up;
            cam.up      = Vector3.back;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveY);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Down
            cam.forward = Vector3.down;
            cam.up      = Vector3.forward;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeY);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Right
            cam.forward = Vector3.right;
            cam.up      = Vector3.down;
            cam.right   = Vector3.forward;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveX);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
            //Left
            cam.forward = Vector3.left;
            cam.up      = Vector3.down;
            cam.right   = Vector3.back;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeX);
            cb.ClearRenderTarget(true, true, Color.white);
            cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset);
        }
예제 #13
0
        public void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer = data.buffer;

            if (!Decal.decalDatas.isCreated)
            {
                buffer.SetGlobalInt(_EnableDecal, 0);
                return;
            }
            buffer.SetGlobalInt(_EnableDecal, 1);
            handle.Complete();
            if (cullJob.count > decalBuffer.count)
            {
                int oldCount = decalBuffer.count;
                decalBuffer.Dispose();
                decalBuffer = new ComputeBuffer((int)max(oldCount * 1.5f, cullJob.count), sizeof(DecalStrct));
            }
            if (!minMaxBoundMat)
            {
                minMaxBoundMat = new Material(data.resources.shaders.minMaxDepthBounding);
            }
            int pixelWidth  = cam.cam.pixelWidth;
            int pixelHeight = cam.cam.pixelHeight;

            decalBuffer.SetDataPtr(sortJob.sortedDecalDatas.unsafePtr, 0, cullJob.count);
            buffer.GetTemporaryRT(_DownSampledDepth0, pixelWidth / 2, pixelHeight / 2, 0, FilterMode.Point, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, false);
            buffer.GetTemporaryRT(_DownSampledDepth1, pixelWidth / 4, pixelHeight / 4, 0, FilterMode.Point, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, false);
            buffer.GetTemporaryRT(_DownSampledDepth2, pixelWidth / 8, pixelHeight / 8, 0, FilterMode.Point, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, false);
            buffer.GetTemporaryRT(_DownSampledDepth3, pixelWidth / 16, pixelHeight / 16, 0, FilterMode.Point, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, false);
            buffer.BlitSRT(_DownSampledDepth0, minMaxBoundMat, 0);
            buffer.SetGlobalTexture(ShaderIDs._TargetDepthTexture, _DownSampledDepth0);
            buffer.BlitSRT(_DownSampledDepth1, minMaxBoundMat, 1);
            buffer.SetGlobalTexture(ShaderIDs._TargetDepthTexture, _DownSampledDepth1);
            buffer.BlitSRT(_DownSampledDepth2, minMaxBoundMat, 1);
            buffer.SetGlobalTexture(ShaderIDs._TargetDepthTexture, _DownSampledDepth2);
            buffer.BlitSRT(_DownSampledDepth3, minMaxBoundMat, 1);
            int2 tileSize = int2(pixelWidth / 16, pixelHeight / 16);
            RenderTextureDescriptor lightTileDisc = new RenderTextureDescriptor
            {
                autoGenerateMips  = false,
                bindMS            = false,
                colorFormat       = RenderTextureFormat.RInt,
                depthBufferBits   = 0,
                dimension         = TextureDimension.Tex3D,
                enableRandomWrite = true,
                width             = tileSize.x,
                height            = tileSize.y,
                msaaSamples       = 1,
                volumeDepth       = CBDRSharedData.MAXLIGHTPERTILE
            };

            buffer.GetTemporaryRT(ShaderIDs._DecalTile, lightTileDisc);
            tileSizeArray[0] = tileSize.x;
            tileSizeArray[1] = tileSize.y;
            float3 * corners  = stackalloc float3[4];
            PerspCam perspCam = new PerspCam
            {
                fov      = cam.cam.fieldOfView,
                up       = cam.cam.transform.up,
                right    = cam.cam.transform.right,
                forward  = cam.cam.transform.forward,
                position = cam.cam.transform.position,
                aspect   = cam.cam.aspect,
            };

            PipelineFunctions.GetFrustumCorner(ref perspCam, 1, corners);
            for (int i = 0; i < 4; ++i)
            {
                frustumCorners[i] = float4(corners[i], 1);
            }
            buffer.SetComputeVectorArrayParam(cbdrShader, ShaderIDs._FrustumCorners, frustumCorners);
            buffer.SetComputeVectorParam(cbdrShader, ShaderIDs._CameraPos, cam.cam.transform.position);
            buffer.SetComputeIntParams(cbdrShader, ShaderIDs._TileSize, tileSizeArray);
            buffer.SetGlobalVector(ShaderIDs._TileSize, new Vector4(tileSize.x, tileSize.y));
            buffer.SetComputeVectorParam(cbdrShader, ShaderIDs._CameraForward, cam.cam.transform.forward);
            buffer.SetComputeTextureParam(cbdrShader, CBDRSharedData.DecalCull, ShaderIDs._DepthBoundTexture, new RenderTargetIdentifier(_DownSampledDepth3));
            buffer.SetComputeTextureParam(cbdrShader, CBDRSharedData.DecalCull, ShaderIDs._DecalTile, new RenderTargetIdentifier(ShaderIDs._DecalTile));
            buffer.SetComputeBufferParam(cbdrShader, CBDRSharedData.DecalCull, ShaderIDs._AllDecals, decalBuffer);
            buffer.SetComputeIntParam(cbdrShader, ShaderIDs._DecalCount, cullJob.count);
            buffer.SetGlobalBuffer(ShaderIDs._AllDecals, decalBuffer);
            buffer.DispatchCompute(cbdrShader, CBDRSharedData.DecalCull, Mathf.CeilToInt(tileSize.x / 8f), Mathf.CeilToInt(tileSize.y / 8f), 1);
            buffer.ReleaseTemporaryRT(_DownSampledDepth0);
            buffer.ReleaseTemporaryRT(_DownSampledDepth1);
            buffer.ReleaseTemporaryRT(_DownSampledDepth2);
            buffer.ReleaseTemporaryRT(_DownSampledDepth3);
            RenderPipeline.ReleaseRTAfterFrame(ShaderIDs._DecalTile);
            decalCullResults.Dispose();
            decalCompareResults.Dispose();
        }
        public static void DrawShadow(MPointLight lit, CommandBuffer cb, MaterialPropertyBlock block, ref CubeCullingBuffer buffer, ref PipelineBaseBuffer baseBuffer, ComputeShader shader, int offset, Material depthMaterial)
        {
            cb.SetComputeIntParam(shader, ShaderIDs._LightOffset, offset);
            ComputeShaderUtility.Dispatch(shader, cb, RunFrustumCull, baseBuffer.clusterCount, 64);
            PerspCam cam = new PerspCam();

            cam.aspect        = 1;
            cam.farClipPlane  = lit.range;
            cam.nearClipPlane = 0.3f;
            cam.position      = lit.position;
            cam.fov           = 90f;
            Matrix4x4 vpMatrix;

            block.SetVector(ShaderIDs._LightPos, new Vector4(lit.position.x, lit.position.y, lit.position.z, lit.range));
            PipelineFunctions.SetShaderBuffer(ref baseBuffer, block);
            //Forward
            cam.forward  = Vector3.forward;
            cam.up       = Vector3.down;
            cam.right    = Vector3.left;
            cam.position = lit.position;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeZ);
            cb.ClearRenderTarget(true, true, Color.white);
            block.SetMatrix(ShaderIDs._VP, vpMatrix);
            offset = offset * 20;
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset, block);
            //Back
            cam.forward = Vector3.back;
            cam.up      = Vector3.down;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveZ);
            cb.ClearRenderTarget(true, true, Color.white);
            block.SetMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset, block);
            //Up
            cam.forward = Vector3.up;
            cam.up      = Vector3.back;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveY);
            cb.ClearRenderTarget(true, true, Color.white);
            block.SetMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset, block);
            //Down
            cam.forward = Vector3.down;
            cam.up      = Vector3.forward;
            cam.right   = Vector3.right;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeY);
            cb.ClearRenderTarget(true, true, Color.white);
            block.SetMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset, block);
            //Right
            cam.forward = Vector3.right;
            cam.up      = Vector3.down;
            cam.right   = Vector3.forward;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveX);
            cb.ClearRenderTarget(true, true, Color.white);
            block.SetMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset, block);
            //Left
            cam.forward = Vector3.left;
            cam.up      = Vector3.down;
            cam.right   = Vector3.back;
            cam.UpdateTRSMatrix();
            cam.UpdateProjectionMatrix();
            vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix;
            cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeX);
            cb.ClearRenderTarget(true, true, Color.white);
            block.SetMatrix(ShaderIDs._VP, vpMatrix);
            cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset, block);
        }