今天按《gpu gem》上的方法写一个ps曲线的shader
代码如下:
Shader "Custom/Color_Correct" {
Properties {
_MainTex ("Texture", 2D) = "white" { }
_ColorCorrMap("Texture",2D)="white"{}
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
sampler2D _MainTex;
sampler2D _ColorCorrMap;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 texcol = tex2D (_MainTex, i.uv);
//return texcol;
half4 OutColor=texcol;
OutColor.r=tex2D(_ColorCorrMap,fixed2(texcol.r, 0)).r;
OutColor.g=tex2D(_ColorCorrMap,fixed2(texcol.g, 0)).g;
OutColor.b=tex2D(_ColorCorrMap,fixed2(texcol.b, 0)).b;
return OutColor;
}
ENDCG
}
}
Fallback "VertexLit"
}