stars wip

This commit is contained in:
minjaesong
2023-08-02 17:52:42 +09:00
parent 821c7c77d8
commit 59d9adbbd1
5 changed files with 62 additions and 34 deletions

View File

@@ -42,7 +42,7 @@ object Skybox : Disposable {
// use internal LUT
/*operator fun get(elevationDeg: Double, turbidity: Double, albedo: Double): TextureRegion {
val elev = elevationDeg.coerceIn(-75.0, 75.0).times(2.0).roundToInt().plus(150)
val turb = turbidity.coerceIn(1.0, 10.0).minus(1.0).times(3.0).roundToInt()
val turb = turbidity.coerceIn(1.0, 10.0).minus(1.0).times(5.0).roundToInt()
val alb = albedo.coerceIn(0.1, 0.9).minus(0.1).times(5.0).roundToInt()
return gradTexBinLowAlbedo[elev * turbCnt + turb]
}*/
@@ -57,7 +57,7 @@ object Skybox : Disposable {
}
fun getUV(elevationDeg: Double, turbidity: Double, albedo: Double): Pair<Texture, FloatArray> {
val turb = turbidity.coerceIn(1.0, 10.0).minus(1.0).times(3.0).roundToInt()
val turb = turbidity.coerceIn(1.0, 10.0).minus(1.0).times(5.0).roundToInt()
val alb = albedo.coerceIn(0.1, 0.9).minus(0.1).times(5.0).roundToInt()
val region = texStripRegions.get(alb, turb)

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.math.Vector2
import com.jme3.math.FastMath
import net.torvald.gdx.graphics.Cvec
import net.torvald.random.HQRNG
@@ -15,7 +16,6 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.WorldTime
import net.torvald.terrarum.gameworld.WorldTime.Companion.DAY_LENGTH
import net.torvald.terrarum.modulebasegame.IngameRenderer
import net.torvald.terrarum.modulebasegame.RNGConsumer
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.clut.Skybox
@@ -67,9 +67,12 @@ internal object WeatherMixer : RNGConsumer {
var forceSolarElev: Double? = null
var forceTurbidity: Double? = null
val starmapTex: TextureRegion = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "weathers/astrum.png")))
val starmapTex: TextureRegion = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "weathers/astrum.png"))).also {
// it.texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear)
it.texture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat)
}
private val shaderBlendMax = App.loadShaderFromClasspath("shaders/blendMax.vert", "shaders/blendMax.frag")
private val shaderBlendMax = App.loadShaderFromClasspath("shaders/blendSkyboxStars.vert", "shaders/blendSkyboxStars.frag")
override fun loadFromSave(s0: Long, s1: Long) {
super.loadFromSave(s0, s1)
@@ -214,10 +217,22 @@ internal object WeatherMixer : RNGConsumer {
val gradY = -(gH - App.scr.height) * ((parallax + 1f) / 2f)
val (tex, uvs) = Skybox.getUV(solarElev, thisTurbidity, 0.3)
starmapTex.texture.bind(1)
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
batch.inUse {
batch.shader = null
batch.shader = shaderBlendMax
shaderBlendMax.setUniformi("tex1", 1)
shaderBlendMax.setUniformf("screenSize", App.scr.wf, App.scr.hf)
shaderBlendMax.setUniformf("drawOffset", 0f, gradY)
shaderBlendMax.setUniformf("drawOffsetSize", App.scr.wf, gH)
shaderBlendMax.setUniform2fv("skyboxUV1", uvs, 0, 2)
shaderBlendMax.setUniform2fv("skyboxUV2", uvs, 2, 2)
batch.color = Color.WHITE
batch.draw(tex, 0f, gradY, App.scr.wf, gH, uvs[0], uvs[1], uvs[2], uvs[3])
batch.draw(tex, 0f, gradY, App.scr.wf, gH, 0f, 0f, 1f, 1f)
batch.color = Color.WHITE
}

View File

@@ -1,22 +0,0 @@
#version 150
#ifdef GL_ES
precision mediump float;
#endif
in vec4 v_color;
in vec2 v_texCoord0;
in vec2 v_texCoord1;
uniform sampler2D u_texture; // world texture, has alpha value that is meaningful
uniform sampler2D tex1; // glow texture, SHOULD contain alpha of all 1.0
out vec4 fragColor;
vec2 boolean = vec2(0.0, 1.0);
void main(void) {
vec4 colorTex0 = texture(u_texture, v_texCoord0); // lightmap (RGB) pre-mixed
vec4 colorTex1 = texture(tex1, v_texCoord1); // lightmap (A) pre-mixed
// fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + boolean.xxxy;
fragColor = colorTex0;
}

View File

@@ -0,0 +1,38 @@
#version 150
#ifdef GL_ES
precision mediump float;
#endif
in vec4 v_color;
in vec2 v_texCoords;
uniform sampler2D u_texture; // world texture, has alpha value that is meaningful
uniform sampler2D tex1; // glow texture, SHOULD contain alpha of all 1.0
out vec4 fragColor;
vec2 boolean = vec2(0.0, 1.0);
uniform vec2 screenSize;
uniform vec2 drawOffset; // value of the 'gradY'
uniform vec2 drawOffsetSize; // value of the 'gradH'
uniform vec2 skyboxUV1; // (u, v) for the skybox drawing
uniform vec2 skyboxUV2; // (u2, v2) for the skybox drawing
uniform vec2 tex1Size = vec2(4096.0, 4096.0);
uniform vec2 astrumScroll = vec2(0.0, 0.0);
// draw call to this function must use UV coord of (0,0,1,1)!
void main(void) {
vec2 skyboxTexCoord = mix(skyboxUV1, skyboxUV2, v_texCoords);
vec2 astrumTexCoord = (v_texCoords * drawOffsetSize + drawOffset + astrumScroll) / tex1Size;
vec4 colorTex0 = texture(u_texture, skyboxTexCoord); // lightmap (RGB) pre-mixed
vec4 colorTex1 = texture(tex1, astrumTexCoord); // lightmap (A) pre-mixed
// fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + boolean.xxxy;
fragColor = colorTex0;
}

View File

@@ -3,17 +3,14 @@
in vec4 a_position;
in vec4 a_color;
in vec2 a_texCoord0;
in vec2 a_texCoord1;
uniform mat4 u_projTrans; // camera.combined
out vec4 v_color;
out vec2 v_texCoord0;
out vec2 v_texCoord1;
out vec2 v_texCoords;
void main() {
v_color = a_color;
v_texCoord0 = a_texCoord0;
v_texCoord1 = a_texCoord1;
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}