Skip to content

Commit a6544e6

Browse files
committed
feat(rendering): 回移植渲染执行层(#P7b 后处理 / #P7c SDF GUI / #P7d CachedBER / #P7e Compute)
回移植 dev/26.1 module.rendering 的四个执行层功能块,执行层从 26.1 GpuDevice/CommandEncoder/RenderPipeline/SubmitNodeStorage 体系重写到 1.21.1 RenderTarget/ShaderInstance/VertexBuffer/GuiGraphics 体系(7121bf6、b5f5420、 6bb3269、0e8290d、64bcf21、eccdc6d、6b5a544、494274e、27a8c79、05a1f6c、 e8ee3f9、d7a8f5d、6d5a97b、2751be4、cff1802、d121047、48bfe55、fba1027、 084c503、7d07f20)。 #P7b 后处理三件套:Bloom 5 级金字塔/GaussianBlur/Glitch 的算法与 GLSL 保留; 新增 postprocess/(GlUniformBuffer 自管 GL UBO、GlPostProcess 全屏 pass、 ALRPostEffectShaders 经 RegisterShadersEvent 注册);BloomSubmitNodeStorage 改 MultiBufferSource.BufferSource 重画;DeltaTracker → getTimer()。 #P7c SDF GUI:SdfGraphics 保留 9 种距离函数编排/旋转居中/collide/MAX_SDFS=256, _draw 改 GuiGraphics BufferSource + std140 UBO(glBindBufferRange 绑定点 2); SdfShaders 注册 sdf_graphics;shader GLSL #version 150 化。 #P7d CachedBER:chunk 表/编译上传队列/失效逻辑保留;GpuBuffer → VertexBuffer (照搬 1.21.1 renderSectionLayer 模式);CachedBlockEntityRenderer 改单阶段 render(...);Iris 集成经反射访问(Modrinth maven 停服,编译依赖注释占位)。 #P7e Compute:ALRComputePipeline.builder() API 形状保留,ShaderDefines → Map<String,String>;GlComputePassBackend 独立自管状态机(glDispatchCompute/ glBindImageTexture/glBindBufferRange/glMemoryBarrier/glObjectLabel,LWJGL 全量); ALRComputeShaderManager 内联 GlslPreprocessor(#moj_import 走 ClientHooks)。
1 parent 2266262 commit a6544e6

57 files changed

Lines changed: 3656 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

module.rendering/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ sourceSets.main.resources { srcDir 'src/generated/resources' }
116116

117117
dependencies {
118118
compileOnly "org.jspecify:jspecify:1.0.0"
119+
120+
// #P7d: optional Iris integration (integration/IrisSupport.java + the two integration mixins).
121+
// The dev/26.1 branch used compileOnly("maven.modrinth:YL57xq9U:...") (Iris) from the Modrinth
122+
// maven; that maven has been shut down, and no other reachable mirror hosts Iris 1.8.x for 1.21.1
123+
// (the API was verified by downloading iris-neoforge-1.8.12+mc1.21.1.jar manually). The integration
124+
// therefore accesses the Iris classes through reflection and needs no compile-time dependency; it
125+
// activates at runtime only when Iris is loaded (gated by ALRIntegrationCompatMixinPlugin + the
126+
// ModList check inside IrisSupport). To restore a compile-time dependency once a mirror is available:
127+
// compileOnly("maven.modrinth:YL57xq9U:t3ruzodq") // iris 1.8.12+1.21.1-neoforge (needs the Modrinth maven repository)
128+
// and revert IrisSupport to direct references (net.irisshaders.iris.api.v0.IrisApi /
129+
// net.irisshaders.iris.vertices.ImmediateState).
119130
}
120131

121132
tasks.register('runStd140LayoutRulesTest', JavaExec) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.anvilcraft.lib.v2.rendering;
2+
3+
import dev.anvilcraft.lib.v2.rendering.bloom.BloomPostEffect;
4+
import dev.anvilcraft.lib.v2.rendering.event.MainTargetResizeEvent;
5+
import dev.anvilcraft.lib.v2.rendering.glitch.GlitchPostEffect;
6+
import lombok.Getter;
7+
import lombok.extern.slf4j.Slf4j;
8+
import net.neoforged.bus.api.SubscribeEvent;
9+
import net.neoforged.fml.common.EventBusSubscriber;
10+
import org.jetbrains.annotations.ApiStatus;
11+
import org.joml.Matrix4f;
12+
13+
@Slf4j
14+
@EventBusSubscriber
15+
public class ALRPostEffects {
16+
@Getter
17+
private static BloomPostEffect bloomPostEffect;
18+
@Getter
19+
private static GlitchPostEffect glitchPostEffect;
20+
21+
public static void createPostEffects() {
22+
bloomPostEffect = new BloomPostEffect();
23+
glitchPostEffect = new GlitchPostEffect();
24+
}
25+
26+
public static void runBloomDraws(Matrix4f mvMat) {
27+
try {
28+
bloomPostEffect.runBloomDraws(mvMat);
29+
} catch (Exception e) {
30+
log.error("runBloomDraws boom!", e);
31+
}
32+
}
33+
34+
@ApiStatus.Internal
35+
@SubscribeEvent
36+
public static void on(MainTargetResizeEvent event) {
37+
BloomPostEffect bloomPostEffect = ALRPostEffects.getBloomPostEffect();
38+
if (bloomPostEffect != null) {
39+
bloomPostEffect.resize(
40+
event.getNewWidth(),
41+
event.getNewHeight()
42+
);
43+
}
44+
}
45+
}

module.rendering/src/main/java/dev/anvilcraft/lib/v2/rendering/AnvilLibRendering.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package dev.anvilcraft.lib.v2.rendering;
22

3+
import dev.anvilcraft.lib.v2.rendering.cachedber.pipeline.CachedBlockEntityRenderingPipeline;
4+
import dev.anvilcraft.lib.v2.rendering.extension.blaze3d.compute.shader.ALRComputeShaderManager;
5+
import dev.anvilcraft.lib.v2.rendering.postprocess.ALRPostEffectShaders;
6+
import dev.anvilcraft.lib.v2.rendering.sdf.SdfGraphics;
7+
import dev.anvilcraft.lib.v2.rendering.sdf.SdfShaders;
38
import lombok.extern.slf4j.Slf4j;
49
import net.minecraft.resources.ResourceLocation;
510
import net.neoforged.api.distmarker.Dist;
@@ -8,6 +13,9 @@
813
import net.neoforged.fml.common.EventBusSubscriber;
914
import net.neoforged.fml.common.Mod;
1015
import net.neoforged.neoforge.client.event.RegisterClientReloadListenersEvent;
16+
import net.neoforged.neoforge.client.event.RegisterShadersEvent;
17+
import net.neoforged.neoforge.client.event.RenderFrameEvent;
18+
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
1119
import org.jetbrains.annotations.ApiStatus;
1220

1321
@Slf4j
@@ -25,8 +33,63 @@ public static ResourceLocation location(String path) {
2533
return ResourceLocation.fromNamespaceAndPath(MODID, path);
2634
}
2735

36+
@SubscribeEvent
37+
public static void on(RegisterShadersEvent event) {
38+
// #P7b: post-processing shaders (bloom downsample/upsample/apply, blur, glitch)
39+
ALRPostEffectShaders.register(event);
40+
// #P7c: SDF GUI shader (sdf_graphics)
41+
SdfShaders.register(event);
42+
}
43+
2844
@SubscribeEvent
2945
public static void on(RegisterClientReloadListenersEvent event) {
30-
// #P7e: register ALRComputeShaderManager.INSTANCE via event.registerReloadListener(...)
46+
// #P7e: compute shader manager (compiles and caches GL compute programs)
47+
event.registerReloadListener(ALRComputeShaderManager.INSTANCE);
48+
}
49+
50+
@SubscribeEvent
51+
public static void on(RenderFrameEvent.Pre event) {
52+
if (ALRPostEffects.getBloomPostEffect() != null) {
53+
ALRPostEffects.getBloomPostEffect().beginFrame();
54+
}
55+
// #P7c: reset the per-frame SDF parameter slots (the 26.1 GuiRendererMixin flush equivalent).
56+
SdfGraphics.flush();
57+
// #P7d: run the cached BER compile + upload queues on the render thread.
58+
if (CachedBlockEntityRenderingPipeline.getInstance() != null) {
59+
CachedBlockEntityRenderingPipeline.getInstance().runTasks();
60+
}
61+
}
62+
63+
@SubscribeEvent
64+
public static void on(RenderLevelStageEvent event) {
65+
if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES) {
66+
ALRPostEffects.runBloomDraws(event.getModelViewMatrix());
67+
} else if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_LEVEL) {
68+
try {
69+
if (ALRPostEffects.getBloomPostEffect() != null) {
70+
ALRPostEffects.getBloomPostEffect().process();
71+
}
72+
} catch (Exception e) {
73+
log.error("ALRPostEffects BloomPostEffect", e);
74+
}
75+
}
76+
}
77+
78+
/**
79+
* #P7d: cached BER rendering. Opaque layers render after the opaque world (mapped from the 26.1
80+
* {@code AfterOpaqueBlocks}), translucent layers after the translucent world (26.1
81+
* {@code AfterTranslucentFeatures}); both exist as {@link RenderLevelStageEvent.Stage}s on 1.21.1.
82+
*/
83+
@SubscribeEvent
84+
public static void onRenderCachedBlockEntities(RenderLevelStageEvent event) {
85+
if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_CUTOUT_BLOCKS) {
86+
if (CachedBlockEntityRenderingPipeline.getInstance() != null) {
87+
CachedBlockEntityRenderingPipeline.getInstance().render(event.getFrustum(), false);
88+
}
89+
} else if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_TRANSLUCENT_BLOCKS) {
90+
if (CachedBlockEntityRenderingPipeline.getInstance() != null) {
91+
CachedBlockEntityRenderingPipeline.getInstance().render(event.getFrustum(), true);
92+
}
93+
}
3194
}
3295
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package dev.anvilcraft.lib.v2.rendering.bloom;
2+
3+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.layout.BufferLayout;
4+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.BufferObject;
5+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.BufferObjectLayoutDefinition;
6+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.BufferObjectLayoutEntry;
7+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.ShaderBufferObjectUsage;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
11+
@Setter
12+
@Getter
13+
public class BloomParametersUbo extends BufferObject<BloomParametersUbo> {
14+
15+
public static final BufferObjectLayoutDefinition<BloomParametersUbo> DEFINITION = BufferObjectLayoutDefinition.create(
16+
BufferObjectLayoutEntry.<BloomParametersUbo>ofFloat().forGetter(BloomParametersUbo::getBloomIntensity).build(),
17+
BufferObjectLayoutEntry.<BloomParametersUbo>ofFloat().forGetter(BloomParametersUbo::getBloomBlendThreshold).build(),
18+
BufferObjectLayoutEntry.<BloomParametersUbo>ofFloat().forGetter(BloomParametersUbo::getLuminanceSensitivity).build()
19+
);
20+
21+
private float bloomIntensity;
22+
private float bloomBlendThreshold;
23+
private float luminanceSensitivity;
24+
25+
public BloomParametersUbo(float bloomIntensity, float bloomBlendThreshold, float luminanceSensitivity) {
26+
super(BufferLayout.STD140, ShaderBufferObjectUsage.UBO);
27+
this.bloomIntensity = bloomIntensity;
28+
this.bloomBlendThreshold = bloomBlendThreshold;
29+
this.luminanceSensitivity = luminanceSensitivity;
30+
}
31+
32+
@Override
33+
protected BufferObjectLayoutDefinition<BloomParametersUbo> getDefinition() {
34+
return DEFINITION;
35+
}
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dev.anvilcraft.lib.v2.rendering.bloom;
2+
3+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.layout.BufferLayout;
4+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.BufferObject;
5+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.BufferObjectLayoutDefinition;
6+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.BufferObjectLayoutEntry;
7+
import dev.anvilcraft.lib.v2.rendering.foundation.buffers.object.ShaderBufferObjectUsage;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
import org.joml.Vector2f;
11+
12+
@Getter
13+
@Setter
14+
public class BloomPipelineParametersUbo extends BufferObject<BloomPipelineParametersUbo> {
15+
16+
public static final BufferObjectLayoutDefinition<BloomPipelineParametersUbo> DEFINITION = BufferObjectLayoutDefinition.create(
17+
BufferObjectLayoutEntry.<BloomPipelineParametersUbo>ofVec2f().forGetter(BloomPipelineParametersUbo::getResolution).build(),
18+
BufferObjectLayoutEntry.<BloomPipelineParametersUbo>ofInt().forGetter(BloomPipelineParametersUbo::getFrameIndex).build()
19+
);
20+
21+
private final Vector2f resolution = new Vector2f();
22+
private int frameIndex;
23+
24+
protected BloomPipelineParametersUbo() {
25+
super(BufferLayout.STD140, ShaderBufferObjectUsage.UBO);
26+
}
27+
28+
public void setResolution(int width, int height) {
29+
this.resolution.set(
30+
1.0f / Math.max(width, 1.0f),
31+
1.0f / Math.max(height, 1.0f)
32+
);
33+
}
34+
35+
@Override
36+
protected BufferObjectLayoutDefinition<BloomPipelineParametersUbo> getDefinition() {
37+
return DEFINITION;
38+
}
39+
}

0 commit comments

Comments
 (0)