Need help with the "brightness" on this scanline shader preset

Hey guys, so I’ve got this shader preset that looks just PHENOMENAL to my eyes anyway, for straight up just scanlines. The problem though is that it darkens the screen WAY too much. Makes sense, it makes half of it black after all.

Here’s the comparison:

Before:

After:

Here is the preset as well:

shaders = "2"
shader0 = "W:\Emulators\RetroArch\shaders\shaders_glsl\anti-aliasing\shaders\reverse-aa.glsl"
filter_linear0 = "false"
wrap_mode0 = "clamp_to_edge"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "false"
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "W:\Emulators\RetroArch\shaders\shaders_glsl\crt\shaders\crt-geom.glsl"
wrap_mode1 = "clamp_to_edge"
mipmap_input1 = "false"
alias1 = ""
float_framebuffer1 = "false"
srgb_framebuffer1 = "false"
parameters = "CRTgamma;monitorgamma;d;CURVATURE;R;cornersize;cornersmooth;x_tilt;y_tilt;overscan_x;overscan_y;DOTMASK;SHARPER;scanline_weight"
CRTgamma = "5.000000"
monitorgamma = "5.000000"
d = "1.500000"
CURVATURE = "0.000000"
R = "2.000000"
cornersize = "0.001000"
cornersmooth = "1000.000000"
x_tilt = "0.000000"
y_tilt = "0.000000"
overscan_x = "100.000000"
overscan_y = "100.000000"
DOTMASK = "0.000000"
SHARPER = "3.000000"
scanline_weight = "0.100000"

I’ve tried a few things to ‘brighten’ up the actual screen content, but with the provided paramaters I end up just washing out the colors.

I tried loading in image-adjustement.glsl in a few different places, but it completely destroys the scanlines from crt-geom…

The only thing that made any real difference was changing “scanline_weight” to “0.200000” but that makes the dead lines have color and it ruins the entire effect I’m going for…

Anyone have any ideas on how to improve this?

EDIT - You might have to double-click the image with scanlines for it to look right.

Crt-geom isn’t really doing much in that combo other than providing the scanlines, which are just solid black, right? if so, you can use some other scanline shaders that have more direct modification parameters, like misc/scanline-fract.glsl

1 Like

So I swapped out crt-geom, as you said it was only being used for the scanlines, for the scanline-fract shader.

This shader is great, I didn’t realize there was still minute color in the crt-geom one - Fract is just like I like my coffee: BLACK.

That being said, I played with it’s own bright-boost setting and also tried throwing image-adjustment at it… but it seems like no matter what I do to try and brighten the image up it just washes out the color.

I tried pumping saturation up, and then altering brightness but It’s not making any difference somehow. :frowning:

Yeah, that’s an unavoidable side effect of low dynamic range. The brightness of an individual color channel can never go beyond 1.0, and as it starts clipping out of range and the other colors keep rising, the whole thing tends toward white, which washes out the image.

The only option to brighten the image without washing it out is to reduce the thickness of the black lines using the ‘Scanline Thickness’ parameter.

if you’d like to be a guinea pig, I’ve been working on modulating the thickness by the luminance of the underlying pixel (enable the ‘hybrid scanlines’ mode in the parameters):

// Super-basic scanline shader
// (looks bad at non-integer scales)
// by hunterk
// license: public domain

// Parameter lines go here:
#pragma parameter THICKNESS "Scanline Thickness" 2.0 1.0 12.0 1.0
#pragma parameter DARKNESS "Scanline Darkness" 0.50 0.0 1.0 0.05
#pragma parameter BRIGHTBOOST "Scanline Boost Bright" 0.1 0.0 0.2 0.1
#pragma parameter HYBRID "Hybrid Scanlines" 0.0 0.0 1.0 1.0

#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)

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

#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 Source Texture
#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
// All parameter floats need to have COMPAT_PRECISION in front of them
uniform COMPAT_PRECISION float THICKNESS;
uniform COMPAT_PRECISION float DARKNESS;
uniform COMPAT_PRECISION float BRIGHTBOOST;
uniform COMPAT_PRECISION float HYBRID;
#else
#define THICKNESS 1.0
#define DARKNESS 0.5
#define BRIGHTBOOST 1.1
#define HYBRID 0.0
#endif

vec3 RGBtoYIQ(vec3 RGB){
	const mat3 yiqmat = mat3(
		0.2989, 0.5870, 0.1140,
		0.5959, -0.2744, -0.3216,
		0.2115, -0.5229, 0.3114);
	return RGB * yiqmat;
}

float modulate(float var, float luma, float toggle){
	float temp = var;
	temp -= round(luma * 0.55 * var) * toggle;
	return clamp(temp, 0.0, 10.0);
}

void main()
{
	float lines = fract(vTexCoord.y * SourceSize.y);
	float scale_factor = floor((OutputSize.y / InputSize.y) + 0.4999);
	vec4 screen = COMPAT_TEXTURE(Source, vTexCoord);
	float luma = RGBtoYIQ(screen.rgb).r;
	float thick = modulate(THICKNESS, luma, HYBRID);
	float dark = modulate(DARKNESS, luma, HYBRID);

    FragColor = (lines > (1.0 / scale_factor * thick)) ? screen : screen * vec4(1.0 - dark);
} 
#endif

That should make the image significantly brighter by letting more of the brighter lines shine through.

1 Like

That actually makes perfect sense… lol but what a bummer.

So I tried out the shader and it has some interesting effects going on.

The bright-boost function seems completely disabled - None of the settings seem to make a difference.

When setting scanline darkness you can no longer get to full black. With the Hybrid scanlines enabled, scanline darkness does this odd effect where if it’s above .90 anything that is pure white no longer has scanlines.

I do like though, with hybrid enabled, how switching through the various thickness settings would stagger though light/dark sections as it increased the size of the blank spaces.

I think if you could get the darkness slider so 1.00 equates to solid black again, and fixed (remove?) the bright-boost setting, this would be pretty handy as a middle ground for the BlackLines:Brightness issue.

Yeah, brightboost wasn’t hooked up to anything because it conflicted with the hybrid scanline mode and clipped colors on the non-hybrid mode. I just hadn’t removed the parameter yet.

The darkness thing was intentional, to try and compensate for the weird color thing that happens as the darkness value increases (it’s basically like messing with the black level). It didn’t really do much to help that, though, so I got rid of it, too.

// Super-basic scanline shader
// (looks bad at non-integer scales)
// by hunterk
// license: public domain

// Parameter lines go here:
#pragma parameter THICKNESS "Scanline Thickness" 2.0 1.0 12.0 1.0
#pragma parameter DARKNESS "Scanline Darkness" 0.50 0.0 1.0 0.05
#pragma parameter HYBRID "Hybrid Scanlines" 0.0 0.0 1.0 1.0

#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)

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

#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 Source Texture
#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
// All parameter floats need to have COMPAT_PRECISION in front of them
uniform COMPAT_PRECISION float THICKNESS;
uniform COMPAT_PRECISION float DARKNESS;
uniform COMPAT_PRECISION float HYBRID;
#else
#define THICKNESS 1.0
#define DARKNESS 0.5
#define HYBRID 0.0
#endif

float modulate(float var, float luma, float toggle){
	float temp = var;
	temp -= round(luma * 0.55 * var) * toggle;
	return clamp(temp, 0.0, 10.0);
}

void main()
{
	float lines = fract(vTexCoord.y * SourceSize.y);
	float scale_factor = floor((OutputSize.y / InputSize.y) + 0.4999);
	vec4 screen = COMPAT_TEXTURE(Source, vTexCoord);
	float luma = dot(screen.rgb, vec3(0.299, 0.587, 0.114));
	float thick = modulate(THICKNESS, luma, HYBRID);
//	float dark = modulate(DARKNESS, luma, HYBRID);

    FragColor = (lines > (1.0 / scale_factor * thick)) ? screen : screen * vec4(1.0 - DARKNESS);
} 
#endif

For me, the best way to counterbalnce the darkness caused by scanlines is to turn up the monitor brightness

It’s probably not the answer you’re looking for, but everything else seems to mess up the image.

2 Likes