Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma parameter H_SHARPNESS "H. Sharpness" 0.5 0.0 1.0 0.05
- #pragma parameter V_SHARPNESS "V. Sharpness" 1.0 0.0 1.0 0.05
- #pragma parameter SCANLINE_STRENGTH "Scanline Strength" 0.5 0.0 1.0 0.05
- #pragma parameter BEAM_WIDTH "Beam Width" 1.5 1.0 5.0 0.5
- #pragma parameter BRIGHT_BOOST_MIN "Bright Boost Min." 0.25 0.0 1.0 0.05
- #pragma parameter BRIGHT_BOOST_MAX "Bright Boost Max." 0.5 0.0 1.0 0.05
- #pragma parameter DOTMASK_STRENGTH "Dot Mask Strength" 0.0 0.0 1.0 0.01
- #pragma parameter INPUT_GAMMA "Input Gamma" 2.0 1.0 3.0 0.1
- #pragma parameter OUTPUT_GAMMA "Output Gamma" 1.8 1.0 3.0 0.1
- #ifdef PARAMETER_UNIFORM
- uniform float H_SHARPNESS;
- uniform float V_SHARPNESS;
- uniform float SCANLINE_STRENGTH;
- uniform float BEAM_WIDTH;
- uniform float BRIGHT_BOOST_MIN;
- uniform float BRIGHT_BOOST_MAX;
- uniform float DOTMASK_STRENGTH;
- uniform float INPUT_GAMMA;
- uniform float OUTPUT_GAMMA;
- #else
- #define H_SHARPNESS 0.45
- #define V_SHARPNESS 1.2
- #define SCANLINE_STRENGTH 1.2
- #define BEAM_WIDTH 2.0
- #define BRIGHT_BOOST_MIN 0.1
- #define BRIGHT_BOOST_MAX 0.5
- #define DOTMASK_STRENGTH 0.35
- #define INPUT_GAMMA 2.0
- #define OUTPUT_GAMMA 2.1
- #endif
- #define PI 3.141592653589
- #define LINEAR_PROCESSING
- #ifdef LINEAR_PROCESSING
- #define TEX2D(c) pow(tex2D(tex, c).rgb, float3(INPUT_GAMMA, INPUT_GAMMA, INPUT_GAMMA))
- #else
- #define TEX2D(c) tex2D(tex, c).rgb
- #endif
- /*
- CRT Shader by EasyMode
- Copyright (C) 2014 EasyMode
- 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.
- */
- void main_vertex
- (
- float4 position : POSITION,
- out float4 oPosition : POSITION,
- uniform float4x4 modelViewProj,
- float2 tex : TEXCOORD,
- out float2 oTex : TEXCOORD
- )
- {
- oPosition = mul(modelViewProj, position);
- oTex = tex;
- }
- struct input
- {
- float2 video_size;
- float2 texture_size;
- float2 output_size;
- float frame_count;
- float frame_direction;
- float frame_rotation;
- };
- float curve_distance(float x, float sharp)
- {
- // apply half-circle s-curve to distance for sharper (more pixelated) interpolation
- // single line formula for Graph Toy:
- // 0.5 - sqrt(0.25 - (x - step(0.5, x)) * (x - step(0.5, x))) * sign(0.5 - x)
- float x_step = step(0.5, x);
- float curve = 0.5 - sqrt(0.25 - (x - x_step) * (x - x_step)) * sign(0.5 - x);
- return lerp(x, curve, sharp);
- }
- float4 main_fragment(uniform sampler2D tex : TEXUNIT0, float2 coords : TEXCOORD0, uniform input IN) : COLOR
- {
- float2 one = 1.0 / IN.texture_size;
- float2 one_half = one / 2.0;
- float2 c1 = floor((coords - one_half) / one) * one + one_half;
- float2 c2 = float2(c1.x + one.x, c1.y);
- float2 c3 = float2(c1.x, c1.y + one.y);
- float2 c4 = float2(c2.x, c3.y);
- float2 dist = (coords - c1) / (c4 - c1);
- float x_curve = curve_distance(dist.x, H_SHARPNESS);
- float3 col = lerp(TEX2D(c1), TEX2D(c2), x_curve);
- float3 col2 = lerp(TEX2D(c3), TEX2D(c4), x_curve);
- col = lerp(col, col2, curve_distance(dist.y, V_SHARPNESS));
- #ifndef LINEAR_PROCESSING
- col = pow(col, float3(INPUT_GAMMA, INPUT_GAMMA, INPUT_GAMMA));
- #endif
- float luma = dot(float3(0.2126, 0.7152, 0.0722), col);
- float bright = (max(col.r, max(col.g, col.b)) + luma) / 2.0;
- float boost = clamp(bright, BRIGHT_BOOST_MIN, BRIGHT_BOOST_MAX);
- float scan_weight = 1.0 - pow(cos(coords.y * 2.0 * PI * IN.texture_size.y) * 0.5 + 0.5, BEAM_WIDTH) * SCANLINE_STRENGTH;
- float mod_factor = coords.x * IN.output_size.x * IN.texture_size.x / IN.video_size.x;
- float mask = 1.0 - DOTMASK_STRENGTH;
- float3 mask_weight = lerp(float3(1.0, mask, 1.0), float3(mask, 1.0, mask), floor(mod(mod_factor, 2.0)));
- // color modification
- col.r *= 0.9 ;
- col.g *= 0.9 ;
- col.b *= 1.2 ;
- col.r += 0.001 ;
- col.g += 0.001 ;
- col.b += 0.01 ;
- col2 = float3(col.r, col.g, col.b);
- col *= float3(scan_weight, scan_weight, scan_weight);
- col = lerp(col, col2, boost);
- // color boost
- col *= 1.45 ;
- col *= mask_weight;
- col = pow(col, float3(1.0 / OUTPUT_GAMMA, 1.0 / OUTPUT_GAMMA, 1.0 / OUTPUT_GAMMA));
- return float4(col, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment