parallax (sky looks bluer when you go up)

This commit is contained in:
minjaesong
2017-07-20 18:39:05 +09:00
parent 5d86f054e8
commit 6f2c1e578e
35 changed files with 144 additions and 17 deletions

2
.gitignore vendored
View File

@@ -5,3 +5,5 @@ Thumbs.db
*.jar *.jar
.DS_Store .DS_Store
~$* ~$*
assets/modules/basegame/demoworld
assets/modules/basegame/demoworld.gz

View File

@@ -5,6 +5,8 @@ uniform sampler2D u_texture;
uniform vec3 topColor; uniform vec3 topColor;
uniform vec3 bottomColor; uniform vec3 bottomColor;
uniform float parallax = 0.0; // +1.0: all top col, -1.0: all bototm col, 0.0: normal grad
uniform float parallax_size = 1.0/3.0; // 0: no parallax
// "steps" of R, G and B. Must be integer && equal or greater than 2 // "steps" of R, G and B. Must be integer && equal or greater than 2
@@ -48,7 +50,9 @@ vec4 nearestColour(vec4 incolor) {
void main(void) { void main(void) {
float spread = 1.0 / (0.299 * (rcount - 1.0) + 0.587 * (gcount - 1.0) + 0.114 * (bcount - 1.0)); // this spread value is optimised one -- try your own values for various effects! float spread = 1.0 / (0.299 * (rcount - 1.0) + 0.587 * (gcount - 1.0) + 0.114 * (bcount - 1.0)); // this spread value is optimised one -- try your own values for various effects!
float scale = v_texCoords.y; float scale = v_texCoords.y * (1.0 - parallax_size) + (parallax_size / 2.0) + (parallax * parallax_size / 2.0);
float inR = mix(bottomColor.r, topColor.r, scale); float inR = mix(bottomColor.r, topColor.r, scale);
float inG = mix(bottomColor.g, topColor.g, scale); float inG = mix(bottomColor.g, topColor.g, scale);
float inB = mix(bottomColor.b, topColor.b, scale); float inB = mix(bottomColor.b, topColor.b, scale);
@@ -58,4 +62,16 @@ void main(void) {
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize)); vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
gl_FragColor = nearestColour(inColor + spread * (bayer[int(entry.y)][int(entry.x)] / bayerDivider - 0.5)); gl_FragColor = nearestColour(inColor + spread * (bayer[int(entry.y)][int(entry.x)] / bayerDivider - 0.5));
} }
/*
UV mapping coord.y
-+ <- 1.0 =
D| = // parallax of +1
i| = =
s| = // parallax of 0
p| = =
.| = // parallax of -1
-+ <- 0.0 =
*/

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Модули"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Moduly"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Moduler"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Modulen"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Ενότητες"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Modules"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Módulos"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Moduulit"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Modules"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Modulok"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Einingar"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Moduli"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "モジュール"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "モジュール"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "모듈"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Modules"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Moduler"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Moduły"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Módulos"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Módulos"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Module"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Модули"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Moduler"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "โมดูล"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "Modüller"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "模块"
}

View File

@@ -0,0 +1,3 @@
{
"MENU_MODULES" : "模塊"
}

View File

@@ -400,18 +400,18 @@ object Terrarum : Game() {
//ingame = Ingame(batch) ingame = Ingame(batch)
//ingame!!.gameLoadInfoPayload = Ingame.NewWorldParameters(8192, 2048, HQRNG().nextLong()) //ingame!!.gameLoadInfoPayload = Ingame.NewWorldParameters(8192, 2048, HQRNG().nextLong())
// TODO: create world being used by title screen, and serialise it. // TODO: create world being used by title screen, and serialise it.
//ingame!!.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong()) ingame!!.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
//ingame!!.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW ingame!!.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
//LoadScreen.screenToLoad = ingame!! LoadScreen.screenToLoad = ingame!!
super.setScreen(TitleScreen(batch)) //super.setScreen(TitleScreen(batch))
//super.setScreen(LoadScreen) super.setScreen(LoadScreen)
//super.setScreen(ingame) //super.setScreen(ingame)
} }

View File

@@ -79,7 +79,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
) )
cameraPlayer.hitbox.setDimension(2.0, 2.0) cameraPlayer.hitbox.setDimension(2.0, 2.0)
demoWorld.time.timeDelta = 45 demoWorld.time.timeDelta = 60
LightmapRenderer.world = demoWorld LightmapRenderer.world = demoWorld

View File

@@ -12,6 +12,7 @@ class UIStartMenu : UICanvas() {
"MENU_MODE_SINGLEPLAYER", "MENU_MODE_SINGLEPLAYER",
"MENU_OPTIONS", "MENU_OPTIONS",
"MENU_MODULES", "MENU_MODULES",
"MENU_LABEL_LANGUAGE",
"MENU_LABEL_EXIT" "MENU_LABEL_EXIT"
) )
@@ -34,6 +35,8 @@ class UIStartMenu : UICanvas() {
readFromLang = true, readFromLang = true,
activeBackCol = Color(0), activeBackCol = Color(0),
highlightBackCol = Color(0), highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null defaultSelection = null
) )

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.weather
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.* import com.badlogic.gdx.graphics.*
import javafx.scene.effect.Light
import net.torvald.terrarum.utils.JsonFetcher import net.torvald.terrarum.utils.JsonFetcher
import net.torvald.colourutil.* import net.torvald.colourutil.*
import net.torvald.random.HQRNG import net.torvald.random.HQRNG
@@ -11,6 +12,10 @@ import net.torvald.terrarum.gameactors.ParticleTestRain
import net.torvald.terrarum.gamecontroller.KeyToggler import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.WorldTime import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarum.worldgenerator.WorldGenerator
import java.io.File import java.io.File
import java.util.* import java.util.*
@@ -89,6 +94,9 @@ object WeatherMixer {
} }
private val parallaxZeroPos = WorldGenerator.TERRAIN_AVERAGE_HEIGHT// + WorldGenerator.TERRAIN_UNDULATION.div(2)
private val parallaxDomainSize = WorldGenerator.TERRAIN_UNDULATION / 2f
fun render(camera: Camera, world: GameWorld) { fun render(camera: Camera, world: GameWorld) {
// we will not care for nextSkybox for now // we will not care for nextSkybox for now
@@ -100,16 +108,33 @@ object WeatherMixer {
globalLightNow.set(globalLight) globalLightNow.set(globalLight)
/* (copied from the shader source)
UV mapping coord.y
-+ <- 1.0 =
D| = // parallax of +1
i| = =
s| = // parallax of 0
p| = =
.| = // parallax of -1
-+ <- 0.0 =
*/
val parallax: Float = (parallaxZeroPos - WorldCamera.gdxCamY.div(FeaturesDrawer.TILE_SIZE.toFloat())) / parallaxDomainSize
// draw skybox to provided graphics instance // draw skybox to provided graphics instance
val topCol = getGradientColour(skyboxColourMap, 0, timeNow) val topCol = getGradientColour(skyboxColourMap, 0, timeNow)
val bottomCol = getGradientColour(skyboxColourMap, 1, timeNow) val bottomCol = getGradientColour(skyboxColourMap, 1, timeNow)
println("zero pos: $parallaxZeroPos, domain_size: $parallaxDomainSize")
//Terrarum.textureWhiteSquare.bind(0) //Terrarum.textureWhiteSquare.bind(0)
Terrarum.shaderBayerSkyboxFill.begin() Terrarum.shaderBayerSkyboxFill.begin()
Terrarum.shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined) Terrarum.shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined)
Terrarum.shaderBayerSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b) Terrarum.shaderBayerSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b)
Terrarum.shaderBayerSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b) Terrarum.shaderBayerSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b)
Terrarum.shaderBayerSkyboxFill.setUniformf("parallax", parallax)
Terrarum.fullscreenQuad.render(Terrarum.shaderBayerSkyboxFill, GL20.GL_TRIANGLES) Terrarum.fullscreenQuad.render(Terrarum.shaderBayerSkyboxFill, GL20.GL_TRIANGLES)
Terrarum.shaderBayerSkyboxFill.end() Terrarum.shaderBayerSkyboxFill.end()
} }

View File

@@ -39,16 +39,16 @@ object WorldGenerator {
private val NOISE_SIMPLEX_ORE_START = 1.42 private val NOISE_SIMPLEX_ORE_START = 1.42
private val NOISE_SIMPLEX_ORE_END = 1.28 private val NOISE_SIMPLEX_ORE_END = 1.28
private val TERRAIN_UNDULATION = 200 val TERRAIN_UNDULATION = 200
private val SIMPLEXGEN_LARGEST_FEATURE = 200 val SIMPLEXGEN_LARGEST_FEATURE = 200
private var OCEAN_WIDTH = 400 var OCEAN_WIDTH = 400
private var SHORE_WIDTH = 120 var SHORE_WIDTH = 120
private val MAX_OCEAN_DEPTH = 200 val MAX_OCEAN_DEPTH = 200
private var GLACIER_MOUNTAIN_WIDTH = 900 var GLACIER_MOUNTAIN_WIDTH = 900
private val GLACIER_MOUNTAIN_HEIGHT = 300 val GLACIER_MOUNTAIN_HEIGHT = 300
private val CAVEGEN_THRE_START = 0.4 private val CAVEGEN_THRE_START = 0.4
private val CAVEGEN_THRE_END = 0.1 private val CAVEGEN_THRE_END = 0.1