我是靠谱客的博主 追寻冬瓜,最近开发中收集的这篇文章主要介绍调整屏幕亮度、饱和度、对比度,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

注意在Rendering -> Lighting Settings 下的Ambient Color要设置成白色,否则会在计算环境光时影响最终颜色

// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)

Shader "Custom/Diffuse"
{
    Properties
    {

        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1,1,1,1)
        [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
        //Render渲染;
        [HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
        [HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
        [PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
        [PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
		_Brightness("Brightness", Float) = 1	//调整亮度
		_Saturation("Saturation", Float) = 1	//调整饱和度
		_Contrast("Contrast", Float) = 1		//调整对比度
    }

    SubShader
    {
        Tags
        {
            "Queue"="Transparent"
            "IgnoreProjector"="True"
            "RenderType"="Transparent"
            "PreviewType"="Plane"
            "CanUseSpriteAtlas"="True"
        }

        Cull Off
        Lighting Off
        ZWrite Off
        Blend One OneMinusSrcAlpha

        CGPROGRAM
        #pragma surface surf Lambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing
        #pragma multi_compile_local _ PIXELSNAP_ON
        #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
        #include "UnitySprites.cginc"

		half _Brightness;
		half _Saturation;
		half _Contrast;

        struct Input
        {
        //Maintex的UV坐标,UV坐标为(X,Y);
            float2 uv_MainTex;
        //定义color的参数为fixed4;
            fixed4 color;
        };

        void vert (inout appdata_full v, out Input o)
        {
            v.vertex = UnityFlipSprite(v.vertex, _Flip);

            #if defined(PIXELSNAP_ON)
            v.vertex = UnityPixelSnap (v.vertex);
            #endif

            UNITY_INITIALIZE_OUTPUT(Input, o);
            o.color = v.color * _Color * _RendererColor;
        }

        void surf (Input IN, inout SurfaceOutput o)
        {
            fixed4 c = SampleSpriteTexture (IN.uv_MainTex) * IN.color;
            //o.Albedo = c.rgb * c.a;
            //o.Alpha = c.a;

            // brigtness亮度直接乘以一个系数,也就是RGB整体缩放,调整亮度
            fixed3 finalColor = c.rgb * _Brightness;
            //saturation饱和度:首先根据公式计算同等亮度情况下饱和度最低的值:
            fixed gray = 0.2125 * c.rgb.r + 0.7154 * c.rgb.g + 0.0721 * c.rgb.b;
                  
            fixed3 grayColor = fixed3(gray, gray, gray);
            //根据Saturation在饱和度最低的图像和原图之间差值
            finalColor = lerp(grayColor, finalColor, _Saturation);
            //contrast对比度:首先计算对比度最低的值
            fixed3 avgColor = fixed3(0.5, 0.5, 0.5);
            //根据Contrast在对比度最低的图像和原图之间差值
            finalColor = lerp(avgColor, finalColor, _Contrast);
            o.Albedo = finalColor * c.a;
            o.Alpha = c.a;
        }
        ENDCG
    }

Fallback "Transparent/VertexLit"
}

最后

以上就是追寻冬瓜为你收集整理的调整屏幕亮度、饱和度、对比度的全部内容,希望文章能够帮你解决调整屏幕亮度、饱和度、对比度所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(34)

评论列表共有 0 条评论

立即
投稿
返回
顶部