diff --git a/doc/Sky.md b/doc/Sky.md index 3faea9677..eff953927 100644 --- a/doc/Sky.md +++ b/doc/Sky.md @@ -31,3 +31,14 @@ Resources: - https://minecraft.fandom.com/wiki/Cloud - https://minecraft.fandom.com/wiki/Daylight_cycle - https://minecraft.fandom.com/wiki/Effect_(dimension) + +## Tasks + +- [ ] Light scatter +- [ ] Atmosphere effect +- [ ] improve fog color +- [ ] Lens flare +- [ ] sky texture +- [ ] stars +- [ ] Wither +- [ ] Clouds diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/SkyRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/SkyRenderer.kt index 9a1380cf2..42491fb40 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/SkyRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/SkyRenderer.kt @@ -25,6 +25,7 @@ import de.bixilon.minosoft.gui.rendering.renderer.renderer.RendererBuilder import de.bixilon.minosoft.gui.rendering.sky.box.SkyboxRenderer import de.bixilon.minosoft.gui.rendering.sky.planet.MoonRenderer import de.bixilon.minosoft.gui.rendering.sky.planet.SunRenderer +import de.bixilon.minosoft.gui.rendering.sky.planet.scatter.SunScatterRenderer import de.bixilon.minosoft.gui.rendering.sky.properties.OverworldSkyProperties import de.bixilon.minosoft.gui.rendering.system.base.DepthFunctions import de.bixilon.minosoft.gui.rendering.system.base.PolygonModes @@ -45,11 +46,17 @@ class SkyRenderer( var properties by watched(connection.world.dimension?.skyProperties ?: OverworldSkyProperties) var matrix by watched(Mat4()) val profile = connection.profiles.rendering.sky - private val box = SkyboxRenderer(this).register() - private val sun = SunRenderer(this).register() - private val moon = MoonRenderer(this).register() + private val box = SkyboxRenderer(this) + private val sun = SunRenderer(this) + private val sunScatter = SunScatterRenderer(this, sun) + private val moon = MoonRenderer(this) override fun init(latch: CountUpAndDownLatch) { + box.register() + sunScatter.register() + sun.register() + moon.register() + for (renderer in renderer) { renderer.init() } @@ -78,7 +85,7 @@ class SkyRenderer( } override fun drawPre() { - renderWindow.renderSystem.reset(depth = DepthFunctions.LESS_OR_EQUAL) + renderWindow.renderSystem.reset(depth = DepthFunctions.LESS_OR_EQUAL, depthMask = false) for (renderer in renderer) { renderer.draw() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/PlanetRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/PlanetRenderer.kt index 5ce5e5ebb..9f6ea2c6d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/PlanetRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/PlanetRenderer.kt @@ -31,7 +31,7 @@ abstract class PlanetRenderer( protected val sky: SkyRenderer, ) : SkyChildRenderer { protected abstract val texture: AbstractTexture - protected val shader = sky.renderWindow.renderSystem.createShader(minosoft("weather/planet")) + protected val shader = sky.renderWindow.renderSystem.createShader(minosoft("sky/planet")) private var mesh = PlanetMesh(sky.renderWindow) protected var day = -1L protected var matrix = Mat4() @@ -80,8 +80,8 @@ abstract class PlanetRenderer( private fun calculateMatrix(base: Mat4) { val matrix = Mat4(base) + matrix.rotateAssign(calculateAngle().rad, Vec3(0, 0, 1)) - matrix.translateAssign(Vec3(0.0f, -0.01f, 0.0f)) // prevents face fighting matrix.translateAssign(Vec3(0.0f, -modifier, 0.0f)) // moves the planet closer to the player (appears appears bigger) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/SunRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/SunRenderer.kt index 732da4313..1207ef3e7 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/SunRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/SunRenderer.kt @@ -27,7 +27,7 @@ class SunRenderer( ) : PlanetRenderer(sky) { override val texture = sky.renderWindow.textureManager.staticTextures.createTexture(SUN) - override fun calculateAngle(): Float { + public override fun calculateAngle(): Float { val time = sky.renderWindow.connection.world.time // 270: sunrise (23k-0k) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/scatter/SunScatterMesh.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/scatter/SunScatterMesh.kt new file mode 100644 index 000000000..14a8ff760 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/scatter/SunScatterMesh.kt @@ -0,0 +1,49 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.sky.planet.scatter + +import de.bixilon.minosoft.gui.rendering.RenderWindow +import de.bixilon.minosoft.gui.rendering.system.base.buffer.vertex.PrimitiveTypes +import de.bixilon.minosoft.gui.rendering.util.mesh.Mesh +import de.bixilon.minosoft.gui.rendering.util.mesh.PositionOnlyMeshStruct + +class SunScatterMesh(renderWindow: RenderWindow) : Mesh(renderWindow, PositionOnlyMeshStruct, PrimitiveTypes.TRIANGLE, initialCacheSize = 6 * 2 * 3 * PositionOnlyMeshStruct.FLOATS_PER_VERTEX) { + + init { + data.addAll( + floatArrayOf( + -1.0f, +0.2f, -1.0f, + -1.0f, -0.2f, -1.0f, + +1.0f, -0.2f, -1.0f, + +1.0f, -0.2f, -1.0f, + +1.0f, +0.2f, -1.0f, + -1.0f, +0.2f, -1.0f, + + +1.0f, -0.2f, -1.0f, + +1.0f, -0.2f, +1.0f, + +1.0f, +0.2f, +1.0f, + +1.0f, +0.2f, +1.0f, + +1.0f, +0.2f, -1.0f, + +1.0f, -0.2f, -1.0f, + + -1.0f, -0.2f, +1.0f, + -1.0f, +0.2f, +1.0f, + +1.0f, +0.2f, +1.0f, + +1.0f, +0.2f, +1.0f, + +1.0f, -0.2f, +1.0f, + -1.0f, -0.2f, +1.0f, + ) + ) + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/scatter/SunScatterRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/scatter/SunScatterRenderer.kt new file mode 100644 index 000000000..4ed56aac3 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sky/planet/scatter/SunScatterRenderer.kt @@ -0,0 +1,54 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.sky.planet.scatter + +import de.bixilon.kotlinglm.func.rad +import de.bixilon.kotlinglm.mat4x4.Mat4 +import de.bixilon.kotlinglm.vec3.Vec3 +import de.bixilon.minosoft.gui.rendering.sky.SkyChildRenderer +import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer +import de.bixilon.minosoft.gui.rendering.sky.planet.SunRenderer +import de.bixilon.minosoft.util.KUtil.minosoft + +class SunScatterRenderer( + private val sky: SkyRenderer, + private val sun: SunRenderer, +) : SkyChildRenderer { + private val shader = sky.renderSystem.createShader(minosoft("sky/scatter/sun")) + private val mesh = SunScatterMesh(sky.renderWindow) + private var matrix = Mat4() + + private fun calculateMatrix() { + val matrix = Mat4(sky.matrix) + + matrix.rotateAssign((sun.calculateAngle() + 90.0f).rad, Vec3(0, 0, 1)) + + this.matrix = matrix + } + + override fun init() { + shader.load() + } + + override fun postInit() { + mesh.load() + } + + override fun draw() { + calculateMatrix() + shader.use() + shader.setMat4("uScatterMatrix", matrix) + mesh.draw() + } +} diff --git a/src/main/resources/assets/minosoft/rendering/shader/weather/planet/planet.fsh b/src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.fsh similarity index 100% rename from src/main/resources/assets/minosoft/rendering/shader/weather/planet/planet.fsh rename to src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.fsh diff --git a/src/main/resources/assets/minosoft/rendering/shader/weather/planet/planet.vsh b/src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.vsh similarity index 100% rename from src/main/resources/assets/minosoft/rendering/shader/weather/planet/planet.vsh rename to src/main/resources/assets/minosoft/rendering/shader/sky/planet/planet.vsh diff --git a/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sun.fsh b/src/main/resources/assets/minosoft/rendering/shader/sky/scatter/sun/sun.fsh similarity index 69% rename from src/main/resources/assets/minosoft/rendering/shader/sky/sun/sun.fsh rename to src/main/resources/assets/minosoft/rendering/shader/sky/scatter/sun/sun.fsh index ba6a0267a..9bd1b267c 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sun.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/sky/scatter/sun/sun.fsh @@ -15,19 +15,6 @@ out vec4 foutColor; -in vec4 finTintColor; -flat in uint finTextureIndex; -in vec3 finTextureCoordinates; - -#include "minosoft:texture" - - void main() { - vec4 texelColor = getTexture(finTextureIndex, finTextureCoordinates); - - if (finTintColor.a == 1.0f && texelColor.a == 0) { - discard; - } - // foutColor = vec4(0.0f, 1.0f, 1.0f, 1.0f); - foutColor = texelColor * finTintColor; + foutColor = vec4(1.0f, 0.5f, 0.5f, 1.0f); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sun.vsh b/src/main/resources/assets/minosoft/rendering/shader/sky/scatter/sun/sun.vsh similarity index 58% rename from src/main/resources/assets/minosoft/rendering/shader/sky/sun/sun.vsh rename to src/main/resources/assets/minosoft/rendering/shader/sky/scatter/sun/sun.vsh index 229e907bf..6b0f75792 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/sky/sun/sun.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/sky/scatter/sun/sun.vsh @@ -14,23 +14,10 @@ #version 330 core layout (location = 0) in vec3 vinPosition; -layout (location = 1) in vec2 vinUV; -layout (location = 2) in uint vinIndexLayerAnimation; -layout (location = 3) in uint vinTintColor; -out vec4 finTintColor; -flat out uint finTextureIndex; -out vec3 finTextureCoordinates; +uniform mat4 uScatterMatrix; -uniform mat4 uSkyViewProjectionMatrix; - -#include "minosoft:color" void main() { - gl_Position = (uSkyViewProjectionMatrix * vec4(vinPosition, 1.0f)).xyww - vec4(0.0f, 0.0f, 0.000001f, 0.0f);// prevent face fighting - - finTextureIndex = vinIndexLayerAnimation >> 28u; - finTextureCoordinates = vec3(vinUV, ((vinIndexLayerAnimation >> 12) & 0xFFFFu)); - - finTintColor = getRGBAColor(vinTintColor); + gl_Position = uScatterMatrix * vec4(vinPosition, 1.0); } diff --git a/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.fsh b/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.fsh index a163a075d..f6b7c59fc 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.fsh +++ b/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.fsh @@ -15,8 +15,8 @@ out vec4 foutColor; -in vec4 finColor; +uniform vec4 uSkyColor; void main() { - foutColor = finColor; + foutColor = uSkyColor; } diff --git a/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.vsh b/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.vsh index 1301d4081..ff4045077 100644 --- a/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.vsh +++ b/src/main/resources/assets/minosoft/rendering/shader/sky/skybox/skybox.vsh @@ -15,14 +15,9 @@ layout (location = 0) in vec3 vinPosition; -out vec4 finColor; - uniform mat4 uSkyViewProjectionMatrix; -uniform vec4 uSkyColor; void main() { gl_Position = uSkyViewProjectionMatrix * vec4(vinPosition, 1.0); - - finColor = uSkyColor; }