Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
105 lines (76 sloc) 2.89 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 PI acos(-1)
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
#define crushing_type 0 // 0 - Crush to RGB average, 1 - Crush to 0.5.
#define crushing_amnt 0 // Disabled if =0; 0-1
#define crushing_debug 0 // 0-1
#define split 0
#define flip_split 0
#define split_position 0.5
float4 crusher(float4 color){
float4 c0=color;
float3 colorHSV=rgb2hsv(c0.rgb);
float Crushing_debug=crushing_debug;
float Crushing_amnt=crushing_amnt;
float Crushing_type=crushing_type;
float rgbAvg=dot(c0.rgb,pow(3,-1));
float distGrey=sqrt(pow(rgbAvg-c0.r,2)+pow(rgbAvg-c0.g,2)+pow(rgbAvg-c0.b,2));
float normDistGrey=distGrey*pow(0.5*sqrt(3),-1);
float crsh=1-Crushing_amnt;
float lerper=pow(normDistGrey,Crushing_amnt);
float3 crshAvg=lerp(c0.rgb,rgbAvg,lerper);
float mxOld=max(c0.r,max(c0.g,c0.b));
//float mnOld=min(c0.r,min(c0.g,c0.b));
float mxNew=max(crshAvg.r,max(crshAvg.g,crshAvg.b));
//float mnNew=min(crshAvg.r,min(crshAvg.g,crshAvg.b));
float3 avgRevert=(mxNew==0)?0:c0.rgb*(crshAvg.rgb/mxNew);
float3 crshHalf=(0.5-0.5*crsh) + ((0.5+0.5*crsh) - (0.5-0.5*crsh)) * c0.rgb;
colorHSV.yz=rgb2hsv(crshHalf.rgb).yz;
float fromMin=0.5-0.5*crsh;
float fromMax=0.5+0.5*crsh;
float3 halfRevert= ((c0.rgb - fromMin) / (fromMax - fromMin));
float3 c1=(Crushing_debug==1)?crshAvg:avgRevert;
float3 c2=(Crushing_debug==1)?hsv2rgb(colorHSV):halfRevert;
float3 c3=(Crushing_type==0)?c1:c2;
return float4(c3.xyz,color.w);
}
float4 main(float2 tex : TEXCOORD0) : COLOR
{
float4 c0 = tex2D(s0, tex);
float c0Max=max(c0.r,max(c0.g,c0.b));
float4 c1 = c0;
float Crushing_amnt=crushing_amnt;
float Split=split;
float Split_position=split_position;
float Flip_split=flip_split;
c1.rgb=(Crushing_amnt==0)?c1.rgb:crusher(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.