Exemple #1
0
        private void CreateResources()
        {
            _mainCamera = GetComponent <Camera>();

            _preComposeMaterial = HelperExtensions.CreateMaterialFromShader("Sleek Render/Post Process/PreCompose");
            _composeMaterial    = HelperExtensions.CreateMaterialFromShader("Sleek Render/Post Process/Compose");

            _currentCameraPixelWidth  = Mathf.RoundToInt(_mainCamera.pixelWidth);
            _currentCameraPixelHeight = Mathf.RoundToInt(_mainCamera.pixelHeight);

            // Point for future main render target size changing
            int width  = _currentCameraPixelWidth;
            int height = _currentCameraPixelHeight;

            // Capping max base texture height in pixels
            // We usually don't need extra pixels for precompose and blur passes
            var maxHeight = Mathf.Min(height, 720);
            var ratio     = (float)maxHeight / height;

            int precomposeWidth  = Mathf.RoundToInt((width * ratio) / 5f);
            int precomposeHeight = Mathf.RoundToInt((height * ratio) / 5f);

            _preComposeTexture = HelperExtensions.CreateTransientRenderTexture("Pre Compose", precomposeWidth, precomposeHeight);

            _composeMaterial.SetTexture(Uniforms._PreComposeTex, _preComposeTexture);
            _composeMaterial.SetVector(Uniforms._LuminanceConst, new Vector4(0.2126f, 0.7152f, 0.0722f, 0f));

            _isColorizeAlreadyEnabled = false;
            _isBloomAlreadyEnabled    = false;
            _isVignetteAlreadyEnabled = false;
            _isContrastAndBrightnessAlreadyEnabled = false;

            _passRenderer = _passRenderer ?? new PassRenderer();

            if (_bloomRenderer != null)
            {
                _bloomRenderer.ReleaseResources();
            }

            _bloomRenderer = new DualFilterBloomRenderer(_passRenderer);

            _bloomRenderer.CreateResources(settings, _mainCamera);
        }
Exemple #2
0
        public void CreateResources(SleekRenderSettings settings, Camera camera)
        {
            _bloomPasses         = settings.bloomPasses;
            _preserveAspectRatio = settings.preserveAspectRatio;
            CalculateBloomHeightAndWidth(settings, camera);

            switch (_bloomPasses)
            {
            case 3:
                _blurTextures    = new RenderTexture[3];
                _blurTextures[0] = HelperExtensions.CreateTransientRenderTexture("Brightpass Blur 0",
                                                                                 _baseTextureWidth, _baseTextureHeight);

                _blurTextures[1] = HelperExtensions.CreateTransientRenderTexture("Downsample Blur 1",
                                                                                 _baseTextureWidth / 2, _baseTextureHeight / 2);

                _blurTextures[2] = HelperExtensions.CreateTransientRenderTexture("Downsample Blur 2",
                                                                                 _baseTextureWidth, _baseTextureHeight);
                break;

            default:
                _blurTextures    = new RenderTexture[5];
                _blurTextures[0] = HelperExtensions.CreateTransientRenderTexture("Brightpass Blur 0",
                                                                                 _baseTextureWidth, _baseTextureHeight);

                _blurTextures[1] = HelperExtensions.CreateTransientRenderTexture("Downsample Blur 1",
                                                                                 _baseTextureWidth / 2, _baseTextureHeight / 2);

                _blurTextures[2] = HelperExtensions.CreateTransientRenderTexture("Downsample Blur 2",
                                                                                 _baseTextureWidth / 4, _baseTextureHeight / 4);

                _blurTextures[3] = HelperExtensions.CreateTransientRenderTexture("Downsample Blur 4",
                                                                                 _baseTextureWidth / 2, _baseTextureHeight / 2);

                _blurTextures[4] = HelperExtensions.CreateTransientRenderTexture("Downsample Blur 4",
                                                                                 _baseTextureWidth, _baseTextureHeight);
                break;
            }

            _brightpassBlurMaterial = HelperExtensions.CreateMaterialFromShader("Sleek Render/Post Process/Brightpass Dualfilter Blur");
            _downsampleBlurMaterial = HelperExtensions.CreateMaterialFromShader("Sleek Render/Post Process/Downsample Dualfilter Blur");
        }