stars: more realistic twinkle, change of axial tilt changes starmap 'altitude'

This commit is contained in:
minjaesong
2023-08-03 23:55:19 +09:00
parent c73461a407
commit 385a882937
3 changed files with 25 additions and 9 deletions

View File

@@ -135,11 +135,18 @@ class WorldTime(initTime: Long = 0L) {
val x = (TIME_T % YEAR_SECONDS).toDouble() / DAY_LENGTH + 15 // decimal days. One full day = 1.0
// 51.56 and 23.44 will make yearly min/max elevation to be 75deg
val d = -23.44 * cos(TWO_PI * x / YEAR_DAYS)
return -51.56 * cos(TWO_PI * x) + d
val p = -51.56 * cos(TWO_PI * x)
return d + p
}
val solarElevationRad: Double
get() = Math.toRadians(solarElevationDeg)
val axialTiltDeg: Double
get() {
val x = (TIME_T % YEAR_SECONDS).toDouble() / DAY_LENGTH + 15 // decimal days. One full day = 1.0
return -23.44 * cos(TWO_PI * x / YEAR_DAYS)
}
@Transient private var realSecAcc: Double = 0.0
@Transient private val REAL_SEC_TO_GAME_SECS = 1.0 / GAME_MIN_TO_REAL_SEC // how slow is real-life clock (second-wise) relative to the ingame one

View File

@@ -230,6 +230,7 @@ internal object WeatherMixer : RNGConsumer {
starmapTex.texture.bind(1)
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
val astrumX = world.worldTime.axialTiltDeg.toFloat() * starmapTex.regionWidth / 150f
val astrumY = ((world.worldTime.TIME_T / WorldTime.DIURNAL_MOTION_LENGTH) % 1f) * starmapTex.regionHeight
batch.inUse {
@@ -239,16 +240,16 @@ internal object WeatherMixer : RNGConsumer {
shaderBlendMax.setUniformf("drawOffsetSize", App.scr.wf, gH)
shaderBlendMax.setUniform2fv("skyboxUV1", uvs, 0, 2)
shaderBlendMax.setUniform2fv("skyboxUV2", uvs, 2, 2)
shaderBlendMax.setUniformf("astrumScroll", astrumOffX, astrumOffY + astrumY)
shaderBlendMax.setUniformf("astrumScroll", astrumOffX + astrumX, astrumOffY + astrumY)
shaderBlendMax.setUniformf("randomNumber",
// (world.worldTime.TIME_T.plus(31L) xor 1453L + 31L).and(1023).toFloat(),
// (world.worldTime.TIME_T.plus(37L) xor 862L + 31L).and(1023).toFloat(),
// (world.worldTime.TIME_T.plus(23L) xor 1639L + 29L).and(1023).toFloat(),
// (world.worldTime.TIME_T.plus(29L) xor 2971L + 41L).and(1023).toFloat(),
world.worldTime.TIME_T.div(4.1f).plus(31L),
world.worldTime.TIME_T.div(-3.8f).plus(37L),
world.worldTime.TIME_T.div(3.9f).plus(23L),
world.worldTime.TIME_T.div(-4.3f).plus(29L),
world.worldTime.TIME_T.div(+12.1f).plus(31L),
world.worldTime.TIME_T.div(-11.8f).plus(37L),
world.worldTime.TIME_T.div(+11.9f).plus(23L),
world.worldTime.TIME_T.div(-12.3f).plus(29L),
)
batch.color = Color.WHITE
@@ -256,6 +257,7 @@ internal object WeatherMixer : RNGConsumer {
batch.color = Color.WHITE
}
}
private operator fun Color.times(other: Color) = Color(this.r * other.r, this.g * other.g, this.b * other.b, 1f)

View File

@@ -19,7 +19,7 @@ uniform vec2 skyboxUV1; // (u, v) for the skybox drawing
uniform vec2 skyboxUV2; // (u2, v2) for the skybox drawing
uniform vec2 tex1Size = vec2(4096.0);
uniform vec2 astrumScroll = vec2(0.0);
uniform vec4 randomNumber = vec4(0.0);
uniform vec4 randomNumber = vec4(1.0, -2.0, 3.0, -4.0);
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
@@ -83,11 +83,17 @@ float snoise(vec2 v)
}
vec4 snoise4(vec2 v) {
return vec4(
/*return vec4(
(snoise(v + randomNumber.xy) + snoise(v + randomNumber.zx)) * 0.5,
(snoise(v + randomNumber.zw) + snoise(v + randomNumber.yw)) * 0.5,
(snoise(v + randomNumber.xz) + snoise(v + randomNumber.yx)) * 0.5,
(snoise(v + randomNumber.yw) + snoise(v + randomNumber.wz)) * 0.5 // triangular distribution
);*/
return vec4(
(snoise(v + randomNumber.xy) + snoise(v + randomNumber.zx) + snoise(v + randomNumber.zw) + snoise(v + randomNumber.yw)) * 0.25,
(snoise(v + randomNumber.zw) + snoise(v + randomNumber.yw) + snoise(v + randomNumber.xz) + snoise(v + randomNumber.yx)) * 0.25,
(snoise(v + randomNumber.xz) + snoise(v + randomNumber.yx) + snoise(v + randomNumber.yw) + snoise(v + randomNumber.wz)) * 0.25,
(snoise(v + randomNumber.yw) + snoise(v + randomNumber.wz) + snoise(v + randomNumber.xy) + snoise(v + randomNumber.zx)) * 0.25
);
}
@@ -109,7 +115,7 @@ void main(void) {
vec2 skyboxTexCoord = mix(skyboxUV1, skyboxUV2, v_texCoords);
vec2 astrumTexCoord = (v_texCoords * drawOffsetSize + drawOffset + astrumScroll) / tex1Size;
vec4 randomness = snoise4(gl_FragCoord.xy * 0.16) * 2.0; // multiply by 2 so that the "density" of the stars would be same as the non-random version
vec4 randomness = snoise4((gl_FragCoord.xy - astrumScroll) * 0.16) * 2.0; // multiply by 2 so that the "density" of the stars would be same as the non-random version
vec4 colorTex0 = texture(u_texture, skyboxTexCoord);
@@ -120,4 +126,5 @@ void main(void) {
fragColor = (max(colorTex0, colorTex1) * boolean.yyyx) + boolean.xxxy;
// fragColor = colorTex1;
// fragColor = randomness * boolean.yyyx + boolean.xxxy;
// fragColor = (randomness.rrrr + (colorTex1 * vec4(2.0, -2.0, 2.0, 1.0))) * boolean.yyyx + boolean.xxxy;
}