diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-07-17 11:52:28 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-07-17 11:52:28 +0200 |
| commit | 25f0e7fd62db22036969120843165f4759530b8f (patch) | |
| tree | 262ed44e0e68464ba99f7650fed8df102c982fe5 /src/main/kotlin/features/misc/CustomCapes.kt | |
| parent | 13d64762bbf110fbc52719fb9d93490648199dd2 (diff) | |
| download | Firmament-25f0e7fd62db22036969120843165f4759530b8f.tar.gz Firmament-25f0e7fd62db22036969120843165f4759530b8f.tar.bz2 Firmament-25f0e7fd62db22036969120843165f4759530b8f.zip | |
feat: Launch on 1.21.7
Diffstat (limited to 'src/main/kotlin/features/misc/CustomCapes.kt')
| -rw-r--r-- | src/main/kotlin/features/misc/CustomCapes.kt | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/main/kotlin/features/misc/CustomCapes.kt b/src/main/kotlin/features/misc/CustomCapes.kt index dc5187a..a3725e5 100644 --- a/src/main/kotlin/features/misc/CustomCapes.kt +++ b/src/main/kotlin/features/misc/CustomCapes.kt @@ -1,6 +1,8 @@ package moe.nea.firmament.features.misc +import com.mojang.blaze3d.buffers.GpuBuffer import com.mojang.blaze3d.systems.RenderSystem +import java.nio.ByteBuffer import java.util.OptionalDouble import java.util.OptionalInt import util.render.CustomRenderPipelines @@ -63,34 +65,44 @@ object CustomCapes : FirmamentFeature { vertexConsumerProvider: VertexConsumerProvider, model: (VertexConsumer) -> Unit ) { + // TODO: figure out how exactly the rotation abstraction works + val animationValue = (startTime.passedTime() / animationSpeed).mod(1F) + val commandEncoder = RenderSystem.getDevice().createCommandEncoder() + val animationBufSource = ByteBuffer.allocateDirect(8) + animationBufSource.putFloat(animationValue.toFloat()) + animationBufSource.flip() BufferAllocator(2048).use { allocator -> val bufferBuilder = BufferBuilder(allocator, renderLayer.drawMode, renderLayer.vertexFormat) model(bufferBuilder) bufferBuilder.end().use { buffer -> - val commandEncoder = RenderSystem.getDevice().createCommandEncoder() val vertexBuffer = renderLayer.vertexFormat.uploadImmediateVertexBuffer(buffer.buffer) val indexBufferConstructor = RenderSystem.getSequentialBuffer(renderLayer.drawMode) val indexBuffer = indexBufferConstructor.getIndexBuffer(buffer.drawParameters.indexCount) val templateTexture = MC.textureManager.getTexture(template) val backgroundTexture = MC.textureManager.getTexture(background) val foregroundTexture = MC.textureManager.getTexture(overlay) - commandEncoder.createRenderPass( - MC.instance.framebuffer.colorAttachment, - OptionalInt.empty(), - MC.instance.framebuffer.depthAttachment, - OptionalDouble.empty(), - ).use { renderPass -> - // TODO: account for lighting - renderPass.setPipeline(CustomRenderPipelines.PARALLAX_CAPE_SHADER) - renderPass.bindSampler("Sampler0", templateTexture.glTexture) - renderPass.bindSampler("Sampler1", backgroundTexture.glTexture) - renderPass.bindSampler("Sampler3", foregroundTexture.glTexture) - val animationValue = (startTime.passedTime() / animationSpeed).mod(1F) - renderPass.setUniform("Animation", animationValue.toFloat()) - renderPass.setIndexBuffer(indexBuffer, indexBufferConstructor.indexType) - renderPass.setVertexBuffer(0, vertexBuffer) - renderPass.drawIndexed(0, buffer.drawParameters.indexCount) - } + RenderSystem.getDevice() + .createBuffer({ "Firm Cape Animation" }, GpuBuffer.USAGE_UNIFORM, animationBufSource) + .use { animationUniformBuf -> + commandEncoder.createRenderPass( + { "FirmamentCustomCape" }, + MC.instance.framebuffer.colorAttachmentView, + OptionalInt.empty(), + MC.instance.framebuffer.depthAttachmentView, + OptionalDouble.empty(), + ).use { renderPass -> + // TODO: account for lighting + renderPass.setPipeline(CustomRenderPipelines.PARALLAX_CAPE_SHADER) + renderPass.bindSampler("Sampler0", templateTexture.glTextureView) + renderPass.bindSampler("Sampler1", backgroundTexture.glTextureView) + renderPass.bindSampler("Sampler3", foregroundTexture.glTextureView) + renderPass.setUniform("Animation", animationUniformBuf) + renderPass.setIndexBuffer(indexBuffer, indexBufferConstructor.indexType) + renderPass.setVertexBuffer(0, vertexBuffer) + renderPass.drawIndexed(0, 0, buffer.drawParameters.indexCount, 1) + } + + } } } } |
