mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
adding test code to export fboRGB
This commit is contained in:
@@ -30,7 +30,6 @@ uniform sampler2D tilemap; // RGBA8888
|
||||
|
||||
uniform sampler2D tilesAtlas; // terrain, wire, fluids, etc.
|
||||
uniform sampler2D tilesBlendAtlas; // weather mix (e.g. yellowed grass)
|
||||
uniform sampler2D backbuffer;
|
||||
uniform float tilesBlend = 0.0; // percentage of blending [0f..1f]. 0: draws tilesAtlas, 1: draws tilesBlendAtlas
|
||||
|
||||
uniform ivec2 tilesInAtlas = ivec2(256, 256);
|
||||
@@ -112,10 +111,7 @@ void main() {
|
||||
vec4 finalBreakage = texture2D(tilesAtlas, finalUVCoordForBreakage);
|
||||
|
||||
vec4 finalColor = mix(finalTile, finalBreakage, finalBreakage.a);
|
||||
vec4 backbufferColor = texture2D(backbuffer, gl_FragCoord.xy / screenDimension);
|
||||
|
||||
//gl_FragColor = colourFilter * finalColor;
|
||||
// v
|
||||
gl_FragColor = colourFilter * mix(backbufferColor, finalColor, 1);
|
||||
gl_FragColor = colourFilter * finalColor;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,17 +11,27 @@ import java.io.OutputStream;
|
||||
*/
|
||||
public class PixmapIO2 {
|
||||
|
||||
public static void writeTGA(FileHandle file, Pixmap pixmap) throws IOException {
|
||||
public static void writeTGAHappy(FileHandle file, Pixmap pixmap) throws IOException {
|
||||
OutputStream output = file.write(false);
|
||||
|
||||
try {
|
||||
_writeTGA(output, pixmap);
|
||||
_writeTGA(output, pixmap, false);
|
||||
} finally {
|
||||
StreamUtils.closeQuietly(output);
|
||||
}
|
||||
}
|
||||
|
||||
private static void _writeTGA(OutputStream out, Pixmap pixmap) throws IOException {
|
||||
public static void writeTGA(FileHandle file, Pixmap pixmap) throws IOException {
|
||||
OutputStream output = file.write(false);
|
||||
|
||||
try {
|
||||
_writeTGA(output, pixmap, true);
|
||||
} finally {
|
||||
StreamUtils.closeQuietly(output);
|
||||
}
|
||||
}
|
||||
|
||||
private static void _writeTGA(OutputStream out, Pixmap pixmap, Boolean verbatim) throws IOException {
|
||||
byte[] width = toShortLittle(pixmap.getWidth());
|
||||
byte[] height = toShortLittle(pixmap.getHeight());
|
||||
byte[] zero = toShortLittle(0);
|
||||
@@ -50,7 +60,7 @@ public class PixmapIO2 {
|
||||
int color = pixmap.getPixel(x, y);
|
||||
|
||||
// if alpha == 0, write special value instead
|
||||
if ((color & 0xFF) == 0) {
|
||||
if (verbatim && (color & 0xFF) == 0) {
|
||||
out.write(zeroalpha);
|
||||
}
|
||||
else {
|
||||
@@ -63,7 +73,10 @@ public class PixmapIO2 {
|
||||
// write footer
|
||||
// 00 00 00 00 00 00 00 00 TRUEVISION-XFILE 2E 00
|
||||
out.write(new byte[]{0,0,0,0,0,0,0,0});
|
||||
out.write("TerrarumHappyTGA".getBytes());
|
||||
if (verbatim)
|
||||
out.write("TRUEVISION-XFILE".getBytes());
|
||||
else
|
||||
out.write("TerrarumHappyTGA".getBytes());
|
||||
out.write(new byte[]{0x2E,0});
|
||||
|
||||
|
||||
|
||||
@@ -272,7 +272,7 @@ class SpriteAssemblerPreview: Game() {
|
||||
|
||||
if (doExport && image != null) {
|
||||
doExport = false
|
||||
PixmapIO2.writeTGA(Gdx.files.absolute(exportPath), image)
|
||||
PixmapIO2.writeTGAHappy(Gdx.files.absolute(exportPath), image)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -627,8 +627,18 @@ fun blendDisable(batch: SpriteBatch? = null) {
|
||||
fun gdxClearAndSetBlend(r: Float, g: Float, b: Float, a: Float) {
|
||||
Gdx.gl.glClearColor(r,g,b,a)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
gdxSetBlend()
|
||||
}
|
||||
|
||||
fun gdxSetBlend() {
|
||||
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND)
|
||||
}
|
||||
|
||||
fun gdxSetBlendNormal() {
|
||||
gdxSetBlend()
|
||||
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD)
|
||||
|
||||
// ALPHA *MUST BE* PREMULTIPLIED //
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.terrarum.modulebasegame.console.*
|
||||
import java.util.HashMap
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2016-01-15.
|
||||
@@ -59,7 +59,8 @@ object CommandDict {
|
||||
|
||||
|
||||
/* !! */"exportlayer" to ExportLayerData,
|
||||
/* !! */"importlayer" to ImportLayerData
|
||||
/* !! */"importlayer" to ImportLayerData,
|
||||
/* !! */"exportfborgb" to ExportRendererFboRGB
|
||||
)
|
||||
|
||||
operator fun get(commandName: String): ConsoleCommand {
|
||||
|
||||
14
src/net/torvald/terrarum/console/ExportRendererFboRGB.kt
Normal file
14
src/net/torvald/terrarum/console/ExportRendererFboRGB.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package net.torvald.terrarum.console
|
||||
|
||||
import net.torvald.terrarum.modulebasegame.IngameRenderer
|
||||
|
||||
object ExportRendererFboRGB: ConsoleCommand {
|
||||
|
||||
override fun execute(args: Array<String>) {
|
||||
IngameRenderer.fboRGBexportRequested = true
|
||||
}
|
||||
|
||||
override fun printUsage() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.utils.ScreenUtils
|
||||
import net.torvald.dataclass.CircularArray
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
@@ -18,6 +19,7 @@ import net.torvald.terrarum.worlddrawer.BlocksDrawer
|
||||
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import javax.swing.JFileChooser
|
||||
|
||||
/**
|
||||
* This will be rendered to a postprocessor FBO
|
||||
@@ -220,6 +222,8 @@ object IngameRenderer {
|
||||
processBlur(lightmapFboA, lightmapFboB)
|
||||
}
|
||||
|
||||
internal var fboRGBexportRequested = false
|
||||
|
||||
private fun drawToRGB(
|
||||
actorsRenderBehind: List<ActorWithBody>?,
|
||||
actorsRenderMiddle: List<ActorWithBody>?,
|
||||
@@ -238,7 +242,7 @@ object IngameRenderer {
|
||||
}
|
||||
|
||||
setCameraPosition(0f, 0f)
|
||||
BlocksDrawer.drawWall(batch.projectionMatrix, fboRGB)
|
||||
BlocksDrawer.drawWall(batch.projectionMatrix)
|
||||
|
||||
batch.inUse {
|
||||
moveCameraToWorldCoord()
|
||||
@@ -247,7 +251,7 @@ object IngameRenderer {
|
||||
}
|
||||
|
||||
setCameraPosition(0f, 0f)
|
||||
BlocksDrawer.drawTerrain(batch.projectionMatrix, fboRGB)
|
||||
BlocksDrawer.drawTerrain(batch.projectionMatrix)
|
||||
|
||||
batch.inUse {
|
||||
/////////////////
|
||||
@@ -262,20 +266,42 @@ object IngameRenderer {
|
||||
}
|
||||
|
||||
setCameraPosition(0f, 0f)
|
||||
BlocksDrawer.drawFront(batch.projectionMatrix, false, fboRGB) // blue coloured filter of water, etc.
|
||||
BlocksDrawer.drawFront(batch.projectionMatrix, false) // blue coloured filter of water, etc.
|
||||
|
||||
batch.inUse {
|
||||
FeaturesDrawer.drawEnvOverlay(batch)
|
||||
}
|
||||
}
|
||||
|
||||
if (fboRGBexportRequested) {
|
||||
fboRGBexportRequested = false
|
||||
val fileChooser = JFileChooser()
|
||||
fileChooser.showSaveDialog(null)
|
||||
|
||||
try {
|
||||
if (fileChooser.selectedFile != null) {
|
||||
fboRGB.inAction(null, null) {
|
||||
val p = ScreenUtils.getFrameBufferPixmap(0, 0, fboRGB.width, fboRGB.height)
|
||||
PixmapIO2.writeTGA(Gdx.files.absolute(fileChooser.selectedFile.absolutePath), p)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fboRGB_lightMixed.inAction(camera, batch) {
|
||||
|
||||
setCameraPosition(0f, 0f)
|
||||
val (xrem, yrem) = worldCamToRenderPos()
|
||||
|
||||
gdxSetBlend()
|
||||
|
||||
batch.inUse {
|
||||
|
||||
blendNormal(batch)
|
||||
|
||||
// draw world
|
||||
batch.draw(fboRGB.colorBufferTexture, 0f, 0f)
|
||||
batch.flush()
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.torvald.terrarum.worlddrawer
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.math.Matrix4
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.AppLoader.printdbg
|
||||
@@ -347,43 +346,34 @@ internal object BlocksDrawer {
|
||||
drawTiles(FLUID)
|
||||
}
|
||||
|
||||
internal fun drawWall(projectionMatrix: Matrix4, backbuffer: FrameBuffer) {
|
||||
// blend normal
|
||||
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND)
|
||||
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
internal fun drawWall(projectionMatrix: Matrix4) {
|
||||
gdxSetBlendNormal()
|
||||
|
||||
renderUsingBuffer(WALL, projectionMatrix, backbuffer)
|
||||
renderUsingBuffer(WALL, projectionMatrix)
|
||||
}
|
||||
|
||||
internal fun drawTerrain(projectionMatrix: Matrix4, backbuffer: FrameBuffer) {
|
||||
// blend normal
|
||||
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND)
|
||||
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
internal fun drawTerrain(projectionMatrix: Matrix4) {
|
||||
gdxSetBlendNormal()
|
||||
|
||||
renderUsingBuffer(TERRAIN, projectionMatrix, backbuffer)
|
||||
renderUsingBuffer(FLUID, projectionMatrix, backbuffer)
|
||||
renderUsingBuffer(TERRAIN, projectionMatrix)
|
||||
renderUsingBuffer(FLUID, projectionMatrix)
|
||||
}
|
||||
|
||||
internal fun drawFront(projectionMatrix: Matrix4, drawWires: Boolean, backbuffer: FrameBuffer) {
|
||||
internal fun drawFront(projectionMatrix: Matrix4, drawWires: Boolean) {
|
||||
// blend mul
|
||||
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND)
|
||||
Gdx.gl.glBlendFunc(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
// let's just not MUL on terrain, make it FLUID only...
|
||||
renderUsingBuffer(FLUID, projectionMatrix, backbuffer)
|
||||
renderUsingBuffer(FLUID, projectionMatrix)
|
||||
|
||||
|
||||
|
||||
// blend normal
|
||||
Gdx.gl.glEnable(GL20.GL_TEXTURE_2D)
|
||||
Gdx.gl.glEnable(GL20.GL_BLEND)
|
||||
Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
gdxSetBlendNormal()
|
||||
|
||||
if (drawWires) {
|
||||
renderUsingBuffer(WIRE, projectionMatrix, backbuffer)
|
||||
renderUsingBuffer(WIRE, projectionMatrix)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +675,7 @@ internal object BlocksDrawer {
|
||||
|
||||
private var _tilesBufferAsTex: Texture = Texture(1, 1, Pixmap.Format.RGBA8888)
|
||||
|
||||
private fun renderUsingBuffer(mode: Int, projectionMatrix: Matrix4, backbuffer: FrameBuffer) {
|
||||
private fun renderUsingBuffer(mode: Int, projectionMatrix: Matrix4) {
|
||||
//Gdx.gl.glClearColor(.094f, .094f, .094f, 0f)
|
||||
//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
@@ -728,7 +718,6 @@ internal object BlocksDrawer {
|
||||
_tilesBufferAsTex.dispose()
|
||||
_tilesBufferAsTex = Texture(tilesBuffer)
|
||||
_tilesBufferAsTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
backbuffer.colorBufferTexture.bind(3)
|
||||
tilesTerrainBlend.texture.bind(2)
|
||||
_tilesBufferAsTex.bind(1) // trying 1 and 0...
|
||||
tileAtlas.texture.bind(0) // for some fuck reason, it must be bound as last
|
||||
@@ -740,7 +729,6 @@ internal object BlocksDrawer {
|
||||
shader.setUniformi("tilesAtlas", 0)
|
||||
shader.setUniformi("tilesBlendAtlas", 2)
|
||||
shader.setUniformi("tilemap", 1)
|
||||
shader.setUniformi("backbuffer", 3)
|
||||
shader.setUniformi("tilemapDimension", tilesBuffer.width, tilesBuffer.height)
|
||||
shader.setUniformf("tilesInAxes", tilesInHorizontal.toFloat(), tilesInVertical.toFloat())
|
||||
shader.setUniformi("cameraTranslation", WorldCamera.x fmod TILE_SIZE, WorldCamera.y fmod TILE_SIZE) // usage of 'fmod' and '%' were depend on the for_x_start, which I can't just do naive int div
|
||||
|
||||
Reference in New Issue
Block a user