Skip to content

Instantly share code, notes, and snippets.

@mariodivece
Last active March 10, 2024 16:02
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mariodivece/dab278f82ef3725b06001adec28ef92b to your computer and use it in GitHub Desktop.
Save mariodivece/dab278f82ef3725b06001adec28ef92b to your computer and use it in GitHub Desktop.
A simple, configurable GLSL scanline effect shader for Dolphin
/*
[configuration]
[OptionRangeFloat]
GUIName = Blur Area
OptionName = BLUR_SIZE
MinValue = 0.0
MaxValue = 10.0
StepAmount = 0.1
DefaultValue = 1.6
[OptionRangeFloat]
GUIName = Scanline Alpha
OptionName = SEPARATOR_ALPHA
MinValue = 0.0
MaxValue = 1.0
StepAmount = 0.05
DefaultValue = 0.15
[OptionRangeFloat]
GUIName = Scanline Width
OptionName = SCANLINE_SIZE
MinValue = 0.0
MaxValue = 64
StepAmount = 0.1
DefaultValue = 6.3
[OptionRangeFloat]
GUIName = Brightness Boost
OptionName = BRIGHTNESS_BOOST
MinValue = 0.0
MaxValue = 2.0
StepAmount = 0.01
DefaultValue = 1.25
[/configuration]
*/
void main()
{
const float PI = 3.1415926535897932384626433832795;
float4 c0 = Sample();
float blursize = GetOption(BLUR_SIZE);
float subtleLevel = GetOption(SEPARATOR_ALPHA); // 0 is very dark separator, 1 is no separator
float scanlineSize = GetOption(SCANLINE_SIZE);
float boost = GetOption(BRIGHTNESS_BOOST);
//blur
float4 blurtotal = float4(0.0, 0.0, 0.0, 0.0);
blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, -blursize) * GetInvResolution());
blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, blursize) * GetInvResolution());
blurtotal += SampleLocation(GetCoordinates() + float2( blursize, -blursize) * GetInvResolution());
blurtotal += SampleLocation(GetCoordinates() + float2( blursize, blursize) * GetInvResolution());
blurtotal += SampleLocation(GetCoordinates() + float2(-blursize, 0.0) * GetInvResolution());
blurtotal += SampleLocation(GetCoordinates() + float2( blursize, 0.0) * GetInvResolution());
blurtotal += SampleLocation(GetCoordinates() + float2( 0.0, -blursize) * GetInvResolution());
blurtotal += SampleLocation(GetCoordinates() + float2( 0.0, blursize) * GetInvResolution());
blurtotal *= 0.125;
c0 = blurtotal;
// get color factor intensity based on vertical pixel position
// coordinates are 0 to 1 while resolution is a pixel resolution
float vPos = GetCoordinates().y * GetWindowResolution().y;
float lineIntensity = subtleLevel + abs(cos(PI / scanlineSize * vPos));
// output
SetOutput(c0 * clamp(lineIntensity, 0.0, 1.125) * boost);
}
@Darkslayerpowerful
Copy link

Darkslayerpowerful commented Jan 7, 2022

Hey guy, nice shader, i'm using duckstation emulator and this shade works normally, through the other scanline you made not. Can you make another shader, or its impossible? Using these same codes... I want some shaders which work with Duckstation like this above. If you need sugestion, the bad bloom is one which works too with duckstation.
RTX ON, Ultra Realistic is 2 shaders which i liked but half of the code not work...

@dylankird
Copy link

This is amazing! Thank you for making it! It's really improved my immersion playing Resident Evil 2 :)

@ha7ak3
Copy link

ha7ak3 commented Mar 26, 2023

Works great! 👍

@schmosef
Copy link

Thank you!

@walterg74
Copy link

walterg74 commented Mar 9, 2024

Hi @mariodivece , I also would prefer no flicker so came to get this one. However, while the other one shows the scanlines nice and thin like I expected, this one with default settings shows them way too big:

mad-scanlines:
Scanlines1

vs. scanlines:
Scanlines2

What values should I configure the second one to match the first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment