Skip to content

Instantly share code, notes, and snippets.

@mariodivece
Last active September 14, 2026 05:38
Show Gist options
  • Select an option

  • Save mariodivece/cfa3ec1352c13e5dd00d685528e4edac to your computer and use it in GitHub Desktop.

Select an option

Save mariodivece/cfa3ec1352c13e5dd00d685528e4edac to your computer and use it in GitHub Desktop.
CRT Scanline Effect for Dolphin Emulator
void main()
{
float currentMillis = GetTime() / float(1000.0);
float2 coords = GetCoordinates();
float lineCount = GetWindowResolution().y / 2.0;
// scanlines
int lineIndex = int( ( coords.y + currentMillis * 0.5 ) * lineCount );
#ifdef API_OPENGL
float lineIntensity = mod(float(lineIndex), 2);
#elif API_VULKAN
float lineIntensity = mod(float(lineIndex), 2);
#else
float lineIntensity = float(lineIndex) % 2.0;
#endif
// color shift
float off = lineIntensity * 0.0005;
float4 shift = float4( off, 0, 0, 0 );
// shift R and G channels to simulate NTSC color bleed
float4 colorShift = float4( 0.001, 0, 0, 0 );
float r = (Sample() + colorShift + shift).x;
float g = (Sample() - colorShift + shift).y;
float b = Sample().z;
float4 c = float4( r, g * 0.99, b, 1.0 ) * clamp( lineIntensity, 0.85, 1.0 );
float rollbar = sin( ( coords.y + currentMillis ) * 4.0 );
SetOutput(c + (rollbar * 0.02));
}
@RavenMacDaddy

Copy link
Copy Markdown

Hello

I tried the filter with super Mario galaxy.

In the level where you groundpound things for big larva to connect the apples, and in the end fight a big mole as the boss, I noticed that the filter has a hard time keeping up when the camera is moving fast, creating horizontal lines and darkening of the image that scrolls past the whole screen - similar to when you would film a CRT with a camera back in the day.

Felt like commenting since I really like the filter you've created and would love to see it improved to solve the issues with challenging camera movement.

Keep up the good work!
Cheers

@philou-felin

philou-felin commented Jul 18, 2021

Copy link
Copy Markdown

I found a link to this filter on Dolphin forums. I'll try it later... Wanted dev to know. I'll try with Skyward Sword and other Zelda titles. I mostly played those on CRT. I even had a CRT with component cables input and 480p.

EDIT: I tried with Skyward Sword and it's quite good, although I think it's too flickery 😅

@albion1993

Copy link
Copy Markdown

How to download this?

@Keathens

Copy link
Copy Markdown

How to download this?

same question lol

@mariodivece

Copy link
Copy Markdown
Author

No need to download. simply go to your Dolphin\Sys\Shaders folder, create a new file called mad-scanlines-crt.glsl and paste the contents of this gist. Enjoy :)

@mariodivece

Copy link
Copy Markdown
Author

I made another one if you don't like the flickering
https://gist.github.com/mariodivece/dab278f82ef3725b06001adec28ef92b

@philou-felin

Copy link
Copy Markdown

Thanks! :D

@Alkimical

Copy link
Copy Markdown

@Shalashaskka

Copy link
Copy Markdown

I made another one if you don't like the flickering https://gist.github.com/mariodivece/dab278f82ef3725b06001adec28ef92b

I like the look of this one better than the other one, where I feel the lines are too thick. Is there a way to turn the flickering off on this one?

@Mortendrak

Mortendrak commented Sep 26, 2024

Copy link
Copy Markdown

Here I leave you my own version, see if you like it:

https://www.mediafire.com/file/164jvb9plhi0sjq/scanlines.zip/file

@ashley-wilkinson

Copy link
Copy Markdown

@mariodivece
I've fixed a compilation error with the modulo operator. Line 14 under // scanlines uses '%' for modulo instead of 'mod()'. It has been changed to match the above lines for OpenGL and Vulkan APIs.

Please review my fork here.

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