Skip to content

Commit

Permalink
Update CRT_Cathode
Browse files Browse the repository at this point in the history
Updated and ported CRT Cathode for MagpieFX v2 compatibility
  • Loading branch information
Z-Dante committed May 13, 2022
1 parent 644e169 commit 3ad4c23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 48 deletions.
49 changes: 11 additions & 38 deletions Effects/CRT_Cathode.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,10 @@
//Cathode by nimitz (twitter: @stormoid)
//2017 nimitz All rights reserved

/*
CRT simulation shadowmask style, I also have a trinitron version
optimized for 4X scaling on a ~100ppi display.
The "Scanlines" seen in the simulated picture are only a side effect of the phoshor placement
and decay, instead of being artificially added on at the last step.
I have done some testing and it performs especially well with "hard" input such a faked
(dither based) transparency and faked specular highlights as seen in the bigger sprite.
A version tweaked and made for 4k displays could look pretty close to the real thing.
*/
//Original taken from https://github.com/Blinue/MagpieToys

//!MAGPIE EFFECT
//!VERSION 1


//!CONSTANT
//!VALUE INPUT_PT_X
float inputPtX;

//!CONSTANT
//!VALUE INPUT_PT_Y
float inputPtY;

//!CONSTANT
//!VALUE INPUT_WIDTH
float inputWidth;

//!CONSTANT
//!VALUE INPUT_HEIGHT
float inputHeight;

//!CONSTANT
//!VALUE OUTPUT_WIDTH
float outputWidth;
//!VERSION 2

//!TEXTURE
Texture2D INPUT;
Expand All @@ -48,9 +17,9 @@ Texture2D INPUT;
//!FILTER POINT
SamplerState sam;


//!PASS 1
//!BIND INPUT
//!STYLE PS
//!IN INPUT

//Phosphor decay
float decay(in float d) {
Expand All @@ -67,11 +36,15 @@ float sqd(in float2 a, in float2 b) {
}

float4 Pass1(float2 pos) {
float2 p = pos * float2(inputWidth, inputHeight);
float2 inputSize = GetInputSize();
float2 inputPt = GetInputPt();
float2 outputSize = GetOutputSize();

float2 p = pos * inputSize;

float3 col = 0;
p -= 0.25;
float gl_FragCoordX = pos.x * outputWidth;
float gl_FragCoordX = pos.x * outputSize.x;
p.y += fmod(gl_FragCoordX, 2.) < 1. ? .03 : -0.03;
p.y += fmod(gl_FragCoordX, 4.) < 2. ? .02 : -0.02;

Expand All @@ -81,7 +54,7 @@ float4 Pass1(float2 pos) {
[unroll]
for (int j = -2; j <= 2; j++) {
float2 tap = floor(p) + 0.5 + float2(i, j);
float3 rez = INPUT.Sample(sam, tap * float2(inputPtX, inputPtY)).rgb; //nearest neighbor
float3 rez = INPUT.SampleLevel(sam, tap * float2(inputPt.x, inputPt.y), 0).rgb; //nearest neighbor

//center points
float rd = sqd(tap, p + float2(0.0, 0.2)); //distance to red dot
Expand Down
19 changes: 9 additions & 10 deletions Magpie/Resources/BuiltInScaleModels.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,15 @@
}
]
},
// Best CRT Simulation effect. Waiting for v2 port
// {
// "name": "CRT Cathode",
// "effects": [
// {
// "effect": "CRT_Cathode",
// "scale": [ -1, -1 ]
// }
// ]
// },
{
"name": "CRT Cathode",
"effects": [
{
"effect": "CRT_Cathode",
"scale": [ -1, -1 ]
}
]
},
// For >2x Upscaling
// {
// "name": "ANime4k 3x !", // For large (1440p / 4k) displays only
Expand Down

0 comments on commit 3ad4c23

Please sign in to comment.