Skip to content

Instantly share code, notes, and snippets.

@13xforever
Created April 29, 2022 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 13xforever/cd85f2730a76b18eeddcffbb11de9f36 to your computer and use it in GitHub Desktop.
Save 13xforever/cd85f2730a76b18eeddcffbb11de9f36 to your computer and use it in GitHub Desktop.
Retroarch CRT shader preset
*****************************************************************
You can put it in <RetroArch>/shaders/ with any name you want
This works well with most systems designed for CRT (so GB experience may vary)
You might want to tweak stages (i.e. linearize) and shader parameters per system
*****************************************************************
shaders = "5"
shader0 = "shaders_slang/linear/linearize.slang"
filter_linear0 = "false"
wrap_mode0 = "clamp_to_border"
mipmap_input0 = "false"
alias0 = ""
float_framebuffer0 = "false"
srgb_framebuffer0 = "true"
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
shader1 = "shaders_slang/blend/mister-blend.slang"
filter_linear1 = "true"
wrap_mode1 = "clamp_to_border"
mipmap_input1 = "false"
alias1 = ""
float_framebuffer1 = "false"
srgb_framebuffer1 = "false"
scale_type_x1 = "source"
scale_x1 = "5.000000"
scale_type_y1 = "source"
scale_y1 = "5.000000"
shader2 = "shaders_slang/linear/linear-gamma-correct.slang"
filter_linear2 = "true"
wrap_mode2 = "clamp_to_border"
mipmap_input2 = "false"
alias2 = ""
float_framebuffer2 = "false"
srgb_framebuffer2 = "false"
shader3 = "shaders_slang/crt/shaders/hyllian/crt-hyllian-multipass/crt-hyllian-pass0.slang"
wrap_mode3 = "clamp_to_border"
mipmap_input3 = "false"
alias3 = ""
float_framebuffer3 = "false"
srgb_framebuffer3 = "false"
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"
shader4 = "shaders_slang/crt/shaders/hyllian/crt-hyllian-multipass/crt-hyllian-pass1.slang"
filter_linear4 = "true"
wrap_mode4 = "clamp_to_border"
mipmap_input4 = "false"
alias4 = ""
float_framebuffer4 = "false"
srgb_framebuffer4 = "false"
#version 450
// MiSTer composite blend shader
// ported by Aeana https://twitter.com/Aeana/status/1351718215630503939
// put it at <RetroArch>/shaders/shaders_slang/blend/mister-blend.slang
layout(set = 0, binding = 0, std140) uniform UBO
{
mat4 MVP;
vec4 SourceSize; // Not used here, but doesn't hurt
};
float color_blend(float color_prev, float color_curr, float x)
{
float sum = color_curr;
sum = sum + color_prev;
return sum / 2.0;
}
#pragma name Composite blending
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec2 onePixel = vec2(1.0, 1.0) / SourceSize.xy;
vec3 currentColor = texture(Source, vTexCoord).rgb;
vec3 prevColor = texture(Source, vTexCoord - vec2(onePixel.x, 0)).rgb;
float r = color_blend(prevColor.r, currentColor.r, vTexCoord.x);
float g = color_blend(prevColor.g, currentColor.g, vTexCoord.x);
float b = color_blend(prevColor.b, currentColor.b, vTexCoord.x);
FragColor = vec4(r, g, b, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment