mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
far better fog, improvements
This commit is contained in:
parent
5f93c19690
commit
99febe97be
@ -55,6 +55,10 @@ class Chunk(
|
|||||||
val isFullyLoaded: Boolean
|
val isFullyLoaded: Boolean
|
||||||
get() = isLoaded && neighboursLoaded
|
get() = isLoaded && neighboursLoaded
|
||||||
|
|
||||||
|
init {
|
||||||
|
// connection.world.view.updateServerViewDistance(chunkPosition, true)
|
||||||
|
}
|
||||||
|
|
||||||
operator fun get(sectionHeight: Int): ChunkSection? = sections?.getOrNull(sectionHeight - lowestSection)
|
operator fun get(sectionHeight: Int): ChunkSection? = sections?.getOrNull(sectionHeight - lowestSection)
|
||||||
|
|
||||||
fun unsafeGet(x: Int, y: Int, z: Int): BlockState? {
|
fun unsafeGet(x: Int, y: Int, z: Int): BlockState? {
|
||||||
|
@ -128,6 +128,7 @@ class World(
|
|||||||
neighbour.neighboursLoaded = false
|
neighbour.neighboursLoaded = false
|
||||||
connection.fireEvent(ChunkDataChangeEvent(connection, EventInitiators.UNKNOWN, neighbourPosition, neighbour))
|
connection.fireEvent(ChunkDataChangeEvent(connection, EventInitiators.UNKNOWN, neighbourPosition, neighbour))
|
||||||
}
|
}
|
||||||
|
// connection.world.view.updateServerViewDistance(chunkPosition, false)
|
||||||
connection.fireEvent(ChunkUnloadEvent(connection, EventInitiators.UNKNOWN, chunkPosition, chunk))
|
connection.fireEvent(ChunkUnloadEvent(connection, EventInitiators.UNKNOWN, chunkPosition, chunk))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,51 +1,88 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.camera
|
package de.bixilon.minosoft.gui.rendering.camera
|
||||||
|
|
||||||
|
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||||
|
import de.bixilon.minosoft.data.registries.effects.DefaultStatusEffects
|
||||||
|
import de.bixilon.minosoft.data.registries.fluid.water.WaterFluid
|
||||||
import de.bixilon.minosoft.data.text.ChatColors
|
import de.bixilon.minosoft.data.text.ChatColors
|
||||||
import de.bixilon.minosoft.data.text.RGBColor
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
import de.bixilon.minosoft.util.delegate.watcher.SimpleDelegateWatcher.Companion.watchRendering
|
import de.bixilon.minosoft.util.delegate.watcher.SimpleDelegateWatcher.Companion.watchRendering
|
||||||
|
|
||||||
@Deprecated("Needs some refactoring and improvements")
|
|
||||||
class FogManager(
|
class FogManager(
|
||||||
private val renderWindow: RenderWindow,
|
private val renderWindow: RenderWindow,
|
||||||
) {
|
) {
|
||||||
private var upToDate = false
|
private val blindness = renderWindow.connection.registries.statusEffectRegistry[DefaultStatusEffects.BLINDNESS]
|
||||||
|
private val player = renderWindow.connection.player
|
||||||
|
|
||||||
var fogColor: RGBColor = ChatColors.GREEN
|
var fogColor: RGBColor? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if (field == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
field = value
|
field = value
|
||||||
upToDate = false
|
updateShaders = true
|
||||||
}
|
}
|
||||||
private var fogStart = 0.0f
|
private var fogStart = 0.0f
|
||||||
|
set(value) {
|
||||||
|
if (field == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
field = value
|
||||||
|
updateShaders = true
|
||||||
|
}
|
||||||
private var fogEnd = 0.0f
|
private var fogEnd = 0.0f
|
||||||
|
set(value) {
|
||||||
|
if (field == value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
field = value
|
||||||
|
updateShaders = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private var updateShaders = true
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
renderWindow.connection.world.view::viewDistance.watchRendering(this, true) { calculateFog() }
|
renderWindow.connection.world.view::viewDistance.watchRendering(this, true) { calculateFog() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun draw() {
|
fun draw() {
|
||||||
if (upToDate) {
|
calculateFog()
|
||||||
|
if (!updateShaders) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
calculateFog()
|
|
||||||
updateShaders()
|
updateShaders()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateFog() {
|
private fun calculateFog() {
|
||||||
if (!renderWindow.connection.profiles.rendering.fog.enabled) {
|
var fogStart = if (!renderWindow.connection.profiles.rendering.fog.enabled) {
|
||||||
// ToDo: This is not improving performance
|
Float.MAX_VALUE
|
||||||
fogStart = Float.MAX_VALUE
|
|
||||||
fogEnd = Float.MAX_VALUE
|
|
||||||
} else {
|
} else {
|
||||||
fogStart = renderWindow.connection.world.view.viewDistance * 16.0f - 8.0f // ToDo
|
renderWindow.connection.world.view.viewDistance * ProtocolDefinition.SECTION_WIDTH_X - (ProtocolDefinition.SECTION_WIDTH_X / 2.0f) // could be improved? basically view distance in blocks and then the center of that chunk
|
||||||
fogEnd = fogStart + 10.0f
|
|
||||||
}
|
}
|
||||||
renderWindow.renderer[SkyRenderer]?.let { fogColor = it.baseColor }
|
var fogEnd = fogStart + 15.0f
|
||||||
|
var color: RGBColor? = null
|
||||||
|
|
||||||
|
player.submergedFluid?.nullCast<WaterFluid>()?.let {
|
||||||
|
color = player.positionInfo.biome?.waterFogColor
|
||||||
|
fogStart = 5.0f
|
||||||
|
fogEnd = 10.0f
|
||||||
|
} ?: player.activeStatusEffects[blindness]?.let {
|
||||||
|
color = ChatColors.BLACK
|
||||||
|
fogStart = 3.0f
|
||||||
|
fogEnd = 5.0f
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fogStart = fogStart
|
||||||
|
this.fogEnd = fogEnd
|
||||||
|
this.fogColor = color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun updateShaders() {
|
private fun updateShaders() {
|
||||||
|
val start = fogStart
|
||||||
|
val end = fogEnd
|
||||||
|
val color = fogColor
|
||||||
for (shader in renderWindow.renderSystem.shaders) {
|
for (shader in renderWindow.renderSystem.shaders) {
|
||||||
if (!shader.uniforms.contains("uFogColor")) {
|
if (!shader.uniforms.contains("uFogColor")) {
|
||||||
continue
|
continue
|
||||||
@ -53,9 +90,15 @@ class FogManager(
|
|||||||
|
|
||||||
shader.use()
|
shader.use()
|
||||||
|
|
||||||
shader.setFloat("uFogStart", fogStart)
|
shader["uFogStart"] = start
|
||||||
shader.setFloat("uFogEnd", fogEnd)
|
shader["uFogEnd"] = end
|
||||||
shader["uFogColor"] = fogColor
|
if (color == null) {
|
||||||
|
shader["uUseFogColor"] = false
|
||||||
|
} else {
|
||||||
|
shader["uFogColor"] = color
|
||||||
|
shader["uUseFogColor"] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
updateShaders = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ interface IntegratedFramebuffer : Drawable {
|
|||||||
shader.load()
|
shader.load()
|
||||||
shader.use()
|
shader.use()
|
||||||
shader.setInt("uColor", 0)
|
shader.setInt("uColor", 0)
|
||||||
shader.setInt("uDepth", 1)
|
// shader.setInt("uDepth", 1)
|
||||||
mesh.load()
|
mesh.load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class SkyRenderer(
|
|||||||
private var skySunMesh = SimpleTextureMesh(renderWindow)
|
private var skySunMesh = SimpleTextureMesh(renderWindow)
|
||||||
private lateinit var sunTexture: AbstractTexture
|
private lateinit var sunTexture: AbstractTexture
|
||||||
private var updateSun: Boolean = true
|
private var updateSun: Boolean = true
|
||||||
var baseColor = RenderConstants.DEFAULT_SKY_COLOR
|
private var baseColor = RenderConstants.DEFAULT_SKY_COLOR
|
||||||
override val framebuffer: Framebuffer? = null
|
override val framebuffer: Framebuffer? = null
|
||||||
override val polygonMode: PolygonModes = PolygonModes.DEFAULT
|
override val polygonMode: PolygonModes = PolygonModes.DEFAULT
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ interface Shader {
|
|||||||
fun setVec4(uniformName: String, vec4: Vec4)
|
fun setVec4(uniformName: String, vec4: Vec4)
|
||||||
fun setArray(uniformName: String, array: Array<*>)
|
fun setArray(uniformName: String, array: Array<*>)
|
||||||
fun setRGBColor(uniformName: String, color: RGBColor)
|
fun setRGBColor(uniformName: String, color: RGBColor)
|
||||||
|
fun setBoolean(uniformName: String, boolean: Boolean)
|
||||||
fun setTexture(uniformName: String, textureId: Int)
|
fun setTexture(uniformName: String, textureId: Int)
|
||||||
fun setUniformBuffer(uniformName: String, uniformBuffer: OpenGLUniformBuffer)
|
fun setUniformBuffer(uniformName: String, uniformBuffer: OpenGLUniformBuffer)
|
||||||
|
|
||||||
@ -70,6 +71,7 @@ interface Shader {
|
|||||||
is RGBColor -> setRGBColor(uniformName, data)
|
is RGBColor -> setRGBColor(uniformName, data)
|
||||||
is OpenGLUniformBuffer -> setUniformBuffer(uniformName, data)
|
is OpenGLUniformBuffer -> setUniformBuffer(uniformName, data)
|
||||||
// ToDo: PNGTexture
|
// ToDo: PNGTexture
|
||||||
|
is Boolean -> setBoolean(uniformName, data)
|
||||||
else -> error("Don't know what todo with uniform type ${data::class.simpleName}!")
|
else -> error("Don't know what todo with uniform type ${data::class.simpleName}!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,10 @@ class OpenGLShader(
|
|||||||
glUniform1i(getUniformLocation(uniformName), value)
|
glUniform1i(getUniformLocation(uniformName), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setBoolean(uniformName: String, boolean: Boolean) {
|
||||||
|
setInt(uniformName, if (boolean) 1 else 0)
|
||||||
|
}
|
||||||
|
|
||||||
override fun setMat4(uniformName: String, mat4: Mat4) {
|
override fun setMat4(uniformName: String, mat4: Mat4) {
|
||||||
glUniformMatrix4fv(getUniformLocation(uniformName), false, mat4 to BufferUtils.createFloatBuffer(16))
|
glUniformMatrix4fv(getUniformLocation(uniformName), false, mat4 to BufferUtils.createFloatBuffer(16))
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.Framebuffer
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.FramebufferState
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.FramebufferState
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.texture.FramebufferTexture
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.frame.texture.FramebufferTexture
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.buffer.render.Renderbuffer
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.render.Renderbuffer
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.buffer.render.RenderbufferModes
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.frame.texture.OpenGLFramebufferColorTexture
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.frame.texture.OpenGLFramebufferColorTexture
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.frame.texture.OpenGLFramebufferDepthTexture
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.frame.texture.OpenGLFramebufferDepthTexture
|
||||||
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.render.OpenGLRenderbuffer
|
import de.bixilon.minosoft.gui.rendering.system.opengl.buffer.render.OpenGLRenderbuffer
|
||||||
@ -31,13 +32,13 @@ class OpenGLFramebuffer(var size: Vec2i) : Framebuffer {
|
|||||||
colorTexture.init()
|
colorTexture.init()
|
||||||
attach(colorTexture)
|
attach(colorTexture)
|
||||||
|
|
||||||
//renderbuffer = OpenGLRenderbuffer(RenderbufferModes.DEPTH_COMPONENT24, size)
|
renderbuffer = OpenGLRenderbuffer(RenderbufferModes.DEPTH_COMPONENT24, size)
|
||||||
//renderbuffer.init()
|
renderbuffer.init()
|
||||||
//attach(renderbuffer)
|
attach(renderbuffer)
|
||||||
|
|
||||||
depthTexture = OpenGLFramebufferDepthTexture(size)
|
//depthTexture = OpenGLFramebufferDepthTexture(size)
|
||||||
depthTexture.init()
|
//depthTexture.init()
|
||||||
attach(depthTexture)
|
//attach(depthTexture)
|
||||||
|
|
||||||
glDrawBuffers(intArrayOf(GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT))
|
glDrawBuffers(intArrayOf(GL_COLOR_ATTACHMENT0, GL_DEPTH_ATTACHMENT))
|
||||||
|
|
||||||
@ -77,7 +78,9 @@ class OpenGLFramebuffer(var size: Vec2i) : Framebuffer {
|
|||||||
override fun bindTexture() {
|
override fun bindTexture() {
|
||||||
check(state == FramebufferState.COMPLETE) { "Framebuffer is incomplete!" }
|
check(state == FramebufferState.COMPLETE) { "Framebuffer is incomplete!" }
|
||||||
colorTexture.bind(0)
|
colorTexture.bind(0)
|
||||||
depthTexture.bind(1)
|
if (this::depthTexture.isInitialized) {
|
||||||
|
depthTexture.bind(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resize(size: Vec2i) {
|
override fun resize(size: Vec2i) {
|
||||||
|
@ -96,6 +96,8 @@ class RespawnS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
connection.player.tabListItem.gamemode = gamemode
|
connection.player.tabListItem.gamemode = gamemode
|
||||||
connection.player.velocity = Vec3d.EMPTY
|
connection.player.velocity = Vec3d.EMPTY
|
||||||
|
|
||||||
|
// connection.world.view.serverViewDistance = 0
|
||||||
|
|
||||||
connection.fireEvent(RespawnEvent(connection, this))
|
connection.fireEvent(RespawnEvent(connection, this))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,23 +17,41 @@ in vec3 finFragmentPosition;
|
|||||||
uniform vec3 uCameraPosition;
|
uniform vec3 uCameraPosition;
|
||||||
uniform float uFogStart = 60.0f;
|
uniform float uFogStart = 60.0f;
|
||||||
uniform float uFogEnd = 75.0f;
|
uniform float uFogEnd = 75.0f;
|
||||||
|
uniform vec4 uFogColor;
|
||||||
|
uniform bool uUseFogColor = false;
|
||||||
|
|
||||||
float calulate_fog_alpha(float distance) {
|
float calulate_fog_alpha(float distance) {
|
||||||
if (distance < uFogStart) {
|
if (distance < uFogStart) {
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
}
|
}
|
||||||
if (distance > uFogEnd) {
|
if (distance > uFogEnd) {
|
||||||
discard;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pow(1.0f - (distance - uFogStart) / (uFogEnd - uFogStart), 2);
|
return pow(1.0f - (distance - uFogStart) / (uFogEnd - uFogStart), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
float calculate_fog() {
|
float calculate_fog() {
|
||||||
|
if (uFogStart > 100000.0f) {
|
||||||
|
return 1.0f;
|
||||||
|
};
|
||||||
|
#ifdef FOG_SPHERE
|
||||||
|
float distance = length(finFragmentPosition.xyz - uCameraPosition.xyz);
|
||||||
|
#else
|
||||||
float distance = length(finFragmentPosition.xz - uCameraPosition.xz);
|
float distance = length(finFragmentPosition.xz - uCameraPosition.xz);
|
||||||
|
#endif
|
||||||
return calulate_fog_alpha(distance);
|
return calulate_fog_alpha(distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_fog_alpha() {
|
void set_fog() {
|
||||||
foutColor.a = calculate_fog();
|
float alpha = calculate_fog();
|
||||||
|
if (uUseFogColor) {
|
||||||
|
foutColor.rgb = mix(uFogColor.rgb, foutColor.rgb, alpha);
|
||||||
|
foutColor.a = 1.0f;
|
||||||
|
} else {
|
||||||
|
if (alpha <= 0.0f) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
foutColor.a = alpha;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ void main() {
|
|||||||
#ifdef TRANSPARENT
|
#ifdef TRANSPARENT
|
||||||
set_alpha_transparent();
|
set_alpha_transparent();
|
||||||
#endif
|
#endif
|
||||||
set_fog_alpha();
|
set_fog();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,5 +49,5 @@ void main() {
|
|||||||
#ifdef TRANSPARENT
|
#ifdef TRANSPARENT
|
||||||
set_alpha_transparent();
|
set_alpha_transparent();
|
||||||
#endif
|
#endif
|
||||||
set_fog_alpha();
|
set_fog();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user