Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CG shader
- // NES CRT simulation
- // by r57shell
- // thanks to feos & HardWareMan
- 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;
- };
- const float pi = 3.142;
- vec3 monitor(uniform sampler2D tex : TEXUNIT0, vec2 p, uniform input IN)
- {
- float2 size = IN.texture_size;
- vec2 pos = floor(p*size);
- vec2 uv = floor(pos)/size;
- vec4 res = tex2D(tex, uv);
- vec3 yuv = mul(float3x3(
- 0.2126, 0.7152, 0.0722,
- -0.09991, -0.33609, 0.436,
- 0.615, -0.55861, -0.05639), res.xyz);
- float alpha = (floor(p.x*size.x*4.)/2.0)*pi;
- vec2 sincv = vec2(cos(alpha), sin(alpha));
- if (mod(pos.y + 5.,4.) < 2.)
- sincv.x = -sincv.x;
- if (mod(pos.y, 4.) >= 2.)
- sincv.y = -sincv.y;
- float mc = 1.+dot(sincv, yuv.zy)/yuv.x;
- /*vec3 rgb = vec3(
- yuv.x + 1.28033 * yuv.z,
- yuv.x - 0.21482 * yuv.y - 0.38059 * yuv.z,
- yuv.x + 2.12798 * yuv.y);*/
- return res.xyz*mc;
- }
- // pos (left corner, sample size)
- vec4 monitor_sample(uniform sampler2D tex : TEXUNIT0, vec2 p, vec2 sample, uniform input IN)
- {
- // linear interpolation was...
- // now other thing.
- // http://imgur.com/m8Z8trV
- // AT LAST IT WORKS!!!!
- // going to check in retroarch...
- float2 size = IN.texture_size;
- vec2 next = vec2(.25,1.)/size;
- vec2 f = fract(vec2(4.,1.)*size*p);
- sample *= vec2(4.,1.)*size;
- vec2 l;
- vec2 r;
- if (f.x+sample.x < 1.)
- {
- l.x = f.x+sample.x;
- r.x = 0.;
- }
- else
- {
- l.x = 1.-f.x;
- r.x = min(1.,f.x+sample.x-1.);
- }
- if (f.y+sample.y < 1.)
- {
- l.y = f.y+sample.y;
- r.y = 0.;
- }
- else
- {
- l.y = 1.-f.y;
- r.y = min(1.,f.y+sample.y-1.);
- }
- vec3 top = mix(monitor(tex, p, IN), monitor(tex, p+vec2(next.x,0.), IN), r.x/(l.x+r.x));
- vec3 bottom = mix(monitor(tex, p+vec2(0.,next.y), IN), monitor(tex, p+next, IN), r.x/(l.x+r.x));
- return vec4(mix(top,bottom, r.y/(l.y+r.y)),1.0);
- }
- float4 main_fragment(uniform sampler2D tex : TEXUNIT0, float2 coords : TEXCOORD0, uniform input IN) : COLOR
- {
- return monitor_sample(tex, coords, 1./IN.output_size, IN);
- // difference
- //float zoom = 8;
- //vec4 sampled = monitor_sample(tex, coords, 1./zoom/IN.output_size, IN);
- //vec4 simple = vec4(monitor(tex, coords, IN),1.);
- //return vec4(length(sampled - simple)*5*sin(IN.frame_count/30.))+simple;
- }
Advertisement
Add Comment
Please, Sign In to add comment