Пример #1
0
 /// <summary>
 /// Setup for the next draw command
 /// </summary>
 /// <param name="variant"></param>
 /// <param name="renderDimension"></param>
 /// <param name="forcePixelShader"></param>
 private void PrepareDraw(int variant, RenderDimension renderDimension)
 {
     UpdateRenderIndex(variant);
     DisableRenderKeywords();
     foreach (MaterialKeywords kw in _renderKeywordsBundle)
     {
         SetKeyword(kw, true);
     }
     _renderKeywordsBundle.Clear();
 }
Пример #2
0
        /// <summary>
        /// Create renderbuffers
        /// </summary>
        private void UpdateRenderBuffers()
        {
            RenderDimension renderDimension = new RenderDimension(_renderingCamera.pixelWidth, _renderingCamera.pixelHeight);

            _sourceContext[0].UpdateRenderContext(_renderingCamera, _renderTextureFormat, 0, renderDimension);
            _sourceContext[0].SinglePassStereoAdjustWidth(_renderingCamera.stereoEnabled);
            renderDimension = _sourceContext[0].renderDimension;

            renderDimension.width  /= 2;
            renderDimension.height /= 2;

            float sizeScale = Mathf.Log(Mathf.FloorToInt(Mathf.Max(renderDimension.width, renderDimension.height)), 2.0f);

            PrepareScattering(_settings.bloomScattering, sizeScale, ref _bloomIterations, ref bloomUpsampleSpread);

            _renderingCamera.UpdateMipRenderContext(_renderContext, renderDimension, _bloomIterations + 1, _renderTextureFormat, 0);
        }
Пример #3
0
        /// <summary>
        /// Create renderbuffers
        /// </summary>
        private void UpdateRenderBuffers()
        {
            RenderDimension renderDimension = new RenderDimension((int)((float)_renderingCamera.pixelWidth * _renderScale), (int)((float)_renderingCamera.pixelHeight * _renderScale));

            _sourceContext[0].UpdateRenderContext(_renderingCamera, _renderTextureFormat, 0, renderDimension);
            _sourceContext[0].SinglePassStereoAdjustWidth(_renderingCamera.stereoEnabled);
            Vector2 anamorphic = new Vector2(_settings.anamorphicRatio < 0 ? -_settings.anamorphicRatio : 0f, _settings.anamorphicRatio > 0 ?  _settings.anamorphicRatio : 0f);

            renderDimension = new RenderDimension(Mathf.CeilToInt(_sourceContext[0].width / (2f - anamorphic.x)), Mathf.CeilToInt(_sourceContext[0].height / (2f - anamorphic.y)));

            float sizeScale = Mathf.Log(Mathf.FloorToInt(Mathf.Max(renderDimension.width, renderDimension.height)), 2.0f);

            //float sizeScale = Mathf.FloorToInt(Mathf.Max(renderDimension.width, renderDimension.height));

            PrepareScattering(_settings.bloomScattering, sizeScale, ref _bloomIterations, ref bloomUpsampleSpread);
            _minIterations = _bloomIterations;

            _renderingCamera.UpdateMipRenderContext(_renderContext, renderDimension, _minIterations + 1, _renderTextureFormat, 0);
        }
Пример #4
0
        /// <summary>
        /// Create renderbuffers
        /// </summary>
        private void UpdateRenderBuffers()
        {
            RenderDimension renderDimension = new RenderDimension(_renderingCamera.pixelWidth, _renderingCamera.pixelHeight);

            _sourceContext[0].UpdateRenderContext(_renderingCamera, _renderTextureFormat, 0, renderDimension);
            _sourceContext[0].SinglePassStereoAdjustWidth(_renderingCamera.stereoEnabled);
            renderDimension = new RenderDimension(Mathf.CeilToInt((float)_sourceContext[0].width * ((_settings.anamorphicRatio > 0.0f) ? 1.0f - _settings.anamorphicRatio * 0.5f : 1.0f)),
                                                  Mathf.CeilToInt((float)_sourceContext[0].height * ((_settings.anamorphicRatio < 0.0f) ? 1.0f + _settings.anamorphicRatio * 0.5f : 1.0f)));

            renderDimension.width  /= (int)_settings.quality;
            renderDimension.height /= (int)_settings.quality;

            //float sizeScale = Mathf.Log(Mathf.FloorToInt(Mathf.Max(renderDimension.width, renderDimension.height)), 2.0f);
            float sizeScale = Mathf.FloorToInt(Mathf.Max(renderDimension.width, renderDimension.height));

            PrepareScattering(_settings.bloomScattering, sizeScale, ref _bloomIterations, ref bloomUpsampleSpread);
            _minIterations = _bloomIterations;

            _renderingCamera.UpdateMipRenderContext(_renderContext, renderDimension, _minIterations + 1, _renderTextureFormat, 0);
        }
Пример #5
0
 /// <summary>
 /// Update a mip based render context array
 /// </summary>
 /// <param name="camera"></param>
 /// <param name="renderContexts"></param>
 /// <param name="rawDimension"></param>
 /// <param name="levels"></param>
 /// <param name="format"></param>
 /// <param name="depthBufferBits"></param>
 /// <param name="enableRandomWrite"></param>
 internal static void UpdateMipRenderContext(this CameraData cameraData, RenderContext[] renderContexts, RenderDimension rawDimension, int levels, RenderTextureFormat format, int depthBufferBits, bool enableRandomWrite)
 {
     for (int i = 0; i < levels; i++)
     {
         renderContexts[i].UpdateRenderContext(cameraData.stereoEnabled, format, depthBufferBits, enableRandomWrite, rawDimension);
         rawDimension.width  = Mathf.Max(SinglePassStereoDownscale(cameraData.stereoEnabled, rawDimension.width, 2), 1);
         rawDimension.height = Mathf.Max(rawDimension.height / 2, 1);
     }
 }
Пример #6
0
 internal static void Draw(List <RenderTarget> destinations, ComputeShader computeShader, int kernelIndex, RenderDimension computeThreadGroups)
 {
     //RenderTargetContext.SetRenderTargetContext(destinations);
     computeShader.Dispatch(kernelIndex, computeThreadGroups.width, computeThreadGroups.height, 1);
 }
Пример #7
0
 /// <summary>
 /// Compute the currently setuped render context with its targets
 /// </summary>
 /// <param name="cmd"></param>
 /// <param name="computeShader"></param>
 /// <param name="kernelIndex"></param>
 /// <param name="computeThreadGroups"></param>
 internal static void Draw(this CommandBuffer cmd, List <RenderTarget> destinations, ComputeShader computeShader, int kernelIndex, RenderDimension computeThreadGroups)
 {
     //cmd.SetRenderTargetContext(destinations);
     cmd.DispatchCompute(computeShader, kernelIndex, computeThreadGroups.width, computeThreadGroups.height, 1);
 }
Пример #8
0
        /// <summary>
        /// Update a render context based on rendering settings including xr
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="format"></param>
        /// <param name="depthBufferBits"></param>
        /// <param name="enableRandomWrite"></param>
        /// <param name="dimension"></param>
        internal void UpdateRenderContext(Camera camera, RenderTextureFormat format, int depthBufferBits, RenderDimension dimension)
        {
                        #if UNITY_2018_3_OR_NEWER
            _descriptor.dimension   = camera.stereoEnabled ? UnityEngine.XR.XRSettings.eyeTextureDesc.dimension : UnityEngine.Rendering.TextureDimension.Tex2D;
            _descriptor.vrUsage     = camera.stereoEnabled ? UnityEngine.XR.XRSettings.eyeTextureDesc.vrUsage : VRTextureUsage.None;
            _descriptor.volumeDepth = camera.stereoEnabled ? UnityEngine.XR.XRSettings.eyeTextureDesc.volumeDepth : 1;
                        #elif UNITY_2017_1_OR_NEWER
            _descriptor.dimension   = UnityEngine.Rendering.TextureDimension.Tex2D;
            _descriptor.vrUsage     = VRTextureUsage.None;
            _descriptor.volumeDepth = 1;
                        #endif

                        #if UNITY_2017_1_OR_NEWER
            _descriptor.useMipMap         = false;
            _descriptor.autoGenerateMips  = false;
            _descriptor.colorFormat       = format;
            _descriptor.depthBufferBits   = depthBufferBits;
            _descriptor.enableRandomWrite = false;
            _descriptor.width             = dimension.width;
            _descriptor.height            = dimension.height;
            _descriptor.memoryless        = RenderTextureMemoryless.None;
            _descriptor.msaaSamples       = 1;
            _descriptor.sRGB = RenderTextureReadWrite.Default != RenderTextureReadWrite.Linear;
                        #else
            _descriptor.width  = dimension.width;
            _descriptor.height = dimension.height;
                        #endif
        }
Пример #9
0
        /// <summary>
        /// Update a render context based on rendering settings including xr
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="format"></param>
        /// <param name="depthBufferBits"></param>
        /// <param name="enableRandomWrite"></param>
        /// <param name="dimension"></param>
        internal void UpdateRenderContext(bool stereoEnabled, RenderTextureFormat format, int depthBufferBits, bool enableRandomWrite, RenderDimension dimension)
        {
                        #if UNITY_2018_3_OR_NEWER
                        #if ENABLE_VR
            _descriptor.dimension   = stereoEnabled ? XRSettings.eyeTextureDesc.dimension : UnityEngine.Rendering.TextureDimension.Tex2D;
            _descriptor.vrUsage     = stereoEnabled ? XRSettings.eyeTextureDesc.vrUsage : VRTextureUsage.None;
            _descriptor.volumeDepth = stereoEnabled ? XRSettings.eyeTextureDesc.volumeDepth : 1;
                        #else
            _descriptor.dimension   = UnityEngine.Rendering.TextureDimension.Tex2D;
            _descriptor.vrUsage     = VRTextureUsage.None;
            _descriptor.volumeDepth = 1;
                        #endif
                        #elif UNITY_2017_1_OR_NEWER
            _descriptor.dimension   = UnityEngine.Rendering.TextureDimension.Tex2D;
            _descriptor.vrUsage     = VRTextureUsage.None;
            _descriptor.volumeDepth = 1;
                        #endif

                        #if UNITY_2017_1_OR_NEWER
            _descriptor.colorFormat       = format;
            _descriptor.depthBufferBits   = depthBufferBits;
            _descriptor.enableRandomWrite = enableRandomWrite;
            _descriptor.width             = dimension.width;
            _descriptor.height            = dimension.height;
            _descriptor.memoryless        = RenderTextureMemoryless.None;
            _descriptor.sRGB = RenderTextureReadWrite.Default != RenderTextureReadWrite.Linear;
                        #else
            _enableRandomWrite = enableRandomWrite;
            _descriptor.width  = dimension.width;
            _descriptor.height = dimension.height;
                        #endif
        }