working world-glow blend

This commit is contained in:
minjaesong
2017-07-11 13:34:14 +09:00
parent 3ffdd7233f
commit 1e9c04d7c0
25 changed files with 391 additions and 234 deletions

View File

@@ -12,6 +12,3 @@ import java.io.ByteArrayOutputStream
* Created by minjaesong on 2017-06-26.
*/
class Opus {
}

View File

@@ -77,7 +77,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
/**
* Render to specific coordinates. Will assume bottom-center point as image position.
* Will round to integer.
* Will floor to integer.
* @param g
* *
* @param posX bottom-center point
@@ -97,7 +97,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
if (flipHorizontal && flipVertical) {
batch.draw(region,
Math.round(posX).toFloat() + (2f * parentActor.hitboxTranslateX * parentActor.scale.toFloat() + parentActor.hitbox.width.toFloat()),
FastMath.floor(posX).toFloat() + (2f * parentActor.hitboxTranslateX * parentActor.scale.toFloat() + parentActor.hitbox.width.toFloat()),
FastMath.floor(posY).toFloat() + (2f * parentActor.hitboxTranslateY * parentActor.scale.toFloat() + parentActor.hitbox.height.toFloat()),
-FastMath.floor(cellWidth * scale).toFloat(),
-FastMath.floor(cellHeight * scale).toFloat()
@@ -105,7 +105,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
}
else if (flipHorizontal) {
batch.draw(region,
Math.round(posX).toFloat() + (2f * parentActor.hitboxTranslateX * parentActor.scale.toFloat() + parentActor.hitbox.width.toFloat()),
FastMath.floor(posX).toFloat() + (2f * parentActor.hitboxTranslateX * parentActor.scale.toFloat() + parentActor.hitbox.width.toFloat()),
FastMath.floor(posY).toFloat(),
-FastMath.floor(cellWidth * scale).toFloat(),
FastMath.floor(cellHeight * scale).toFloat()
@@ -113,7 +113,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
}
else if (flipVertical) {
batch.draw(region,
Math.round(posX).toFloat(),
FastMath.floor(posX).toFloat(),
FastMath.floor(posY).toFloat() + (2f * parentActor.hitboxTranslateY * parentActor.scale.toFloat() + parentActor.hitbox.height.toFloat()),
FastMath.floor(cellWidth * scale).toFloat(),
-FastMath.floor(cellHeight * scale).toFloat()
@@ -121,7 +121,7 @@ class SpriteAnimation(val parentActor: ActorWithPhysics) {
}
else {
batch.draw(region,
Math.round(posX).toFloat(),
FastMath.floor(posX).toFloat(),
FastMath.floor(posY).toFloat(),
FastMath.floor(cellWidth * scale).toFloat(),
FastMath.floor(cellHeight * scale).toFloat()

View File

@@ -80,10 +80,11 @@ class Ingame(val batch: SpriteBatch) : Screen {
private val worldFBOformat = if (Terrarum.environment == RunningEnvironment.MOBILE) Pixmap.Format.RGBA4444 else Pixmap.Format.RGBA8888
private val lightFBOformat = Pixmap.Format.RGB888
private val lightUvFBOformat = Pixmap.Format.Intensity
private val lightUvFBOformat = Pixmap.Format.RGB888
var worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
var worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
var worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, true)
// RGB elements of Lightmap for Color Vec4(R, G, B, 1.0) 24-bit
var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), true)
@@ -151,6 +152,23 @@ class Ingame(val batch: SpriteBatch) : Screen {
var camera = OrthographicCamera(Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat())
var fullscreenQuad = Mesh(
true, 4, 6,
VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
)
init {
fullscreenQuad.setVertices(floatArrayOf(
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
Terrarum.WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
))
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
}
// invert Y
fun initViewPort(width: Int, height: Int) {
//val width = if (width % 1 == 1) width + 1 else width
@@ -478,7 +496,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
}
worldGlowFrameBuffer.inAction(null, null) {
Gdx.gl.glClearColor(0f,0f,0f,0f)
Gdx.gl.glClearColor(0f,0f,0f,1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
}
@@ -546,6 +564,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
0f, 0f,
lightTex.width * lightmapDownsample, lightTex.height * lightmapDownsample
)
}
@@ -557,6 +576,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
}
}
@@ -570,17 +590,25 @@ class Ingame(val batch: SpriteBatch) : Screen {
batch.inUse {
batch.shader = null
// using custom code for camera; this is obscure and tricky
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
batch.projectionMatrix = camera.combined
batch.color = Color.WHITE
blendNormal()
//////////////////////
// draw actor glows //
//////////////////////
// FIXME needs some new blending/shader for glow...
actorsRenderMiddle.forEach { it.drawGlow(batch) }
actorsRenderMidTop.forEach { it.drawGlow(batch) }
player?.drawGlow(batch)
actorsRenderFront.forEach { it.drawGlow(batch) }
// --> blendLightenOnly() <-- introduced by childs of ActorWithBody //
// --> blendNormal() <-- introduced by childs of ActorWithBody //
// mix lighpmap canvas to this canvas (UV lights -- A channel)
@@ -600,11 +628,62 @@ class Ingame(val batch: SpriteBatch) : Screen {
0f, 0f,
lightTex.width * lightmapDownsample, lightTex.height * lightmapDownsample
)
}
blendNormal()
}
}
worldBlendFrameBuffer.inAction(camera, batch) {
Gdx.gl.glClearColor(0f, 0f, 0f, 0f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
val glowTex = worldGlowFrameBuffer.colorBufferTexture // GLOW: light_uvlight must be applied beforehand
//Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0)
worldTex.bind(0)
glowTex.bind(1)
/*val quad = Mesh(
true, 4, 6,
VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
)
quad.setVertices(floatArrayOf(
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
Terrarum.WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
))
quad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))*/
Terrarum.shaderBlendGlow.begin()
Terrarum.shaderBlendGlow.setUniformMatrix("u_projTrans", camera.combined)
Terrarum.shaderBlendGlow.setUniformi("u_texture", 0)
Terrarum.shaderBlendGlow.setUniformi("tex1", 1)
fullscreenQuad.render(Terrarum.shaderBlendGlow, GL20.GL_TRIANGLES)
Terrarum.shaderBlendGlow.end()
batch.inUse {
batch.color = Color.WHITE
blendNormal()
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // reset active textureunit to zero (i don't know tbh)
batch.shader = null
batch.color = Color.RED
batch.fillRect(0f, 0f, 16f, 16f)
}
}
/////////////////////////
// draw to main screen //
@@ -625,36 +704,29 @@ class Ingame(val batch: SpriteBatch) : Screen {
WeatherMixer.render(batch)
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
batch.color = Color.WHITE
// blend world_normal and world_glow
batch.shader = null
blendNormal()
batch.draw(blendedTex, 0f, 0f, blendedTex.width.toFloat(), blendedTex.height.toFloat())
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
/*val glowTex = worldGlowFrameBuffer.colorBufferTexture // GLOW: light_uvlight must be applied beforehand
glowTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
Gdx.graphics.gL20.glActiveTexture(GL20.GL_TEXTURE0)
worldTex.bind(GL20.GL_TEXTURE0)
Gdx.graphics.gL20.glActiveTexture(GL20.GL_TEXTURE1)
glowTex.bind(GL20.GL_TEXTURE1)
// setup shader params...*/
batch.color = Color.GREEN
batch.fillRect(16f, 16f, 16f, 16f)
// an old code.
batch.draw(worldTex, 0f, 0f, worldTex.width.toFloat(), worldTex.height.toFloat())
/*batch.shader = null
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
val glowTex = worldGlowFrameBuffer.colorBufferTexture // GLOW: light_uvlight must be applied beforehand
batch.draw(worldTex, 0f, 0f, worldTex.width.toFloat(), worldTex.height.toFloat())*/
batch.shader = null
batch.color = Color.RED
batch.fillRect(0f, 0f, 16f, 16f)
////////////////////////
// debug informations //
////////////////////////
@@ -728,10 +800,6 @@ class Ingame(val batch: SpriteBatch) : Screen {
// ////// //// // //// // //
// // // // // // // //
// //// // // // // // ////
@@ -1385,9 +1453,18 @@ class Ingame(val batch: SpriteBatch) : Screen {
override fun hide() {
}
/**
* @param width same as Terrarum.WIDTH
* @param height same as Terrarum.HEIGHT
* @see net.torvald.terrarum.Terrarum
*/
override fun resize(width: Int, height: Int) {
worldDrawFrameBuffer.dispose()
worldDrawFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
worldGlowFrameBuffer.dispose()
worldGlowFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
worldBlendFrameBuffer.dispose()
worldBlendFrameBuffer = FrameBuffer(worldFBOformat, width, height, true)
lightmapFboA.dispose()
lightmapFboA = FrameBuffer(lightFBOformat, width.div(lightmapDownsample.toInt()), height.div(lightmapDownsample.toInt()), true)
lightmapFboB.dispose()
@@ -1402,11 +1479,32 @@ class Ingame(val batch: SpriteBatch) : Screen {
initViewPort(width, height)
// re-calculate fullscreen quad
fullscreenQuad = Mesh(
true, 4, 6,
VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
)
fullscreenQuad.setVertices(floatArrayOf(
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
Terrarum.WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
))
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
LightmapRenderer.fireRecalculateEvent()
}
override fun dispose() {
worldDrawFrameBuffer.dispose()
worldGlowFrameBuffer.dispose()
lightmapFboA.dispose()
lightmapFboB.dispose()
}

View File

@@ -0,0 +1,36 @@
package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.glester.jopus.JOpusBufferFile
fun main(args: Array<String>) {
val config = LwjglApplicationConfiguration()
LwjglApplication(OpusDecodeTest, config)
}
/**
* Created by minjaesong on 2017-07-09.
*/
object OpusDecodeTest : ApplicationAdapter() {
private lateinit var opusFile: JOpusBufferFile
override fun create() {
}
override fun render() {
val color = Color(0.22f, 0.11f, 0.33f, 0f)
println("${color.r}, ${color.g}, ${color.b}, ${color.a}")
System.exit(0)
}
}

View File

@@ -47,6 +47,9 @@ fun main(args: Array<String>) {
config.foregroundFPS = RENDER_FPS
config.title = GAME_NAME
Terrarum.screenW = config.width
Terrarum.screenH = config.height
println("usevsync = ${Terrarum.USE_VSYNC}")
// the game must run on same speed regardless of the display FPS;
@@ -61,6 +64,9 @@ typealias RGBA8888 = Int
object Terrarum : ApplicationAdapter() {
internal var screenW: Int? = null
internal var screenH: Int? = null
lateinit var batch: SpriteBatch
lateinit var shapeRender: ShapeRenderer // DO NOT USE!! for very limited applications e.g. WeatherMixer
inline fun inShapeRenderer(shapeRendererType: ShapeRenderer.ShapeType = ShapeRenderer.ShapeType.Filled, action: (ShapeRenderer) -> Unit) {
@@ -70,10 +76,6 @@ object Terrarum : ApplicationAdapter() {
}
lateinit var orthoLineTex2px: Texture
lateinit var orthoLineTex3px: Texture
//////////////////////////////
// GLOBAL IMMUTABLE CONFIGS //
//////////////////////////////
@@ -84,10 +86,10 @@ object Terrarum : ApplicationAdapter() {
val VSYNC_TRIGGER_THRESHOLD = 56
inline val WIDTH: Int
get() = Gdx.graphics.width//if (Gdx.graphics.width % 1 == 1) Gdx.graphics.width + 1 else Gdx.graphics.width
inline val HEIGHT: Int
get() = Gdx.graphics.height//if (Gdx.graphics.height % 1 == 1) Gdx.graphics.height + 1 else Gdx.graphics.height
val WIDTH: Int
get() = if (screenW!! % 2 == 0) screenW!! else screenW!! + 1
val HEIGHT: Int
get() = if (screenH!! % 2 == 0) screenH!! else screenH!! + 1
inline val HALFW: Int
get() = WIDTH.ushr(1)
@@ -242,6 +244,7 @@ object Terrarum : ApplicationAdapter() {
lateinit var shaderAOnly: ShaderProgram
lateinit var shader4096: ShaderProgram
lateinit var shader4096Bayer: ShaderProgram
lateinit var shaderBlendGlow: ShaderProgram
init {
@@ -291,9 +294,6 @@ object Terrarum : ApplicationAdapter() {
batch = SpriteBatch()
shapeRender = ShapeRenderer()
orthoLineTex2px = Texture("assets/graphics/ortho_line_tex_2px.tga")
orthoLineTex3px = Texture("assets/graphics/ortho_line_tex_3px.tga")
fontGame = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", flipY = true)
fontSmallNumbers = TinyAlphNum
@@ -313,6 +313,13 @@ object Terrarum : ApplicationAdapter() {
shaderRGBOnly = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/rgbonly.frag"))
shaderAOnly = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/aonly.frag"))
shaderBlendGlow = ShaderProgram(Gdx.files.internal("assets/blendGlow.vert"), Gdx.files.internal("assets/blendGlow.frag"))
if (!shaderBlendGlow.isCompiled) {
Gdx.app.log("Shader", shaderBlendGlow.log)
System.exit(1)
}
ModMgr // invoke Module Manager, will also invoke BlockCodex
@@ -348,7 +355,10 @@ object Terrarum : ApplicationAdapter() {
}
override fun resize(width: Int, height: Int) {
currentScreen.resize(width, height)
screenW = width
screenH = height
currentScreen.resize(WIDTH, HEIGHT)
}

View File

@@ -91,6 +91,7 @@ object BlockCodex {
prop.shadeColR = floatVal(record, "shdr") / LightmapRenderer.MUL_FLOAT
prop.shadeColG = floatVal(record, "shdg") / LightmapRenderer.MUL_FLOAT
prop.shadeColB = floatVal(record, "shdb") / LightmapRenderer.MUL_FLOAT
prop.shadeColA = floatVal(record, "shduv") / LightmapRenderer.MUL_FLOAT
prop.strength = intVal(record, "strength")
prop.density = intVal(record, "dsty")
@@ -98,6 +99,7 @@ object BlockCodex {
prop.lumColR = floatVal(record, "lumr") / LightmapRenderer.MUL_FLOAT
prop.lumColG = floatVal(record, "lumg") / LightmapRenderer.MUL_FLOAT
prop.lumColB = floatVal(record, "lumb") / LightmapRenderer.MUL_FLOAT
prop.lumColA = floatVal(record, "lumuv") / LightmapRenderer.MUL_FLOAT
prop.friction = intVal(record, "friction")
prop.viscosity = intVal(record, "vscs")

View File

@@ -15,12 +15,13 @@ class BlockProp {
var shadeColR = 0f
var shadeColG = 0f
var shadeColB = 0f
var shadeColA = 0f
/**
* @param opacity Raw RGB value, without alpha
*/
inline val opacity: Color
get() = Color(shadeColR, shadeColG, shadeColB, 1f)
get() = Color(shadeColR, shadeColG, shadeColB, shadeColA)
var strength: Int = 0
var density: Int = 0
@@ -35,12 +36,13 @@ class BlockProp {
var lumColR = 0f
var lumColG = 0f
var lumColB = 0f
var lumColA = 0f
/**
* @param luminosity Raw RGB value, without alpha
*/
inline val luminosity: Color
get() = BlockPropUtil.getDynamicLumFunc(Color(lumColR, lumColG, lumColB, 1f), dynamicLuminosityFunction)
get() = BlockPropUtil.getDynamicLumFunc(Color(lumColR, lumColG, lumColB, lumColA), dynamicLuminosityFunction)
var drop: Int = 0

View File

@@ -63,9 +63,9 @@ object BlockPropUtil {
internal fun dynamicLumFuncTickClock() {
// FPS-time compensation
if (Gdx.graphics.framesPerSecond > 0) {
flickerFuncX += Gdx.graphics.framesPerSecond
breathFuncX += Gdx.graphics.framesPerSecond
pulsateFuncX += Gdx.graphics.framesPerSecond
flickerFuncX += Gdx.graphics.deltaTime * 1000f
breathFuncX += Gdx.graphics.deltaTime * 1000f
pulsateFuncX += Gdx.graphics.deltaTime * 1000f
}
// flicker-related vars

View File

@@ -42,6 +42,7 @@ object AVKey {
const val LUMR = "luminosityred"
const val LUMG = "luminositygreen"
const val LUMB = "luminosityblue"
const val LUMA = "luminosityuv"
const val DRAGCOEFF = "dragcoeff"
const val FALLDAMPENMULT = "falldampenmult"

View File

@@ -54,12 +54,13 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
1f
(actorValue.getAsFloat(AVKey.LUMA) ?: 0f) / LightmapRenderer.MUL_FLOAT
)
set(value) {
actorValue[AVKey.LUMR] = value.r * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMG] = value.g * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMB] = value.b * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
}
/**

View File

@@ -1150,6 +1150,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
override fun drawGlow(batch: SpriteBatch) {
if (isVisible && spriteGlow != null) {
blendNormal()
val offsetX = hitboxTranslateX * scale

View File

@@ -15,12 +15,13 @@ interface Luminous {
(actorValue.getAsFloat(AVKey.LUMR) ?: 0f) / LightmapRenderer.MUL_FLOAT,
(actorValue.getAsFloat(AVKey.LUMG) ?: 0f) / LightmapRenderer.MUL_FLOAT,
(actorValue.getAsFloat(AVKey.LUMB) ?: 0f) / LightmapRenderer.MUL_FLOAT,
1f
(actorValue.getAsFloat(AVKey.LUMA) ?: 0f) / LightmapRenderer.MUL_FLOAT,
)
set(value) {
actorValue[AVKey.LUMR] = value.r * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMG] = value.g * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMB] = value.b * LightmapRenderer.MUL_FLOAT
actorValue[AVKey.LUMA] = value.a * LightmapRenderer.MUL_FLOAT
}
*/
var luminosity: Color

View File

@@ -49,9 +49,10 @@ object PlayerBuilderSigrid {
p.actorValue[AVKey.INTELLIGENT] = true
//p.actorValue[AVKey.LUMR] = 0.84f
//p.actorValue[AVKey.LUMR] = 0.93f
//p.actorValue[AVKey.LUMR] = 1.37f
//p.actorValue[AVKey.LUMR] = 0.84
//p.actorValue[AVKey.LUMR] = 0.93
//p.actorValue[AVKey.LUMR] = 1.37
p.actorValue[AVKey.LUMA] = 0.32
p.actorValue[AVKey.BASEDEFENCE] = 141

View File

@@ -111,12 +111,10 @@ class BasicDebugInfoWindow : UICanvas {
val rawR = valRaw?.r?.times(100f)?.round()?.div(100f)
val rawG = valRaw?.g?.times(100f)?.round()?.div(100f)
val rawB = valRaw?.b?.times(100f)?.round()?.div(100f)
val rawA = valRaw?.a?.times(100f)?.round()?.div(100f)
lightVal = if (valRaw == null) ""
else valRaw.toString() + " (" +
rawR.toString() + " " +
rawG.toString() + " " +
rawB.toString() + ")"
else "$rawR $rawG $rawB $rawA"
printLine(batch, 8, "light@cursor $ccG$lightVal")
val tileNum = Terrarum.ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1

View File

@@ -12,8 +12,7 @@ import java.util.*
* Created by minjaesong on 16-07-11.
*/
data class BaseModularWeather(
val globalLightColourMap: GdxColorMap,
var skyboxGradColourMap: GdxColorMap,
var skyboxGradColourMap: GdxColorMap, // row 0: skybox grad top, row 1: skybox grad bottom, row 2: sunlight (RGBA)
val classification: String,
var extraImages: ArrayList<Texture>,
val mixFrom: String? = null,

View File

@@ -87,7 +87,7 @@ object WeatherMixer {
)
Terrarum.ingame!!.addParticle(rainParticle)
}
globalLightNow.set(getGlobalLightOfTime(world.time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 1f))
globalLightNow.set(getGlobalLightOfTime(world.time.todaySeconds).mul(0.3f, 0.3f, 0.3f, 0.58f))
}
}
}
@@ -107,7 +107,6 @@ object WeatherMixer {
// we will not care for nextSkybox for now
val timeNow = Terrarum.ingame!!.world.time.todaySeconds
val skyboxColourMap = currentWeather.skyboxGradColourMap
val lightColourMap = currentWeather.globalLightColourMap
// calculate global light
val globalLight = getGradientColour(skyboxColourMap, 2, timeNow)
@@ -139,7 +138,7 @@ object WeatherMixer {
* Get a GL of specific time
*/
fun getGlobalLightOfTime(timeInSec: Int): Color =
getGradientColour(currentWeather.globalLightColourMap, 0, timeInSec)
getGradientColour(currentWeather.skyboxGradColourMap, 2, timeInSec)
// TODO colour gradient load from image, store to array
fun getGradientColour(colorMap: GdxColorMap, row: Int, timeInSec: Int): Color {
@@ -167,8 +166,6 @@ object WeatherMixer {
return newCol
}
fun Color.toStringRGB() = "RGB8(${this.r}, ${this.g}, ${this.b})"
fun getWeatherList(classification: String) = weatherList[classification]!!
fun getRandomWeather(classification: String) =
getWeatherList(classification)[HQRNG().nextInt(getWeatherList(classification).size)]
@@ -178,8 +175,7 @@ object WeatherMixer {
fun readFromJson(path: String): BaseModularWeather {
/* JSON structure:
{
"globalLight": "colourmap/sky_colour.tga", // integer for static, string (path to image) for dynamic
"skyboxGradColourMap": "colourmap/sky_colour.tga", // integer for static, string (path to image) for dynamic
"skyboxGradColourMap": "colourmap/sky_colour.tga", // string (path to image) for dynamic. Image must be RGBA8888 or RGB888
"extraImages": [
// if any, it will be like:
sun01.tga,
@@ -193,25 +189,13 @@ object WeatherMixer {
val JSON = JsonFetcher(path)
val globalLightInJson = JSON.get("globalLight").asJsonPrimitive
val skyboxInJson = JSON.get("skyboxGradColourMap").asJsonPrimitive
val extraImagesPath = JSON.getAsJsonArray("extraImages")
val globalLight = if (globalLightInJson.isString)
GdxColorMap(ModMgr.getGdxFile("basegame", "$pathToImage/${globalLightInJson.asString}"))
else if (globalLightInJson.isNumber)
GdxColorMap(globalLightInJson.asNumber.toInt())
else
throw IllegalStateException("In weather descriptor $path -- globalLight seems malformed.")
val skybox = if (skyboxInJson.isString)
GdxColorMap(ModMgr.getGdxFile("basegame", "$pathToImage/${skyboxInJson.asString}"))
else if (globalLightInJson.isNumber)
GdxColorMap(skyboxInJson.asNumber.toInt())
else
throw IllegalStateException("In weather descriptor $path -- skyboxGradColourMap seems malformed.")
@@ -240,7 +224,6 @@ object WeatherMixer {
return BaseModularWeather(
globalLightColourMap = globalLight,
skyboxGradColourMap = skybox,
classification = classification,
extraImages = extraImages

View File

@@ -268,7 +268,7 @@ object LightmapRenderer {
val thisWall = Terrarum.ingame!!.world.getTileFromWall(x, y)
val thisTileLuminosity = BlockCodex[thisTerrain].luminosity // already been div by four
val thisTileOpacity = BlockCodex[thisTerrain].opacity // already been div by four
val sunLight = Terrarum.ingame!!.world.globalLight.cpy().mul(DIV_FLOAT, DIV_FLOAT, DIV_FLOAT, 1f)
val sunLight = Terrarum.ingame!!.world.globalLight.cpy().mul(DIV_FLOAT, DIV_FLOAT, DIV_FLOAT, DIV_FLOAT)
// MIX TILE
// open air
@@ -478,7 +478,7 @@ object LightmapRenderer {
* @param rgb2
* @return
*/
private infix fun Color.maxBlend(other: Color): Color {
infix fun Color.maxBlend(other: Color): Color {
return Color(
if (this.r > other.r) this.r else other.r,
if (this.g > other.g) this.g else other.g,