Float16FrameBuffer

This commit is contained in:
minjaesong
2023-08-16 17:51:31 +09:00
parent fdfec960ca
commit e4b947ce69
5 changed files with 82 additions and 33 deletions

View File

@@ -0,0 +1,50 @@
package com.badlogic.gdx.graphics.glutils;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.GdxRuntimeException;
/**
* Created by minjaesong on 2023-08-16.
*/
public class Float16FrameBuffer extends FrameBuffer {
Float16FrameBuffer () {
}
/** Creates a GLFrameBuffer from the specifications provided by bufferBuilder
*
* @param bufferBuilder **/
protected Float16FrameBuffer (GLFrameBufferBuilder<? extends GLFrameBuffer<Texture>> bufferBuilder) {
super(bufferBuilder);
}
/** Creates a new FrameBuffer with a float backing texture, having the given dimensions and potentially a depth buffer
* attached.
*
* @param width the width of the framebuffer in pixels
* @param height the height of the framebuffer in pixels
* @param hasDepth whether to attach a depth buffer
* @throws GdxRuntimeException in case the FrameBuffer could not be created */
public Float16FrameBuffer (int width, int height, boolean hasDepth) {
FloatFrameBufferBuilder bufferBuilder = new FloatFrameBufferBuilder(width, height);
bufferBuilder.addFloatAttachment(GL30.GL_RGBA16F, GL30.GL_RGBA, GL30.GL_FLOAT, false);
if (hasDepth) bufferBuilder.addBasicDepthRenderBuffer();
this.bufferBuilder = bufferBuilder;
build();
}
@Override
protected Texture createTexture (FrameBufferTextureAttachmentSpec attachmentSpec) {
FloatTextureData data = new FloatTextureData(bufferBuilder.width, bufferBuilder.height, attachmentSpec.internalFormat,
attachmentSpec.format, attachmentSpec.type, attachmentSpec.isGpuOnly);
Texture result = new Texture(data);
result.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
result.setWrap(Texture.TextureWrap.ClampToEdge, Texture.TextureWrap.ClampToEdge);
return result;
}
}

View File

@@ -273,7 +273,7 @@ public class App implements ApplicationListener {
private static float loadTimer = 0f;
private static final float showupTime = 100f / 1000f;
private static FloatFrameBuffer renderFBO;
private static Float16FrameBuffer renderFBO;
public static HashSet<File> tempFilePool = new HashSet<>();
@@ -753,12 +753,12 @@ public class App implements ApplicationListener {
(renderFBO.getWidth() != scr.getWidth() ||
renderFBO.getHeight() != scr.getHeight())
) {
renderFBO = new FloatFrameBuffer(
renderFBO = new Float16FrameBuffer(
scr.getWidth(),
scr.getHeight(),
false
);
postProcessorOutFBO2 = new FloatFrameBuffer(
postProcessorOutFBO2 = new Float16FrameBuffer(
scr.getWidth() * 2,
scr.getHeight() * 2,
false

View File

@@ -4,11 +4,10 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FloatFrameBuffer
import com.badlogic.gdx.graphics.glutils.Float16FrameBuffer
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.utils.Disposable
import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
import net.torvald.terrarum.App.*
@@ -53,20 +52,20 @@ object IngameRenderer : Disposable {
private lateinit var blurWriteQuad2: Mesh
// private lateinit var blurWriteQuad4: Mesh
private lateinit var lightmapFbo: FloatFrameBuffer
private lateinit var fboRGB: FloatFrameBuffer
private lateinit var fboRGB_lightMixed: FloatFrameBuffer
private lateinit var fboA: FloatFrameBuffer
private lateinit var fboA_lightMixed: FloatFrameBuffer
private lateinit var fboMixedOut: FloatFrameBuffer
private lateinit var lightmapFbo: Float16FrameBuffer
private lateinit var fboRGB: Float16FrameBuffer
private lateinit var fboRGB_lightMixed: Float16FrameBuffer
private lateinit var fboA: Float16FrameBuffer
private lateinit var fboA_lightMixed: Float16FrameBuffer
private lateinit var fboMixedOut: Float16FrameBuffer
private lateinit var rgbTex: TextureRegion
private lateinit var aTex: TextureRegion
private lateinit var mixedOutTex: TextureRegion
private lateinit var lightTex: TextureRegion
private lateinit var blurTex: TextureRegion
private lateinit var fboBlurHalf: FloatFrameBuffer
// private lateinit var fboBlurQuarter: FloatFrameBuffer
private lateinit var fboBlurHalf: Float16FrameBuffer
// private lateinit var fboBlurQuarter: Float16FrameBuffer
// you must have lightMixed FBO; otherwise you'll be reading from unbaked FBO and it freaks out GPU
@@ -694,7 +693,7 @@ object IngameRenderer : Disposable {
private const val KAWASE_POWER = 1.5f
fun processNoBlur(outFbo: FloatFrameBuffer) {
fun processNoBlur(outFbo: Float16FrameBuffer) {
blurtex0.dispose()
@@ -710,7 +709,7 @@ object IngameRenderer : Disposable {
}
}
fun processKawaseBlur(outFbo: FloatFrameBuffer) {
fun processKawaseBlur(outFbo: Float16FrameBuffer) {
blurtex0.dispose()
@@ -807,12 +806,12 @@ object IngameRenderer : Disposable {
//fboBlurQuarter.dispose()
}
fboRGB = FloatFrameBuffer(width, height, false)
fboRGB_lightMixed = FloatFrameBuffer(width, height, false)
fboA = FloatFrameBuffer(width, height, false)
fboA_lightMixed = FloatFrameBuffer(width, height, false)
fboMixedOut = FloatFrameBuffer(width, height, false)
lightmapFbo = FloatFrameBuffer(
fboRGB = Float16FrameBuffer(width, height, false)
fboRGB_lightMixed = Float16FrameBuffer(width, height, false)
fboA = Float16FrameBuffer(width, height, false)
fboA_lightMixed = Float16FrameBuffer(width, height, false)
fboMixedOut = Float16FrameBuffer(width, height, false)
lightmapFbo = Float16FrameBuffer(
LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt(),
LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt(),
false
@@ -823,13 +822,13 @@ object IngameRenderer : Disposable {
blurTex = TextureRegion()
mixedOutTex = TextureRegion(fboMixedOut.colorBufferTexture)
fboBlurHalf = FloatFrameBuffer(
fboBlurHalf = Float16FrameBuffer(
LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 2,
LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 2,
false
)
/*fboBlurQuarter = FloatFrameBuffer(
/*fboBlurQuarter = Float16FrameBuffer(
LightmapRenderer.lightBuffer.width * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 4,
LightmapRenderer.lightBuffer.height * LightmapRenderer.DRAW_TILE_SIZE.toInt() / 4,
false

View File

@@ -8,7 +8,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FloatFrameBuffer
import com.badlogic.gdx.graphics.glutils.Float16FrameBuffer
import com.jme3.math.FastMath
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
@@ -147,7 +147,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
internal lateinit var uiRemoCon: UIRemoCon
internal lateinit var uiFakeBlurOverlay: UICanvas
private lateinit var worldFBO: FloatFrameBuffer
private lateinit var worldFBO: Float16FrameBuffer
private val warning32bitJavaIcon = TextureRegion(Texture(Gdx.files.internal("assets/graphics/gui/32_bit_warning.tga")))
private val warningAppleRosettaIcon = TextureRegion(Texture(Gdx.files.internal("assets/graphics/gui/apple_rosetta_warning.tga")))
@@ -262,7 +262,7 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
Gdx.input.inputProcessor = TitleScreenController(this)
worldFBO = FloatFrameBuffer(App.scr.width, App.scr.height, false)
worldFBO = Float16FrameBuffer(App.scr.width, App.scr.height, false)
// load list of savegames
printdbg(this, "update list of savegames")

View File

@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FloatFrameBuffer
import com.badlogic.gdx.graphics.glutils.Float16FrameBuffer
import com.badlogic.gdx.utils.Disposable
import com.jme3.math.FastMath
import net.torvald.random.HQRNG
@@ -48,9 +48,9 @@ object Toolkit : Disposable {
private val shaderBoxDown = App.loadShaderFromClasspath("shaders/default.vert", "shaders/boxdown.frag")
private val shaderBoxUp = App.loadShaderFromClasspath("shaders/default.vert", "shaders/boxup.frag")
private lateinit var fboBlur: FloatFrameBuffer
private lateinit var fboBlurHalf: FloatFrameBuffer
private lateinit var fboBlurQuarter: FloatFrameBuffer
private lateinit var fboBlur: Float16FrameBuffer
private lateinit var fboBlurHalf: Float16FrameBuffer
private lateinit var fboBlurQuarter: Float16FrameBuffer
private lateinit var blurWriteQuad: Mesh
private lateinit var blurWriteQuad2: Mesh
private lateinit var blurWriteQuad4: Mesh
@@ -326,17 +326,17 @@ object Toolkit : Disposable {
val fw = App.scr.width//MathUtils.nextPowerOfTwo(App.scr.width)
val fh = App.scr.height//MathUtils.nextPowerOfTwo(App.scr.height)
fboBlur = FloatFrameBuffer(
fboBlur = Float16FrameBuffer(
fw,
fh,
false
)
fboBlurHalf = FloatFrameBuffer(
fboBlurHalf = Float16FrameBuffer(
fw / 2,
fh / 2,
false
)
fboBlurQuarter = FloatFrameBuffer(
fboBlurQuarter = Float16FrameBuffer(
fw / 4,
fh / 4,
false