Esempio n. 1
0
        public override void Render(PostProcessRenderContext context)
        {
        #if UNITY_EDITOR
            // In editor, copy gradient color keys every frame.
            _gradientCache = settings.fillGradient.value.colorKeys;
        #endif

            var cmd = context.command;
            cmd.BeginSample("Recolor");

            var sheet = context.propertySheets.Get(Shader.Find("Hidden/Kino/PostProcessing/Recolor"));
            sheet.properties.SetColor(ShaderIDs.EdgeColor, settings.edgeColor);
            sheet.properties.SetVector(ShaderIDs.EdgeThresholds, EdgeThresholdVector);
            sheet.properties.SetFloat(ShaderIDs.FillOpacity, settings.fillOpacity);
            GradientUtility.SetColorKeys(sheet, _gradientCache);

            var pass = (int)settings.edgeSource.value;
            if (settings.fillOpacity > 0 && _gradientCache.Length > 3)
            {
                pass += 3;
            }
            if (settings.fillGradient.value.mode == GradientMode.Blend)
            {
                pass += 6;
            }
            cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, pass);

            cmd.EndSample("Recolor");
        }
Esempio n. 2
0
        public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle srcRT, RTHandle destRT)
        {
            if (_ditherType != ditherType.value || _ditherTexture == null)
            {
                CoreUtils.Destroy(_ditherTexture);
                _ditherType    = ditherType.value;
                _ditherTexture = GenerateDitherTexture(_ditherType);
            }

#if UNITY_EDITOR
            // In Editor, the gradient will be modified without any hint,
            // so we have to copy the color keys every frame.
            if (true)
#else
            // In Player, we assume no one can modify gradients in profiles,
            // so we update the cache only when the reference was updated.
            if (_cachedGradient != fillGradient.value)
#endif
            {
                _cachedGradient  = fillGradient.value;
                _cachedColorKeys = _cachedGradient.colorKeys;
            }

            Vector2 edgeThresh;

            if (edgeSource.value == EdgeSource.Depth)
            {
                var thresh = 1 / Mathf.Lerp(1000, 1, edgeThreshold.value);
                var scaler = 1 + 2 / (1.01f - edgeContrast.value);
                edgeThresh = new Vector2(thresh, thresh * scaler);
            }
            else // Depth & Color
            {
                var t1 = edgeThreshold.value;
                var t2 = t1 + 1.01f - edgeContrast.value;
                edgeThresh = new Vector2(t1, t2);
            }

            _material.SetColor(ShaderIDs.EdgeColor, edgeColor.value);
            _material.SetVector(ShaderIDs.EdgeThresholds, edgeThresh);
            _material.SetFloat(ShaderIDs.FillOpacity, fillOpacity.value);
            GradientUtility.SetColorKeys(_material, _cachedColorKeys);

            _material.SetTexture(ShaderIDs.DitherTexture, _ditherTexture);
            _material.SetFloat(ShaderIDs.DitherStrength, ditherStrength.value);

            var pass = (int)edgeSource.value;
            if (fillOpacity.value > 0 && _cachedColorKeys.Length > 4)
            {
                pass += 3;
            }
            if (fillGradient.value.mode == GradientMode.Blend)
            {
                pass += 6;
            }

            // Blit to destRT with the overlay shader.
            _material.SetTexture(ShaderIDs.InputTexture, srcRT);
            HDUtils.DrawFullScreen(cmd, _material, destRT, null, pass);
        }
Esempio n. 3
0
        public override void Render(PostProcessRenderContext context)
        {
            // Skip it when opacity is zero.
            if (settings.opacity == 0)
            {
                return;
            }

            // Common parameters
            var sheet = context.propertySheets.Get(Shader.Find("Hidden/Kino/PostProcessing/Overlay"));

            sheet.properties.SetFloat(ShaderIDs.Opacity, settings.opacity);

            var pass = (int)settings.blendMode.value * 3;

            if (settings.source == Overlay.Source.Color)
            {
                // Single color mode parameters
                sheet.properties.SetColor(ShaderIDs.Color, settings.color);
                sheet.properties.SetTexture(ShaderIDs.SourceTex, RuntimeUtilities.whiteTexture);
                sheet.properties.SetFloat(ShaderIDs.UseSourceAlpha, 0);
            }
            else if (settings.source == Overlay.Source.Gradient)
            {
            #if UNITY_EDITOR
                // In editor, copy gradient color keys every frame.
                _gradientCache = settings.gradient.value.colorKeys;
            #endif

                // Gradient mode parameters
                sheet.properties.SetVector(ShaderIDs.Direction, DirectionVector);
                GradientUtility.SetColorKeys(sheet, _gradientCache);
                pass += _gradientCache.Length > 3 ? 2 : 1;
            }
            else // Overlay.Source.Texture
            {
                // Skip it when no texture is given.
                if (settings.texture.value == null)
                {
                    return;
                }

                // Texture mode parameters
                sheet.properties.SetColor(ShaderIDs.Color, Color.white);
                sheet.properties.SetTexture(ShaderIDs.SourceTex, settings.texture);
                sheet.properties.SetFloat(ShaderIDs.UseSourceAlpha, settings.sourceAlpha ? 1 : 0);
            }

            // Blit with the shader
            var cmd = context.command;
            cmd.BeginSample("Overlay");
            cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, pass);
            cmd.EndSample("Overlay");
        }
Esempio n. 4
0
        public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle srcRT, RTHandle destRT)
        {
            if (_ditherType != ditherType.value)
            {
                CoreUtils.Destroy(_ditherTexture);
                _ditherType    = ditherType.value;
                _ditherTexture = GenerateDitherTexture(_ditherType);
            }

        #if UNITY_EDITOR
            // In editor, copy gradient color keys every frame.
            _gradientCache = fillGradient.value.colorKeys;
        #endif

            Vector2 edgeThresh;

            if (edgeSource == EdgeSource.Depth)
            {
                var thresh = 1 / Mathf.Lerp(1000, 1, edgeThreshold.value);
                var scaler = 1 + 2 / (1.01f - edgeContrast.value);
                edgeThresh = new Vector2(thresh, thresh * scaler);
            }
            else // Depth & Color
            {
                var t1 = edgeThreshold.value;
                var t2 = t1 + 1.01f - edgeContrast.value;
                edgeThresh = new Vector2(t1, t2);
            }

            _material.SetColor(ShaderIDs.EdgeColor, edgeColor.value);
            _material.SetVector(ShaderIDs.EdgeThresholds, edgeThresh);
            _material.SetFloat(ShaderIDs.FillOpacity, fillOpacity.value);
            GradientUtility.SetColorKeys(_material, _gradientCache);

            _material.SetTexture(ShaderIDs.DitherTexture, _ditherTexture);
            _material.SetFloat(ShaderIDs.DitherStrength, ditherStrength.value);

            var pass = (int)edgeSource.value;
            if (fillOpacity.value > 0 && _gradientCache.Length > 3)
            {
                pass += 3;
            }
            if (fillGradient.value.mode == GradientMode.Blend)
            {
                pass += 6;
            }

            // Blit to destRT with the overlay shader.
            _material.SetTexture(ShaderIDs.InputTexture, srcRT);
            HDUtils.DrawFullScreen(cmd, _material, destRT, null, pass);
        }
Esempio n. 5
0
        public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle srcRT, RTHandle destRT)
        {
            _material.SetFloat(ShaderIDs.Opacity, opacity.value);

            var pass = (int)blendMode.value * 3;

            if (sourceType == Overlay.SourceType.Color)
            {
                // Single color mode parameters
                _material.SetColor(ShaderIDs.Color, color.value);
                _material.SetTexture(ShaderIDs.OverlayTexture, Texture2D.whiteTexture);
                _material.SetFloat(ShaderIDs.UseTextureAlpha, 0);
            }
            else if (sourceType == Overlay.SourceType.Gradient)
            {
            #if UNITY_EDITOR
                // In editor, copy gradient color keys every frame.
                _gradientCache = gradient.value.colorKeys;
            #endif

                // Gradient direction vector
                var rad = Mathf.Deg2Rad * angle.value;
                var dir = new Vector2(Mathf.Sin(rad), Mathf.Cos(rad));

                // Gradient mode parameters
                _material.SetVector(ShaderIDs.Direction, dir);
                GradientUtility.SetColorKeys(_material, _gradientCache);
                pass += _gradientCache.Length > 3 ? 2 : 1;
            }
            else // Overlay.Source.Texture
            {
                // Skip when no texture is given.
                if (texture.value == null)
                {
                    return;
                }

                // Texture mode parameters
                _material.SetColor(ShaderIDs.Color, Color.white);
                _material.SetTexture(ShaderIDs.OverlayTexture, texture.value);
                _material.SetFloat(ShaderIDs.UseTextureAlpha, sourceAlpha.value ? 1 : 0);
            }

            // Blit to destRT with the overlay shader.
            _material.SetTexture(ShaderIDs.InputTexture, srcRT);
            HDUtils.DrawFullScreen(cmd, _material, destRT, null, pass);
        }
Esempio n. 6
0
        public override void Render(PostProcessRenderContext context)
        {
        #if UNITY_EDITOR
            // In editor, copy gradient color keys every frame.
            _gradientCache = settings.gradient.value.colorKeys;
        #endif

            var cmd = context.command;
            cmd.BeginSample("Overlay");

            var sheet = context.propertySheets.Get(Shader.Find("Hidden/Kino/PostProcessing/Overlay"));
            sheet.properties.SetFloat(ShaderIDs.Opacity, settings.opacity);
            sheet.properties.SetVector(ShaderIDs.Direction, DirectionVector);
            GradientUtility.SetColorKeys(sheet, _gradientCache);

            var pass = _gradientCache.Length > 3 ? 1 : 0;
            cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, pass);

            cmd.EndSample("Overlay");
        }