Skip to content

Instantly share code, notes, and snippets.

@mariodivece
Last active August 17, 2024 15:29
Show Gist options
  • 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);
}
@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?

@IntoTheVoid13
Copy link

Can you please port The Shader "crt-royale" to Dolphin? I tried renaming the one i found from ".glslp" to ".glsl" Format and putting it in the shaders folder of my Dolphin Folder, it shows up in Dolphin's Graphics Enhancement Menu, but when i select it and run a game it just gives me error messages. i tried both of your Dolphin shaders you made, they work fine, but i don't prefer them, "crt-royale" is actually really awesome CRT Shader on Duckstation that is almost perfect, and i would really love if you would make this one work for Dolphin.

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