Skip to content

Commit 7adc132

Browse files
committed
Merge branch '1.20.1/dev' into 1.21.1/dev
# Conflicts: # common/src/api/java/dev/engine_room/flywheel/api/Flywheel.java # common/src/main/java/dev/engine_room/flywheel/impl/event/RenderContextImpl.java # common/src/main/java/dev/engine_room/flywheel/impl/mixin/LevelRendererMixin.java # fabric/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshEmitter.java # fabric/src/main/java/dev/engine_room/flywheel/impl/FabricFlwConfig.java # forge/src/main/java/dev/engine_room/flywheel/impl/FlywheelForge.java # neoforge/src/main/java/dev/engine_room/flywheel/impl/NeoForgeFlwConfig.java
2 parents 6e3b696 + dc4d869 commit 7adc132

File tree

85 files changed

+1628
-1014
lines changed

Some content is hidden

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

85 files changed

+1628
-1014
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package dev.engine_room.flywheel.api;
22

3-
import net.minecraft.resources.ResourceLocation;
4-
53
public final class Flywheel {
4+
/**
5+
* The mod ID and resource namespace of Flywheel.
6+
*/
67
public static final String ID = "flywheel";
78

89
private Flywheel() {
910
}
10-
11-
public static ResourceLocation rl(String path) {
12-
return ResourceLocation.fromNamespaceAndPath(ID, path);
13-
}
1411
}

common/src/api/java/dev/engine_room/flywheel/api/backend/Engine.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import org.jetbrains.annotations.ApiStatus;
66
import org.jetbrains.annotations.Range;
77

8-
import dev.engine_room.flywheel.api.RenderContext;
98
import dev.engine_room.flywheel.api.instance.Instance;
109
import dev.engine_room.flywheel.api.task.Plan;
11-
import dev.engine_room.flywheel.api.visualization.VisualType;
1210
import dev.engine_room.flywheel.api.visualization.VisualizationContext;
1311
import it.unimi.dsi.fastutil.longs.LongSet;
1412
import net.minecraft.client.Camera;
@@ -22,14 +20,13 @@ public interface Engine {
2220
/**
2321
* Create a visualization context that will be used to create visuals of the given type.
2422
*
25-
* @param visualType The type of visual.
2623
* @return A new visualization context.
2724
*/
28-
VisualizationContext createVisualizationContext(VisualType visualType);
25+
VisualizationContext createVisualizationContext();
2926

3027
/**
3128
* Create a plan that will start execution after the start of the level render and
32-
* finish execution before {@link #setupRender} is called.
29+
* finish execution before {@link #render} is called.
3330
*
3431
* @return A new plan.
3532
*/
@@ -60,32 +57,20 @@ public interface Engine {
6057
void onLightUpdate(SectionPos sectionPos, LightLayer layer);
6158

6259
/**
63-
* Set up rendering for the current level render.
60+
* Render all instances necessary for the given visual type.
6461
*
6562
* <p>This method is guaranteed to be called after
6663
* {@linkplain #createFramePlan() the frame plan} has finished execution and before
67-
* {@link #render} and {@link #renderCrumbling} are called. This method is guaranteed to
68-
* be called on the render thread.
69-
*
70-
* @param context The context for the current level render.
71-
*/
72-
void setupRender(RenderContext context);
73-
74-
/**
75-
* Render all instances necessary for the given visual type.
76-
*
77-
* <p>This method is guaranteed to be called after {@link #setupRender} for the current
78-
* level render. This method is guaranteed to be called on the render thread.
64+
* {@link #renderCrumbling} are called. This method is guaranteed to be called on the render thread.
7965
*
8066
* @param context The context for the current level render.
81-
* @param visualType The type of visual.
8267
*/
83-
void render(RenderContext context, VisualType visualType);
68+
void render(RenderContext context);
8469

8570
/**
8671
* Render the given instances as a crumbling overlay.
8772
*
88-
* <p>This method is guaranteed to be called after {@link #setupRender} for the current
73+
* <p>This method is guaranteed to be called after {@link #render} for the current
8974
* level render. This method is guaranteed to be called on the render thread.
9075
*
9176
* @param context The context for the current level render.

common/src/api/java/dev/engine_room/flywheel/api/RenderContext.java renamed to common/src/api/java/dev/engine_room/flywheel/api/backend/RenderContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.engine_room.flywheel.api;
1+
package dev.engine_room.flywheel.api.backend;
22

33
import org.joml.Matrix4fc;
44

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,81 @@
11
package dev.engine_room.flywheel.api.material;
22

33
public enum Transparency {
4+
/**
5+
* No blending. Used for solid and cutout geometry.
6+
*/
47
OPAQUE,
8+
9+
/**
10+
* Additive blending.
11+
*
12+
* <p>Each fragment blends color and alpha with the following equation:
13+
* <pre>
14+
* {@code
15+
* out = src + dst
16+
* }
17+
* </pre>
18+
*/
519
ADDITIVE,
20+
21+
/**
22+
* Lightning transparency.
23+
*
24+
* <p>Each fragment blends color and alpha with the following equation:
25+
* <pre>
26+
* {@code
27+
* out = src * alpha_src + dst
28+
* }
29+
* </pre>
30+
*/
631
LIGHTNING,
32+
33+
/**
34+
* Glint transparency. Used for the enchantment effect.
35+
*
36+
* <p>Each fragment blends with the following equations:
37+
* <pre>
38+
* {@code
39+
* color_out = color_src^2 + color_dst
40+
* alpha_out = alpha_dst
41+
* }
42+
* </pre>
43+
*/
744
GLINT,
45+
46+
/**
47+
* Crumbling transparency. Used for the block breaking overlay.
48+
*
49+
* <p>Each fragment blends with the following equations:
50+
* <pre>
51+
* {@code
52+
* color_out = 2 * color_src * color_dst
53+
* alpha_out = alpha_src
54+
* }
55+
* </pre>
56+
*/
857
CRUMBLING,
58+
59+
/**
60+
* Translucent transparency.
61+
*
62+
* <p>Each fragment blends with the following equations:
63+
* <pre>
64+
* {@code
65+
* color_out = color_src * alpha_src + color_dst * (1 - alpha_src)
66+
* alpha_out = alpha_src + alpha_dst * (1 - alpha_src)
67+
* }
68+
* </pre>
69+
*/
970
TRANSLUCENT,
71+
72+
/**
73+
* If supported by the backend, this mode will use OIT that approximates {@code TRANSLUCENT} transparency.
74+
*
75+
* <p>If a backend does not support OIT, it must treat this the same as {@code TRANSLUCENT}.
76+
*
77+
* <p>It is recommended to use this option when possible, though for cases where blend modes are used as an
78+
* overlay against solid geometry the order dependent modes are preferred.
79+
*/
80+
ORDER_INDEPENDENT,
1081
}

common/src/api/java/dev/engine_room/flywheel/api/visualization/VisualType.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

common/src/api/java/dev/engine_room/flywheel/api/visualization/VisualizationManager.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.jetbrains.annotations.ApiStatus;
66
import org.jetbrains.annotations.Nullable;
77

8-
import dev.engine_room.flywheel.api.RenderContext;
8+
import dev.engine_room.flywheel.api.backend.RenderContext;
99
import dev.engine_room.flywheel.api.internal.FlwApiLink;
1010
import dev.engine_room.flywheel.api.visual.Effect;
1111
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -47,14 +47,31 @@ static VisualizationManager getOrThrow(@Nullable LevelAccessor level) {
4747

4848
@ApiStatus.NonExtendable
4949
interface RenderDispatcher {
50+
/**
51+
* Prepare visuals for render.
52+
*
53+
* <p>Guaranteed to be called before {@link #afterEntities} and {@link #beforeCrumbling}.
54+
* <br>Guaranteed to be called after the render thread has processed all light updates.
55+
* <br>The caller is otherwise free to choose an invocation site, but it is recommended to call
56+
* this as early as possible to give the VisualizationManager time to process things off-thread.
57+
*/
5058
void onStartLevelRender(RenderContext ctx);
5159

52-
void afterBlockEntities(RenderContext ctx);
53-
60+
/**
61+
* Render instances.
62+
*
63+
* <p>Guaranteed to be called after {@link #onStartLevelRender} and before {@link #beforeCrumbling}.
64+
* <br>The caller is otherwise free to choose an invocation site, but it is recommended to call
65+
* this between rendering entities and block entities.
66+
*/
5467
void afterEntities(RenderContext ctx);
5568

69+
/**
70+
* Render crumbling block entities.
71+
*
72+
* <p>Guaranteed to be called after {@link #onStartLevelRender} and {@link #afterEntities}
73+
* @param destructionProgress The destruction progress map from {@link net.minecraft.client.renderer.LevelRenderer LevelRenderer}.
74+
*/
5675
void beforeCrumbling(RenderContext ctx, Long2ObjectMap<SortedSet<BlockDestructionProgress>> destructionProgress);
57-
58-
void afterParticles(RenderContext ctx);
5976
}
6077
}

common/src/backend/java/dev/engine_room/flywheel/backend/Backends.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package dev.engine_room.flywheel.backend;
22

3-
import dev.engine_room.flywheel.api.Flywheel;
43
import dev.engine_room.flywheel.api.backend.Backend;
54
import dev.engine_room.flywheel.backend.compile.IndirectPrograms;
65
import dev.engine_room.flywheel.backend.compile.InstancingPrograms;
76
import dev.engine_room.flywheel.backend.engine.EngineImpl;
87
import dev.engine_room.flywheel.backend.engine.indirect.IndirectDrawManager;
98
import dev.engine_room.flywheel.backend.engine.instancing.InstancedDrawManager;
9+
import dev.engine_room.flywheel.backend.gl.Driver;
1010
import dev.engine_room.flywheel.backend.gl.GlCompat;
1111
import dev.engine_room.flywheel.lib.backend.SimpleBackend;
12+
import dev.engine_room.flywheel.lib.util.ResourceUtil;
1213
import dev.engine_room.flywheel.lib.util.ShadersModHelper;
1314

1415
public final class Backends {
@@ -19,16 +20,25 @@ public final class Backends {
1920
.engineFactory(level -> new EngineImpl(level, new InstancedDrawManager(InstancingPrograms.get()), 256))
2021
.priority(500)
2122
.supported(() -> GlCompat.SUPPORTS_INSTANCING && InstancingPrograms.allLoaded() && !ShadersModHelper.isShaderPackInUse())
22-
.register(Flywheel.rl("instancing"));
23+
.register(ResourceUtil.rl("instancing"));
2324

2425
/**
2526
* Use Compute shaders to cull instances.
2627
*/
2728
public static final Backend INDIRECT = SimpleBackend.builder()
2829
.engineFactory(level -> new EngineImpl(level, new IndirectDrawManager(IndirectPrograms.get()), 256))
29-
.priority(1000)
30+
.priority(() -> {
31+
// Read from GlCompat in these provider because loading GlCompat
32+
// at the same time the backends are registered causes GlCapabilities to be null.
33+
if (GlCompat.DRIVER == Driver.INTEL) {
34+
// Intel has very poor performance with indirect rendering, and on top of that has graphics bugs
35+
return 1;
36+
} else {
37+
return 1000;
38+
}
39+
})
3040
.supported(() -> GlCompat.SUPPORTS_INDIRECT && IndirectPrograms.allLoaded() && !ShadersModHelper.isShaderPackInUse())
31-
.register(Flywheel.rl("indirect"));
41+
.register(ResourceUtil.rl("indirect"));
3242

3343
private Backends() {
3444
}

common/src/backend/java/dev/engine_room/flywheel/backend/InternalVertex.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import java.util.List;
44

5-
import dev.engine_room.flywheel.api.Flywheel;
65
import dev.engine_room.flywheel.api.layout.FloatRepr;
76
import dev.engine_room.flywheel.api.layout.Layout;
87
import dev.engine_room.flywheel.api.layout.LayoutBuilder;
98
import dev.engine_room.flywheel.backend.gl.array.VertexAttribute;
9+
import dev.engine_room.flywheel.lib.util.ResourceUtil;
1010
import dev.engine_room.flywheel.lib.vertex.FullVertexView;
1111
import dev.engine_room.flywheel.lib.vertex.VertexView;
1212
import net.minecraft.resources.ResourceLocation;
@@ -24,7 +24,7 @@ public final class InternalVertex {
2424
public static final List<VertexAttribute> ATTRIBUTES = LayoutAttributes.attributes(LAYOUT);
2525
public static final int STRIDE = LAYOUT.byteSize();
2626

27-
public static final ResourceLocation LAYOUT_SHADER = Flywheel.rl("internal/vertex_input.vert");
27+
public static final ResourceLocation LAYOUT_SHADER = ResourceUtil.rl("internal/vertex_input.vert");
2828

2929
private InternalVertex() {
3030
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package dev.engine_room.flywheel.backend;
2+
3+
import java.io.IOException;
4+
5+
import org.jetbrains.annotations.UnknownNullability;
6+
import org.lwjgl.opengl.GL32;
7+
8+
import com.mojang.blaze3d.platform.NativeImage;
9+
import com.mojang.blaze3d.systems.RenderSystem;
10+
11+
import dev.engine_room.flywheel.backend.gl.GlTextureUnit;
12+
import dev.engine_room.flywheel.lib.util.ResourceUtil;
13+
import net.minecraft.client.renderer.texture.DynamicTexture;
14+
import net.minecraft.resources.ResourceLocation;
15+
import net.minecraft.server.packs.resources.ResourceManager;
16+
17+
public class NoiseTextures {
18+
public static final ResourceLocation NOISE_TEXTURE = ResourceUtil.rl("textures/flywheel/noise/blue.png");
19+
20+
@UnknownNullability
21+
public static DynamicTexture BLUE_NOISE;
22+
23+
public static void reload(ResourceManager manager) {
24+
if (BLUE_NOISE != null) {
25+
BLUE_NOISE.close();
26+
BLUE_NOISE = null;
27+
}
28+
var optional = manager.getResource(NOISE_TEXTURE);
29+
30+
if (optional.isEmpty()) {
31+
return;
32+
}
33+
34+
try (var is = optional.get()
35+
.open()) {
36+
var image = NativeImage.read(NativeImage.Format.LUMINANCE, is);
37+
38+
BLUE_NOISE = new DynamicTexture(image);
39+
40+
GlTextureUnit.T0.makeActive();
41+
BLUE_NOISE.bind();
42+
43+
NoiseTextures.BLUE_NOISE.setFilter(true, false);
44+
RenderSystem.texParameter(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_WRAP_S, GL32.GL_REPEAT);
45+
RenderSystem.texParameter(GL32.GL_TEXTURE_2D, GL32.GL_TEXTURE_WRAP_T, GL32.GL_REPEAT);
46+
47+
RenderSystem.bindTexture(0);
48+
} catch (IOException e) {
49+
50+
}
51+
}
52+
}

common/src/backend/java/dev/engine_room/flywheel/backend/Samplers.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ public class Samplers {
1010
public static final GlTextureUnit INSTANCE_BUFFER = GlTextureUnit.T4;
1111
public static final GlTextureUnit LIGHT_LUT = GlTextureUnit.T5;
1212
public static final GlTextureUnit LIGHT_SECTIONS = GlTextureUnit.T6;
13+
14+
public static final GlTextureUnit DEPTH_RANGE = GlTextureUnit.T7;
15+
public static final GlTextureUnit COEFFICIENTS = GlTextureUnit.T8;
16+
public static final GlTextureUnit NOISE = GlTextureUnit.T9;
1317
}

0 commit comments

Comments
 (0)