Skip to content

Commit

Permalink
improve fog distance calculation, thick nether fog
Browse files Browse the repository at this point in the history
  • Loading branch information
Bixilon committed Feb 29, 2024
1 parent d21f1d0 commit 48358f2
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 32 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# This software is not affiliated with Mojang AB, the original developer of Minecraft.
#
kotlin.daemon.jvmargs=-Xmx2G
kotlin.daemon.jvmargs=-Xmx3G
kotlin.code.style=official
javafx.version=19.0.2.1
lwjgl.version=3.3.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -14,7 +14,7 @@
package de.bixilon.minosoft.protocol.packets.s2c.play

import de.bixilon.minosoft.data.abilities.Gamemodes
import de.bixilon.minosoft.data.registries.dimension.effects.OverworldEffects
import de.bixilon.minosoft.data.registries.dimension.effects.minecraft.OverworldEffects
import org.testng.Assert.*
import org.testng.annotations.Test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -20,8 +20,8 @@ import de.bixilon.minosoft.config.profile.profiles.block.rendering.entities.Enti
class RenderingC(profile: BlockProfile) {

/**
* This option tries to do its best to fix any occurring [Moiré Patterns](https://en.wikipedia.org/wiki/Moir%C3%A9_pattern)
* If set position based random block models are disabled
* This option tries to do its best to fix any occurring [Moiré Patterns](https://en.wikipedia.org/wiki/Moir%C3%A9_pattern).
* If set position based random block models are enabled
*/
var antiMoirePattern by BooleanDelegate(profile, true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import de.bixilon.kutil.primitive.FloatUtil.toFloat
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.registries.dimension.effects.DefaultDimensionEffects
import de.bixilon.minosoft.data.registries.dimension.effects.DimensionEffects
import de.bixilon.minosoft.data.registries.dimension.effects.OverworldEffects
import de.bixilon.minosoft.data.registries.dimension.effects.minecraft.OverworldEffects
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.toResourceLocation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -13,6 +13,9 @@

package de.bixilon.minosoft.data.registries.dimension.effects

import de.bixilon.minosoft.data.registries.dimension.effects.minecraft.EndEffects
import de.bixilon.minosoft.data.registries.dimension.effects.minecraft.NetherEffects
import de.bixilon.minosoft.data.registries.dimension.effects.minecraft.OverworldEffects
import de.bixilon.minosoft.util.ResourceLocationMap

object DefaultDimensionEffects : ResourceLocationMap<DimensionEffects>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand Down Expand Up @@ -33,5 +33,5 @@ interface DimensionEffects : Identified {

val brighten: Vec3? get() = null

val fog: Boolean
val fog: FogEffects?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Minosoft
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/

package de.bixilon.minosoft.data.registries.dimension.effects

data class FogEffects(
val start: Float = 1.0f,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -11,10 +11,12 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/

package de.bixilon.minosoft.data.registries.dimension.effects
package de.bixilon.minosoft.data.registries.dimension.effects.minecraft

import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kutil.exception.Broken
import de.bixilon.minosoft.data.registries.dimension.effects.DimensionEffects
import de.bixilon.minosoft.data.registries.dimension.effects.FogEffects
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
Expand All @@ -37,5 +39,5 @@ object EndEffects : DimensionEffects {

override val brighten = Vec3(0.99f, 1.12f, 1.0f) // bit more green

override val fog: Boolean get() = false
override val fog: FogEffects? get() = null
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -11,9 +11,11 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/

package de.bixilon.minosoft.data.registries.dimension.effects
package de.bixilon.minosoft.data.registries.dimension.effects.minecraft

import de.bixilon.kutil.exception.Broken
import de.bixilon.minosoft.data.registries.dimension.effects.DimensionEffects
import de.bixilon.minosoft.data.registries.dimension.effects.FogEffects
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection

Expand All @@ -32,5 +34,5 @@ object NetherEffects : DimensionEffects {
override fun getCloudHeight(connection: PlayConnection): IntRange = Broken()


override val fog: Boolean get() = true
override val fog = FogEffects(0.5f)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
Expand All @@ -11,9 +11,11 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/

package de.bixilon.minosoft.data.registries.dimension.effects
package de.bixilon.minosoft.data.registries.dimension.effects.minecraft

import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
import de.bixilon.minosoft.data.registries.dimension.effects.DimensionEffects
import de.bixilon.minosoft.data.registries.dimension.effects.FogEffects
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection

Expand All @@ -37,7 +39,7 @@ object OverworldEffects : DimensionEffects {
return 128..132
}

override val fog: Boolean get() = true
override val fog = FogEffects()

override fun toString(): String {
return identifier.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ open class LavaFluid(identifier: ResourceLocation = Companion.identifier) : Flui
return LavaFluidModel()
}

override fun getFogOptions(world: World, position: EntityPositionInfo) = FOG_OPTIONS
override fun getFogOptions(world: World, position: EntityPositionInfo) = FOG_OPTIONS // TODO: check for fire resistance

companion object : FluidFactory<LavaFluid>, AliasedIdentified {
override val identifier = minecraft("lava")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.camera.fog

import de.bixilon.kutil.math.interpolation.FloatInterpolation.interpolateLinear
import de.bixilon.kutil.time.TimeUtil.millis
import de.bixilon.minosoft.data.registries.dimension.effects.FogEffects
import de.bixilon.minosoft.data.registries.effects.vision.VisionEffect
import de.bixilon.minosoft.data.text.formatting.color.ColorInterpolation.interpolateSine
import de.bixilon.minosoft.data.text.formatting.color.Colors
Expand All @@ -31,7 +32,7 @@ class FogManager(

private var interpolation = FogInterpolationStart()
private val state = FogState()
private var options = FogOptions()
private var options: FogOptions? = null


private var shaderRevision = -1
Expand All @@ -44,28 +45,32 @@ class FogManager(
updateShaders()
}

private fun getOptions(): FogOptions {
private fun getOptions(effects: FogEffects): FogOptions? {
val fluid = player.physics.submersion.eye

return when {
fluid is FoggedFluid -> fluid.getFogOptions(context.connection.world, player.physics.positionInfo)
player.effects[VisionEffect.Blindness] != null -> VisionEffect.Blindness.FOG_OPTIONS
// TODO: void fog (if under minY)
// TODO: powder snow
else -> {
val fogStart = (context.connection.world.view.viewDistance - 2.0f) * ProtocolDefinition.SECTION_WIDTH_X // could be improved? basically view distance in blocks and then the center of that chunk
FogOptions(fogStart, fogStart + 15.0f, null)
val end = (context.connection.world.view.viewDistance - 1.0f) * ProtocolDefinition.SECTION_WIDTH_X
val distance = end / 10.0f

FogOptions(effects.start * (end - distance), end)
}
}
}

private fun update() {
val sky = context.connection.world.dimension.effects
val enabled = sky.fog && context.connection.profiles.rendering.fog.enabled
val effects = context.connection.world.dimension.effects.fog
val enabled = effects != null && context.connection.profiles.rendering.fog.enabled
if (state.enabled != enabled) {
state.revision++
}
if (!state.enabled) return

val options = getOptions()
val options = getOptions(effects!!)
if (this.options == options) {
return
}
Expand All @@ -87,9 +92,9 @@ class FogManager(
private fun interpolate(time: Long = millis()) {
val delta = time - interpolation.change
val progress = delta / INTERPOLATE_DURATION.toFloat()
state.start = interpolateLinear(progress, interpolation.start, options.start)
state.end = interpolateLinear(progress, interpolation.end, options.end)
var color: RGBColor? = interpolateSine(progress, interpolation.color ?: Colors.TRANSPARENT, options.color ?: Colors.TRANSPARENT)
state.start = interpolateLinear(progress, interpolation.start, options?.start ?: 0.0f)
state.end = interpolateLinear(progress, interpolation.end, options?.end ?: 0.0f)
var color: RGBColor? = interpolateSine(progress, interpolation.color ?: Colors.TRANSPARENT, options?.color ?: Colors.TRANSPARENT)
if (color == Colors.TRANSPARENT) {
color = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ import de.bixilon.minosoft.physics.EntityPositionInfo

interface FoggedFluid {

fun getFogOptions(world: World, position: EntityPositionInfo): FogOptions
fun getFogOptions(world: World, position: EntityPositionInfo): FogOptions?
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ float fog_alpha_from_distance(float distance2) {

float fog_calculate_distance() {
vec3 distance = finFragmentPosition.xyz - uCameraPosition.xyz;
distance.y /= 2.0f;// increase possible distance on y axis
distance.y *= 0.7f;// increase possible distance on y axis
return dot(distance, distance);
}

Expand Down

0 comments on commit 48358f2

Please sign in to comment.