Skip to content

Commit

Permalink
fog flags, improve and refactor fog
Browse files Browse the repository at this point in the history
FogFlags are way cleaner and allow further extension of the fog system (e.g. custom behavior for versions, change shape of shader, ...)

This fixe the invisible block glitch when being e.g. in a debugger/profiler while joining (the fog settings were messed up because the interpolation sucked)
  • Loading branch information
Bixilon committed Feb 29, 2024
1 parent f3f6380 commit d21f1d0
Show file tree
Hide file tree
Showing 21 changed files with 374 additions and 230 deletions.
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 @@ -18,8 +18,10 @@ import de.bixilon.minosoft.data.registries.effects.properties.categories.Benefic
import de.bixilon.minosoft.data.registries.effects.properties.categories.HarmfulEffect
import de.bixilon.minosoft.data.registries.identified.Identified
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.data.text.formatting.color.Colored
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor
import de.bixilon.minosoft.gui.rendering.camera.fog.FogOptions

interface VisionEffect {

Expand All @@ -32,6 +34,7 @@ interface VisionEffect {
object Blindness : StatusEffectType(), VisionEffect, Identified, Colored, HarmfulEffect {
override val identifier = minecraft("blindness")
override val color = 0x1F1F23.asRGBColor()
val FOG_OPTIONS = FogOptions(start = 3.0f, end = 5.0f, color = ChatColors.BLACK)
}

object NightVision : StatusEffectType(), VisionEffect, Identified, Colored, BeneficalEffect {
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 @@ -27,19 +27,24 @@ import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.particle.ParticleType
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.gui.rendering.camera.fog.FogOptions
import de.bixilon.minosoft.gui.rendering.camera.fog.FoggedFluid
import de.bixilon.minosoft.gui.rendering.models.fluid.fluids.LavaFluidModel
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.lava.LavaParticle
import de.bixilon.minosoft.gui.rendering.util.VecUtil.horizontal
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3d
import de.bixilon.minosoft.physics.EntityPositionInfo
import de.bixilon.minosoft.physics.entities.EntityPhysics
import de.bixilon.minosoft.physics.entities.living.LivingEntityPhysics
import de.bixilon.minosoft.physics.input.MovementInput
import de.bixilon.minosoft.physics.parts.input.InputPhysics.applyMovementInput
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import java.util.*

open class LavaFluid(identifier: ResourceLocation = Companion.identifier) : Fluid(identifier), FluidCollisionHandler {
open class LavaFluid(identifier: ResourceLocation = Companion.identifier) : Fluid(identifier), FluidCollisionHandler, FoggedFluid {
private val lavaParticleType: ParticleType = unsafeNull()
override val priority: Int get() = 1

Expand Down Expand Up @@ -75,7 +80,6 @@ open class LavaFluid(identifier: ResourceLocation = Companion.identifier) : Flui
return other is LavaFluid
}


override fun randomTick(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, random: Random) {
super.randomTick(connection, blockState, blockPosition, random)
val particle = connection.world.particle ?: return
Expand Down Expand Up @@ -103,9 +107,12 @@ open class LavaFluid(identifier: ResourceLocation = Companion.identifier) : Flui
return LavaFluidModel()
}

override fun getFogOptions(world: World, position: EntityPositionInfo) = FOG_OPTIONS

companion object : FluidFactory<LavaFluid>, AliasedIdentified {
override val identifier = minecraft("lava")
override val identifiers = setOf(minecraft("flowing_lava"))
private val FOG_OPTIONS = FogOptions(start = 0.2f, end = 1.0f, color = RGBColor(0.6f, 0.1f, 0.0f))
const val FRICTION = 0.5

override fun build(resourceLocation: ResourceLocation, registries: Registries) = LavaFluid()
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 @@ -32,12 +32,16 @@ import de.bixilon.minosoft.data.registries.identified.AliasedIdentified
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.gui.rendering.camera.fog.FogOptions
import de.bixilon.minosoft.gui.rendering.camera.fog.FoggedFluid
import de.bixilon.minosoft.gui.rendering.models.fluid.fluids.WaterFluidModel
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.water.UnderwaterParticle
import de.bixilon.minosoft.gui.rendering.tint.TintedBlock
import de.bixilon.minosoft.gui.rendering.tint.tints.fluid.WaterTintProvider
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3d
import de.bixilon.minosoft.physics.EntityPositionInfo
import de.bixilon.minosoft.physics.entities.EntityPhysics
import de.bixilon.minosoft.physics.entities.living.LivingEntityPhysics
import de.bixilon.minosoft.physics.input.MovementInput
Expand All @@ -47,7 +51,7 @@ import de.bixilon.minosoft.physics.parts.input.InputPhysics.applyMovementInput
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import java.util.*

class WaterFluid(resourceLocation: ResourceLocation = identifier) : Fluid(resourceLocation), FluidEnterHandler, FluidCollisionHandler, TintedBlock {
class WaterFluid(resourceLocation: ResourceLocation = identifier) : Fluid(resourceLocation), FluidEnterHandler, FluidCollisionHandler, TintedBlock, FoggedFluid {
override val priority: Int get() = 0
override val tintProvider get() = WaterTintProvider

Expand Down Expand Up @@ -136,6 +140,10 @@ class WaterFluid(resourceLocation: ResourceLocation = identifier) : Fluid(resour
onCollision(physics, height)
}

override fun getFogOptions(world: World, position: EntityPositionInfo): FogOptions {
return FogOptions(start = 5.0f, end = 10.0f, color = position.biome?.waterFogColor)
}

companion object : FluidFactory<WaterFluid>, AliasedIdentified {
override val identifier = minecraft("water")
override val identifiers = setOf(minecraft("flowing_water"))
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 @@ -19,6 +19,7 @@ import de.bixilon.kutil.time.TimeUtil.millis
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.RenderUtil.runAsync
import de.bixilon.minosoft.gui.rendering.camera.fog.FogManager
import de.bixilon.minosoft.gui.rendering.camera.view.ViewManager
import de.bixilon.minosoft.gui.rendering.camera.visibility.WorldVisibilityGraph

Expand Down
176 changes: 0 additions & 176 deletions src/main/java/de/bixilon/minosoft/gui/rendering/camera/FogManager.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.gui.rendering.camera.fog

import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.kutil.enums.ValuesEnum.Companion.names

enum class FogFlags {
ENABLE,
USE_COLOR,
;


val mask = 0x01 shl ordinal


companion object : ValuesEnum<FogFlags> {
override val VALUES = values()
override val NAME_MAP = names()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.gui.rendering.camera.fog

import de.bixilon.minosoft.data.text.formatting.color.RGBColor

class FogInterpolationStart {
var start: Float = 0.0f
var end: Float = 0.0f
var color: RGBColor? = null
var change = -1L
}
Loading

0 comments on commit d21f1d0

Please sign in to comment.