mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-22 12:01:38 -04:00
clouds: basic color
This commit is contained in:
parent
c33492d8c1
commit
3f4b234736
@ -14,19 +14,22 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.sky.clouds
|
package de.bixilon.minosoft.gui.rendering.sky.clouds
|
||||||
|
|
||||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
import de.bixilon.kotlinglm.vec4.Vec4
|
import de.bixilon.kotlinglm.vec4.Vec4
|
||||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||||
import de.bixilon.minosoft.data.direction.Directions
|
import de.bixilon.minosoft.data.direction.Directions
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.data.world.time.WorldTime
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||||
import de.bixilon.minosoft.gui.rendering.renderer.renderer.Renderer
|
import de.bixilon.minosoft.gui.rendering.renderer.renderer.Renderer
|
||||||
import de.bixilon.minosoft.gui.rendering.renderer.renderer.RendererBuilder
|
import de.bixilon.minosoft.gui.rendering.renderer.renderer.RendererBuilder
|
||||||
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.RenderingCapabilities
|
import de.bixilon.minosoft.gui.rendering.system.base.RenderingCapabilities
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.TranslucentDrawable
|
import de.bixilon.minosoft.gui.rendering.system.base.phases.OpaqueDrawable
|
||||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.EMPTY
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.util.KUtil.minosoft
|
import de.bixilon.minosoft.util.KUtil.minosoft
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
@ -35,15 +38,16 @@ class CloudsRenderer(
|
|||||||
private val sky: SkyRenderer,
|
private val sky: SkyRenderer,
|
||||||
private val connection: PlayConnection,
|
private val connection: PlayConnection,
|
||||||
override val renderWindow: RenderWindow,
|
override val renderWindow: RenderWindow,
|
||||||
) : Renderer, TranslucentDrawable {
|
) : Renderer, OpaqueDrawable {
|
||||||
override val renderSystem: RenderSystem = renderWindow.renderSystem
|
override val renderSystem: RenderSystem = renderWindow.renderSystem
|
||||||
private val shader = renderSystem.createShader(minosoft("sky/clouds"))
|
private val shader = renderSystem.createShader(minosoft("sky/clouds"))
|
||||||
val matrix = CloudMatrix()
|
val matrix = CloudMatrix()
|
||||||
private var position = Vec2i(Int.MIN_VALUE)
|
private var position = Vec2i(Int.MIN_VALUE)
|
||||||
private val arrays: Array<CloudArray> = arrayOfNulls<CloudArray?>(4).unsafeCast()
|
private val arrays: Array<CloudArray> = arrayOfNulls<CloudArray?>(4).unsafeCast()
|
||||||
|
private var color: Vec3 = Vec3.EMPTY
|
||||||
|
|
||||||
|
|
||||||
override val skipTranslucent: Boolean
|
override val skipOpaque: Boolean
|
||||||
get() = !sky.properties.clouds || !sky.profile.clouds || connection.profiles.block.viewDistance < 3
|
get() = !sky.properties.clouds || !sky.profile.clouds || connection.profiles.block.viewDistance < 3
|
||||||
|
|
||||||
|
|
||||||
@ -65,10 +69,10 @@ class CloudsRenderer(
|
|||||||
for (array in arrays.unsafeCast<Array<CloudArray?>>()) {
|
for (array in arrays.unsafeCast<Array<CloudArray?>>()) {
|
||||||
array?.unload()
|
array?.unload()
|
||||||
}
|
}
|
||||||
arrays[0] = CloudArray(this, cloudPosition + Vec2i(+0, -1))
|
arrays[0] = CloudArray(this, cloudPosition + Vec2i(-1, -1))
|
||||||
arrays[1] = CloudArray(this, cloudPosition + Vec2i(-1, -1))
|
arrays[1] = CloudArray(this, cloudPosition + Vec2i(+0, -1))
|
||||||
arrays[2] = CloudArray(this, cloudPosition + Vec2i(+0, +0))
|
arrays[2] = CloudArray(this, cloudPosition + Vec2i(-1, +0))
|
||||||
arrays[3] = CloudArray(this, cloudPosition + Vec2i(-1, +0))
|
arrays[3] = CloudArray(this, cloudPosition + Vec2i(+0, +0))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Vec2i.cloudPosition(): Vec2i {
|
private fun Vec2i.cloudPosition(): Vec2i {
|
||||||
@ -96,11 +100,11 @@ class CloudsRenderer(
|
|||||||
} else {
|
} else {
|
||||||
// push array in our direction
|
// push array in our direction
|
||||||
if (arrayDelta.x == -1) {
|
if (arrayDelta.x == -1) {
|
||||||
push(from = 1, to = 0, Directions.WEST)
|
push(from = 0, to = 1, Directions.WEST)
|
||||||
push(from = 3, to = 2, Directions.WEST)
|
push(from = 2, to = 3, Directions.WEST)
|
||||||
} else if (arrayDelta.x == 1) {
|
} else if (arrayDelta.x == 1) {
|
||||||
push(from = 0, to = 1, Directions.EAST)
|
push(from = 1, to = 0, Directions.EAST)
|
||||||
push(from = 2, to = 3, Directions.EAST)
|
push(from = 3, to = 2, Directions.EAST)
|
||||||
}
|
}
|
||||||
if (arrayDelta.y == -1) {
|
if (arrayDelta.y == -1) {
|
||||||
push(from = 0, to = 2, Directions.NORTH)
|
push(from = 0, to = 2, Directions.NORTH)
|
||||||
@ -114,14 +118,35 @@ class CloudsRenderer(
|
|||||||
this.position = position
|
this.position = position
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupTranslucent() {
|
override fun setupOpaque() {
|
||||||
super.setupTranslucent()
|
super.setupOpaque()
|
||||||
renderSystem.disable(RenderingCapabilities.FACE_CULLING)
|
renderSystem.disable(RenderingCapabilities.FACE_CULLING)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawTranslucent() {
|
private fun calculateNormal(time: WorldTime): Vec3 {
|
||||||
|
return Vec3(1.0f)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateRainColor(time: WorldTime, rain: Float): Vec3 {
|
||||||
|
return Vec3(0.5f)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculateCloudsColor(): Vec3 {
|
||||||
|
val weather = connection.world.weather
|
||||||
|
val time = sky.time
|
||||||
|
if (weather.rain > 0.0f || weather.thunder > 0.0f) {
|
||||||
|
return calculateRainColor(time, maxOf(weather.rain, weather.thunder))
|
||||||
|
}
|
||||||
|
return calculateNormal(time)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun drawOpaque() {
|
||||||
shader.use()
|
shader.use()
|
||||||
shader.setVec4("uCloudsColor", Vec4(1.0f, 1.0f, 1.0f, 1.0f))
|
val color = calculateCloudsColor()
|
||||||
|
if (color != this.color) {
|
||||||
|
shader.setVec4("uCloudsColor", Vec4(color, 1.0f))
|
||||||
|
this.color = color
|
||||||
|
}
|
||||||
|
|
||||||
for (array in arrays) {
|
for (array in arrays) {
|
||||||
array.draw()
|
array.draw()
|
||||||
|
@ -17,11 +17,11 @@ out vec4 foutColor;
|
|||||||
|
|
||||||
uniform vec4 uCloudsColor;
|
uniform vec4 uCloudsColor;
|
||||||
|
|
||||||
flat in float finAlpha;
|
flat in float finBrightness;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// TODO
|
// TODO
|
||||||
foutColor = uCloudsColor;
|
foutColor = uCloudsColor;
|
||||||
// foutColor.r = finAlpha;
|
foutColor.rgb *= finBrightness;
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,18 @@
|
|||||||
layout (location = 0) in vec3 vinPosition;
|
layout (location = 0) in vec3 vinPosition;
|
||||||
layout (location = 1) in uint vinSide;
|
layout (location = 1) in uint vinSide;
|
||||||
|
|
||||||
flat out float finAlpha;
|
flat out float finBrightness;
|
||||||
|
|
||||||
uniform mat4 uViewProjectionMatrix;
|
uniform mat4 uViewProjectionMatrix;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = uViewProjectionMatrix * vec4(vinPosition, 1.0);
|
gl_Position = uViewProjectionMatrix * vec4(vinPosition, 1.0);
|
||||||
finAlpha = float(vinSide) / 6.0f;
|
|
||||||
|
switch (vinSide) {
|
||||||
|
case 0u: finBrightness = 0.5f; break; // DOWN
|
||||||
|
case 1u: finBrightness = 1.0f; break; // UP
|
||||||
|
case 2u: case 3u: finBrightness = 0.8f; break; // NORTH, SOUTH
|
||||||
|
case 4u: case 5u: finBrightness = 0.6f; break; // WEST, EAST
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user