wtf is going on

This commit is contained in:
minjaesong
2023-07-21 17:41:22 +09:00
parent fbce707cac
commit 0af2e57368
3 changed files with 75 additions and 25 deletions

View File

@@ -245,6 +245,7 @@ public class App implements ApplicationListener {
public static Mesh fullscreenQuad;
public static Mesh fullscreenQuad2x;
public static Mesh fullscreenQuad2d;
private static OrthographicCamera camera;
private static FlippingSpriteBatch logoBatch;
public static TextureRegion logo;
@@ -493,8 +494,15 @@ public class App implements ApplicationListener {
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
);
fullscreenQuad2d = new Mesh(
true, 4, 6,
VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
);
updateFullscreenQuad(fullscreenQuad, scr.getWidth(), scr.getHeight());
updateFullscreenQuad(fullscreenQuad2x, scr.getWidth(), scr.getHeight());
updateFullscreenQuad(fullscreenQuad2x, scr.getWidth() * 2, scr.getHeight() * 2);
updateFullscreenQuad(fullscreenQuad2d, scr.getWidth() / 2, scr.getHeight() / 2);
// set up renderer info variables
renderer = Gdx.graphics.getGLVersion().getRendererString();
@@ -508,6 +516,7 @@ public class App implements ApplicationListener {
}
private FrameBuffer postProcessorOutFBO;
private FrameBuffer postProcessorOutFBO2;
@Override
public void render() {
@@ -568,10 +577,10 @@ public class App implements ApplicationListener {
// process screenshot request
if (screenshotRequested) {
/*if (screenshotRequested) {
FrameBufferManager.begin(postProcessorOutFBO);
try {
Pixmap p = Pixmap.createFromFrameBuffer(0, 0, scr.getWidth(), scr.getHeight());
Pixmap p = Pixmap.createFromFrameBuffer(0, 0, postProcessorOutFBO.getWidth(), postProcessorOutFBO.getHeight());
PixmapIO.writePNG(Gdx.files.absolute(defaultDir+"/Screenshot-"+String.valueOf(System.currentTimeMillis())+".png"), p, 9, true);
p.dispose();
Terrarum.INSTANCE.getIngame().sendNotification("Screenshot taken");
@@ -582,23 +591,58 @@ public class App implements ApplicationListener {
}
FrameBufferManager.end();
screenshotRequested = false;
}
}*/
if (getConfigString("screenmagnifyingfilter").equals("hq2x")) {
int canvasWidth = scr.getWidth() * 2;
int canvasHeight = scr.getHeight() * 2;
int canvasWidth = postProcessorOutFBO.getWidth(); // not zoomed dimension
int canvasHeight = postProcessorOutFBO.getHeight();
FrameBufferManager.begin(postProcessorOutFBO2);
shaderHQ2x.bind();
shaderHQ2x.setUniformMatrix("u_projTrans", camera.combined);
shaderHQ2x.setUniformi("u_lut", 1);
shaderHQ2x.setUniformi("u_texture", 0);
shaderHQ2x.setUniformf("u_textureSize", canvasWidth / 2f, canvasHeight / 2f);
shaderHQ2x.setUniformf("u_textureSize", canvasWidth, canvasHeight);
hq2xLut.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
hq2xLut.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
hq2xLut.bind(1);
postProcessorOutFBO.getColorBufferTexture().setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
postProcessorOutFBO.getColorBufferTexture().setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
postProcessorOutFBO.getColorBufferTexture().bind(0);
fullscreenQuad2x.render(shaderHQ2x, GL20.GL_TRIANGLES);
fullscreenQuad.render(shaderHQ2x, GL20.GL_TRIANGLES); // the shader expects the target texture size to be 2x the input dimension
FrameBufferManager.end();
if (screenshotRequested) {
FrameBufferManager.begin(postProcessorOutFBO2);
try {
Pixmap p = Pixmap.createFromFrameBuffer(0, 0, postProcessorOutFBO2.getWidth(), postProcessorOutFBO2.getHeight());
PixmapIO.writePNG(Gdx.files.absolute(defaultDir+"/Screenshot-"+String.valueOf(System.currentTimeMillis())+".png"), p, 9, true);
p.dispose();
Terrarum.INSTANCE.getIngame().sendNotification("Screenshot taken");
}
catch (Throwable e) {
e.printStackTrace();
Terrarum.INSTANCE.getIngame().sendNotification("Failed to take screenshot: "+e.getMessage());
}
FrameBufferManager.end();
screenshotRequested = false;
}
shaderPassthruRGBA.bind();
shaderPassthruRGBA.setUniformMatrix("u_projTrans", camera.combined);
shaderPassthruRGBA.setUniformi("u_texture", 0);
postProcessorOutFBO2.getColorBufferTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
postProcessorOutFBO2.getColorBufferTexture().setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
postProcessorOutFBO2.getColorBufferTexture().bind(0);
fullscreenQuad.render(shaderPassthruRGBA, GL20.GL_TRIANGLES);
}
else if (getConfigDouble("screenmagnifying") < 1.01 || getConfigString("screenmagnifyingfilter").equals("none")) {
shaderPassthruRGBA.bind();
@@ -751,7 +795,8 @@ public class App implements ApplicationListener {
if (currentScreen != null) currentScreen.resize(scr.getWidth(), scr.getHeight());
TerrarumPostProcessor.INSTANCE.resize(scr.getWidth(), scr.getHeight());
updateFullscreenQuad(fullscreenQuad, scr.getWidth(), scr.getHeight());
updateFullscreenQuad(fullscreenQuad2x, scr.getWidth(), scr.getHeight());
updateFullscreenQuad(fullscreenQuad2x, scr.getWidth() * 2, scr.getHeight() * 2);
updateFullscreenQuad(fullscreenQuad2d, scr.getWidth() / 2, scr.getHeight() / 2);
if (renderFBO == null ||
@@ -763,6 +808,11 @@ public class App implements ApplicationListener {
scr.getHeight(),
false
);
postProcessorOutFBO2 = new FloatFrameBuffer(
scr.getWidth() * 2,
scr.getHeight() * 2,
false
);
if (IS_DEVELOPMENT_BUILD) {
@@ -822,6 +872,7 @@ public class App implements ApplicationListener {
CommonResourcePool.INSTANCE.dispose();
fullscreenQuad.dispose();
fullscreenQuad2x.dispose();
fullscreenQuad2d.dispose();
logoBatch.dispose();
batch.dispose();
// shapeRender.dispose();

View File

@@ -3,11 +3,7 @@
#version 150
#ifdef GL_ES
#define PRECISION mediump
precision PRECISION float;
precision PRECISION int;
#else
#define PRECISION
precision mediump float;
#endif
#define SCALE 2.0
@@ -83,5 +79,9 @@ void main() {
float sum = dot(weights, vec4(1));
vec3 res = (pixels * (weights / sum)).rgb;
fragColor.rgb = res;
fragColor = vec4(res.rgb, 1.0);
// fragColor = vec4(v_texCoord[0].x, v_texCoord[0].y, 0.0, 1.0);
}

View File

@@ -1,11 +1,8 @@
#version 150
#ifdef GL_ES
#define PRECISION mediump
precision PRECISION float;
precision PRECISION int;
#else
#define PRECISION
precision mediump float;
#endif
#define SCALE 1.0
in vec4 a_position;
in vec2 a_texCoord0;
@@ -16,12 +13,14 @@ out vec2 u_textureSize;
out vec4 v_texCoord[4];
void main() {
gl_Position = u_projTrans * a_position;
gl_Position = u_projTrans * a_position / SCALE;
vec2 ps = 1.0/u_textureSize;
float dx = ps.x;
float dy = ps.y;
vec2 a_texCoord00 = a_texCoord0 / SCALE;
// +----+----+----+
// | | | |
// | w1 | w2 | w3 |
@@ -34,8 +33,8 @@ void main() {
// +----+----+----+
v_texCoord[0].zw = ps;
v_texCoord[0].xy = a_texCoord0.xy;
v_texCoord[1] = a_texCoord0.xxxy + vec4(-dx, 0, dx, -dy); // w1 | w2 | w3
v_texCoord[2] = a_texCoord0.xxxy + vec4(-dx, 0, dx, 0); // w4 | w5 | w6
v_texCoord[3] = a_texCoord0.xxxy + vec4(-dx, 0, dx, dy); // w7 | w8 | w9
v_texCoord[0].xy = a_texCoord00.xy;
v_texCoord[1] = a_texCoord00.xxxy + vec4(-dx, 0, dx, -dy); // w1 | w2 | w3
v_texCoord[2] = a_texCoord00.xxxy + vec4(-dx, 0, dx, 0); // w4 | w5 | w6
v_texCoord[3] = a_texCoord00.xxxy + vec4(-dx, 0, dx, dy); // w7 | w8 | w9
}