Add simple DMG shader

This commit is contained in:
Maximilian Mader 2018-05-23 17:05:19 +02:00
parent d95ad1ca54
commit de43ac4cfb
Signed by: Max
GPG Key ID: F71D56A3151C4FB3
3 changed files with 97 additions and 57 deletions

View File

@ -29,6 +29,7 @@
@"Bilinear",
@"SmoothBilinear",
@"LCD",
@"DMG",
@"Scale2x",
@"Scale4x",
@"AAScale2x",

View File

@ -357,6 +357,7 @@ struct shader_name {
{"Bilinear", "Bilinear"},
{"SmoothBilinear", "Smooth Bilinear"},
{"LCD", "LCD Display"},
{"DMG", "DMG Display"},
{"Scale2x", "Scale2x"},
{"Scale4x", "Scale4x"},
{"AAScale2x", "Anti-aliased Scale2x"},

38
Shaders/DMG.fsh Normal file
View File

@ -0,0 +1,38 @@
vec4 pixelize(vec4 image, vec2 scaleVec, vec2 texCoord) {
float scale = max(scaleVec.x, scaleVec.y);
float x = fract(texCoord.x * 160.0) * scale;
float y = fract(texCoord.y * 144.0) * scale;
float border = 1.0;
if (scale > 5.0) {
border = 2.0;
}
if (x < border || x > scale - border || y < border || y > scale - border) {
return vec4(.95, .95, .95, 1);
}
return image;
}
vec4 scale(sampler2D image) {
vec2 displayScale = uResolution / vec2(160.0, 144.0);
vec2 texCoord = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) / uResolution;
vec4 sampled = texture(image, texCoord);
if (displayScale.x < 3.0 || displayScale.y < 3.0) {
return sampled;
}
float mixValue = 1.0;
if (displayScale.x >= 5.0 && displayScale.y >= 5.0) {
mixValue = 0.5;
}
else if (displayScale.x >= 3.0 && displayScale.y >= 3.0) {
mixValue = 0.8;
}
return mix(pixelize(sampled, displayScale, texCoord), sampled, mixValue);
}