Add shader loading functionality
[no changelog]
This commit is contained in:
24
src/main/kotlin/events/RegisterCustomShadersEvent.kt
Normal file
24
src/main/kotlin/events/RegisterCustomShadersEvent.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package moe.nea.firmament.events
|
||||
|
||||
import com.mojang.datafixers.util.Pair
|
||||
import java.util.function.Consumer
|
||||
import net.minecraft.client.gl.ShaderProgram
|
||||
import net.minecraft.client.render.VertexFormat
|
||||
import net.minecraft.resource.ResourceFactory
|
||||
import moe.nea.firmament.Firmament
|
||||
|
||||
data class RegisterCustomShadersEvent(
|
||||
val list: MutableList<Pair<ShaderProgram, Consumer<ShaderProgram>>>,
|
||||
val resourceFactory: ResourceFactory,
|
||||
) : FirmamentEvent() {
|
||||
companion object : FirmamentEventBus<RegisterCustomShadersEvent>()
|
||||
|
||||
fun register(name: String, vertexFormat: VertexFormat, saver: Consumer<ShaderProgram>) {
|
||||
require(name.startsWith("firmament_"))
|
||||
try {
|
||||
list.add(Pair.of(ShaderProgram(resourceFactory, name, vertexFormat), saver))
|
||||
} catch (ex: Exception) {
|
||||
Firmament.logger.fatal("Could not load firmament shader $name", ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/main/kotlin/util/render/FirmamentShaders.kt
Normal file
23
src/main/kotlin/util/render/FirmamentShaders.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package moe.nea.firmament.util.render
|
||||
|
||||
import net.minecraft.client.gl.ShaderProgram
|
||||
import net.minecraft.client.render.RenderPhase
|
||||
import net.minecraft.client.render.VertexFormats
|
||||
import moe.nea.firmament.annotations.Subscribe
|
||||
import moe.nea.firmament.events.RegisterCustomShadersEvent
|
||||
|
||||
object FirmamentShaders {
|
||||
|
||||
|
||||
private lateinit var _LINES: ShaderProgram
|
||||
val LINES = RenderPhase.ShaderProgram({ _LINES })
|
||||
|
||||
@Subscribe
|
||||
fun registerCustomShaders(event: RegisterCustomShadersEvent) {
|
||||
event.register(
|
||||
"firmament_rendertype_lines",
|
||||
VertexFormats.LINES,
|
||||
{ _LINES = it },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class RenderInWorldContext private constructor(
|
||||
false, false, // do we need translucent? i dont think so
|
||||
RenderLayer.MultiPhaseParameters.builder()
|
||||
.depthTest(RenderPhase.ALWAYS_DEPTH_TEST)
|
||||
.program(RenderPhase.LINES_PROGRAM)
|
||||
.program(FirmamentShaders.LINES)
|
||||
.build(false)
|
||||
)
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class RenderInWorldContext private constructor(
|
||||
points.zipWithNext().forEach { (a, b) ->
|
||||
val normal = Vector3f(b.x.toFloat(), b.y.toFloat(), b.z.toFloat())
|
||||
.sub(a.x.toFloat(), a.y.toFloat(), a.z.toFloat())
|
||||
.normalize()
|
||||
// .normalize()
|
||||
val lastNormal0 = lastNormal ?: normal
|
||||
lastNormal = normal
|
||||
buffer.vertex(matrix.positionMatrix, a.x.toFloat(), a.y.toFloat(), a.z.toFloat())
|
||||
|
||||
Reference in New Issue
Block a user