public void Register(IHizCullingBoxObject _object)
 {
     if (m_HizCullingQueue != null)
     {
         m_HizCullingQueue.Enqueue(_object);
     }
 }
        bool fillBuffer(ComputeShader _cs, IHizCullingBoxObject _obj)
        {
            if (_obj == null)
            {
                return(false);
            }

            return(_obj.getBuffers(out postionBuffer, out cullingResultBuffer));
        }
 void Process(CommandBuffer _cmd, ComputeShader _cs, Camera _camera, IHizCullingBoxObject _obj)
 {
     if (_camera == Camera.main)
     {
         ProcessMainCamera(_cmd, _cs, _camera, _obj);
     }
     else
     {
         ProcessOtherCamera(_cmd, _cs, _camera, _obj);
     }
 }
 void ProcessOtherCamera(CommandBuffer _cmd, ComputeShader _cs, Camera _camera, IHizCullingBoxObject _obj)
 {
     _obj.onRender(_cmd);
 }
        void ProcessMainCamera(CommandBuffer _cmd, ComputeShader _cs, Camera _camera, IHizCullingBoxObject _obj)
        {
            Texture hiz = Shader.GetGlobalTexture(Shader.PropertyToID("_HiZTexture"));

            if (hiz == null)
            {
                _obj.onRender(_cmd);
                return;
            }

            Vector3 boundMin, boundMax;

            if (_obj.getBounds(out boundMax, out boundMin) == false)
            {
                return;
            }

            int kanel = _cs.FindKernel("CSCullingBox");

            uint sizeX;

            _cs.GetKernelThreadGroupSizes(
                kanel,
                out sizeX,
                out _,
                out _
                );

            int count = postionBuffer.count;

            cullingResultBuffer.SetCounterValue(0);

            _cs.SetVector(Shader.PropertyToID("_boundMin"), boundMin);
            _cs.SetVector(Shader.PropertyToID("_boundMax"), boundMax);

            _cs.SetBool("_isOpenGL", _camera.projectionMatrix.Equals(GL.GetGPUProjectionMatrix(_camera.projectionMatrix, false)));

            _cs.SetInt(Shader.PropertyToID("_ObjectCount"), count);

            var viewProj = GL.GetGPUProjectionMatrix(_camera.projectionMatrix, false) * _camera.worldToCameraMatrix;

            _cs.SetMatrix(Shader.PropertyToID("matrixVP"), viewProj);

            _cs.SetTexture(kanel, Shader.PropertyToID("_HiZTexture"), hiz);

            _cs.SetVector(Shader.PropertyToID("_RT_Size"), texSize);
            _cs.SetFloat(Shader.PropertyToID("_MaxMipLevel"), 6);

            _cs.SetBuffer(kanel, Shader.PropertyToID("postionBuffer"), postionBuffer);
            _cs.SetBuffer(kanel, Shader.PropertyToID("cullingResult"), cullingResultBuffer);

            _cs.Dispatch(kanel,
                         Mathf.CeilToInt((count + sizeX - 1) / sizeX),
                         1, 1);

            _obj.onRender(_cmd);
        }