多分これが役立つでしょう。Adobe のシェーダー言語である Pixel Bender を介して、Photoshop と Flash の拡張機能としてこれを書きましたが、他のシェーダー言語と同等です。これは、Adobe ShaderLab を CG シェーダー言語に大まかに変換したものです。
Shader "Filters/ColorBalance"
{
Properties
{
_MainTex ("Main (RGB)", 2D) = "white" {}
// Red, Green, Blue
_Shadows ("shadows", Vector) = (0.0,0.0,0.0,0.0)
_Midtones ("midtones", Vector) = (0.0,0.0,0.0,0.0)
_Hilights ("hilights", Vector) = (0.0,0.0,0.0,0.0)
_Amount ("amount mix", Range (0.0, 1.0)) = 1.0
}
SubShader
{
Tags {"RenderType"="Transparent" "Queue"="Transparent"}
Lighting Off
Pass
{
ZWrite Off
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
sampler2D _MainTex;
uniform float4 _Shadows;
uniform float4 _Midtones;
uniform float4 _Hilights;
uniform float _Amount;
uniform float pi = 3.14159265358979;
struct appdata
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR;
};
// vertex output
struct vertdata
{
float4 pos : SV_POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR;
};
vertdata vert(appdata ad)
{
vertdata o;
o.pos = mul(UNITY_MATRIX_MVP, ad.vertex);
o.texcoord = ad.texcoord;
o.color = ad.color;
return o;
}
fixed4 frag(vertdata i) : COLOR
{
float4 dst = tex2D(_MainTex, i.texcoord);
float intensity = (dst.r + dst.g + dst.b) * 0.333333333;
// Exponencial Shadows
float shadowsBleed = 1.0 - intensity;
shadowsBleed *= shadowsBleed;
shadowsBleed *= shadowsBleed;
// Exponencial midtones
float midtonesBleed = 1.0 - abs(-1.0 + intensity * 2.0);
midtonesBleed *= midtonesBleed;
midtonesBleed *= midtonesBleed;
// Exponencial Hilights
float hilightsBleed = intensity;
hilightsBleed *= hilightsBleed;
hilightsBleed *= hilightsBleed;
float3 colorization = dst.rgb + _Shadows.rgb * shadowsBleed +
_Midtones.rgb * midtonesBleed +
_Hilights.rgb * hilightsBleed;
dst.rgb = lerp(dst.rgb, colorization, _Amount);
return dst;
}
ENDCG
}
}
}