lightmap visualizer

This commit is contained in:
Bixilon 2022-11-09 09:15:40 +01:00
parent 03a1aa3d0a
commit e76e9dc87a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
14 changed files with 122 additions and 12 deletions

View File

@ -52,7 +52,6 @@ package:
- ./gradlew fatJar --stacktrace
only:
- master
- test/gradle
artifacts:
paths:
- build/libs/minosoft-fat-*.jar

View File

@ -44,11 +44,11 @@ Resources:
- [x] Clouds
- [ ] interpolate world time
- [ ] Lightmap
- potion effects (nigh vision, underwater visibility, conduit)
- potion effects (nigh vision, underwater visibility, conduit, darkness)
- submerged fluid
- gamma setting
- weather, thunder flashing
- wither
- dimension (e.g. fullbright)
- dimension (e.g. fulbright)
- fullbright setting/key
- stars/moon

View File

@ -19,4 +19,6 @@ object DebugOptions {
const val SIMULATE_TIME = true
const val CLOUD_RASTER = false
const val LIGHTMAP_DEBUG_WINDOW = true
}

View File

@ -102,7 +102,7 @@ class RenderWindow(
lateinit var thread: Thread
private set
var state by watched(RenderingStates.RUNNING)
var state by watched(RenderingStates.LOADING)
init {
connection::state.observe(this) {
@ -221,6 +221,7 @@ class RenderWindow(
latch.dec()
latch.await()
this.latch.await()
state = RenderingStates.RUNNING
window.visible = true
Log.log(LogMessageType.RENDERING_GENERAL) { "Showing window after ${stopwatch.totalTime()}" }
}

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.gui.rendering
enum class RenderingStates {
LOADING,
RUNNING,
SLOW,
PAUSED,

View File

@ -32,7 +32,7 @@ object EndSkyProperties : SkyProperties {
override val clouds: Boolean get() = false
override fun getCloudHeight(connection: PlayConnection): IntRange = Broken()
override val fullbright: Boolean get() = true
override val brighten: Boolean get() = true
override val fog: Boolean get() = false
}

View File

@ -29,7 +29,7 @@ object NetherSkyProperties : SkyProperties {
override val clouds: Boolean get() = false
override fun getCloudHeight(connection: PlayConnection): IntRange = Broken()
override val fullbright: Boolean get() = true
override val brighten: Boolean get() = true
override val fog: Boolean get() = true
}

View File

@ -35,7 +35,7 @@ object OverworldSkyProperties : SkyProperties {
return 128..132
}
override val fullbright: Boolean get() = false
override val brighten: Boolean get() = false
override val fog: Boolean get() = true
}

View File

@ -28,7 +28,7 @@ interface SkyProperties : ResourceLocationAble {
val clouds: Boolean
fun getCloudHeight(connection: PlayConnection): IntRange
val fullbright: Boolean get() = false
val brighten: Boolean get() = false
val fog: Boolean
}

View File

@ -21,9 +21,9 @@ import de.bixilon.minosoft.gui.rendering.world.light.updater.FullbrightLightUpda
import de.bixilon.minosoft.gui.rendering.world.light.updater.LegacyLightmapUpdater
import de.bixilon.minosoft.gui.rendering.world.light.updater.LightmapUpdater
class Lightmap(light: RenderLight) {
class Lightmap(private val light: RenderLight) {
private val profile = light.renderWindow.connection.profiles.rendering
private val buffer = LightmapBuffer(light.renderWindow.renderSystem)
val buffer = LightmapBuffer(light.renderWindow.renderSystem)
private var updater: LightmapUpdater = FullbrightLightUpdater
set(value) {
field = value
@ -31,9 +31,11 @@ class Lightmap(light: RenderLight) {
}
private var force: Boolean = true
private val defaultUpdater: LightmapUpdater = LegacyLightmapUpdater(light.renderWindow.connection)
private lateinit var defaultUpdater: LightmapUpdater
fun init() {
// defaultUpdater = NormalLightmapUpdater(light.renderWindow.connection, light.renderWindow.renderer[SkyRenderer])
defaultUpdater = LegacyLightmapUpdater(light.renderWindow.connection)
buffer.init()
profile.light::fullbright.profileWatch(this, profile = profile) { setLightmapUpdater() }
setLightmapUpdater()

View File

@ -20,7 +20,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import org.lwjgl.system.MemoryUtil.memAllocFloat
class LightmapBuffer(renderSystem: RenderSystem) {
private val buffer = renderSystem.createFloatUniformBuffer(memAllocFloat(UNIFORM_BUFFER_SIZE))
val buffer = renderSystem.createFloatUniformBuffer(memAllocFloat(UNIFORM_BUFFER_SIZE))
private var upload = false
fun init() {

View File

@ -14,16 +14,22 @@
package de.bixilon.minosoft.gui.rendering.world.light
import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
import de.bixilon.minosoft.config.DebugOptions
import de.bixilon.minosoft.config.key.KeyActions
import de.bixilon.minosoft.config.key.KeyBinding
import de.bixilon.minosoft.config.key.KeyCodes
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.RenderingStates
import de.bixilon.minosoft.gui.rendering.world.WorldRenderer
import de.bixilon.minosoft.gui.rendering.world.light.debug.LightmapDebugWindow
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import de.bixilon.minosoft.util.delegate.JavaFXDelegate.observeFX
class RenderLight(val renderWindow: RenderWindow) {
private val connection = renderWindow.connection
val map = Lightmap(this)
private val debugWindow = if (DebugOptions.LIGHTMAP_DEBUG_WINDOW) LightmapDebugWindow(map) else null
fun init() {
map.init()
@ -52,6 +58,15 @@ class RenderLight(val renderWindow: RenderWindow) {
connection.profiles.rendering.light.fullbright = it
connection.util.sendDebugMessage("Fullbright: $it")
}
if (DebugOptions.LIGHTMAP_DEBUG_WINDOW) {
renderWindow::state.observeFX(this) {
if (it == RenderingStates.RUNNING) {
JavaFXUtil.runLater { debugWindow?.show() }
} else if (it == RenderingStates.QUITTING) {
debugWindow?.close()
}
}
}
}
fun updateAsync() {
@ -60,5 +75,6 @@ class RenderLight(val renderWindow: RenderWindow) {
fun update() {
map.update()
debugWindow?.update()
}
}

View File

@ -0,0 +1,68 @@
/*
* 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.world.light.debug
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.gui.eros.controller.JavaFXWindowController
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.gui.rendering.world.light.Lightmap
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.minosoft
import javafx.fxml.FXML
import javafx.scene.canvas.Canvas
class LightmapDebugWindow(private val lightmap: Lightmap) : JavaFXWindowController() {
private var show = false
@FXML private lateinit var canvasFX: Canvas
public override fun show() {
if (show) {
return
}
JavaFXUtil.openModalAsync("Lightmap", LAYOUT, controller = this) { super.show(); show = true }
}
override fun close() {
super.close()
show = false
}
private fun _update() {
if (!show) {
return
}
val buffer = lightmap.buffer.buffer.buffer
for (sky in 0 until ProtocolDefinition.LIGHT_LEVELS) {
for (block in 0 until ProtocolDefinition.LIGHT_LEVELS) {
val offset = ((sky shl 4) or block) * 4
val color = RGBColor(buffer.get(offset + 0), buffer.get(offset + 1), buffer.get(offset + 2))
canvasFX.graphicsContext2D.pixelWriter.setArgb(block, sky, color.argb)
}
}
}
fun update() {
if (!show) {
return
}
JavaFXUtil.runLater { _update() }
}
companion object {
private val LAYOUT = minosoft("eros/debug/lightmap.fxml")
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.layout.HBox?>
<!--
~ 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.
-->
<HBox xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="512.0" prefWidth="512.0" xmlns="http://javafx.com/javafx/18">
<Canvas fx:id="canvasFX" height="16.0" scaleX="32.0" scaleY="32.0" translateX="240.0" translateY="240.0" width="16.0" HBox.hgrow="NEVER"/>
</HBox>