A new little shader i did (glsl)

@Cyber tell me what you think of this after accepted PR :wink: Still looking around the C code and merging stuff tbh, let’s call this “alpha”

3 Likes

Darius, didn’t know about your thread. Just to let you know I really appreciate your work, trying to simplify some shaders for users who can’t run heavier alternatives or don’t want too many options. I see a few have been ported to slang, do you plan to eventually port more of them?

1 Like

Thanks. Tell me which one you want and I will port it to slang.

No shader in particular, I was just asking. But thanks s a lot for your disposition. Just wrote that because I thought it would be interesting to showcase your work for a wider audience. I really mean that I appreciate your effort, it’s interesting, works well and provides freedom of choice for many different users. I helped quite a few people to set up your gdv-mini (which already has a slang version) and they were quite delighted with the results. Until then, they thought shaders were too complicated or needed a powerhouse PC.

1 Like

For now I believe Ntsc-simple is the most useful to update to slang (current slang version is fairly recent). Probably crt-sines too, I wrote that after reading some reddit comments that “there is no light shader with glow”. The rest are mostly up-to-date. Try gdv-mini-ultra-Trinitron, that looks cool too :wink:

That blargg shader is heavy, running tons of passes on each pixel, barely 60 fps on Hd630 laptop. But I can make it more light as an option (reduce passes as a parameter)

2 Likes

Added option to tweak color carrier angle etc, so effectively one can make it look like any system he wants, if he knows how it supposed to look like ofc

5 Likes

No problem, Is there anything specific you would like me to do with it?

Play around tell me what you think. Evaluate lol

That “phase angle” option is effectively changing the “colorburst/pixel clock” frequency (since PI should be constant in reality) so it would look-alike any system if you know how it looks like, except if it has something strange going on.

1 Like

Actual megadrive ntsc shot

Ntsc/ntsc-j has rainbow effect and no dot crawl…

PAL no rainbow effect-dot crawl yes

7 Likes

Also I have that problem on my android phone Are you know how fix it? I like NTSC-Adaptive

Do you notice that the rainbow effect seems to dissipate over the blue water and as it reaches the grass cannot be seen anymore.

While in your example here:

…possibly due to the settings used, it’s much more prominent all the way from the top to the bottom of the screen.

The TV is probably using a comb filter, it cancels chroma better than a simple low pass filter used in the example. NTSC-Blastem is using a comb filter. Low Pass was the crude way done on very early TVs (60s-70s).

If you reduce comb filter strength to 0.0 you have this

3 Likes

Wow! That is amazing man, keep it up! To me it’s worth it to have most if not all of Blargg’s implementation as a shader if even for preservation purposes.

I’m tagging @Nesguy because he also was very interested in a new NTSC shader so I’m sure he’ll be very appreciative of your efforts thus far as well as going forward.

Who knows, maybe there can be some dialog, input and further understanding of how these things work to be gained from his knowledge and expertise on the subject matter?

2 Likes

Here is a single pass ntsc like blastem with comb filter and all, runs 800 fps on hd630 on 1x scale.

#version 110

#pragma parameter comb_filter "Comb Filter Strength" 0.6 0.0 1.0 0.05
#pragma parameter lpass "Low Pass" 0.25 0.0 1.0 0.01

#if defined(VERTEX)

#if __VERSION__ >= 130
#define COMPAT_VARYING out
#define COMPAT_ATTRIBUTE in
#define COMPAT_TEXTURE texture
#else
#define COMPAT_VARYING varying 
#define COMPAT_ATTRIBUTE attribute 
#define COMPAT_TEXTURE texture2D
#endif

#ifdef GL_ES
#define COMPAT_PRECISION mediump
#else
#define COMPAT_PRECISION
#endif

COMPAT_ATTRIBUTE vec4 VertexCoord;
COMPAT_ATTRIBUTE vec4 COLOR;
COMPAT_ATTRIBUTE vec4 TexCoord;
COMPAT_VARYING vec4 COL0;
COMPAT_VARYING vec4 TEX0;

vec4 _oPosition1; 
uniform mat4 MVPMatrix;
uniform COMPAT_PRECISION int FrameDirection;
uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;

// compatibility #defines
#define vTexCoord TEX0.xy
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
#define OutSize vec4(OutputSize, 1.0 / OutputSize)

#ifdef PARAMETER_UNIFORM
uniform COMPAT_PRECISION float WHATEVER;
#else
#define WHATEVER 0.0
#endif

void main()
{
    gl_Position = MVPMatrix * VertexCoord;
    TEX0.xy = TexCoord.xy*1.0001;
}

#elif defined(FRAGMENT)

#if __VERSION__ >= 130
#define COMPAT_VARYING in
#define COMPAT_TEXTURE texture
out vec4 FragColor;
#else
#define COMPAT_VARYING varying
#define FragColor gl_FragColor
#define COMPAT_TEXTURE texture2D
#endif

#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#define COMPAT_PRECISION mediump
#else
#define COMPAT_PRECISION
#endif

uniform COMPAT_PRECISION int FrameDirection;
uniform COMPAT_PRECISION int FrameCount;
uniform COMPAT_PRECISION vec2 OutputSize;
uniform COMPAT_PRECISION vec2 TextureSize;
uniform COMPAT_PRECISION vec2 InputSize;
uniform sampler2D Texture;
COMPAT_VARYING vec4 TEX0;

// compatibility #defines
#define vTexCoord TEX0.xy
#define Source Texture
#define SourceSize vec4(TextureSize, 1.0 / TextureSize) //either TextureSize or InputSize
#define OutSize vec4(OutputSize, 1.0 / OutputSize)

#ifdef PARAMETER_UNIFORM
uniform COMPAT_PRECISION float comb_filter;
uniform COMPAT_PRECISION float lpass;

#else
#define comb_filter 0.0
#define lpass 0.0

#endif

#define PI   3.14159265358979323846

const mat3 RGBYUV = mat3(0.299, 0.587, 0.114,
                        -0.299, -0.587, 0.886, 
                         0.701, -0.587, -0.114);

const mat3 YUV2RGB = mat3(1.0, 0.0, 1.13983,
                          1.0, -0.39465, -0.58060,
                          1.0, 2.03211, 0.0);
vec2 dx,dy;
float compo0 ( float p, vec3 phase)
{
vec3 yiq = COMPAT_TEXTURE(Source,vTexCoord+p*dx).rgb*RGBYUV;
return dot(vec3(1.0),yiq*phase);
}

float compo1 ( float p, vec3 phase)
{
vec3 yiq = COMPAT_TEXTURE(Source,vTexCoord+p*dx-dy).rgb*RGBYUV;
return dot(vec3(1.0),yiq*phase);
}

void main() {
dx = vec2(SourceSize.z*0.5,0.0);
dy = vec2(0.0,SourceSize.w*0.25);
vec3 final = vec3(0.0);
float sum = 0.0;

for (int n=-3; n<4; n++)
{
float p = float(n);   
float w = exp(-lpass*p*p);
float carrier    =  (vTexCoord.x * SourceSize.x / 170.667 * InputSize.x + p)*PI*0.5;
float carrier_up =  (vTexCoord.x * SourceSize.x / 170.667 * InputSize.x + p)*PI*0.5 + PI;
vec3 phase    = vec3(1.0,cos(carrier)   ,sin(carrier));
vec3 phase_up = vec3(1.0,cos(carrier_up),sin(carrier_up));

float line_cur = compo0(p,phase);
float line_up  = compo1(p,phase_up);

vec3 rgb = vec3(0.0);
// luma
rgb.r = (line_up+line_cur)/2.0;
// chroma
rgb.gb = vec2(line_cur-(line_up+line_cur)/2.0*comb_filter);
final += w*rgb*phase;
sum += w;
}
final /= sum;
FragColor.rgb = final*YUV2RGB;
}
#endif
4 Likes

Wow! Coming along nicely! I see that you’re trying and starting to match the real CRT shot even closer!

1 Like

That early megadrive very poor encoder is causing the rainbow bands (NTSC only). It should look like crt-consumer (with convergence lifted) otherwise with a good encoder with minimal chroma leaking.

https://www.reddit.com/r/SEGAGENESIS/comments/u8fnsg/quick_comparison_of_composite_video_on_genesis_vs/

2 Likes

crt-geom-mini GLSL, after some changes i did to match my CRT better on filtering at least, as it has a slot mask (20 inches)

3 Likes

So I got a pi zero 2w, cool device-2 small fingers size lol, pretty fast for 20 euros, running zxbaremulator on composite hack here (poor soldering by me on the other side heh) .

All dither results in another color but not any visible artifacts otherwise (that’s running on 240p pal setting sdtv_mode=18, ntsc has a lot more rolling on retropie) . Pretty much what you will see if you increase “convergence” on crt-consumer, zfast-composite, crt-sines etc. Of course I also have retropie installed on another SD card. Probably the video mode is not exactly what a real zx spectrum would output.

4 Likes

@DariusG, I noticed something when using crt-pocket. These artifacts appear when ntsc colors are enabled:

Looks like it’s clipping some color values.

Just passing by to let you know about it.

Anyway, congrats for all your shaders!

4 Likes

Probably needs a clamp at some point, will check that.

3 Likes