Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma parameter B "B" 0.5 0.0 1.0 0.01
- #pragma parameter C "C" 0.5 0.0 1.0 0.01
- #pragma parameter First_Switch "First Switch" 1.0 0.0 2.0 0.01
- #pragma parameter Second_Switch "Second Switch" 2.0 2.0 3.0 0.01
- #ifdef PARAMETER_UNIFORM
- uniform float B;
- uniform float C;
- uniform float First_Switch;
- uniform float Second_Switch;
- #else
- #define B 0.5
- #define C 0.5
- #define First_Switch 1.0
- #define Second_Switch 2.0
- #endif
- // END PARAMETERS //
- /* COMPATIBILITY
- - HLSL compilers
- - Cg compilers
- */
- /*
- Hyllian's EWA-cubic with anti-ringing Shader
- Copyright (C) 2011-2014 Hyllian - sergiogdb@gmail.com
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- // Some known filters use these values:
- // B = 0.0, C = 0.0 => Hermite cubic filter.
- // B = 1.0, C = 0.0 => Cubic B-Spline filter.
- // B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
- // B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
- // B = 0.3782, C = 0.3109 => Robidoux filter.
- // B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
- // B = 0.36, C = 0.28 => My best config for ringing elimination in pixel art (Hyllian).
- // Change these params to configure the horizontal filter.
- //#define B 0.5
- //#define C 0.5
- // Calculates the distance between two points
- float d(float2 pt1, float2 pt2)
- {
- float2 v = pt2 - pt1;
- return sqrt(dot(v,v));
- }
- float3 min4(float3 a, float3 b, float3 c, float3 d)
- {
- return min(a, min(b, min(c, d)));
- }
- float3 max4(float3 a, float3 b, float3 c, float3 d)
- {
- return max(a, max(b, max(c, d)));
- }
- struct input
- {
- float2 video_size;
- float2 texture_size;
- float2 output_size;
- float frame_count;
- float frame_direction;
- float frame_rotation;
- };
- struct out_vertex {
- float4 position : POSITION;
- float4 color : COLOR;
- float2 texCoord : TEXCOORD0;
- };
- /* VERTEX_SHADER */
- out_vertex main_vertex
- (
- float4 position : POSITION,
- float4 color : COLOR,
- float2 texCoord1 : TEXCOORD0,
- uniform float4x4 modelViewProj,
- uniform input IN
- )
- {
- // This line fix a bug in ATI cards.
- float2 tex = texCoord1;
- out_vertex OUT = {
- mul(modelViewProj, position),
- color,
- tex
- };
- return OUT;
- }
- float4 resampler(float4 x)
- {
- float4 res, x2, x3;
- x2 = x*x;
- x3 = x2*x;
- float4 w1 = ((12.0-9.0*B-6.0*C)*x3 + (-18.0+12.0*B+6.0*C)*x2 + float4(6.0 - 2.0*B))/6.0;
- float4 w2 = ((-B-6.0*C)*x3 + (6.0*B+30.0*C)*x2 + (-12.0*B-48.0*C)*x + float4(8.0*B + 24.0*C))/6.0;
- res = (x<float4(First_Switch)) ? w1 : (x<float4(Second_Switch)) ? w2 : float4(0.0);
- return res;
- }
- float4 main_fragment(in out_vertex VAR, uniform sampler2D s_p : TEXUNIT0, uniform input IN) : COLOR
- {
- float3 color;
- float4x4 weights;
- float2 dx = float2(1.0, 0.0);
- float2 dy = float2(0.0, 1.0);
- float2 pc = VAR.texCoord*IN.texture_size;
- float2 tc = (floor(pc-float2(0.5,0.5))+float2(0.5,0.5));
- weights[0] = resampler(float4(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy), d(pc, tc+2.0*dx -dy)));
- weights[1] = resampler(float4(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx ), d(pc, tc+2.0*dx )));
- weights[2] = resampler(float4(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy), d(pc, tc+2.0*dx +dy)));
- weights[3] = resampler(float4(d(pc, tc -dx+2.0*dy), d(pc, tc +2.0*dy), d(pc, tc +dx+2.0*dy), d(pc, tc+2.0*dx+2.0*dy)));
- dx = dx/IN.texture_size;
- dy = dy/IN.texture_size;
- tc = tc/IN.texture_size;
- // reading the texels
- float3 c00 = tex2D(s_p, tc -dx -dy).xyz;
- float3 c10 = tex2D(s_p, tc -dy).xyz;
- float3 c20 = tex2D(s_p, tc +dx -dy).xyz;
- float3 c30 = tex2D(s_p, tc+2.0*dx -dy).xyz;
- float3 c01 = tex2D(s_p, tc -dx ).xyz;
- float3 c11 = tex2D(s_p, tc ).xyz;
- float3 c21 = tex2D(s_p, tc +dx ).xyz;
- float3 c31 = tex2D(s_p, tc+2.0*dx ).xyz;
- float3 c02 = tex2D(s_p, tc -dx +dy).xyz;
- float3 c12 = tex2D(s_p, tc +dy).xyz;
- float3 c22 = tex2D(s_p, tc +dx +dy).xyz;
- float3 c32 = tex2D(s_p, tc+2.0*dx +dy).xyz;
- float3 c03 = tex2D(s_p, tc -dx+2.0*dy).xyz;
- float3 c13 = tex2D(s_p, tc +2.0*dy).xyz;
- float3 c23 = tex2D(s_p, tc +dx+2.0*dy).xyz;
- float3 c33 = tex2D(s_p, tc+2.0*dx+2.0*dy).xyz;
- // Get min/max samples
- float3 min_sample = min4(c11, c21, c12, c22);
- float3 max_sample = max4(c11, c21, c12, c22);
- color = mul(weights[0], float4x3(c00, c10, c20, c30));
- color+= mul(weights[1], float4x3(c01, c11, c21, c31));
- color+= mul(weights[2], float4x3(c02, c12, c22, c32));
- color+= mul(weights[3], float4x3(c03, c13, c23, c33));
- color = color/(dot(mul(weights, float4(1)), 1)); // weight normalization
- // Anti-ringing
- float3 aux = color;
- color = clamp(color, min_sample, max_sample);
- color = lerp(color, aux, 0.5);
- return float4(color, 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement