diff --git a/src/main/kotlin/com/lambda/graphics/animation/Animation.kt b/src/main/kotlin/com/lambda/graphics/animation/Animation.kt deleted file mode 100644 index ff779816d..000000000 --- a/src/main/kotlin/com/lambda/graphics/animation/Animation.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2025 Lambda - * - * 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 . - */ - -package com.lambda.graphics.animation - -import com.lambda.Lambda.mc -import com.lambda.util.extension.partialTicks -import com.lambda.util.math.lerp -import kotlin.math.abs -import kotlin.reflect.KProperty - -class Animation(initialValue: Double, val update: (Double) -> Double) { - private var prevValue = initialValue - private var currValue = initialValue - - operator fun getValue(thisRef: Any?, property: KProperty<*>) = value() - operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn) - - fun value(): Double = lerp(mc.partialTicks, prevValue, currValue) - - fun setValue(valueIn: Double) { - prevValue = valueIn - currValue = valueIn - } - - fun tick() { - prevValue = currValue - currValue = update(currValue) - } - - companion object { - fun AnimationTicker.exp(min: () -> Double, max: () -> Double, speed: Double, flag: () -> Boolean) = - exp(min, max, { speed }, flag) - - fun AnimationTicker.exp(min: Double, max: Double, speed: () -> Double, flag: () -> Boolean) = - exp({ min }, { max }, speed, flag) - - fun AnimationTicker.exp(min: Double, max: Double, speed: Double, flag: () -> Boolean) = - exp({ min }, { max }, { speed }, flag) - - fun AnimationTicker.exp(speed: Double, target: () -> Double) = - exp(target, target, { speed }, { true }) - - fun AnimationTicker.exp(min: () -> Double, max: () -> Double, speed: () -> Double, flag: () -> Boolean) = - Animation(min()) { - val minVal = min() - val maxVal = max() - val target = if (flag()) maxVal else minVal - - if (abs(target - it) < CLAMP * abs(maxVal - minVal)) target - else lerp(speed(), it, target) - }.apply(::register) - - // Exponent animation never reaches target value - private const val CLAMP = 0.01 - } -} - diff --git a/src/main/kotlin/com/lambda/graphics/animation/AnimationTicker.kt b/src/main/kotlin/com/lambda/graphics/animation/AnimationTicker.kt deleted file mode 100644 index eb0bbcdcc..000000000 --- a/src/main/kotlin/com/lambda/graphics/animation/AnimationTicker.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2025 Lambda - * - * 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 . - */ - -package com.lambda.graphics.animation - -class AnimationTicker { - private val animations = mutableListOf() - - fun register(animation: Animation) = - animations.add(animation) - - fun tick() = - animations.forEach(Animation::tick) -} diff --git a/src/main/kotlin/com/lambda/graphics/renderer/esp/ShapeDsl.kt b/src/main/kotlin/com/lambda/graphics/renderer/esp/ShapeDsl.kt index 5f9921d5c..eaf223370 100644 --- a/src/main/kotlin/com/lambda/graphics/renderer/esp/ShapeDsl.kt +++ b/src/main/kotlin/com/lambda/graphics/renderer/esp/ShapeDsl.kt @@ -19,13 +19,11 @@ package com.lambda.graphics.renderer.esp import com.lambda.graphics.pipeline.VertexBuilder import com.lambda.graphics.renderer.esp.DirectionMask.hasDirection -import com.lambda.graphics.renderer.esp.Treed.Companion.cameraPos import com.lambda.threading.runSafe import com.lambda.util.BlockUtils.blockState import com.lambda.util.extension.max import com.lambda.util.extension.min import com.lambda.util.extension.outlineShape -import com.lambda.util.math.minus import net.minecraft.block.BlockState import net.minecraft.block.entity.BlockEntity import net.minecraft.entity.Entity @@ -48,12 +46,11 @@ class ShapeBuilder( sides : Int = DirectionMask.ALL, ) = faces.apply { val boxes = box.pair ?: return@apply - val camera = cameraPos - val pos11 = boxes.first.min - camera - val pos12 = boxes.first.max - camera - val pos21 = boxes.second.min - camera - val pos22 = boxes.second.max - camera + val pos11 = boxes.first.min + val pos12 = boxes.first.max + val pos21 = boxes.second.min + val pos22 = boxes.second.max val blb by lazy { vertex { vec3(pos11.x, pos11.y, pos11.z).vec3(pos21.x, pos21.y, pos21.z).color(color) } } val blf by lazy { vertex { vec3(pos11.x, pos11.y, pos12.z).vec3(pos21.x, pos21.y, pos22.z).color(color) } } @@ -79,9 +76,8 @@ class ShapeBuilder( topColor : Color = bottomColor, sides : Int = DirectionMask.ALL ) = faces.apply { - val camera = cameraPos - val pos1 = box.min - camera - val pos2 = box.max - camera + val pos1 = box.min + val pos2 = box.max val blb by lazy { vertex { vec3(pos1.x, pos1.y, pos1.z).color(bottomColor) } } val blf by lazy { vertex { vec3(pos1.x, pos1.y, pos2.z).color(bottomColor) } } @@ -156,12 +152,11 @@ class ShapeBuilder( mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.Or, ) = edges.apply { val boxes = box.pair ?: return@apply - val camera = cameraPos - val pos11 = boxes.first.min - camera - val pos12 = boxes.first.max - camera - val pos21 = boxes.second.min - camera - val pos22 = boxes.second.max - camera + val pos11 = boxes.first.min + val pos12 = boxes.first.max + val pos21 = boxes.second.min + val pos22 = boxes.second.max val blb by lazy { vertex { vec3(pos11.x, pos11.y, pos11.z).vec3(pos21.x, pos21.y, pos21.z).color(color) } } val blf by lazy { vertex { vec3(pos11.x, pos11.y, pos12.z).vec3(pos21.x, pos21.y, pos22.z).color(color) } } @@ -203,9 +198,8 @@ class ShapeBuilder( sides : Int = DirectionMask.ALL, mode : DirectionMask.OutlineMode = DirectionMask.OutlineMode.Or, ) = edges.apply { - val camera = cameraPos - val pos1 = box.min - camera - val pos2 = box.max - camera + val pos1 = box.min + val pos2 = box.max val blb by lazy { vertex { vec3(pos1.x, pos1.y, pos1.z).color(bottomColor) } } val blf by lazy { vertex { vec3(pos1.x, pos1.y, pos2.z).color(bottomColor) } } diff --git a/src/main/kotlin/com/lambda/graphics/renderer/esp/Treed.kt b/src/main/kotlin/com/lambda/graphics/renderer/esp/Treed.kt index 91ad80d08..42394ed93 100644 --- a/src/main/kotlin/com/lambda/graphics/renderer/esp/Treed.kt +++ b/src/main/kotlin/com/lambda/graphics/renderer/esp/Treed.kt @@ -23,16 +23,14 @@ import com.lambda.graphics.buffer.vertex.attributes.VertexMode import com.lambda.graphics.gl.GlStateUtils import com.lambda.graphics.pipeline.VertexBuilder import com.lambda.graphics.pipeline.VertexPipeline -import com.lambda.graphics.shader.Shader.Companion.shader +import com.lambda.graphics.shader.Shader import com.lambda.module.modules.client.StyleEditor import com.lambda.util.extension.partialTicks -import com.lambda.util.math.minus -import net.minecraft.util.math.Vec3d /** * Open class for 3d rendering. It contains two pipelines, one for edges and the other for faces. */ -open class Treed(static: Boolean) { +open class Treed(private val static: Boolean) { val shader = if (static) staticMode.first else dynamicMode.first val faces = VertexPipeline(VertexMode.Triangles, if (static) staticMode.second else dynamicMode.second) @@ -48,8 +46,9 @@ open class Treed(static: Boolean) { fun render() { shader.use() - shader["u_TickDelta"] = mc.partialTicks - shader["u_CameraLerp"] = cachedCameraPos - mc.gameRenderer.camera.pos + + if (!static) + shader["u_TickDelta"] = mc.partialTicks GlStateUtils.withFaceCulling(faces::render) GlStateUtils.withLineWidth(StyleEditor.outlineWidth, edges::render) @@ -76,14 +75,7 @@ open class Treed(static: Boolean) { object Dynamic : Treed(false) companion object { - private val staticMode = shader("renderer/box_static") to VertexAttrib.Group.STATIC_RENDERER - private val dynamicMode = shader("renderer/box_dynamic") to VertexAttrib.Group.DYNAMIC_RENDERER - - var cachedCameraPos: Vec3d = Vec3d.ZERO - val cameraPos: Vec3d - get() { - cachedCameraPos = mc.gameRenderer.camera.pos - return cachedCameraPos - } + private val staticMode = Shader("shaders/vertex/box_static.glsl", "shaders/fragment/pos_color.glsl") to VertexAttrib.Group.STATIC_RENDERER + private val dynamicMode = Shader("shaders/vertex/box_dynamic.glsl", "shaders/fragment/pos_color.glsl") to VertexAttrib.Group.DYNAMIC_RENDERER } } diff --git a/src/main/kotlin/com/lambda/graphics/renderer/gui/FontRenderer.kt b/src/main/kotlin/com/lambda/graphics/renderer/gui/FontRenderer.kt index aa8f53aa7..69dc6bf3b 100644 --- a/src/main/kotlin/com/lambda/graphics/renderer/gui/FontRenderer.kt +++ b/src/main/kotlin/com/lambda/graphics/renderer/gui/FontRenderer.kt @@ -22,7 +22,6 @@ import com.lambda.graphics.pipeline.VertexBuilder import com.lambda.graphics.renderer.gui.font.core.GlyphInfo import com.lambda.graphics.renderer.gui.font.core.LambdaAtlas.get import com.lambda.graphics.renderer.gui.font.core.LambdaAtlas.height -import com.lambda.graphics.shader.Shader.Companion.shader import com.lambda.graphics.texture.TextureOwner.bind import com.lambda.gui.components.ClickGuiLayout import com.lambda.module.modules.client.LambdaMoji @@ -39,7 +38,7 @@ import java.awt.Color * Renders text and emoji glyphs using a shader-based font rendering system. * This class handles text and emoji rendering, shadow effects, and text scaling. */ -object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("renderer/font")) { +/*object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("renderer/font")) { private val chars get() = StyleEditor.textFont private val emojis get() = StyleEditor.emojiFont @@ -278,4 +277,4 @@ object FontRenderer : AbstractGUIRenderer(VertexAttrib.Group.FONT, shader("rende (color.blue * StyleEditor.shadowBrightness).toInt(), color.alpha ) -} +}*/ diff --git a/src/main/kotlin/com/lambda/graphics/shader/ParsedShader.kt b/src/main/kotlin/com/lambda/graphics/shader/ParsedShader.kt deleted file mode 100644 index 3f09e3677..000000000 --- a/src/main/kotlin/com/lambda/graphics/shader/ParsedShader.kt +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2025 Lambda - * - * 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 . - */ - -package com.lambda.graphics.shader - -import com.lambda.util.stream -import org.apache.commons.io.IOUtils - -class ParsedShader(path: String) { - private val text = IOUtils.toString("shaders/$path.glsl".stream, Charsets.UTF_8) - - private val blocks = text.getBlocks() - private val dependencies = text.getDependencies() - - val methods = text.getMethods() - val definitions = text.getDefinitions() - - val attribs = blocks.getBlock("attributes") - val uniforms = blocks.getBlock("uniforms") - val exported = blocks.getBlock("export") - - init { - dependencies.forEach { dependencyName -> - val dependency = ParsedShader("shared/$dependencyName") - - //attribs.addAll(shader.blocks.getBlock("attributes")) - dependency.attribs.forEach { attrib -> - check(attribs.any { it.name == attrib.name && it.type == attrib.type }) { - "[${path}]: dependency \"$dependencyName\" requires \"${attrib.type} ${attrib.name}\" attribute to be present" - } - } - - uniforms.addAll(dependency.uniforms) - exported.addAll(dependency.exported) - - definitions.addAll(dependency.definitions) - methods.addAll(dependency.methods.filter { - it.name != "fragment" && it.name != "vertex" - }) - } - } - - data class Field(val type: String, val name: String, val flag: String?) - data class Method(val name: String, val returnType: String, val parameters: String, var code: String) { - fun construct(constructedName: String = name): String { - return "$returnType $constructedName($parameters) {\n $code\n}\n" - } - } - - companion object { - private val blockRegex = Regex("""\s*(\w+)\s*\{(.*?)}\s*""", RegexOption.DOT_MATCHES_ALL) - private val methodRegex = Regex( - """^\s*(\w+)\s+(\w+)\s*\((.*?)\)\s*\{(.*?)}#""", - setOf(RegexOption.DOT_MATCHES_ALL, RegexOption.MULTILINE) - ) - - private val fieldRegex = Regex("""\s*(\w+(?:\s+\w+)*)\s+(\w+)\s*;\s*(#.*)?""") - private val includeRegex = Regex("""^#include\s+"([\w-]+)"""", RegexOption.MULTILINE) - private val defineRegex = Regex("""^#define\s+(\w+)\s+(.+)""", RegexOption.MULTILINE) - - private fun String.getBlocks() = mutableMapOf>().apply { - blockRegex.findAll(this@getBlocks).forEach { match -> - val blockName = match.groupValues[1] - val blockFieldsStr = match.groupValues[2] - - val fields = fieldRegex.findAll(blockFieldsStr).map { fieldMatch -> - val type = fieldMatch.groupValues[1] - val name = fieldMatch.groupValues[2] - - val flag = fieldMatch.groupValues[3] - .removePrefix("#").trim() - .takeIf { it.isNotEmpty() } - - Field(type, name, flag) - }.toMutableSet() - - getOrPut(blockName, ::mutableSetOf).addAll(fields) - } - } - - private fun String.getMethods() = mutableSetOf().apply { - methodRegex.findAll(this@getMethods).forEach { match -> - val returnType = match.groupValues[1] - val methodName = match.groupValues[2] - val parameters = match.groupValues[3] - val code = match.groupValues[4].trim() - - add(Method(methodName, returnType, parameters, code)) - } - } - - private fun String.getDependencies() = includeRegex.findAll(this) - .map { it.groupValues[1] } - .toSet() - - private fun String.getDefinitions() = mutableSetOf().apply { - defineRegex.findAll(this@getDefinitions).forEach { match -> - add(Field(match.groupValues[2].trim(), match.groupValues[1], null)) - } - } - - private fun MutableMap>.getBlock(name: String) = - getOrDefault(name, mutableSetOf()) - } -} diff --git a/src/main/kotlin/com/lambda/graphics/shader/Shader.kt b/src/main/kotlin/com/lambda/graphics/shader/Shader.kt index 440c98571..6a4ae1e06 100644 --- a/src/main/kotlin/com/lambda/graphics/shader/Shader.kt +++ b/src/main/kotlin/com/lambda/graphics/shader/Shader.kt @@ -17,11 +17,15 @@ package com.lambda.graphics.shader +import com.lambda.Lambda.mc import com.lambda.graphics.RenderMain import com.lambda.graphics.shader.ShaderUtils.createShaderProgram import com.lambda.graphics.shader.ShaderUtils.loadShader import com.lambda.graphics.shader.ShaderUtils.uniformMatrix +import com.lambda.util.LambdaResource import com.lambda.util.math.Vec2d +import com.lambda.util.stream +import com.lambda.util.text import it.unimi.dsi.fastutil.objects.Object2IntMap import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap import net.minecraft.util.math.Vec3d @@ -35,23 +39,26 @@ import org.lwjgl.opengl.GL20C.glUniform4f import org.lwjgl.opengl.GL20C.glUseProgram import java.awt.Color -class Shader private constructor(name: String) { +class Shader(vertex: LambdaResource, fragment: LambdaResource) { private val uniformCache: Object2IntMap = Object2IntOpenHashMap() - private val id: Int + private val id: Int = createShaderProgram( + loadShader(ShaderType.VertexShader, vertex.text), + loadShader(ShaderType.FragmentShader, fragment.text) + ) - init { - val texts = buildShaderSource(name) - - id = createShaderProgram( - loadShader(ShaderType.VertexShader, texts.first), - loadShader(ShaderType.FragmentShader, texts.second) - ) - } - - fun use() { + fun use() { glUseProgram(id) set("u_ProjModel", RenderMain.projModel) + + val x = mc.gameRenderer.camera.pos.x.toFloat() + val y = mc.gameRenderer.camera.pos.y.toFloat() + val z = mc.gameRenderer.camera.pos.z.toFloat() + + val view = Matrix4f() + .translation(-x, -y, -z) + + set("u_View", view) } private fun loc(name: String) = @@ -89,13 +96,4 @@ class Shader private constructor(name: String) { operator fun set(name: String, mat: Matrix4f) = uniformMatrix(loc(name), mat) - - companion object { - private val shaderCache = hashMapOf() - - fun shader(path: String) = - shaderCache.getOrPut(path) { - Shader(path) - } - } } diff --git a/src/main/kotlin/com/lambda/graphics/shader/ShaderInterp.kt b/src/main/kotlin/com/lambda/graphics/shader/ShaderInterp.kt deleted file mode 100644 index 8c5d8cd61..000000000 --- a/src/main/kotlin/com/lambda/graphics/shader/ShaderInterp.kt +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2025 Lambda - * - * 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 . - */ - -package com.lambda.graphics.shader - - -fun buildShaderSource(path: String): Pair { - val shader = ParsedShader(path) - - val vertexShader = StringBuilder().appendLine(HEADER) - val fragmentShader = StringBuilder().appendLine(HEADER) - val shaders = setOf(vertexShader, fragmentShader) - - /* Build attribs for vertex shader */ - shader.attribs.apply { - if (isNotEmpty()) vertexShader.appendLine() - - forEachIndexed { i, attribute -> - vertexShader.appendLine( - "layout (location = $i) in ${attribute.type} ${attribute.name};" - ) - } - } - - /* Build uniforms */ - shader.uniforms.apply { - val vertex = mutableSetOf() - val fragment = mutableSetOf() - - vertex.add("uniform mat4 u_ProjModel;") - forEach { uniform -> - val line = "uniform ${uniform.type} ${uniform.name};" - - when (uniform.flag) { - "vertex" -> vertex += line - "fragment" -> fragment += line - "global" -> { vertex += line; fragment += line } - else -> throw IllegalStateException("Destination of \"$line\" is not specified") - } - } - - vertex.apply { - vertexShader.appendLine() - forEach { vertexShader.appendLine(it) } - } - - fragment.apply { - if (isNotEmpty()) fragmentShader.appendLine() - forEach { fragmentShader.appendLine(it) } - } - } - - /* Does "v_TexCoord = uv" in the vertex shader for you */ - val autoAssignment = StringBuilder() - - /* Build in/out vars */ - shader.exported.apply { - if (isNotEmpty()) shaders.forEach(StringBuilder::appendLine) - - // Add gl_Position = u_ProjModel * pos; by default - val hasPosAttribute = shader.attribs.any { it.name == "pos" && it.type == "vec4" } - val glPosImplemented = any { it.name == "gl_Position" } - if (hasPosAttribute && !glPosImplemented) { - autoAssignment.appendLine(" gl_Position = u_ProjModel * pos;") - } - - forEach { export -> - if (export.type != "core") { - vertexShader.appendLine("out ${export.type} ${export.name};") - fragmentShader.appendLine("in ${export.type} ${export.name};") - } - - export.flag?.let { expr -> /* Add assignment if present */ - autoAssignment.appendLine(" ${export.name} = ${expr};") - } - } - - fragmentShader.appendLine() - fragmentShader.appendLine("out vec4 color;") - } - - /* Build definitions */ - shader.definitions.apply { - if (isNotEmpty()) fragmentShader.appendLine() - - forEach { definition -> - fragmentShader.appendLine("#define ${definition.name} ${definition.type}") - } - } - - /* Build methods */ - shaders.forEach(StringBuilder::appendLine) - val methods = shader.methods - - val vertexMain = methods.takeMain("vertex").apply { - code += autoAssignment.trim() - }.construct("main") - vertexShader.appendLine(vertexMain) - - val fragmentMain = methods.takeMain("fragment").construct("main") - methods.forEach { fragmentShader.appendLine(it.construct()) } - fragmentShader.appendLine(fragmentMain) - - return vertexShader.toString().trimEnd() to fragmentShader.toString().trimEnd() -} - -private fun MutableSet.takeMain(name: String) = firstOrNull { - it.name == name && it.returnType == "void" && it.parameters.isEmpty() -}.apply(this::remove) ?: ParsedShader.Method(name, "void", "", "") - -private const val HEADER = "#version 330 core" diff --git a/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt b/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt index 78d330827..708ded845 100644 --- a/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt +++ b/src/main/kotlin/com/lambda/module/modules/combat/CrystalAura.kt @@ -17,19 +17,12 @@ package com.lambda.module.modules.combat -import com.lambda.Lambda import com.lambda.config.groups.RotationSettings import com.lambda.config.groups.Targeting import com.lambda.context.SafeContext import com.lambda.event.events.EntityEvent -import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent import com.lambda.event.listener.SafeListener.Companion.listen -import com.lambda.graphics.gl.Matrices -import com.lambda.graphics.gl.Matrices.buildWorldProjection -import com.lambda.graphics.gl.Matrices.withVertexTransform -import com.lambda.graphics.renderer.gui.FontRenderer -import com.lambda.graphics.renderer.gui.FontRenderer.drawString import com.lambda.interaction.material.StackSelection.Companion.selectStack import com.lambda.interaction.material.container.ContainerManager.transfer import com.lambda.interaction.material.container.containers.MainHandContainer @@ -192,19 +185,6 @@ object CrystalAura : Module( updatesThisFrame = 0 } - listen { - if (!debug) return@listen - - Matrices.push { - val c = Lambda.mc.gameRenderer.camera.pos.negate() - translate(c.x, c.y, c.z) - // Build the buffer - blueprint.values.forEach { - it.buildDebug() - } - } - } - // Update last received entity spawn listen(alwaysListen = true) { event -> lastEntityId = event.entity.id @@ -524,27 +504,6 @@ object CrystalAura : Module( } } } - - fun buildDebug() { - withVertexTransform(buildWorldProjection(blockPos.crystalPosition, 0.4, Matrices.ProjRotationMode.ToCamera)) { - val lines = arrayOf( - "Decision: ${actionType.name} ${priority.roundToStep(0.01)}", - "", - "Blocked: $blocked", - "Crystal: $hasCrystal", - "", - "Target Damage: ${target.roundToStep(0.01)}", - "Self Damage: ${self.roundToStep(0.01)}" - ) - - var height = -0.5 * lines.size * (FontRenderer.getHeight() + 2) - - lines.forEach { - drawString(it, Vec2d(-FontRenderer.getWidth(it) * 0.5, height)) - height += FontRenderer.getHeight() + 2 - } - } - } } private val EndCrystalEntity.baseBlockPos get() = diff --git a/src/main/kotlin/com/lambda/module/modules/render/Particles.kt b/src/main/kotlin/com/lambda/module/modules/render/Particles.kt index 8a9924fdf..a50eb92a9 100644 --- a/src/main/kotlin/com/lambda/module/modules/render/Particles.kt +++ b/src/main/kotlin/com/lambda/module/modules/render/Particles.kt @@ -33,7 +33,7 @@ import com.lambda.graphics.gl.Matrices.buildWorldProjection import com.lambda.graphics.gl.Matrices.withVertexTransform import com.lambda.graphics.pipeline.VertexBuilder import com.lambda.graphics.pipeline.VertexPipeline -import com.lambda.graphics.shader.Shader.Companion.shader +import com.lambda.graphics.shader.Shader import com.lambda.gui.components.ClickGuiLayout import com.lambda.interaction.managers.rotating.Rotation import com.lambda.module.Module @@ -53,6 +53,7 @@ import com.mojang.blaze3d.opengl.GlConst.GL_ONE import com.mojang.blaze3d.opengl.GlConst.GL_SRC_ALPHA import net.minecraft.entity.Entity import net.minecraft.util.math.Vec3d +import org.joml.Matrix4f import kotlin.math.sin // FixMe: Do not call render stuff in the initialization block @@ -82,7 +83,7 @@ object Particles : Module( private var particles = mutableListOf() private val pipeline = VertexPipeline(VertexMode.Triangles, VertexAttrib.Group.PARTICLE) - private val shader = shader("renderer/particle") + private val shader = Shader("shaders/vertex/particles.glsl", "shaders/fragment/particles.glsl") init { listen { @@ -97,8 +98,6 @@ object Particles : Module( withBlendFunc(GL_SRC_ALPHA, GL_ONE) { shader.use() - shader["u_CameraPosition"] = mc.gameRenderer.camera.pos - pipeline.upload(builder) withDepth(false, pipeline::render) pipeline.clear() diff --git a/src/main/kotlin/com/lambda/util/LambdaResource.kt b/src/main/kotlin/com/lambda/util/LambdaResource.kt index 19f0b7c8d..64278cf41 100644 --- a/src/main/kotlin/com/lambda/util/LambdaResource.kt +++ b/src/main/kotlin/com/lambda/util/LambdaResource.kt @@ -31,6 +31,10 @@ val LambdaResource.stream: InputStream get() = Lambda::class.java.getResourceAsStream("/assets/lambda/$this") ?: throw FileNotFoundException("File \"/assets/lambda/$this\" not found") +val LambdaResource.text: String + get() = Lambda::class.java.getResourceAsStream("/assets/lambda/$this")?.readAllBytes()?.decodeToString() + ?: throw FileNotFoundException("File \"/assets/lambda/$this\" not found") + val LambdaResource.url: URL get() = Lambda::class.java.getResource("/assets/lambda/$this") ?: throw FileNotFoundException("File \"/assets/lambda/$this\" not found") diff --git a/src/main/resources/assets/lambda/shaders/fragment/font.glsl b/src/main/resources/assets/lambda/shaders/fragment/font.glsl new file mode 100644 index 000000000..afb98a7ff --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/fragment/font.glsl @@ -0,0 +1,24 @@ +#version 420 + +in vec2 v_TexCoord; +in vec4 v_Color; + +out vec4 color; + +float sdf(float channel, float min, float max) { + return 1.0 - smoothstep(min, max, 1.0 - channel); +} + +void main() +{ + bool isEmoji = v_TexCoord.x < 0.0; + + if (isEmoji) { + vec4 c = texture(u_EmojiTexture, -v_TexCoord); + color = vec4(c.rgb, sdf(c.a, u_SDFMin, u_SDFMax)) * v_Color; + return; + } + + float sdf = sdf(texture(u_FontTexture, v_TexCoord).r, u_SDFMin, u_SDFMax); + color = vec4(1.0, 1.0, 1.0, sdf) * v_Color; +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/fragment/particles.glsl b/src/main/resources/assets/lambda/shaders/fragment/particles.glsl new file mode 100644 index 000000000..967ef6a91 --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/fragment/particles.glsl @@ -0,0 +1,12 @@ +#version 330 core + +in vec2 v_TexCoord; +in vec4 v_Color; + +out vec4 color; + +void main() +{ + float a = 1.0 - length(v_TexCoord - 0.5) * 2.0; + color = v_Color * vec4(1.0, 1.0, 1.0, a); +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/fragment/pos_color.glsl b/src/main/resources/assets/lambda/shaders/fragment/pos_color.glsl new file mode 100644 index 000000000..2eb6b4242 --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/fragment/pos_color.glsl @@ -0,0 +1,9 @@ +#version 420 + +in vec4 v_Color; +out vec4 color; + +void main() +{ + color = v_Color; +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/fragment/pos_tex.glsl b/src/main/resources/assets/lambda/shaders/fragment/pos_tex.glsl new file mode 100644 index 000000000..efac6ba5c --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/fragment/pos_tex.glsl @@ -0,0 +1,11 @@ +#version 330 core + +in vec2 v_TexCoord; +out vec4 color; + +uniform sampler2D u_Texture; + +void main() +{ + color = texture(u_Texture, v_TexCoord); +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/fragment/pos_tex_color.glsl b/src/main/resources/assets/lambda/shaders/fragment/pos_tex_color.glsl new file mode 100644 index 000000000..09f3f6b96 --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/fragment/pos_tex_color.glsl @@ -0,0 +1,13 @@ +#version 330 core + +in vec2 v_TexCoord; +in vec4 v_Color; + +out vec4 color; + +uniform sampler2D u_Texture; + +void main() +{ + color = texture(u_Texture, v_TexCoord) * v_Color +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/pos_color.glsl b/src/main/resources/assets/lambda/shaders/pos_color.glsl deleted file mode 100644 index c8536f01b..000000000 --- a/src/main/resources/assets/lambda/shaders/pos_color.glsl +++ /dev/null @@ -1,12 +0,0 @@ -attributes { - vec4 pos; - vec4 color; -}; - -export { - vec4 v_Color; # color -}; - -void fragment() { - color = v_Color; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/pos_tex.glsl b/src/main/resources/assets/lambda/shaders/pos_tex.glsl deleted file mode 100644 index b058e7bc2..000000000 --- a/src/main/resources/assets/lambda/shaders/pos_tex.glsl +++ /dev/null @@ -1,16 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; -}; - -uniforms { - sampler2D u_Texture; # fragment -}; - -export { - vec2 v_TexCoord; # uv -}; - -void fragment() { - color = texture(u_Texture, v_TexCoord); -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/pos_tex_color.glsl b/src/main/resources/assets/lambda/shaders/pos_tex_color.glsl deleted file mode 100644 index e10b9a4a8..000000000 --- a/src/main/resources/assets/lambda/shaders/pos_tex_color.glsl +++ /dev/null @@ -1,18 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; - vec4 color; -}; - -uniforms { - sampler2D u_Texture; # fragment -}; - -export { - vec2 v_TexCoord; # uv - vec4 v_Color; # color -}; - -void fragment() { - color = texture(u_Texture, v_TexCoord) * v_Color; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/pos_tex_shady.glsl b/src/main/resources/assets/lambda/shaders/pos_tex_shady.glsl deleted file mode 100644 index 395642309..000000000 --- a/src/main/resources/assets/lambda/shaders/pos_tex_shady.glsl +++ /dev/null @@ -1,18 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; -}; - -uniforms { - sampler2D u_Texture; # fragment -}; - -export { - vec2 v_TexCoord; # uv -}; - -#include "shade" - -void fragment() { - color = texture(u_Texture, v_TexCoord) * shade; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/box_dynamic.glsl b/src/main/resources/assets/lambda/shaders/renderer/box_dynamic.glsl deleted file mode 100644 index 439df238b..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/box_dynamic.glsl +++ /dev/null @@ -1,20 +0,0 @@ -attributes { - vec3 pos1; - vec3 pos2; - vec4 color; -}; - -uniforms { - mat4 u_ProjModel; # vertex - float u_TickDelta; # vertex - vec3 u_CameraLerp; # vertex -}; - -export { - core gl_Position; # u_ProjModel * vec4(mix(pos1, pos2, u_TickDelta) + u_CameraLerp, 1.0) - vec4 v_Color; # color -}; - -void fragment() { - color = v_Color; -}# diff --git a/src/main/resources/assets/lambda/shaders/renderer/box_static.glsl b/src/main/resources/assets/lambda/shaders/renderer/box_static.glsl deleted file mode 100644 index 5b0a11abc..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/box_static.glsl +++ /dev/null @@ -1,18 +0,0 @@ -attributes { - vec3 pos; - vec4 color; -}; - -uniforms { - mat4 u_ProjModel; # vertex - vec3 u_CameraLerp; # vertex -}; - -export { - core gl_Position; # u_ProjModel * vec4(pos + u_CameraLerp, 1.0) - vec4 v_Color; # color -}; - -void fragment() { - color = v_Color; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/font.glsl b/src/main/resources/assets/lambda/shaders/renderer/font.glsl deleted file mode 100644 index 5d4abd1dc..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/font.glsl +++ /dev/null @@ -1,32 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; - vec4 color; -}; - -uniforms { - sampler2D u_FontTexture; # fragment - sampler2D u_EmojiTexture; # fragment - float u_SDFMin; # fragment - float u_SDFMax; # fragment -}; - -export { - vec2 v_TexCoord; # uv - vec4 v_Color; # color -}; - -#include "sdf" - -void fragment() { - bool isEmoji = v_TexCoord.x < 0.0; - - if (isEmoji) { - vec4 c = texture(u_EmojiTexture, -v_TexCoord); - color = vec4(c.rgb, sdf(c.a, u_SDFMin, u_SDFMax)) * v_Color; - return; - } - - float sdf = sdf(texture(u_FontTexture, v_TexCoord).r, u_SDFMin, u_SDFMax); - color = vec4(1.0, 1.0, 1.0, sdf) * v_Color; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/hue_circle.glsl b/src/main/resources/assets/lambda/shaders/renderer/hue_circle.glsl deleted file mode 100644 index a4ead7707..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/hue_circle.glsl +++ /dev/null @@ -1,21 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; -}; - -export { - vec2 v_TexCoord; # uv -}; - -#include "hsb" -#include "sdf" - -void fragment() { - float dst = 0.5 - length(v_TexCoord - 0.5); - float sdf = sdf(dst, 0.98, 1.0); - - float hue255 = hue(vec2(v_TexCoord.y, 1.0 - v_TexCoord.x)); - vec3 rgb = hsb2rgb(vec3(hue255, 1.0 - dst * 2.0, 1.0)); - - color = vec4(rgb, sdf); -}# diff --git a/src/main/resources/assets/lambda/shaders/renderer/particle.glsl b/src/main/resources/assets/lambda/shaders/renderer/particle.glsl deleted file mode 100644 index 9444708e9..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/particle.glsl +++ /dev/null @@ -1,20 +0,0 @@ -attributes { - vec3 pos; - vec2 uv; - vec4 color; -}; - -uniforms { - vec3 u_CameraPosition; # vertex -}; - -export { - core gl_Position; # u_ProjModel * vec4(pos - u_CameraPosition, 1.0) - vec2 v_TexCoord; # uv - vec4 v_Color; # color -}; - -void fragment() { - float a = 1.0 - length(v_TexCoord - 0.5) * 2.0; - color = v_Color * vec4(1.0, 1.0, 1.0, a); -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/rect_filled.glsl b/src/main/resources/assets/lambda/shaders/renderer/rect_filled.glsl deleted file mode 100644 index 7ee5ec204..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/rect_filled.glsl +++ /dev/null @@ -1,13 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; - vec4 color; -}; - -#include "rect" - -void fragment() { - float distance = signedDistance(); - float alpha = 1 - smoothstep(-SMOOTHING, SMOOTHING, distance); - color = v_Color * vec4(1.0, 1.0, 1.0, alpha) * shade + noise; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/rect_glow.glsl b/src/main/resources/assets/lambda/shaders/renderer/rect_glow.glsl deleted file mode 100644 index 094f9c373..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/rect_glow.glsl +++ /dev/null @@ -1,40 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; - vec4 color; -}; - -uniforms { - float u_RectWidth; # fragment - float u_InnerRectWidth; # fragment - - float u_InnerRoundLeftTop; # fragment - float u_InnerRoundLeftBottom; # fragment - float u_InnerRoundRightBottom; # fragment - float u_InnerRoundRightTop; # fragment -}; - -#include "rect" - -void fragment() { - float distance = signedDistance(); - float innerDistance = signedDistance(vec4( - u_InnerRoundRightBottom, - u_InnerRoundRightTop, - u_InnerRoundLeftBottom, - u_InnerRoundLeftTop - )); - - float bloomDistance = distance; - if (innerDistance > 0.0 && distance < 0.0) bloomDistance = 0.0; - if (innerDistance < 0.0) bloomDistance = innerDistance; - - float bloomSpread = ((bloomDistance > 0.0) ? u_RectWidth : -u_InnerRectWidth); - float bloomAlpha = 1.0 / (1.0 + bloomDistance / bloomSpread); - - float glowAlpha = - smoothstep(-u_InnerRectWidth, 0.0, bloomDistance) - - smoothstep(0.0, u_RectWidth, bloomDistance); - - color = v_Color * vec4(1.0, 1.0, 1.0, bloomAlpha * glowAlpha) * shade + noise; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/rect_outline.glsl b/src/main/resources/assets/lambda/shaders/renderer/rect_outline.glsl deleted file mode 100644 index d27ac5873..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/rect_outline.glsl +++ /dev/null @@ -1,18 +0,0 @@ -attributes { - vec4 pos; - vec2 uv; - vec4 color; -}; - -uniforms { - float u_RectWidth; # fragment -}; - -#include "rect" - -void fragment() { - float distance = signedDistance(); - float innerAlpha = smoothstep(-u_RectWidth - SMOOTHING, -u_RectWidth + SMOOTHING, distance); - float outerAlpha = 1 - smoothstep(u_RectWidth - SMOOTHING, u_RectWidth + SMOOTHING, distance); - color = v_Color * vec4(1.0, 1.0, 1.0, min(innerAlpha, outerAlpha)) * shade + noise; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/tracer_dynamic.glsl b/src/main/resources/assets/lambda/shaders/renderer/tracer_dynamic.glsl deleted file mode 100644 index a178426fd..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/tracer_dynamic.glsl +++ /dev/null @@ -1,27 +0,0 @@ -attributes { - vec3 pos1; - vec3 pos2; - vec4 color; -}; - -uniforms { - mat4 u_ProjModel; # vertex - float u_TickDelta; # vertex - vec3 u_CameraPosition; # vertex -}; - -export { - core gl_Position; # vec4(0.0, 0.0, 0.0, 1.0) - vec4 v_Color; # color -}; - -void vertex() { - if (gl_VertexID % 2 == 0) { - vec3 VERTEX_POSITION = mix(pos1, pos2, u_TickDelta) - u_CameraPosition; - gl_Position = u_ProjModel * vec4(VERTEX_POSITION, 1.0); - } -}# - -void fragment() { - color = v_Color; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/renderer/tracer_static.glsl b/src/main/resources/assets/lambda/shaders/renderer/tracer_static.glsl deleted file mode 100644 index 8197af918..000000000 --- a/src/main/resources/assets/lambda/shaders/renderer/tracer_static.glsl +++ /dev/null @@ -1,25 +0,0 @@ -attributes { - vec3 pos; - vec4 color; -}; - -uniforms { - mat4 u_ProjModel; # vertex - vec3 u_CameraPosition; # vertex -}; - -export { - core gl_Position; # vec4(0.0, 0.0, 0.0, 1.0) - vec4 v_Color; # color -}; - -void vertex() { - if (gl_VertexID % 2 == 0) { - vec3 VERTEX_POSITION = pos - u_CameraPosition; - gl_Position = u_ProjModel * vec4(VERTEX_POSITION, 1.0); - } -}# - -void fragment() { - color = v_Color; -}# \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/vertex/box_dynamic.glsl b/src/main/resources/assets/lambda/shaders/vertex/box_dynamic.glsl new file mode 100644 index 000000000..aad9c7385 --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/vertex/box_dynamic.glsl @@ -0,0 +1,17 @@ +#version 330 core + +layout (location = 0) in vec3 pos1; +layout (location = 1) in vec3 pos2; +layout (location = 2) in vec4 color; + +out vec4 v_Color; + +uniform mat4 u_ProjModel; +uniform mat4 u_View; +uniform float u_TickDelta; + +void main() +{ + gl_Position = u_ProjModel * u_View * vec4(mix(pos1, pos2, u_TickDelta), 1.0); + v_Color = color; +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/vertex/box_static.glsl b/src/main/resources/assets/lambda/shaders/vertex/box_static.glsl new file mode 100644 index 000000000..ba73727da --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/vertex/box_static.glsl @@ -0,0 +1,15 @@ +#version 330 core + +layout (location = 0) in vec3 pos; +layout (location = 1) in vec4 color; + +out vec4 v_Color; + +uniform mat4 u_ProjModel; +uniform mat4 u_View; + +void main() +{ + gl_Position = u_ProjModel * u_View * vec4(pos, 1.0); + v_Color = color; +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/vertex/font.glsl b/src/main/resources/assets/lambda/shaders/vertex/font.glsl new file mode 100644 index 000000000..e8a0f3b92 --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/vertex/font.glsl @@ -0,0 +1,19 @@ +#version 330 core + +layout (location = 0) in vec4 pos; +layout (location = 1) in vec2 uv; +layout (location = 2) in vec4 color; // Does this fuck the padding ? + +out vec2 v_TexCoord; +out vec4 v_Color; + +uniform sampler2D u_FontTexture; +uniform sampler2D u_EmojiTexture; +uniform float u_SDFMin; +uniform float u_SDFMin; + +void main() +{ + v_TexCoord = uv; + v_Color = color; +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/vertex/particles.glsl b/src/main/resources/assets/lambda/shaders/vertex/particles.glsl new file mode 100644 index 000000000..08e0e0a43 --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/vertex/particles.glsl @@ -0,0 +1,19 @@ +#version 330 core + +layout (location = 0) in vec3 pos; +layout (location = 1) in vec2 uv; +layout (location = 2) in vec4 color; + +out vec2 v_TexCoord; +out vec4 v_Color; + +uniform mat4 u_ProjModel; +uniform mat4 u_View; + +void main() +{ + gl_Position = u_ProjModel * u_View * vec4(pos, 1.0); + + v_TexCoord = uv; + v_Color = color; +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/vertex/tracer_dynamic.glsl b/src/main/resources/assets/lambda/shaders/vertex/tracer_dynamic.glsl new file mode 100644 index 000000000..2d7f171e5 --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/vertex/tracer_dynamic.glsl @@ -0,0 +1,20 @@ +#version 330 core + +layout (location = 0) in vec3 pos1; +layout (location = 1) in vec2 pos1; +layout (location = 2) in vec4 color; + +out vec4 v_Color; + +uniform mat4 u_ProjModel; +uniform mat4 u_View; +uniform float u_TickDelta; + +void main() +{ + if (l_VertexID % 2 != 0) + return; + + vec3 VERTEX_POSITION = mix(pos1, pos2, u_TickDelta); + gl_Position = u_ProjModel * u_View * vec4(VERTEX_POSITION, 1.0); +} \ No newline at end of file diff --git a/src/main/resources/assets/lambda/shaders/vertex/tracer_static.glsl b/src/main/resources/assets/lambda/shaders/vertex/tracer_static.glsl new file mode 100644 index 000000000..1d111b6ca --- /dev/null +++ b/src/main/resources/assets/lambda/shaders/vertex/tracer_static.glsl @@ -0,0 +1,17 @@ +#version 330 core + +layout (location = 0) in vec3 pos; +layout (location = 1) in vec4 color; + +out vec4 v_Color; + +uniform mat4 u_ProjModel; +uniform mat4 u_View; + +void main() +{ + if (gl_VertexID % 2 != 0) + return; + + gl_Position = u_ProjModel * u_View * vec4(pos, 1.0); +} \ No newline at end of file