new skybox drawing wip

This commit is contained in:
minjaesong
2019-12-10 15:24:05 +09:00
parent 75dad8a78c
commit 01783387ad
16 changed files with 91 additions and 57 deletions

View File

@@ -351,6 +351,8 @@ class Cvec {
return fromHsv(hsv[0], hsv[1], hsv[2])
}
fun toGdxColor() = Color(r, g, b, a)
/** Extract Hue-Saturation-Value. This is the inverse of [.fromHsv].
* @param hsv The HSV array to be modified.
* @return HSV components for chaining.

View File

@@ -213,7 +213,7 @@ public class AppLoader implements ApplicationListener {
private static ShaderProgram shaderBayerSkyboxFill;
private static ShaderProgram shaderBayerSkyboxFill; // ONLY to be used by the splash screen
public static ShaderProgram shaderHicolour;
public static ShaderProgram shaderPassthruRGB;
public static ShaderProgram shaderColLUT;
@@ -235,8 +235,12 @@ public class AppLoader implements ApplicationListener {
private static LoadScreenBase currentSetLoadScreen;
public static int screenW = 0;
public static int screenH = 0;
public static float screenWf = 0f;
public static float screenHf = 0f;
public static int halfScreenW = 0;
public static int halfScreenH = 0;
public static float halfScreenWf = 0f;
public static float halfScreenHf = 0f;
public static Texture textureWhiteSquare;
public static Texture textureWhiteCircle;
@@ -665,6 +669,11 @@ public class AppLoader implements ApplicationListener {
halfScreenW = screenW / 2;
halfScreenH = screenH / 2;
screenWf = (float) screenW;
screenHf = (float) screenH;
halfScreenWf = (float) halfScreenW;
halfScreenHf = (float) halfScreenH;
updateFullscreenQuad(screenW, screenH);
printdbg(this, "Resize end");

View File

@@ -865,7 +865,7 @@ class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
/////////////////////////
// draw to main screen //
/////////////////////////
camera.setToOrtho(true, AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
camera.setToOrtho(true, AppLoader.screenWf, AppLoader.screenHf)
batch.projectionMatrix = camera.combined
batch.inUse {

View File

@@ -20,7 +20,7 @@ open class LoadScreenBase : ScreenAdapter(), Disposable {
internal var errorTrapped = false
internal var doContextChange = false
var camera = OrthographicCamera(AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
var camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
override fun show() {
messages.clear()

View File

@@ -64,7 +64,7 @@ object PostProcessor : Disposable {
debugUI.setPosition(0, 0)
batch = SpriteBatch()
camera = OrthographicCamera(AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
camera.setToOrtho(true)
batch.projectionMatrix = camera.combined
@@ -155,8 +155,8 @@ object PostProcessor : Disposable {
// centre ind
shapeRenderer.color = safeAreaCol2
shapeRenderer.line(0f, 0f, AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
shapeRenderer.line(0f, AppLoader.screenH.toFloat(), AppLoader.screenW.toFloat(), 0f)
shapeRenderer.line(0f, 0f, AppLoader.screenWf, AppLoader.screenHf)
shapeRenderer.line(0f, AppLoader.screenHf, AppLoader.screenWf, 0f)
// safe action area
shapeRenderer.color = safeAreaCol2

View File

@@ -141,7 +141,7 @@ object SanicLoadScreen : LoadScreenBase() {
// almost black background
it.color = Color(0x181818ff)
it.fillRect(0f, 0f, AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
it.fillRect(0f, 0f, AppLoader.screenWf, AppLoader.screenHf)
it.color = Color.WHITE
@@ -184,7 +184,7 @@ object SanicLoadScreen : LoadScreenBase() {
// message backgrounds
it.color = messageBackgroundColour
it.fillRect(0f, 60f, AppLoader.screenW.toFloat(), 40f + (messages.size) * AppLoader.fontGame.lineHeight)
it.fillRect(0f, 60f, AppLoader.screenWf, 40f + (messages.size) * AppLoader.fontGame.lineHeight)
// log messages
it.color = messageForegroundColour
@@ -209,7 +209,7 @@ object SanicLoadScreen : LoadScreenBase() {
// message backgrounds
it.color = messageBackgroundColour
it.fillRect(0f, 60f, AppLoader.screenW.toFloat(), 40f + (messages.size) * AppLoader.fontGame.lineHeight)
it.fillRect(0f, 60f, AppLoader.screenWf, 40f + (messages.size) * AppLoader.fontGame.lineHeight)
// log messages
it.color = messageForegroundColour

View File

@@ -328,7 +328,7 @@ inline fun FrameBuffer.inAction(camera: OrthographicCamera?, batch: SpriteBatch?
//this.end()
FrameBufferManager.end()
camera?.setToOrtho(true, AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
camera?.setToOrtho(true, AppLoader.screenWf, AppLoader.screenHf)
camera?.update()
batch?.projectionMatrix = camera?.combined
}

View File

@@ -45,7 +45,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
fun enter() {
// init view port
camera = OrthographicCamera(AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
img = Texture("assets/test_texture.tga")
@@ -147,7 +147,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
}
camera.setToOrtho(true, AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
camera.setToOrtho(true, AppLoader.screenWf, AppLoader.screenHf)
batch.projectionMatrix = camera.combined
batch.inUse {

View File

@@ -38,7 +38,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
// todo register titlescreen as the ingame, similar in a way that the buildingmaker did
var camera = OrthographicCamera(AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
var camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
// invert Y
@@ -235,7 +235,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
//camera.setToOrtho(true, AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
//camera.setToOrtho(true, AppLoader.screenWf, AppLoader.screenHf)
// render world
gdxClearAndSetBlend(.64f, .754f, .84f, 1f)

View File

@@ -30,8 +30,8 @@ object BlockStats {
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return
val renderWidth = FastMath.ceil(AppLoader.screenW.toFloat())
val renderHeight = FastMath.ceil(AppLoader.screenH.toFloat())
val renderWidth = FastMath.ceil(AppLoader.screenWf)
val renderHeight = FastMath.ceil(AppLoader.screenHf)
val noZoomCameraX = Math.round(FastMath.clamp(
player.hitbox.centeredX.toFloat() - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))

View File

@@ -46,7 +46,6 @@ object IngameRenderer : Disposable {
val shaderBlur: ShaderProgram
val shaderBayer: ShaderProgram
val shaderSkyboxFill: ShaderProgram
val shaderBlendGlow: ShaderProgram
val shaderRGBOnly: ShaderProgram
val shaderAtoGrey: ShaderProgram
@@ -91,17 +90,9 @@ object IngameRenderer : Disposable {
shaderBayer.setUniformf("gcount", 64f)
shaderBayer.setUniformf("bcount", 64f)
shaderBayer.end()
shaderSkyboxFill = AppLoader.loadShader("assets/4096.vert", "assets/4096_bayer_skyboxfill.frag")
shaderSkyboxFill.begin()
shaderSkyboxFill.setUniformf("rcount", 64f)
shaderSkyboxFill.setUniformf("gcount", 64f)
shaderSkyboxFill.setUniformf("bcount", 64f)
shaderSkyboxFill.end()
}
else {
shaderBayer = AppLoader.loadShader("assets/4096.vert", "assets/passthrurgb.frag")
shaderSkyboxFill = AppLoader.loadShader("assets/4096.vert", "assets/skyboxfill.frag")
}
@@ -122,11 +113,6 @@ object IngameRenderer : Disposable {
Gdx.app.log("shaderBayer", shaderBayer.log)
exitProcess(1)
}
if (!shaderSkyboxFill.isCompiled) {
Gdx.app.log("shaderSkyboxFill", shaderSkyboxFill.log)
exitProcess(1)
}
}
initialise()
@@ -229,7 +215,7 @@ object IngameRenderer : Disposable {
///////////////////////////////////////////////////////////////////////
// draw sky
WeatherMixer.render(camera, world)
WeatherMixer.render(camera, batch, world)
///////////////////////////////////////////////////////////////////////
@@ -759,7 +745,6 @@ object IngameRenderer : Disposable {
shaderBlur.dispose()
shaderBayer.dispose()
shaderSkyboxFill.dispose()
shaderBlendGlow.dispose()
shaderRGBOnly.dispose()
shaderAtoGrey.dispose()

View File

@@ -301,13 +301,13 @@ class UIInventoryFull(
val gradBottomEnd = AppLoader.screenH - gradTopStart
shapeRenderer.inUse {
shapeRenderer.rect(0f, gradTopStart, AppLoader.screenW.toFloat(), gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, gradBottomEnd, AppLoader.screenW.toFloat(), -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, gradTopStart, AppLoader.screenWf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, gradBottomEnd, AppLoader.screenWf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, gradTopStart + gradHeight, AppLoader.screenW.toFloat(), internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, gradTopStart + gradHeight, AppLoader.screenWf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
shapeRenderer.rect(0f, 0f, AppLoader.screenW.toFloat(), gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
shapeRenderer.rect(0f, AppLoader.screenH.toFloat(), AppLoader.screenW.toFloat(), -(AppLoader.screenH.toFloat() - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
shapeRenderer.rect(0f, 0f, AppLoader.screenWf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
shapeRenderer.rect(0f, AppLoader.screenHf, AppLoader.screenWf, -(AppLoader.screenHf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
}

View File

@@ -2,10 +2,9 @@ package net.torvald.terrarum.modulebasegame.weather
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
@@ -118,10 +117,13 @@ internal object WeatherMixer : RNGConsumer {
//private val parallaxZeroPos = WorldGenerator.TERRAIN_AVERAGE_HEIGHT * 0.75f // just an arb multiplier (266.66666 -> 200)
private val parallaxDomainSize = WorldGenerator.TERRAIN_UNDULATION / 2f
private val skyboxPixmap = Pixmap(2, 2, Pixmap.Format.RGBA8888)
private var skyboxTexture = Texture(skyboxPixmap)
/**
* Sub-portion of IngameRenderer. You are not supposed to directly deal with this.
*/
internal fun render(camera: Camera, world: GameWorld) {
internal fun render(camera: Camera, batch: SpriteBatch, world: GameWorld) {
val parallaxZeroPos = (world.height / 3) * 0.75f // just an arb multiplier (266.66666 -> 200)
@@ -145,16 +147,37 @@ internal object WeatherMixer : RNGConsumer {
.| = // parallax of -1
-+ <- 0.0 =
*/
val parallax: Float = (parallaxZeroPos - WorldCamera.gdxCamY.div(CreateTileAtlas.TILE_SIZE.toFloat())) / parallaxDomainSize
val parallax = ((parallaxZeroPos - WorldCamera.gdxCamY.div(CreateTileAtlas.TILE_SIZE.toFloat())) / parallaxDomainSize).coerceIn(-1f, 1f)
val parallaxSize = 1f / 3f
// draw skybox to provided graphics instance
val topCol = getGradientColour(world, skyboxColourMap, 0, timeNow)
val bottomCol = getGradientColour(world, skyboxColourMap, 1, timeNow)
val colTopmost = getGradientColour(world, skyboxColourMap, 0, timeNow).toGdxColor()
val colBottommost = getGradientColour(world, skyboxColourMap, 1, timeNow).toGdxColor()
val colMid = colorMix(colTopmost, colBottommost, 0.5f)
val colTop = colorMix(colTopmost, colBottommost, (parallax + parallaxSize / 2f) * 2f - 1f)
val colBottom = colorMix(colTopmost, colBottommost, (parallax - parallaxSize / 2f) * 2f - 1f)
// draw using shaperenderer or whatever
//Terrarum.textureWhiteSquare.bind(0)
gdxSetBlendNormal()
// draw to skybox texture
skyboxPixmap.setColor(colTop)
skyboxPixmap.drawPixel(0, 0); skyboxPixmap.drawPixel(1, 0)
skyboxPixmap.setColor(colBottom)
skyboxPixmap.drawPixel(0, 1); skyboxPixmap.drawPixel(1, 1)
skyboxTexture.dispose()
skyboxTexture = Texture(skyboxPixmap)
batch.shader = IngameRenderer.shaderBayer
batch.inUse {
it.draw(skyboxTexture, 0f, 0f, AppLoader.screenWf, AppLoader.screenHf)
}
// don't use shader to just fill the whole screen... frag shader will be called a million times and it's best to not burden it
/*
IngameRenderer.shaderSkyboxFill.begin()
IngameRenderer.shaderSkyboxFill.setUniformMatrix("u_projTrans", camera.combined)
IngameRenderer.shaderSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b)
@@ -164,6 +187,7 @@ internal object WeatherMixer : RNGConsumer {
IngameRenderer.shaderSkyboxFill.setUniformf("zoomInv", 1f / (Terrarum.ingame?.screenZoom ?: 1f))
AppLoader.fullscreenQuad.render(IngameRenderer.shaderSkyboxFill, GL20.GL_TRIANGLES)
IngameRenderer.shaderSkyboxFill.end()
*/
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
@@ -174,6 +198,15 @@ internal object WeatherMixer : RNGConsumer {
private operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f)
fun colorMix(one: Color, two: Color, scale: Float): Color {
return Color(
FastMath.interpolateLinear(scale, one.r, two.r),
FastMath.interpolateLinear(scale, one.g, two.g),
FastMath.interpolateLinear(scale, one.b, two.b),
FastMath.interpolateLinear(scale, one.a, two.a)
)
}
/**
* Get a GL of specific time
*/
@@ -270,6 +303,11 @@ internal object WeatherMixer : RNGConsumer {
}
fun dispose() {
try {
skyboxTexture.dispose()
}
catch (e: Throwable) {}
skyboxPixmap.dispose()
}
}

View File

@@ -307,12 +307,12 @@ abstract class UICanvas(
).roundInt()
Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
AppLoader.screenW.toFloat(),
AppLoader.screenWf,
AppLoader.screenW - ui.width.toFloat()
).roundInt()
Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
AppLoader.screenH.toFloat(),
AppLoader.screenHf,
AppLoader.screenH - ui.height.toFloat()
).roundInt()
}
@@ -332,12 +332,12 @@ abstract class UICanvas(
Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
AppLoader.screenW - ui.width.toFloat(),
AppLoader.screenW.toFloat()
AppLoader.screenWf
).roundInt()
Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
AppLoader.screenH - ui.height.toFloat(),
AppLoader.screenH.toFloat()
AppLoader.screenHf
).roundInt()
}
}

View File

@@ -660,8 +660,8 @@ internal object BlocksDrawer {
var tilesInVertical = -1; private set
fun resize(screenW: Int, screenH: Int) {
tilesInHorizontal = (screenW.toFloat() / TILE_SIZE).ceilInt() + 1
tilesInVertical = (screenH.toFloat() / TILE_SIZE).ceilInt() + 1
tilesInHorizontal = (AppLoader.screenWf / TILE_SIZE).ceilInt() + 1
tilesInVertical = (AppLoader.screenHf / TILE_SIZE).ceilInt() + 1
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilInt() + 1
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilInt() + 1
@@ -687,9 +687,9 @@ internal object BlocksDrawer {
tilesQuad.setVertices(floatArrayOf( // WARNING! not ususal quads; TexCoords of Y is flipped
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 0f,
screenW.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
screenW.toFloat(), screenH.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 1f,
0f, screenH.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 1f
AppLoader.screenWf, 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
AppLoader.screenWf, AppLoader.screenHf, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
0f, AppLoader.screenHf, 0f, 1f, 1f, 1f, 1f, 0f, 1f
))
tilesQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
}

View File

@@ -756,8 +756,8 @@ object LightmapRenderer {
// copied from BlocksDrawer, duh!
// FIXME 'lightBuffer' is not zoomable in this way
val tilesInHorizontal = (screenW.toFloat() / TILE_SIZE).ceilInt() + 1
val tilesInVertical = (screenH.toFloat() / TILE_SIZE).ceilInt() + 1
val tilesInHorizontal = (AppLoader.screenWf / TILE_SIZE).ceilInt() + 1
val tilesInVertical = (AppLoader.screenHf / TILE_SIZE).ceilInt() + 1
LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenW).div(TILE_SIZE).ceil() + overscan_open * 2 + 3
LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenH).div(TILE_SIZE).ceil() + overscan_open * 2 + 3