playing around with colour threshold filter

This commit is contained in:
DaniTheSkunk 2022-12-14 10:41:31 +00:00
parent 4a25dc4694
commit 0bc2be66b3
3 changed files with 64 additions and 5 deletions

View File

@ -18,7 +18,7 @@ public class Test3D extends BaseGame {
public Test3D() {
super(new Vec2i(1920, 1080), "Skunkworks 3d test");
window.setRenderSize(new Vec2i(1920/8, 1080/8));
window.setRenderSize(new Vec2i(1920, 1080));
System.out.printf("assimp version: %d.%d.%d\n",
Assimp.aiGetVersionMajor(),
Assimp.aiGetVersionMinor(),
@ -48,7 +48,7 @@ public class Test3D extends BaseGame {
@Override
protected void render3D(IRenderContext3D rc) {
rc.clear(Color.GRAY);
rc.clear(Color.BLACK);
rc.renderModel(model);
}

View File

@ -0,0 +1,55 @@
package com.danitheskunk.skunkworks.backends.gl;
public class FilterColorThreshold extends Filter {
private static final String fragmentSource = """
#version 450
layout(location = 1) in vec2 texCoord;
layout(binding = 0) uniform sampler2D tex;
out vec4 color;
void main() {
vec4 col = texture(tex, texCoord);
/*
if(col.r > 0.5)
col.r = 1.0;
else
col.r = 0.0;
if(col.g > 0.5)
col.g = 1.0;
else
col.g = 0.0;
if(col.b > 0.5)
col.b = 1.0;
else
col.b = 0.0;
*/
if(col.r > 0.5 && col.g < 0.5 && col.b < 0.5) {
col.r = 1.0;
col.g = 0.0;
col.b = 0.0;
} else if(col.r + col.g + col.b > 2.5) {
col.r = 1.0;
col.g = 1.0;
col.b = 1.0;
} else {
col.r = 0.0;
col.g = 0.0;
col.b = 0.0;
}
if(col.a > 0.0) {
color = col;
}
}
""";
private static final String vertexSource = """
#version 450
layout(location = 0) in vec2 pos;
layout(location = 1) out vec2 out_texCoord;
void main() {
gl_Position = vec4(pos, 0.0f, 1.0f);
out_texCoord = vec2(pos.x * 0.5 + 0.5, pos.y * 0.5 + 0.5);
}
""";
public FilterColorThreshold(Framebuffer input) {
super(input, new Program(vertexSource, fragmentSource), false);
}
}

View File

@ -24,6 +24,7 @@ public class Window extends BaseWindow {
private final Pipeline2D pipeline2D;
private final Pipeline3D pipeline3D;
private final Map<String, Filter> scalers;
private final Filter filter;
private final TextureAtlas textureAtlas;
private final long window;
private boolean shouldClose;
@ -66,10 +67,12 @@ public class Window extends BaseWindow {
pipeline2D = new Pipeline2D(framebuffer, textureAtlas);
pipeline3D = new Pipeline3D(framebuffer, textureAtlas);
filter = new FilterColorThreshold(framebuffer);
var out = filter.output;
scalers = new HashMap<>();
scalers.put("stretch", new ScalerStretch(framebuffer));
scalers.put("aspect", new ScalerAspect(framebuffer));
scalers.put("integer", new ScalerInteger(framebuffer));
scalers.put("stretch", new ScalerStretch(out));
scalers.put("aspect", new ScalerAspect(out));
scalers.put("integer", new ScalerInteger(out));
scaler = "aspect";
mouse = new Mouse(window, scalers.get(scaler));
@ -145,6 +148,7 @@ public class Window extends BaseWindow {
@Override
public void runScaler() {
filter.apply();
scalers.get(scaler).apply();
scalers.get(scaler).getOutput().copyToScreen();
}