still broken, still renders

because im going to break it once again
See my comment in PostProcessor.kt
This commit is contained in:
minjaesong
2018-06-28 21:31:39 +09:00
parent 9736d39e04
commit abd1827182
8 changed files with 111 additions and 53 deletions

2
.gitignore vendored
View File

@@ -8,3 +8,5 @@ Thumbs.db
assets/modules/basegame/demoworld
assets/modules/basegame/demoworld.gz
external_resource_packs.zip
.idea/workspace.xml
.tmp*

View File

@@ -11,17 +11,17 @@ uniform sampler2D u_texture;
uniform vec2 resolution;
uniform vec3 phosphor_colour = vec3(1.3, 0.8567, 0.0);
vec3 scanline_darkening = vec3(0.45, 0.45, 0.45);
vec3 scanline_darkening = vec3(0.66, 0.66, 0.66);
// 0: every odd line will get darkened; 1: every even line will get darkened
uniform float alternative_scanline = 0.0; // 1.0: true
uniform float blur_blend = 0.3;
uniform float blur_blend = 0.8;
void main(void) {
vec3 color = texture2D(u_texture, v_texCoords).rgb;
vec3 color_pre = texture2D(u_texture, (gl_FragCoord + vec2(-1.0, 0.0)) / resolution).rgb;
vec3 color_next = texture2D(u_texture, (gl_FragCoord + vec2( 1.0, 0.0)) / resolution).rgb;
vec4 color = texture2D(u_texture, v_texCoords).rgba;
vec4 color_pre = texture2D(u_texture, (v_texCoords + (vec2(-2.0, 0.0) / resolution))).rgba;
vec4 color_next = texture2D(u_texture, (v_texCoords + (vec2( 2.0, 0.0) / resolution))).rgba;
color = color * (1.0 - blur_blend) + color_pre * (blur_blend / 2.0) + color_next * (blur_blend / 2.0);
@@ -34,11 +34,12 @@ void main(void) {
) / 8.0;
// out colour
color = vec3(color_luminosity) * phosphor_colour;
vec3 out_color = vec3(color_luminosity) * phosphor_colour;
if (is_scanline) {
color = color * scanline_darkening;
out_color = out_color * scanline_darkening;
}
gl_FragColor = vec4(color, 1.0);
gl_FragColor = vec4(out_color, 0.5);
}

View File

@@ -83,7 +83,7 @@ public class AppLoader implements ApplicationListener {
return String.format("%d.%d.%d", VERSION_RAW >>> 24, (VERSION_RAW & 0xff0000) >>> 16, VERSION_RAW & 0xFFFF);
}
private static LwjglApplicationConfiguration appConfig;
public static LwjglApplicationConfiguration appConfig;
public static GameFontBase fontGame;
@@ -107,10 +107,11 @@ public class AppLoader implements ApplicationListener {
}
private ShaderProgram shaderBayerSkyboxFill;
private Mesh fullscreenQuad;
private static ShaderProgram shaderBayerSkyboxFill;
public static ShaderProgram shader18Bit;
public static Mesh fullscreenQuad;
private OrthographicCamera camera;
private SpriteBatch batch;
private SpriteBatch logoBatch;
public static TextureRegion logo;
private Color gradWhiteTop = new Color(0xd8d8d8ff);
@@ -136,7 +137,7 @@ public class AppLoader implements ApplicationListener {
@Override
public void create() {
batch = new SpriteBatch();
logoBatch = new SpriteBatch();
camera = new OrthographicCamera(((float) appConfig.width), ((float) appConfig.height));
@@ -145,6 +146,13 @@ public class AppLoader implements ApplicationListener {
shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"));
//shader18Bit = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/18BitColour.frag"));
// Q & D test for the new post shader
shader18Bit = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/crt.frag"));
fullscreenQuad = new Mesh(
true, 4, 6,
@@ -171,10 +179,7 @@ public class AppLoader implements ApplicationListener {
@Override
public void render() {
renderFBO.begin();
Gdx.gl.glClearColor(0f,0f,0f,0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (screen == null) {
shaderBayerSkyboxFill.begin();
@@ -185,17 +190,17 @@ public class AppLoader implements ApplicationListener {
fullscreenQuad.render(shaderBayerSkyboxFill, GL20.GL_TRIANGLES);
shaderBayerSkyboxFill.end();
batch.begin();
batch.setColor(Color.WHITE);
logoBatch.begin();
logoBatch.setColor(Color.WHITE);
//blendNormal();
batch.setShader(null);
logoBatch.setShader(null);
setCameraPosition(0f, 0f);
batch.draw(logo, (appConfig.width - logo.getRegionWidth()) / 2f,
logoBatch.draw(logo, (appConfig.width - logo.getRegionWidth()) / 2f,
(appConfig.height - logo.getRegionHeight()) / 2f
);
batch.end();
logoBatch.end();
loadTimer += Gdx.graphics.getRawDeltaTime();
@@ -207,12 +212,25 @@ public class AppLoader implements ApplicationListener {
}
}
else {
renderFBO.begin();
//Gdx.gl.glClearColor(.094f, .094f, .094f, 0f);
//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//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);
screen.render(Gdx.graphics.getDeltaTime());
renderFBO.end();
//PostProcessor.INSTANCE.draw(renderFBO);
}
renderFBO.end();
PostProcessor.INSTANCE.draw(renderFBO);
GLOBAL_RENDER_TIMER += 1;
@@ -272,6 +290,6 @@ public class AppLoader implements ApplicationListener {
private void setCameraPosition(float newX, float newY) {
camera.position.set((-newX + appConfig.width / 2), (-newY + appConfig.height / 2), 0f);
camera.update();
batch.setProjectionMatrix(camera.combined);
logoBatch.setProjectionMatrix(camera.combined);
}
}

View File

@@ -2,16 +2,21 @@ package net.torvald.terrarum
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.GL20
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.FrameBuffer
import kotlin.system.measureNanoTime
/**
* Must be called by the App Loader
*/
object PostProcessor {
private val batch = SpriteBatch()
private lateinit var batch: SpriteBatch // not nulling to save some lines of code
private var textureRegion: TextureRegion? = null
private lateinit var lutTex: Texture
@@ -19,21 +24,48 @@ object PostProcessor {
lutTex = Texture(Gdx.files.internal("assets/clut/$filename"))
}
fun draw(screenTexHolder: FrameBuffer) {
//Gdx.gl.glClearColor(.094f, .094f, .094f, 1f)
fun draw(fbo: FrameBuffer) {
//Gdx.gl.glClearColor(.094f, .094f, .094f, 0f)
//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
//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)
batch.shader = Terrarum.shader18Bit // essential design decision; 262 144 colours VGA; NOT related with LCD monitor's internals
batch.inUse {
val texture = screenTexHolder.colorBufferTexture
batch.shader.setUniformMatrix("u_projTrans", batch.projectionMatrix)
batch.draw(texture, 0f, 0f, texture.width.toFloat(), texture.height.toFloat())
if (textureRegion == null) {
textureRegion = TextureRegion(fbo.colorBufferTexture)
batch = SpriteBatch()
}
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
// FIXME something's really fucked between sky_gradient and the actual_world_render,
// maybe overlaying world over grad
// OR mixing lightmap (less likely?)
// known symptom: when localising the spritebatch, greyscale lightmap and the UI are the
// only thing gets drawn
Terrarum.debugTimers["GFX.PostProcessor"] = measureNanoTime {
val shader = AppLoader.shader18Bit
// no-screen screen renders but the game don't? wtf?
batch.inUse {
batch.shader = shader
shader.setUniformf("resolution", AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat())
batch.draw(textureRegion, 0f, 0f)
}
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // don't know why it is needed; it really depresses me
}
}
}

View File

@@ -36,10 +36,12 @@ object ShitOnGlsl : ApplicationAdapter() {
lateinit var fucktex: Texture
lateinit var testTex: Texture
override fun create() {
ShaderProgram.pedantic = false
shader = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/loadingCircle.frag"))
shader = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/crt.frag"))
font = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", flipY = false)
@@ -76,6 +78,7 @@ object ShitOnGlsl : ApplicationAdapter() {
batch = SpriteBatch()
fucktex = Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"))
testTex = Texture(Gdx.files.internal("assets/test_texture.tga"))
}
@@ -91,14 +94,15 @@ object ShitOnGlsl : ApplicationAdapter() {
batch.shader = shader
shader.setUniformMatrix("u_projTrans", camera.combined)
shader.setUniformi("u_texture", 0)
//shader.setUniformMatrix("u_projTrans", camera.combined)
//shader.setUniformi("u_texture", 0)
shader.setUniformf("resolution", 1072f, 742f)
shader.setUniformf("circleCentrePoint", Gdx.graphics.width / 2f, Gdx.graphics.height / 2f)
shader.setUniformf("colorCentrePoint", Gdx.graphics.width / 2f, Gdx.graphics.height / 2f)
shader.setUniformf("circleSize", 200f)
//fullscreenQuad.render(shader, GL20.GL_TRIANGLES)
batch.draw(fucktex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
//batch.draw(fucktex, 0f, 0f, Gdx.graphics.width.toFloat(), Gdx.graphics.height.toFloat())
batch.draw(testTex, 0f, 0f)
}

View File

@@ -43,6 +43,8 @@ typealias RGBA8888 = Int
*/
object Terrarum : Screen {
val debugTimers = HashMap<String, Long>()
var screenW = 0
var screenH = 0
@@ -191,7 +193,6 @@ object Terrarum : Screen {
lateinit var shaderBlendGlow: ShaderProgram
lateinit var shaderRGBOnly: ShaderProgram
lateinit var shaderAtoGrey: ShaderProgram
lateinit var shader18Bit: ShaderProgram
lateinit var shaderMulRGBX: ShaderProgram
lateinit var shaderMulAAAX: ShaderProgram
@@ -380,9 +381,6 @@ object Terrarum : Screen {
shaderMulAAAX = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/aaaxmul.frag"))
shader18Bit = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/18BitColour.frag"))
if (!shaderBlendGlow.isCompiled) {
Gdx.app.log("shaderBlendGlow", shaderBlendGlow.log)
System.exit(1)

View File

@@ -46,6 +46,7 @@ import net.torvald.terrarum.modulebasegame.ui.*
import net.torvald.terrarum.ui.*
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
import kotlin.system.measureNanoTime
/**
@@ -529,7 +530,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
while (updateDeltaCounter >= updateRate) {
//updateGame(delta)
measureRuntime({ updateGame(delta) }, prependMsg = "Update Game: ")
Terrarum.debugTimers["Ingame.update"] = measureNanoTime { updateGame(delta) }
updateDeltaCounter -= updateRate
updateTries++
@@ -544,14 +545,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
/** RENDER CODE GOES HERE */
//renderGame(batch)
measureRuntime({ renderGame(batch) }, prependMsg = "Render Game: ")
}
private fun measureRuntime(function: (() -> Unit), out: PrintStream = System.err, prependMsg: String = "", appendMsg: String = "") {
val startTime = System.nanoTime()
function.invoke()
val endTime = System.nanoTime()
println("$prependMsg${endTime - startTime} ns$appendMsg")
Terrarum.debugTimers["Ingame.render"] = measureNanoTime { renderGame(batch) }
}
protected fun updateGame(delta: Float) {
@@ -998,6 +992,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
blendNormal()
}
}
fun processBlur(lightmapFboA: FrameBuffer, lightmapFboB: FrameBuffer, mode: Int) {

View File

@@ -119,6 +119,14 @@ class BasicDebugInfoWindow : UICanvas() {
printLine(batch, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
var dbgCnt = 11
Terrarum.debugTimers.forEach { t, u ->
printLine(batch, dbgCnt, "$ccM$t $ccG$u$ccY ns")
dbgCnt++
}
/**
* Second column
*/