55//Cathode by nimitz (twitter: @stormoid)
66//2017 nimitz All rights reserved
77
8- /*
9- CRT simulation shadowmask style, I also have a trinitron version
10- optimized for 4X scaling on a ~100ppi display.
11-
12- The "Scanlines" seen in the simulated picture are only a side effect of the phoshor placement
13- and decay, instead of being artificially added on at the last step.
14-
15- I have done some testing and it performs especially well with "hard" input such a faked
16- (dither based) transparency and faked specular highlights as seen in the bigger sprite.
17- A version tweaked and made for 4k displays could look pretty close to the real thing.
18- */
8+ //Original taken from https://github.com/Blinue/MagpieToys
199
2010//!MAGPIE EFFECT
21- //!VERSION 1
22-
23-
24- //!CONSTANT
25- //!VALUE INPUT_PT_X
26- float inputPtX;
27-
28- //!CONSTANT
29- //!VALUE INPUT_PT_Y
30- float inputPtY;
31-
32- //!CONSTANT
33- //!VALUE INPUT_WIDTH
34- float inputWidth;
35-
36- //!CONSTANT
37- //!VALUE INPUT_HEIGHT
38- float inputHeight;
39-
40- //!CONSTANT
41- //!VALUE OUTPUT_WIDTH
42- float outputWidth;
11+ //!VERSION 2
4312
4413//!TEXTURE
4514Texture2D INPUT;
@@ -48,9 +17,9 @@ Texture2D INPUT;
4817//!FILTER POINT
4918SamplerState sam;
5019
51-
5220//!PASS 1
53- //!BIND INPUT
21+ //!STYLE PS
22+ //!IN INPUT
5423
5524//Phosphor decay
5625float decay (in float d) {
@@ -67,11 +36,15 @@ float sqd(in float2 a, in float2 b) {
6736}
6837
6938float4 Pass1 (float2 pos) {
70- float2 p = pos * float2 (inputWidth, inputHeight);
39+ float2 inputSize = GetInputSize ();
40+ float2 inputPt = GetInputPt ();
41+ float2 outputSize = GetOutputSize ();
42+
43+ float2 p = pos * inputSize;
7144
7245 float3 col = 0 ;
7346 p -= 0.25 ;
74- float gl_FragCoordX = pos.x * outputWidth ;
47+ float gl_FragCoordX = pos.x * outputSize.x ;
7548 p.y += fmod (gl_FragCoordX, 2 .) < 1 . ? .03 : -0.03 ;
7649 p.y += fmod (gl_FragCoordX, 4 .) < 2 . ? .02 : -0.02 ;
7750
@@ -81,7 +54,7 @@ float4 Pass1(float2 pos) {
8154 [unroll]
8255 for (int j = -2 ; j <= 2 ; j++) {
8356 float2 tap = floor (p) + 0.5 + float2 (i, j);
84- float3 rez = INPUT.Sample (sam, tap * float2 (inputPtX, inputPtY) ).rgb; //nearest neighbor
57+ float3 rez = INPUT.SampleLevel (sam, tap * float2 (inputPt.x, inputPt.y), 0 ).rgb; //nearest neighbor
8558
8659 //center points
8760 float rd = sqd (tap, p + float2 (0.0 , 0.2 )); //distance to red dot
0 commit comments