Ejemplo n.º 1
0
        /// <summary>
        /// Request current contents of cameras shape texture. queue pattern inspired by: https://github.com/keijiro/AsyncCaptureTest
        /// </summary>
        void EnqueueReadbackRequest(RenderTexture target, int lodIndex, LodTransform.RenderData renderData, float previousFrameTime)
        {
            if (!_doReadback)
            {
                return;
            }

            var lodData = _perLodData[renderData._texelWidth];

            // only queue up requests while time is advancing
            if (previousFrameTime <= lodData._resultData._time)
            {
                return;
            }

            if (lodData._requests.Count < MAX_REQUESTS)
            {
                lodData._requests.Enqueue(
                    new ReadbackRequest
                {
                    _request    = AsyncGPUReadback.Request(target, 0, 0, target.width, 0, target.height, lodIndex, 1),
                    _renderData = renderData,
                    _time       = previousFrameTime,
                }
                    );
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Request current contents of cameras shape texture.
        /// </summary>
        public void UpdateReadback(Camera cam, LodTransform.RenderData renderData)
        {
            // queue pattern inspired by: https://github.com/keijiro/AsyncCaptureTest

            // beginning of update turns out to be a good time to sample the textures to ensure everything in the frame is done.
            EnqueueReadbackRequest(cam.targetTexture, renderData);

            // remove any failed readback requests
            for (int i = 0; i < MAX_REQUESTS && _requests.Count > 0; i++)
            {
                var request = _requests.Peek();
                if (request._request.hasError)
                {
                    _requests.Dequeue();
                }
                else
                {
                    break;
                }
            }

            // create array to hold data if we don't have one already
            var num = ((int)_textureFormat) * cam.targetTexture.width * cam.targetTexture.height;

            if (!_dataNative.IsCreated || _dataNative.Length != num)
            {
                _dataNative = new NativeArray <ushort>(num, Allocator.Persistent);
            }

            // process current request queue
            if (_requests.Count > 0)
            {
                var request = _requests.Peek();
                if (request._request.done)
                {
                    _requests.Dequeue();

                    // eat up any more completed requests to squeeze out latency wherever possible
                    ReadbackRequest nextRequest;
                    while (_requests.Count > 0 && (nextRequest = _requests.Peek())._request.done)
                    {
                        request = nextRequest;
                        _requests.Dequeue();
                    }

                    Profiler.BeginSample("Copy out readback data");

                    var data = request._request.GetData <ushort>();
                    data.CopyTo(_dataNative);
                    _dataRenderData = request._renderData;

                    Profiler.EndSample();
                }
            }
        }
Ejemplo n.º 3
0
 public void EnqueueReadbackRequest(RenderTexture target, LodTransform.RenderData renderData)
 {
     if (_requests.Count < MAX_REQUESTS)
     {
         _requests.Enqueue(
             new ReadbackRequest
         {
             _request    = AsyncGPUReadback.Request(target),
             _renderData = renderData
         }
             );
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Request current contents of cameras shape texture.
        /// </summary>
        public void UpdateReadback(Camera cam, LodTransform.RenderData renderData)
        {
            if (!_active)
            {
                return;
            }

            // queue pattern inspired by: https://github.com/keijiro/AsyncCaptureTest

            // beginning of update turns out to be a good time to sample the textures to ensure everything in the frame is done.
            EnqueueReadbackRequest(cam.targetTexture, renderData, _prevTime);
            _prevTime = Time.time;
        }
Ejemplo n.º 5
0
        public void EnqueueReadbackRequest(RenderTexture target, LodTransform.RenderData renderData, float time)
        {
            if (time <= _result._time)
            {
                return;
            }

            if (_requests.Count < MAX_REQUESTS)
            {
                _requests.Enqueue(
                    new ReadbackRequest
                {
                    _request    = AsyncGPUReadback.Request(target),
                    _renderData = renderData,
                    _time       = time,
                }
                    );
            }
        }
Ejemplo n.º 6
0
        protected override void BindData(int shapeSlot, IPropertyWrapper properties, Texture applyData, bool blendOut, ref LodTransform.RenderData renderData)
        {
            base.BindData(shapeSlot, properties, applyData, blendOut, ref renderData);

            // need to blend out shape if this is the largest lod, and the ocean might get scaled down later (so the largest lod will disappear)
            bool  needToBlendOutShape = LodTransform.LodIndex == LodTransform.LodCount - 1 && OceanRenderer.Instance.ScaleCouldDecrease && blendOut;
            float shapeWeight         = needToBlendOutShape ? OceanRenderer.Instance.ViewerAltitudeLevelAlpha : 1f;

            properties.SetVector(_paramsOceanParams[shapeSlot],
                                 new Vector4(LodTransform._renderData._texelWidth, LodTransform._renderData._textureRes, shapeWeight, 1f / LodTransform._renderData._textureRes));
        }
Ejemplo n.º 7
0
        protected virtual void BindData(int lodIdx, int shapeSlot, IPropertyWrapper properties, Texture applyData, bool blendOut, ref LodTransform.RenderData renderData)
        {
            if (applyData)
            {
                properties.SetTexture(GetParamIdSampler(shapeSlot), applyData);
            }

            var lt = OceanRenderer.Instance._lods[lodIdx];

            properties.SetVector(LodTransform.ParamIdPosScale(shapeSlot), new Vector3(renderData._posSnapped.x, renderData._posSnapped.z, lt.transform.lossyScale.x));
            properties.SetVector(LodTransform.ParamIdOcean(shapeSlot),
                                 new Vector4(renderData._texelWidth, renderData._textureRes, 1f, 1f / renderData._textureRes));
        }
Ejemplo n.º 8
0
        protected virtual void BindData(int shapeSlot, IPropertyWrapper properties, Texture applyData, bool blendOut, ref LodTransform.RenderData renderData)
        {
            if (applyData)
            {
                properties.SetTexture(_paramsLodDataSampler[shapeSlot], applyData);
            }

            properties.SetVector(_paramsPosScale[shapeSlot], new Vector3(renderData._posSnapped.x, renderData._posSnapped.z, transform.lossyScale.x));
            properties.SetFloat(_paramsLodIdx[shapeSlot], LodTransform.LodIndex);
            properties.SetVector(_paramsOceanParams[shapeSlot],
                                 new Vector4(renderData._texelWidth, renderData._textureRes, 1f, 1f / renderData._textureRes));
        }