colour grading proof-of-concept on postprocessing

This commit is contained in:
minjaesong
2022-04-08 16:47:54 +09:00
parent 6238e92f65
commit 9b2d85c640
6 changed files with 143 additions and 38 deletions

View File

@@ -236,7 +236,6 @@ public class App implements ApplicationListener {
public static ShaderProgram shaderHicolour;
public static ShaderProgram shaderDebugDiff;
public static ShaderProgram shaderPassthruRGBA;
public static ShaderProgram shaderDitherRGBA;
public static ShaderProgram shaderColLUT;
public static ShaderProgram shaderReflect;
public static ShaderProgram shaderGhastlyWhite;
@@ -444,7 +443,6 @@ public class App implements ApplicationListener {
shaderHicolour = loadShaderFromClasspath("shaders/default.vert", "shaders/hicolour.frag");
shaderDebugDiff = loadShaderFromClasspath("shaders/default.vert", "shaders/diff.frag");
shaderPassthruRGBA = SpriteBatch.createDefaultShader();
shaderDitherRGBA = loadShaderFromClasspath("shaders/default.vert", "shaders/float_to_disp_dither.frag"); // always load the shader regardless of config because the config may cange
shaderColLUT = loadShaderFromClasspath("shaders/default.vert", "shaders/passthrurgb.frag");
shaderReflect = loadShaderFromClasspath("shaders/default.vert", "shaders/reflect.frag");
shaderGhastlyWhite = loadShaderFromClasspath("shaders/default.vert", "shaders/ghastlywhite.frag");
@@ -592,6 +590,8 @@ public class App implements ApplicationListener {
KeyToggler.INSTANCE.update(currentScreen instanceof TerrarumIngame);
// nested FBOs are just not a thing in GL!
FrameBufferManager.end();

View File

@@ -38,7 +38,7 @@ object ColorLimiterTest : ApplicationAdapter() {
override fun create() {
ShaderProgram.pedantic = false
shader4096 = ShaderProgram(Gdx.files.internal("assets/shaders/default.vert"), Gdx.files.internal("assets/shaders/float_to_disp_dither.frag"))
shader4096 = ShaderProgram(Gdx.files.internal("assets/shaders/default.vert"), Gdx.files.internal("assets/shaders/postproc_dither.frag"))
shader4096.bind()
shader4096.setUniformf("rcount", 4f)
shader4096.setUniformf("gcount", 4f)

View File

@@ -41,6 +41,11 @@ object PostProcessor : Disposable {
private val functionRowHelper = Texture(Gdx.files.internal("assets/graphics/function_row_help.png"))
private val shaderPostDither = App.loadShaderFromClasspath("shaders/default.vert", "shaders/postproc_dither.frag")
private val shaderPostNoDither = App.loadShaderFromClasspath("shaders/default.vert", "shaders/postproc_nodither.frag")
private val shaderQuant = mapOf(
8 to 255f,
10 to 1023f,
@@ -62,6 +67,8 @@ object PostProcessor : Disposable {
lutTex.dispose()
}
catch (e: UninitializedPropertyAccessException) { }
shaderPostDither.dispose()
shaderPostNoDither.dispose()
}
fun draw(projMat: Matrix4, fbo: FrameBuffer) {
@@ -138,26 +145,23 @@ object PostProcessor : Disposable {
private fun postShader(projMat: Matrix4, fbo: FrameBuffer) {
if (App.getConfigBoolean("fx_dither")) {
App.getCurrentDitherTex().bind(1)
fbo.colorBufferTexture.bind(0)
val shader = if (App.getConfigBoolean("fx_dither"))
shaderPostDither
else
shaderPostNoDither
App.shaderDitherRGBA.bind()
App.shaderDitherRGBA.setUniformMatrix("u_projTrans", projMat)
App.shaderDitherRGBA.setUniformi("u_texture", 0)
App.shaderDitherRGBA.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
App.shaderDitherRGBA.setUniformi("u_pattern", 1)
App.shaderDitherRGBA.setUniformf("quant", shaderQuant[App.getConfigInt("displaycolourdepth")] ?: 255f)
App.fullscreenQuad.render(App.shaderDitherRGBA, GL20.GL_TRIANGLES)
}
else {
fbo.colorBufferTexture.bind(0)
App.shaderPassthruRGBA.bind()
App.shaderPassthruRGBA.setUniformMatrix("u_projTrans", projMat)
App.shaderPassthruRGBA.setUniformi("u_texture", 0)
App.fullscreenQuad.render(App.shaderPassthruRGBA, GL20.GL_TRIANGLES)
}
App.getCurrentDitherTex().bind(1)
fbo.colorBufferTexture.bind(0)
shader.bind()
shader.setUniformMatrix("u_projTrans", projMat)
shader.setUniformi("u_texture", 0)
shader.setUniformi("rnd", rng.nextInt(8192), rng.nextInt(8192))
shader.setUniformi("u_pattern", 1)
shader.setUniformf("quant", shaderQuant[App.getConfigInt("displaycolourdepth")] ?: 255f)
App.fullscreenQuad.render(shader, GL20.GL_TRIANGLES)
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it