mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-08 23:13:10 -04:00
wip sun scatter
This commit is contained in:
parent
db2e9c5c86
commit
97e1b57cda
11
doc/Sky.md
11
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
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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()
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -15,8 +15,8 @@
|
||||
|
||||
out vec4 foutColor;
|
||||
|
||||
in vec4 finColor;
|
||||
uniform vec4 uSkyColor;
|
||||
|
||||
void main() {
|
||||
foutColor = finColor;
|
||||
foutColor = uSkyColor;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user