shader--灰白Image

游戏很多时候需要将图片变灰,其实用shader做一点不难,自己写了个。留以后项目使用。

首先要了解:颜色有两个重要概念饱和度,亮度。

饱和度:rgb差值越到色彩越强烈,越小越暗淡。

亮度:rgb三个值越高越明亮。这个一般用在调节颜色亮度就是rgb * 数值。

AlphaBlend
透明混合 是加法和乘法的组合运用。
公式:
NewColor =SrcColor*(1-Alpha)+Color*Alpha;
o.Emission = c.rgb*(1 - b.a) + b.rgb * b.a;

说白了shader渲染就是将数学模型转换成程序。

  Shader "xinghua/BlackWhite" {
Properties {
_MainTexture("Main Texture",2D) = "white"{}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows


// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0


sampler2D _MainTexture;


struct Input {
float2 uv_MainTexture;
};


void surf (Input IN, inout SurfaceOutputStandard o) {
//o.Albedo = c.rgb;
//o.Alpha = c.a;
//采样
float4 c = tex2D(_MainTexture,IN.uv_MainTexture);
//改变饱和度(饱和度越接近越暗淡)
float gray = c.r*0.3 + c.g*0.59 + c.b *0.11;
o.Emission = gray;
o.Alpha = c.a;
}
ENDCG

FallBack "Diffuse"
}

shader--灰白Image_第1张图片

你可能感兴趣的:(shader--灰白Image)