Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma parameter RSUBPIX_R "Colour of R subpixel: R" 1.0 0.0 1.0 0.01
- #pragma parameter RSUBPIX_G "Colour of R subpixel: G" 0.0 0.0 1.0 0.01
- #pragma parameter RSUBPIX_B "Colour of R subpixel: B" 0.0 0.0 1.0 0.01
- #pragma parameter GSUBPIX_R "Colour of G subpixel: R" 0.0 0.0 1.0 0.01
- #pragma parameter GSUBPIX_G "Colour of G subpixel: G" 1.0 0.0 1.0 0.01
- #pragma parameter GSUBPIX_B "Colour of G subpixel: B" 0.0 0.0 1.0 0.01
- #pragma parameter BSUBPIX_R "Colour of B subpixel: R" 0.0 0.0 1.0 0.01
- #pragma parameter BSUBPIX_G "Colour of B subpixel: G" 0.0 0.0 1.0 0.01
- #pragma parameter BSUBPIX_B "Colour of B subpixel: B" 1.0 0.0 1.0 0.01
- #pragma parameter gain "Gain" 1.0 0.5 2.0 0.05
- #pragma parameter gamma "LCD Gamma" 3.0 0.5 5.0 0.1
- #pragma parameter blacklevel "Black level" 0.05 0.0 0.5 0.01
- #pragma parameter ambient "Ambient" 0.0 0.0 0.5 0.01
- #pragma parameter BGR "BGR" 0 0 1 1
- #ifdef PARAMETER_UNIFORM
- uniform float RSUBPIX_R;
- uniform float RSUBPIX_G;
- uniform float RSUBPIX_B;
- uniform float GSUBPIX_R;
- uniform float GSUBPIX_G;
- uniform float GSUBPIX_B;
- uniform float BSUBPIX_R;
- uniform float BSUBPIX_G;
- uniform float BSUBPIX_B;
- uniform float gain;
- uniform float gamma;
- uniform float blacklevel;
- uniform float ambient;
- uniform float BGR;
- #else
- #define RSUBPIX_R 1.0
- #define RSUBPIX_G 0.0
- #define RSUBPIX_B 0.0
- #define GSUBPIX_R 1.0
- #define GSUBPIX_G 1.0
- #define GSUBPIX_B 0.0
- #define BSUBPIX_R 0.0
- #define BSUBPIX_G 0.0
- #define BSUBPIX_B 1.0
- #define gain 1.0
- #define gamma 3.0
- #define blacklevel 0.05
- #define ambient 0.0
- #define BGR 0.0
- #endif
- #define outgamma 2.2
- void main_vertex
- (
- float4 position : POSITION,
- float2 texCoord : TEXCOORD0,
- uniform float4x4 modelViewProj,
- out float4 oPosition : POSITION,
- out float2 otexCoord : TEXCOORD
- )
- {
- oPosition = mul(modelViewProj, position);
- otexCoord = texCoord;
- }
- struct input
- {
- float2 video_size;
- float2 texCoord_size;
- float2 output_size;
- float frame_count;
- float frame_direction;
- float frame_rotation;
- float2 texture_size;
- sampler2D texture : TEXUNIT0;
- };
- struct output
- {
- float4 col : COLOR;
- };
- #define fetch_offset(coord,offset) (pow(float3(gain) * texelFetchOffset(IN.texture, (coord), 0, (offset)).rgb + float3(blacklevel), float3(gamma)) + float3(ambient))
- // integral of (1 - x^2 - x^4 + x^6)^2
- const float coeffs_x[] = float[](1.0, -2.0/3.0, -1.0/5.0, 4.0/7.0, -1.0/9.0, -2.0/11.0, 1.0/13.0);
- // integral of (1 - 2x^4 + x^6)^2
- const float coeffs_y[] = float[](1.0, 0.0, -4.0/5.0, 2.0/7.0, 4.0/9.0, -4.0/11.0, 1.0/13.0);
- float intsmear_func(float z, float coeffs[7])
- {
- float z2 = z*z;
- float zn = z;
- float ret = 0.0;
- for (int i = 0; i < 7; i++) {
- ret += zn*coeffs[i];
- zn *= z2;
- }
- return ret;
- }
- float intsmear(float x, float dx, float d, float coeffs[7])
- {
- float zl = clamp((x-dx*0.5)/d,-1.0,1.0);
- float zh = clamp((x+dx*0.5)/d,-1.0,1.0);
- return d * ( intsmear_func(zh,coeffs) - intsmear_func(zl,coeffs) )/dx;
- }
- output main_fragment(in float2 texCoord : TEXCOORD0,
- uniform input IN,
- uniform sampler2D texture : TEXUNIT0
- )
- {
- float2 texelSize = 1.0 / IN.texture_size;
- float2 range;
- range = IN.video_size / (IN.output_size * IN.texture_size);
- //float2 range = sourceSize[0].xy / (targetSize.xy * sourceSize[0].xy);
- float3 cred = pow(float3(RSUBPIX_R, RSUBPIX_G, RSUBPIX_B), float3(outgamma));
- float3 cgreen = pow(float3(GSUBPIX_R, GSUBPIX_G, GSUBPIX_B), float3(outgamma));
- float3 cblue = pow(float3(BSUBPIX_R, BSUBPIX_G, BSUBPIX_B), float3(outgamma));
- int2 tli = int2(floor(texCoord/texelSize-float2(0.4999)));
- float3 lcol, rcol;
- float subpix = (texCoord.x/texelSize.x - 0.4999 - float(tli.x))*3.0;
- float rsubpix = range.x/texelSize.x * 3.0;
- lcol = float3(intsmear(subpix+1.0,rsubpix, 1.5, coeffs_x),
- intsmear(subpix ,rsubpix, 1.5, coeffs_x),
- intsmear(subpix-1.0,rsubpix, 1.5, coeffs_x));
- rcol = float3(intsmear(subpix-2.0,rsubpix, 1.5, coeffs_x),
- intsmear(subpix-3.0,rsubpix, 1.5, coeffs_x),
- intsmear(subpix-4.0,rsubpix, 1.5, coeffs_x));
- if (BGR > 0.5) {
- lcol.rgb = lcol.bgr;
- rcol.rgb = rcol.bgr;
- }
- float tcol, bcol;
- subpix = texCoord.y/texelSize.y - 0.4999 - float(tli.y);
- rsubpix = range.y/texelSize.y;
- tcol = intsmear(subpix ,rsubpix, 0.63, coeffs_y);
- bcol = intsmear(subpix-1.0,rsubpix, 0.63, coeffs_y);
- float3 topLeftColor = fetch_offset(tli, int2(0,0)) * lcol * float3(tcol);
- float3 bottomRightColor = fetch_offset(tli, int2(1,1)) * rcol * float3(bcol);
- float3 bottomLeftColor = fetch_offset(tli, int2(0,1)) * lcol * float3(bcol);
- float3 topRightColor = fetch_offset(tli, int2(1,0)) * rcol * float3(tcol);
- float3 averageColor = topLeftColor + bottomRightColor + bottomLeftColor + topRightColor;
- averageColor = mul(averageColor, mat3x3(cred, cgreen, cblue));
- output OUT;
- OUT.col = float4(pow(averageColor,float3(1.0/outgamma)),0.0);
- return OUT;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement