Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* COMPATIBILITY
- - HLSL compilers
- - Cg compilers
- */
- /*
- Author: Themaister
- License: Public domain
- */
- struct sine_coord
- {
- float2 texel;
- float2 offset;
- float2 omega;
- };
- struct input
- {
- float2 video_size;
- float2 texture_size;
- float2 output_size;
- float frame_count;
- float frame_direction;
- float frame_rotation;
- };
- void main_vertex
- (
- float4 position : POSITION,
- out float4 oPosition : POSITION,
- uniform float4x4 modelViewProj,
- float4 color : COLOR,
- out float4 oColor : COLOR,
- float2 tex : TEXCOORD,
- out float2 oTex : TEXCOORD,
- uniform input IN,
- out sine_coord coords : TEXCOORD2
- )
- {
- oPosition = mul(modelViewProj, position);
- oColor = color;
- oTex = tex;
- coords.texel = tex * IN.texture_size;
- coords.offset = tex - float2(0.0, 0.25 / IN.texture_size.y);
- coords.omega = float2(3.1415 * IN.output_size.x * IN.texture_size.x / IN.video_size.x, 2.0 * 3.1415 * IN.texture_size.y);
- }
- #pragma parameter SCANLINE_BASE_BRIGHTNESS "Scanline Base Brightness" 1.0 0.0 1.0 0.01
- #pragma parameter SCANLINE_SINE_COMP_A "Scanline Sine Comp A" 0.1 0.0 0.10 0.01
- #pragma parameter SCANLINE_SINE_COMP_B "Scanline Sine Comp B" 0.15 0.0 1.0 0.05
- #pragma parameter SHARP_BILINEAR_PRE_SCALE "Sharp Bilinear Prescale" 1.25 1.0 10.0 0.05
- #ifdef PARAMETER_UNIFORM
- uniform float SCANLINE_BASE_BRIGHTNESS;
- uniform float SCANLINE_SINE_COMP_A;
- uniform float SCANLINE_SINE_COMP_B;
- uniform float SHARP_BILINEAR_PRE_SCALE;
- #else
- #define SCANLINE_BASE_BRIGHTNESS 1.0
- #define SCANLINE_SINE_COMP_A 0.1
- #define SCANLINE_SINE_COMP_B 0.15
- #define SHARP_BILINEAR_PRE_SCALE 1.25
- #endif
- float4 main_fragment (in sine_coord co : TEXCOORD2, uniform sampler2D s0 : TEXUNIT0, uniform input IN) : COLOR
- {
- float2 texel_floored = floor(co.texel);
- float2 s = fract(co.texel);
- float region_range = 0.5 - 0.5 / SHARP_BILINEAR_PRE_SCALE;
- // Figure out where in the texel to sample to get correct pre-scaled bilinear.
- // Uses the hardware bilinear interpolator to avoid having to sample 4 times manually.
- float2 center_dist = s - 0.5;
- float2 f = (center_dist - clamp(center_dist, -region_range, region_range)) * SHARP_BILINEAR_PRE_SCALE + 0.5;
- float2 mod_texel = texel_floored + f;
- float3 res = tex2D(s0, mod_texel / IN.texture_size).rgb;
- float2 sine_comp = float2(SCANLINE_SINE_COMP_A, SCANLINE_SINE_COMP_B);
- float3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(co.offset * co.omega), float2(1.0)));
- return float4(scanline, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement