Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/multiloader-common.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ val modAuthor = project.findProperty("mod_author")?.toString() ?: ""
val minecraftVersionRange = project.property("minecraft_version_range").toString()
val fabricVersion = project.property("fabric_version").toString()
val fabricLoaderVersion = project.property("fabric_loader_version").toString()
val fabricMinecraftVersionRange = project.findProperty("fabric_minecraft_version_range")?.toString() ?: "~$minecraftVersion"
val license = project.property("license").toString()
val neoforgeVersion = project.property("neoforge_version").toString()
val neoforgeLoaderVersionRange = project.property("neoforge_loader_version_range").toString()
Expand Down Expand Up @@ -76,6 +77,7 @@ tasks.named<ProcessResources>("processResources") {
"minecraft_version_range" to minecraftVersionRange,
"fabric_version" to fabricVersion,
"fabric_loader_version" to fabricLoaderVersion,
"fabric_minecraft_version_range" to fabricMinecraftVersionRange,
"mod_name" to modName,
"mod_author" to modAuthor,
"mod_id" to modId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.epsilon.assets.holders.TranslateHolder;
import com.github.epsilon.modules.impl.ClientSetting;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.locale.Language;

public class DefaultTranslateComponent implements TranslateComponent {

Expand Down Expand Up @@ -38,7 +39,7 @@ public void refresh() {
}

private static String resolveTranslation(String key) {
if (I18n.exists(key)) {
if (Language.getInstance().has(key)) {
return I18n.get(key);
}
return ClientSetting.INSTANCE.i18nFallback.getValue() ? formatKey(key) : key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,78 +1,92 @@
package com.github.epsilon.graphics;

import com.github.epsilon.assets.resources.ResourceLocationUtils;
import com.mojang.blaze3d.PrimitiveTopology;
import com.mojang.blaze3d.pipeline.BindGroupLayout;
import com.mojang.blaze3d.pipeline.BlendFunction;
import com.mojang.blaze3d.pipeline.ColorTargetState;
import com.mojang.blaze3d.pipeline.RenderPipeline;
import com.mojang.blaze3d.shaders.UniformType;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.BindGroupLayouts;
import net.minecraft.client.renderer.RenderPipelines;


public class LuminRenderPipelines {

private final static RenderPipeline.Snippet NO_BLEND_DEPTH_SNIPPET = RenderPipeline.builder(RenderPipelines.MATRICES_PROJECTION_SNIPPET)
private final static BindGroupLayout TTF_INFO_UBO = BindGroupLayout.builder()
.withUniform("TtfInfo", UniformType.UNIFORM_BUFFER)
.build();

private final static RenderPipeline.Snippet NO_BLEND_DEPTH_SNIPPET = RenderPipeline.builder()
.withBindGroupLayout(BindGroupLayouts.MATRICES_PROJECTION)
.withColorTargetState(new ColorTargetState(BlendFunction.TRANSLUCENT))
.buildSnippet();

public final static RenderPipeline RECTANGLE = RenderPipeline.builder(NO_BLEND_DEPTH_SNIPPET)
.withLocation(ResourceLocationUtils.getIdentifier("pipelines/rectangle"))
.withVertexFormat(DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.QUADS)
.withVertexBinding(0, DefaultVertexFormat.POSITION_COLOR)
.withPrimitiveTopology(PrimitiveTopology.QUADS)
.withVertexShader(ResourceLocationUtils.getIdentifier("rectangle"))
.withFragmentShader(ResourceLocationUtils.getIdentifier("rectangle"))
.withCull(false)
.build();

private final static RenderPipeline.Snippet TTF_SNIPPET = RenderPipeline.builder(NO_BLEND_DEPTH_SNIPPET)
.withUniform("TtfInfo", UniformType.UNIFORM_BUFFER)
.withBindGroupLayout(TTF_INFO_UBO)
.buildSnippet();

public final static RenderPipeline TTF_FONT = RenderPipeline.builder(TTF_SNIPPET)
.withLocation(ResourceLocationUtils.getIdentifier("pipelines/ttf_font"))
.withVertexFormat(DefaultVertexFormat.POSITION_TEX_COLOR, VertexFormat.Mode.QUADS)
.withVertexBinding(0, DefaultVertexFormat.POSITION_TEX_COLOR)
.withPrimitiveTopology(PrimitiveTopology.QUADS)
.withVertexShader(ResourceLocationUtils.getIdentifier("ttf_font"))
.withFragmentShader(ResourceLocationUtils.getIdentifier("ttf_font"))
.withSampler("Sampler0")
.withBindGroupLayout(BindGroupLayouts.SAMPLER0)
.withCull(false)
.build();

public final static RenderPipeline ROUND_RECT = RenderPipeline.builder(NO_BLEND_DEPTH_SNIPPET)
.withLocation(ResourceLocationUtils.getIdentifier("pipelines/round_rectangle"))
.withVertexFormat(LuminVertexFormats.ROUND_RECT, VertexFormat.Mode.QUADS)
.withVertexBinding(0, LuminVertexFormats.ROUND_RECT)
.withPrimitiveTopology(PrimitiveTopology.QUADS)
.withVertexShader(ResourceLocationUtils.getIdentifier("round_rectangle"))
.withFragmentShader(ResourceLocationUtils.getIdentifier("round_rectangle"))
.withCull(false)
.build();

public final static RenderPipeline ROUND_RECT_OUTLINE = RenderPipeline.builder(NO_BLEND_DEPTH_SNIPPET)
.withLocation(ResourceLocationUtils.getIdentifier("pipelines/round_rectangle_outline"))
.withVertexFormat(LuminVertexFormats.ROUND_RECT_OUTLINE, VertexFormat.Mode.QUADS)
.withVertexBinding(0, LuminVertexFormats.ROUND_RECT_OUTLINE)
.withPrimitiveTopology(PrimitiveTopology.QUADS)
.withVertexShader(ResourceLocationUtils.getIdentifier("round_rectangle_outline"))
.withFragmentShader(ResourceLocationUtils.getIdentifier("round_rectangle_outline"))
.withCull(false)
.build();

public final static RenderPipeline SHADOW = RenderPipeline.builder(NO_BLEND_DEPTH_SNIPPET)
.withLocation(ResourceLocationUtils.getIdentifier("pipelines/shadow"))
.withVertexFormat(LuminVertexFormats.ROUND_RECT, VertexFormat.Mode.QUADS)
.withVertexBinding(0, LuminVertexFormats.ROUND_RECT)
.withPrimitiveTopology(PrimitiveTopology.QUADS)
.withVertexShader(ResourceLocationUtils.getIdentifier("shadow"))
.withFragmentShader(ResourceLocationUtils.getIdentifier("shadow"))
.withCull(false)
.build();

public final static RenderPipeline TEXTURE = RenderPipeline.builder(NO_BLEND_DEPTH_SNIPPET)
.withLocation(ResourceLocationUtils.getIdentifier("pipelines/texture"))
.withVertexFormat(LuminVertexFormats.TEXTURE, VertexFormat.Mode.QUADS)
.withVertexBinding(0, LuminVertexFormats.TEXTURE)
.withPrimitiveTopology(PrimitiveTopology.QUADS)
.withVertexShader(ResourceLocationUtils.getIdentifier("texture"))
.withFragmentShader(ResourceLocationUtils.getIdentifier("texture"))
.withSampler("Sampler0")
.withBindGroupLayout(BindGroupLayouts.SAMPLER0)
.withCull(false)
.build();

public final static RenderPipeline TRIANGLE = RenderPipeline.builder(NO_BLEND_DEPTH_SNIPPET)
.withLocation(ResourceLocationUtils.getIdentifier("pipelines/triangle"))
.withVertexFormat(DefaultVertexFormat.POSITION_COLOR, VertexFormat.Mode.TRIANGLES)
.withVertexBinding(0, DefaultVertexFormat.POSITION_COLOR)
.withPrimitiveTopology(PrimitiveTopology.TRIANGLES)
.withVertexShader(ResourceLocationUtils.getIdentifier("triangle"))
.withFragmentShader(ResourceLocationUtils.getIdentifier("triangle"))
.withCull(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import com.github.epsilon.assets.holders.RenderTargetHolder;
import com.github.epsilon.assets.holders.RendererHolder;
import com.github.epsilon.assets.resources.ResourceLocationUtils;
import com.github.epsilon.graphics.text.StaticFontLoader;
import com.github.epsilon.graphics.vulkan.LuminVulkanContext;
import com.github.epsilon.modules.impl.player.ComputeTest;
import com.mojang.blaze3d.GpuFormat;
import com.mojang.blaze3d.PrimitiveTopology;
import com.mojang.blaze3d.ProjectionType;
import com.mojang.blaze3d.buffers.GpuBuffer;
import com.mojang.blaze3d.buffers.GpuBufferSlice;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.textures.*;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Projection;
import net.minecraft.client.renderer.ProjectionMatrixBuffer;
import net.minecraft.client.renderer.rendertype.TextureTransform;
Expand All @@ -31,14 +36,20 @@ public class LuminRenderSystem {
@Nullable
private static LuminRenderTarget activeTarget = null;

public static final LuminVulkanContext vulkanContext = new LuminVulkanContext();

public static void setActiveTarget(@Nullable LuminRenderTarget target) {
activeTarget = target;
}

public static void destroyAll() {
ComputeTest.INSTANCE.destroy();

guiProjectionMatrixBuffer.close();
RenderTargetHolder.INSTANCE.destroyAll();
StaticFontLoader.destroyAll();
RendererHolder.INSTANCE.destroyAll();
vulkanContext.destroy();
}

@Nullable
Expand All @@ -47,7 +58,7 @@ public static LuminRenderTarget getActiveTarget() {
}

public static void applyOrthoProjection() {
WindowRenderState windowState = mc.gameRenderer.getGameRenderState().windowRenderState;
WindowRenderState windowState = mc.gameRenderer.gameRenderState().windowRenderState;

guiOrthoProjection
.setupOrtho(-1000.0F, 1000.0F,
Expand All @@ -65,13 +76,13 @@ public static void applyOrthoProjection() {
*/
public static GpuTextureView resolveColorView() {
if (activeTarget != null) return activeTarget.colorView();
return mc.getMainRenderTarget().getColorTextureView();
return mc.gameRenderer.mainRenderTarget().getColorTextureView();
}

@Nullable
public static GpuTextureView resolveDepthView() {
if (activeTarget != null) return activeTarget.depthView();
return mc.getMainRenderTarget().getDepthTextureView();
return Minecraft.getInstance().gameRenderer.mainRenderTarget().getDepthTextureView();
}

public static QuadRenderingInfo prepareQuadRendering(int vertexCount) {
Expand All @@ -84,14 +95,14 @@ public static QuadRenderingInfo prepareQuadRendering(int vertexCount) {
final var indexCount = vertexCount / 4 * 6;

RenderSystem.AutoStorageIndexBuffer autoIndices =
RenderSystem.getSequentialBuffer(VertexFormat.Mode.QUADS);
RenderSystem.getSequentialBuffer(PrimitiveTopology.QUADS);
GpuBuffer ibo = autoIndices.getBuffer(indexCount);

GpuBufferSlice dynamicUniforms = RenderSystem.getDynamicUniforms().writeTransform(
RenderSystem.getModelViewMatrix(),
RenderSystem.getModelViewMatrixCopy(),
new Vector4f(1, 1, 1, 1),
new Vector3f(0, 0, 0),
TextureTransform.DEFAULT_TEXTURING.getMatrix()
TextureTransform.DEFAULT_TEXTURING.createMatrix()
);

return new QuadRenderingInfo(colorView, depthView, autoIndices, ibo, indexCount, dynamicUniforms);
Expand Down Expand Up @@ -119,7 +130,7 @@ public static final class LuminRenderTarget implements AutoCloseable {
private LuminRenderTarget(String name, int width, int height) {
this.width = width;
this.height = height;
this.identifier = ResourceLocationUtils.getIdentifier("lumin-rt" + name);
this.identifier = ResourceLocationUtils.getIdentifier("epsilon-rt" + name);
createTextures();
}

Expand All @@ -133,15 +144,15 @@ private void createTextures() {
final var colorTexture = device.createTexture(
"lumin-rt-color",
GpuTexture.USAGE_TEXTURE_BINDING | GpuTexture.USAGE_RENDER_ATTACHMENT | GpuTexture.USAGE_COPY_DST | GpuTexture.USAGE_COPY_SRC,
TextureFormat.RGBA8,
GpuFormat.RGBA8_UNORM,
width, height, 1, 1
);
final var colorView = device.createTextureView(colorTexture);

depthTexture = device.createTexture(
"lumin-rt-depth",
GpuTexture.USAGE_TEXTURE_BINDING | GpuTexture.USAGE_RENDER_ATTACHMENT | GpuTexture.USAGE_COPY_DST | GpuTexture.USAGE_COPY_SRC,
TextureFormat.DEPTH32,
GpuFormat.D32_FLOAT,
width, height, 1, 1
);
depthView = device.createTextureView(depthTexture);
Expand Down Expand Up @@ -171,7 +182,7 @@ public Identifier getIdentifier() {

public void clear() {
var encoder = RenderSystem.getDevice().createCommandEncoder();
encoder.clearColorAndDepthTextures(colorTexture.getTexture(), 0, depthTexture, 1.0);
encoder.clearColorAndDepthTextures(colorTexture.getTexture(), new Vector4f(0, 0, 0, 0), depthTexture, 1.0);
}

public GpuTextureView colorView() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,31 @@
package com.github.epsilon.graphics;

import com.mojang.blaze3d.GpuFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormatElement;

public class LuminVertexFormats {

private static final int ROUND_INNER_RECT_ID = findNextId();
private static final int ROUND_RADIUS_ID = findNextId(ROUND_INNER_RECT_ID + 1);
private static final int ROUND_OUTLINE_WIDTH_ID = findNextId(ROUND_RADIUS_ID + 1);

public static final VertexFormatElement ROUND_INNER_RECT = VertexFormatElement.register(ROUND_INNER_RECT_ID, 2, VertexFormatElement.Type.FLOAT, false, 4);
public static final VertexFormatElement ROUND_RADIUS = VertexFormatElement.register(ROUND_RADIUS_ID, 4, VertexFormatElement.Type.FLOAT, false, 4);
public static final VertexFormatElement ROUND_OUTLINE_WIDTH = VertexFormatElement.register(ROUND_OUTLINE_WIDTH_ID, 1, VertexFormatElement.Type.FLOAT, false, 1);

public static final VertexFormat ROUND_RECT = VertexFormat.builder()
.add("Position", VertexFormatElement.POSITION)
.add("Color", VertexFormatElement.COLOR)
.add("InnerRect", ROUND_INNER_RECT)
.add("Radius", ROUND_RADIUS)
public static final VertexFormat ROUND_RECT = VertexFormat.builder(0)
.addAttribute("Position", GpuFormat.RGB32_FLOAT)
.addAttribute("Color", GpuFormat.RGBA8_UNORM)
.addAttribute("InnerRect", GpuFormat.RGBA32_FLOAT)
.addAttribute("Radius", GpuFormat.RGBA32_FLOAT)
.build();

public static final VertexFormat ROUND_RECT_OUTLINE = VertexFormat.builder()
.add("Position", VertexFormatElement.POSITION)
.add("Color", VertexFormatElement.COLOR)
.add("InnerRect", ROUND_INNER_RECT)
.add("Radius", ROUND_RADIUS)
.add("OutlineWidth", ROUND_OUTLINE_WIDTH)
public static final VertexFormat ROUND_RECT_OUTLINE = VertexFormat.builder(0)
.addAttribute("Position", GpuFormat.RGB32_FLOAT)
.addAttribute("Color", GpuFormat.RGBA8_UNORM)
.addAttribute("InnerRect", GpuFormat.RGBA32_FLOAT)
.addAttribute("Radius", GpuFormat.RGBA32_FLOAT)
.addAttribute("OutlineWidth", GpuFormat.R32_FLOAT)
.build();

public static final VertexFormat TEXTURE = VertexFormat.builder()
.add("Position", VertexFormatElement.POSITION)
.add("Color", VertexFormatElement.COLOR)
.add("UV0", VertexFormatElement.UV0)
.add("InnerRect", ROUND_INNER_RECT)
.add("Radius", ROUND_RADIUS)
public static final VertexFormat TEXTURE = VertexFormat.builder(0)
.addAttribute("Position", GpuFormat.RGB32_FLOAT)
.addAttribute("Color", GpuFormat.RGBA8_UNORM)
.addAttribute("UV0", GpuFormat.RG32_FLOAT)
.addAttribute("InnerRect", GpuFormat.RGBA32_FLOAT)
.addAttribute("Radius", GpuFormat.RGBA32_FLOAT)
.build();

private static int findNextId() {
return findNextId(0);
}

private static int findNextId(int start) {
for (int i = Math.max(0, start); i < VertexFormatElement.MAX_COUNT; i++) {
if (VertexFormatElement.byId(i) == null) {
return i;
}
}
throw new IllegalStateException("VertexFormatElement count limit exceeded");
}

}
2 changes: 1 addition & 1 deletion common/src/main/java/com/github/epsilon/graphics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Minecraft libraries) to ensure safe and lazy initialization.

```java
// Recommended initialization method
private final Supplier<RectRenderer> rectRenderer = Suppliers.memoize(RectRenderer::new);
private final Supplier<RectRenderer> rectRenderer = Suppliers.memoize(RectRenderer::create);

// Use .get() to access the renderer instance
rectRenderer.get().addRect(10f,10f,100f,100f,Color.WHITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Lumin Graphics 的所有渲染操作均通过专门的 **Renderer(渲染器)

```java
// 推荐的初始化方式
private final Supplier<RectRenderer> rectRenderer = Suppliers.memoize(RectRenderer::new);
private final Supplier<RectRenderer> rectRenderer = Suppliers.memoize(RectRenderer::create);

// 使用 .get() 获取渲染器实例
rectRenderer.get().addRect(10f,10f,100f,100f,Color.WHITE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.epsilon.graphics.buffer;

import com.mojang.blaze3d.buffers.GpuBuffer;
import com.mojang.blaze3d.buffers.GpuBufferSlice;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.renderer.MappableRingBuffer;

Expand All @@ -15,7 +16,7 @@ public class LuminRingBuffer {

private final MappableRingBuffer ringBuffer;

private GpuBuffer.MappedView mappedBuffer;
private GpuBufferSlice.MappedView mappedBuffer;

private boolean mapped;

Expand All @@ -41,8 +42,8 @@ public ByteBuffer getMappedBuffer() {
*/
public void tryMap() {
if (mapped) return;
mappedBuffer = RenderSystem.getDevice().createCommandEncoder().mapBuffer(
ringBuffer.currentBuffer(), false, true
mappedBuffer = ringBuffer.currentBuffer().map(
false, true
);
mapped = true;
}
Expand Down
Loading
Loading