Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
129 lines (91 sloc) 3.43 KB
sampler s0 : register(s0);
float4 p0 : register(c0);
float4 p1 : register(c1);
#define width (p0[0])
#define height (p0[1])
#define counter (p0[2])
#define clock (p0[3])
#define one_over_width (p1[0])
#define one_over_height (p1[1])
#define hueRotate_Amnt 0
#define satChange_Amnt 1
#define valChange_Amnt 1
#define redChange_Amnt 1
#define greenChange_Amnt 1
#define blueChange_Amnt 1
#define rgbChange_Amnt 1
#define greyChange_Amnt 1
#define curveMids 0
#define split 0
#define flip_split 0
#define split_position 0.5
float3 rgb2hsv(float3 c)
{
float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}
float3 hsv2rgb(float3 c)
{
float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
//Source: http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl
float s_curver(float color, int mid, float gamma){
color*=2;
[flatten]if(mid==1){
color=(color<1)?0.5*(1-pow(abs(1-color),gamma)):0.5*(pow(abs(color-1),gamma)+1);
}else{
color=(color<1)?pow(abs(0.5*color),gamma):0.5*(2-pow(abs(2-color),gamma));
}
return color;
}
float hue_rotate(float hue, float deg){
deg*=pow(360,-1);
float r=hue+deg;
float r1=(r<=1)?r:r-1;
hue=(r<0)?1+r:r1;
return hue;
}
float4 sCurve(float4 c0, float2 tex, int mids){
float3 colorHSV=rgb2hsv(c0.rgb);
float3 colorHSVOg=colorHSV;
float c0Max=max(c0.r,max(c0.g,c0.b));
float hueRotateAmnt=hueRotate_Amnt;
float satChangeAmnt=satChange_Amnt;
float valChangeAmnt=valChange_Amnt;
float redChangeAmnt=redChange_Amnt;
float greenChangeAmnt=greenChange_Amnt;
float blueChangeAmnt=blueChange_Amnt;
float rgbChangeAmnt=rgbChange_Amnt;
float greyChangeAmnt=greyChange_Amnt;
colorHSV.x=(hueRotateAmnt==0)?colorHSV.x:hue_rotate(colorHSV.x,hueRotateAmnt);
colorHSV.y=(satChangeAmnt==1)?colorHSV.y:s_curver(colorHSV.y,mids,satChangeAmnt);
colorHSV.z=(valChangeAmnt==1)?colorHSV.z:s_curver(colorHSV.z,mids,valChangeAmnt);
c0.rgb=(colorHSVOg==colorHSV)?c0.rgb:hsv2rgb(colorHSV);
c0.r =(redChangeAmnt==1)?c0.r:s_curver(c0.r,mids,redChangeAmnt);
c0.g =(greenChangeAmnt==1)?c0.g:s_curver(c0.g,mids,greenChangeAmnt);
c0.b =(blueChangeAmnt==1)?c0.b:s_curver(c0.b,mids,blueChangeAmnt);
c0.rgb =(rgbChangeAmnt==1)?c0.rgb:float3(s_curver(c0.r,mids,rgbChangeAmnt),s_curver(c0.g,mids,rgbChangeAmnt),s_curver(c0.b,mids,rgbChangeAmnt));
c0.rgb =(greyChangeAmnt==1)?c0.rgb:saturate(s_curver(c0Max,mids,greyChangeAmnt)*(c0.rgb/c0Max));
return c0;
}
float4 main(float2 tex : TEXCOORD0) : COLOR {
float4 c0=tex2D(s0, tex);
float Split=split;
float Split_position=split_position;
float Flip_split=flip_split;
int crvMds=curveMids;
float4 c1=sCurve(c0, tex, crvMds);
c1.rgb=(crvMds==1)?lerp(c1.rgb,c0.rgb,2*abs(0.5-c1.rgb)):lerp(c0.rgb,c1.rgb,2*abs(0.5-c1.rgb));
float4 c2=(tex.x>=Split_position*Split)?c1:c0;
float4 c3=(tex.x<=Split_position*Split)?c1:c0;
float4 c4=(Flip_split*Split==1)?c3:c2;
float divLine = abs(tex.x - Split_position) < one_over_width;
c4 =(Split==0)?c4: c4*(1.0 - divLine); //invert divline
return c4;
}
You can’t perform that action at this time.