diff options
Diffstat (limited to 'src')
3 files changed, 44 insertions, 16 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/feature/devcosmetics/CustomCapeFeatureRenderer.java b/src/main/java/moe/nea/firmament/mixins/feature/devcosmetics/CustomCapeFeatureRenderer.java index e1bdd7e..c9115d2 100644 --- a/src/main/java/moe/nea/firmament/mixins/feature/devcosmetics/CustomCapeFeatureRenderer.java +++ b/src/main/java/moe/nea/firmament/mixins/feature/devcosmetics/CustomCapeFeatureRenderer.java @@ -35,6 +35,7 @@ public abstract class CustomCapeFeatureRenderer extends FeatureRenderer<PlayerEn vertexConsumer, RenderLayer.getEntitySolid(skinTextures.capeTexture()), vertexConsumerProvider, + matrixStack, updatedConsumer -> { original.call(instance, matrixStack, updatedConsumer, light, overlay); return Unit.INSTANCE; diff --git a/src/main/kotlin/features/misc/CustomCapes.kt b/src/main/kotlin/features/misc/CustomCapes.kt index a3725e5..5004c15 100644 --- a/src/main/kotlin/features/misc/CustomCapes.kt +++ b/src/main/kotlin/features/misc/CustomCapes.kt @@ -1,10 +1,13 @@ package moe.nea.firmament.features.misc import com.mojang.blaze3d.buffers.GpuBuffer +import com.mojang.blaze3d.buffers.Std140Builder import com.mojang.blaze3d.systems.RenderSystem import java.nio.ByteBuffer +import java.nio.ByteOrder import java.util.OptionalDouble import java.util.OptionalInt +import org.joml.Vector4f import util.render.CustomRenderPipelines import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -16,6 +19,7 @@ import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.entity.state.PlayerEntityRenderState import net.minecraft.client.util.BufferAllocator import net.minecraft.client.util.SkinTextures +import net.minecraft.client.util.math.MatrixStack import net.minecraft.util.Identifier import moe.nea.firmament.Firmament import moe.nea.firmament.features.FirmamentFeature @@ -38,6 +42,7 @@ object CustomCapes : FirmamentFeature { fun replaceRender( renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, model: (VertexConsumer) -> Unit ) } @@ -48,6 +53,7 @@ object CustomCapes : FirmamentFeature { override fun replaceRender( renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, model: (VertexConsumer) -> Unit ) { model(vertexConsumerProvider.getBuffer(RenderLayer.getEntitySolid(location))) @@ -63,14 +69,16 @@ object CustomCapes : FirmamentFeature { override fun replaceRender( renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, 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() + val animationBufSource = Std140Builder.intoBuffer(ByteBuffer.allocateDirect(16).order(ByteOrder.nativeOrder())) + .putFloat(animationValue.toFloat()) + .align(16) + .get() BufferAllocator(2048).use { allocator -> val bufferBuilder = BufferBuilder(allocator, renderLayer.drawMode, renderLayer.vertexFormat) model(bufferBuilder) @@ -81,14 +89,29 @@ object CustomCapes : FirmamentFeature { val templateTexture = MC.textureManager.getTexture(template) val backgroundTexture = MC.textureManager.getTexture(background) val foregroundTexture = MC.textureManager.getTexture(overlay) + val dynamicTransforms = RenderSystem.getDynamicUniforms() + .write( + RenderSystem.getModelViewMatrix(), + Vector4f(1.0F, 1.0F, 1.0F, 1.0F), + RenderSystem.getModelOffset(), + RenderSystem.getTextureMatrix(), + RenderSystem.getShaderLineWidth() + ) + val framebuffer = MC.instance.framebuffer + val colorAttachment = + RenderSystem.outputColorTextureOverride ?: framebuffer.getColorAttachmentView() + val depthAttachment = + (RenderSystem.outputDepthTextureOverride + ?: framebuffer.getDepthAttachmentView()).takeIf { framebuffer.useDepthAttachment } + RenderSystem.getDevice() - .createBuffer({ "Firm Cape Animation" }, GpuBuffer.USAGE_UNIFORM, animationBufSource) + .createBuffer({ "Firm Cape Animation" }, GpuBuffer.USAGE_UNIFORM or GpuBuffer.USAGE_MAP_READ, animationBufSource) .use { animationUniformBuf -> commandEncoder.createRenderPass( { "FirmamentCustomCape" }, - MC.instance.framebuffer.colorAttachmentView, + colorAttachment, OptionalInt.empty(), - MC.instance.framebuffer.depthAttachmentView, + depthAttachment, OptionalDouble.empty(), ).use { renderPass -> // TODO: account for lighting @@ -96,6 +119,8 @@ object CustomCapes : FirmamentFeature { renderPass.bindSampler("Sampler0", templateTexture.glTextureView) renderPass.bindSampler("Sampler1", backgroundTexture.glTextureView) renderPass.bindSampler("Sampler3", foregroundTexture.glTextureView) + RenderSystem.bindDefaultUniforms(renderPass) + renderPass.setUniform("DynamicTransforms", dynamicTransforms) renderPass.setUniform("Animation", animationUniformBuf) renderPass.setIndexBuffer(indexBuffer, indexBufferConstructor.indexType) renderPass.setVertexBuffer(0, vertexBuffer) @@ -166,12 +191,13 @@ object CustomCapes : FirmamentFeature { vertexConsumer: VertexConsumer, renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, model: (VertexConsumer) -> Unit ) { val capeStorage = CapeStorage.cast(playerEntityRenderState) val firmCape = capeStorage.cape_firmament if (firmCape != null) { - firmCape.render.replaceRender(renderLayer, vertexConsumerProvider, model) + firmCape.render.replaceRender(renderLayer, vertexConsumerProvider, matrixStack, model) } else { model(vertexConsumer) } diff --git a/src/main/resources/assets/firmament/shaders/cape/parallax.fsh b/src/main/resources/assets/firmament/shaders/cape/parallax.fsh index bc9a440..5ee269d 100644 --- a/src/main/resources/assets/firmament/shaders/cape/parallax.fsh +++ b/src/main/resources/assets/firmament/shaders/cape/parallax.fsh @@ -1,19 +1,20 @@ #version 150 #moj_import <minecraft:fog.glsl> +#moj_import <minecraft:dynamictransforms.glsl> + #define M_PI 3.1415926535897932384626433832795 #define M_TAU (2.0 * M_PI) uniform sampler2D Sampler0; uniform sampler2D Sampler1; uniform sampler2D Sampler3; -uniform vec4 ColorModulator; -uniform float FogStart; -uniform float FogEnd; -uniform vec4 FogColor; -uniform float Animation; +layout(std140) uniform Animation { + float AnimationPosition; +}; -in float vertexDistance; +in float sphericalVertexDistance; +in float cylindricalVertexDistance; in vec4 vertexColor; in vec4 lightMapColor; in vec4 overlayColor; @@ -35,13 +36,13 @@ void main() { vec4 color = texture(Sampler0, texCoord0); if (color.g > 0.99) { // TODO: maybe this speed in each direction should be a uniform - color = texture(Sampler1, texCoord0 + Animation * vec2(3.0, -2.0)); + color = texture(Sampler1, texCoord0 + AnimationPosition * vec2(3.0, -2.0)); } vec4 highlightColor = texture(Sampler3, texCoord0); if (highlightColor.a > 0.5) { color = highlightColor; - float animationHighlight = highlightDistance(texCoord0, vec2(-12.0, 2.0), Animation); + float animationHighlight = highlightDistance(texCoord0, vec2(-12.0, 2.0), AnimationPosition); color.rgb += (animationHighlight); } #ifdef ALPHA_CUTOUT @@ -49,5 +50,5 @@ void main() { discard; } #endif - fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor); + fragColor = apply_fog(color, sphericalVertexDistance, cylindricalVertexDistance, FogEnvironmentalStart, FogEnvironmentalEnd, FogRenderDistanceStart, FogRenderDistanceEnd, FogColor); } |
