gpu: add toggle for color banding

Co-authored-by: Toocanzs <dupanzszs@gmail.com>
This commit is contained in:
Adam
2018-11-23 16:07:21 -05:00
parent e530f2e7ff
commit f0bb1666fd
5 changed files with 34 additions and 3 deletions

View File

@@ -220,6 +220,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
private int uniBlockSmall; private int uniBlockSmall;
private int uniBlockLarge; private int uniBlockLarge;
private int uniBlockMain; private int uniBlockMain;
private int uniSmoothBanding;
@Override @Override
protected void startUp() protected void startUp()
@@ -469,6 +470,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
{ {
uniProjectionMatrix = gl.glGetUniformLocation(glProgram, "projectionMatrix"); uniProjectionMatrix = gl.glGetUniformLocation(glProgram, "projectionMatrix");
uniBrightness = gl.glGetUniformLocation(glProgram, "brightness"); uniBrightness = gl.glGetUniformLocation(glProgram, "brightness");
uniSmoothBanding = gl.glGetUniformLocation(glProgram, "smoothBanding");
uniTex = gl.glGetUniformLocation(glUiProgram, "tex"); uniTex = gl.glGetUniformLocation(glUiProgram, "tex");
uniTextures = gl.glGetUniformLocation(glProgram, "textures"); uniTextures = gl.glGetUniformLocation(glProgram, "textures");
@@ -937,6 +939,7 @@ public class GpuPlugin extends Plugin implements DrawCallbacks
// Brightness happens to also be stored in the texture provider, so we use that // Brightness happens to also be stored in the texture provider, so we use that
gl.glUniform1f(uniBrightness, (float) textureProvider.getBrightness()); gl.glUniform1f(uniBrightness, (float) textureProvider.getBrightness());
gl.glUniform1f(uniSmoothBanding, config.smoothBanding() ? 0f : 1f);
for (int id = 0; id < textures.length; ++id) for (int id = 0; id < textures.length; ++id)
{ {

View File

@@ -34,10 +34,22 @@ public interface GpuPluginConfig extends Config
@ConfigItem( @ConfigItem(
keyName = "drawDistance", keyName = "drawDistance",
name = "Draw Distance", name = "Draw Distance",
description = "Draw distance" description = "Draw distance",
position = 1
) )
default int drawDistance() default int drawDistance()
{ {
return 25; return 25;
} }
@ConfigItem(
keyName = "smoothBanding",
name = "Remove Color Banding",
description = "Smooths out the color banding that is present in the CPU renderer",
position = 2
)
default boolean smoothBanding()
{
return false;
}
} }

View File

@@ -27,14 +27,23 @@
uniform sampler2DArray textures; uniform sampler2DArray textures;
uniform vec2 textureOffsets[64]; uniform vec2 textureOffsets[64];
uniform float brightness; uniform float brightness;
uniform float smoothBanding;
in vec4 Color; in vec4 Color;
in float fHsl;
in vec4 fUv; in vec4 fUv;
out vec4 FragColor; out vec4 FragColor;
#include hsl_to_rgb.glsl
void main() { void main() {
float n = fUv.x; float n = fUv.x;
int hsl = int(fHsl);
vec3 rgb = hslToRgb(hsl) * smoothBanding + Color.rgb * (1.f - smoothBanding);
vec4 smoothColor = vec4(rgb, Color.a);
if (n > 0.0) { if (n > 0.0) {
n -= 1.0; n -= 1.0;
int textureIdx = int(n); int textureIdx = int(n);
@@ -45,8 +54,8 @@ void main() {
vec4 textureColor = texture(textures, vec3(animatedUv, n)); vec4 textureColor = texture(textures, vec3(animatedUv, n));
vec4 textureColorBrightness = pow(textureColor, vec4(brightness, brightness, brightness, 1.0f)); vec4 textureColorBrightness = pow(textureColor, vec4(brightness, brightness, brightness, 1.0f));
FragColor = textureColorBrightness * Color; FragColor = textureColorBrightness * smoothColor;
} else { } else {
FragColor = Color; FragColor = smoothColor;
} }
} }

View File

@@ -47,9 +47,11 @@ uniform mat4 projectionMatrix;
in ivec3 vPosition[]; in ivec3 vPosition[];
in vec4 vColor[]; in vec4 vColor[];
in float vHsl[];
in vec4 vUv[]; in vec4 vUv[];
out vec4 Color; out vec4 Color;
out float fHsl;
out vec4 fUv; out vec4 fUv;
#include to_screen.glsl #include to_screen.glsl
@@ -67,18 +69,21 @@ void main() {
vec4 tmp = vec4(screenA.xyz, 1.0); vec4 tmp = vec4(screenA.xyz, 1.0);
Color = vColor[0]; Color = vColor[0];
fHsl = vHsl[0];
fUv = vUv[0]; fUv = vUv[0];
gl_Position = projectionMatrix * tmp; gl_Position = projectionMatrix * tmp;
EmitVertex(); EmitVertex();
tmp = vec4(screenB.xyz, 1.0); tmp = vec4(screenB.xyz, 1.0);
Color = vColor[1]; Color = vColor[1];
fHsl = vHsl[1];
fUv = vUv[1]; fUv = vUv[1];
gl_Position = projectionMatrix * tmp; gl_Position = projectionMatrix * tmp;
EmitVertex(); EmitVertex();
tmp = vec4(screenC.xyz, 1.0); tmp = vec4(screenC.xyz, 1.0);
Color = vColor[2]; Color = vColor[2];
fHsl = vHsl[2];
fUv = vUv[2]; fUv = vUv[2];
gl_Position = projectionMatrix * tmp; gl_Position = projectionMatrix * tmp;
EmitVertex(); EmitVertex();

View File

@@ -32,6 +32,7 @@ uniform float brightness;
out ivec3 vPosition; out ivec3 vPosition;
out vec4 vColor; out vec4 vColor;
out float vHsl;
out vec4 vUv; out vec4 vUv;
#include hsl_to_rgb.glsl #include hsl_to_rgb.glsl
@@ -47,5 +48,6 @@ void main()
vPosition = vertex; vPosition = vertex;
vColor = vec4(rgb, 1.f - a); vColor = vec4(rgb, 1.f - a);
vHsl = float(hsl);
vUv = uv; vUv = uv;
} }