Skip to content

Commit 3ad4c23

Browse files
committed
Update CRT_Cathode
Updated and ported CRT Cathode for MagpieFX v2 compatibility
1 parent 644e169 commit 3ad4c23

File tree

2 files changed

+20
-48
lines changed

2 files changed

+20
-48
lines changed

Effects/CRT_Cathode.hlsl

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,10 @@
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
4514
Texture2D INPUT;
@@ -48,9 +17,9 @@ Texture2D INPUT;
4817
//!FILTER POINT
4918
SamplerState sam;
5019

51-
5220
//!PASS 1
53-
//!BIND INPUT
21+
//!STYLE PS
22+
//!IN INPUT
5423

5524
//Phosphor decay
5625
float decay(in float d) {
@@ -67,11 +36,15 @@ float sqd(in float2 a, in float2 b) {
6736
}
6837

6938
float4 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

Magpie/Resources/BuiltInScaleModels.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,15 @@
259259
}
260260
]
261261
},
262-
// Best CRT Simulation effect. Waiting for v2 port
263-
// {
264-
// "name": "CRT Cathode",
265-
// "effects": [
266-
// {
267-
// "effect": "CRT_Cathode",
268-
// "scale": [ -1, -1 ]
269-
// }
270-
// ]
271-
// },
262+
{
263+
"name": "CRT Cathode",
264+
"effects": [
265+
{
266+
"effect": "CRT_Cathode",
267+
"scale": [ -1, -1 ]
268+
}
269+
]
270+
},
272271
// For >2x Upscaling
273272
// {
274273
// "name": "ANime4k 3x !", // For large (1440p / 4k) displays only

0 commit comments

Comments
 (0)