From d0c6669a49e18c06503b21cc2538f09666c430a9 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sat, 23 Jul 2022 17:53:57 -0700 Subject: [PATCH] Fragments of utility - Give material fragment shaders a use - Add new variables to api/fragment.glsl - Add flw_initFragment to context shaders - Add flw_vertexOverlay - Normalize flw_vertexLight - Values are now [0, 1] where 0 is no light and 1 is max light - All light values sent to layout shaders and instance shaders are now [0, 15] and not normalized - Remove util/light.glsl - Rename program samplers - Add FileResolution.isWeak() - Add BackendType.getShortName() - Tweak default material - Move ShaderField to parse package - Organize imports --- .../java/com/jozufozu/flywheel/Flywheel.java | 7 ++++++- .../flywheel/api/material/Material.java | 1 - .../flywheel/backend/gl/VertexAttribute.java | 1 + .../instancing/InstancedRenderDispatcher.java | 1 - .../instancing/InstancingEngine.java | 5 ----- .../jozufozu/flywheel/config/BackendType.java | 8 ++++++- .../flywheel/core/ComponentRegistry.java | 1 - .../jozufozu/flywheel/core/Components.java | 2 +- .../com/jozufozu/flywheel/core/Materials.java | 2 +- .../core/compile/FragmentCompiler.java | 4 +++- .../core/compile/ProgramCompiler.java | 3 --- .../flywheel/core/compile/VertexCompiler.java | 2 +- .../core/crumbling/CrumblingProgram.java | 4 +--- .../core/crumbling/CrumblingRenderer.java | 1 - .../flywheel/core/layout/CommonItems.java | 4 ++-- .../flywheel/core/shader/WorldProgram.java | 10 +++++---- .../flywheel/core/source/FileResolution.java | 12 ++++++++--- .../flywheel/core/source/SourceFile.java | 1 + .../core/source/{ => parse}/ShaderField.java | 3 +-- .../core/structs/ColoredLitWriterUnsafe.java | 4 ++-- .../core/structs/oriented/OrientedPart.java | 1 - .../flywheel/core/uniform/FogProvider.java | 2 -- .../flywheel/core/uniform/UniformBuffer.java | 1 - .../flywheel/core/uniform/ViewProvider.java | 2 -- .../core/vertex/BlockWriterUnsafe.java | 2 +- .../jozufozu/flywheel/util/MatrixWrite.java | 1 - .../flywheel/vanilla/ChestInstance.java | 1 - .../flywheel/vanilla/MinecartInstance.java | 1 - .../flywheel/flywheel/api/fragment.glsl | 9 ++++++++ .../assets/flywheel/flywheel/api/vertex.glsl | 1 + .../flywheel/flywheel/context/crumbling.frag | 12 +++++++++-- .../flywheel/flywheel/context/world.frag | 21 ++++++++++++++----- .../flywheel/flywheel/instance/oriented.vert | 5 ++--- .../flywheel/instance/transformed.vert | 5 ++--- .../flywheel/flywheel/layout/block.vert | 6 +++--- .../flywheel/layout/pos_tex_normal.vert | 3 ++- .../flywheel/flywheel/uniform/view.glsl | 1 - .../assets/flywheel/flywheel/util/light.glsl | 4 ---- 38 files changed, 88 insertions(+), 66 deletions(-) rename src/main/java/com/jozufozu/flywheel/core/source/{ => parse}/ShaderField.java (89%) delete mode 100644 src/main/resources/assets/flywheel/flywheel/util/light.glsl diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index f288cea5f..d3fea1c6c 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -11,7 +11,12 @@ import com.jozufozu.flywheel.backend.model.MeshPool; import com.jozufozu.flywheel.config.BackendTypeArgument; import com.jozufozu.flywheel.config.FlwCommands; import com.jozufozu.flywheel.config.FlwConfig; -import com.jozufozu.flywheel.core.*; +import com.jozufozu.flywheel.core.Components; +import com.jozufozu.flywheel.core.GameStateRegistry; +import com.jozufozu.flywheel.core.Models; +import com.jozufozu.flywheel.core.PartialModel; +import com.jozufozu.flywheel.core.QuadConverter; +import com.jozufozu.flywheel.core.StitchedSprite; import com.jozufozu.flywheel.core.compile.ProgramCompiler; import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer; import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider; diff --git a/src/main/java/com/jozufozu/flywheel/api/material/Material.java b/src/main/java/com/jozufozu/flywheel/api/material/Material.java index a8cb56f7f..42df89830 100644 --- a/src/main/java/com/jozufozu/flywheel/api/material/Material.java +++ b/src/main/java/com/jozufozu/flywheel/api/material/Material.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.api.material; import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.core.source.FileResolution; -import com.jozufozu.flywheel.core.source.SourceFile; import net.minecraft.client.renderer.RenderType; diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/VertexAttribute.java b/src/main/java/com/jozufozu/flywheel/backend/gl/VertexAttribute.java index be1394e9e..c425183c4 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/gl/VertexAttribute.java +++ b/src/main/java/com/jozufozu/flywheel/backend/gl/VertexAttribute.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.backend.gl; +// TODO: support glVertexAttribIPointer /** * A bindable attribute in a vertex array. * diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index ea5c9f5e8..f58abbb2a 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -14,7 +14,6 @@ import com.jozufozu.flywheel.util.WorldAttached; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.RenderType; import net.minecraft.core.Vec3i; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.LevelAccessor; diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java index 1aaa07182..b4fd04b11 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/instancing/InstancingEngine.java @@ -8,18 +8,13 @@ import java.util.Map; import org.jetbrains.annotations.NotNull; import com.google.common.collect.ListMultimap; -import com.google.common.collect.Multimaps; import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.api.vertex.VertexType; -import com.jozufozu.flywheel.backend.gl.GlVertexArray; -import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer; -import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType; import com.jozufozu.flywheel.backend.instancing.Engine; import com.jozufozu.flywheel.backend.instancing.InstanceManager; -import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher; import com.jozufozu.flywheel.backend.instancing.TaskEngine; import com.jozufozu.flywheel.backend.model.MeshPool; import com.jozufozu.flywheel.core.CoreShaderInfoMap.CoreShaderInfo; diff --git a/src/main/java/com/jozufozu/flywheel/config/BackendType.java b/src/main/java/com/jozufozu/flywheel/config/BackendType.java index f28eb34f6..822c28973 100644 --- a/src/main/java/com/jozufozu/flywheel/config/BackendType.java +++ b/src/main/java/com/jozufozu/flywheel/config/BackendType.java @@ -26,20 +26,26 @@ public enum BackendType { static { lookup = new HashMap<>(); for (BackendType value : values()) { - lookup.put(value.name().toLowerCase(Locale.ROOT), value); + lookup.put(value.getShortName(), value); } } private final String properName; + private final String shortName; BackendType(String properName) { this.properName = properName; + shortName = name().toLowerCase(Locale.ROOT); } public String getProperName() { return properName; } + public String getShortName() { + return shortName; + } + @Nullable public static BackendType byName(String name) { return lookup.get(name); diff --git a/src/main/java/com/jozufozu/flywheel/core/ComponentRegistry.java b/src/main/java/com/jozufozu/flywheel/core/ComponentRegistry.java index ce93ff6f2..46b9c18bc 100644 --- a/src/main/java/com/jozufozu/flywheel/core/ComponentRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/core/ComponentRegistry.java @@ -12,7 +12,6 @@ import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.api.uniform.UniformProvider; import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.core.compile.ContextShader; -import com.jozufozu.flywheel.core.vertex.BlockVertex; import net.minecraft.resources.ResourceLocation; diff --git a/src/main/java/com/jozufozu/flywheel/core/Components.java b/src/main/java/com/jozufozu/flywheel/core/Components.java index 2f536ccf0..32c35a119 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Components.java +++ b/src/main/java/com/jozufozu/flywheel/core/Components.java @@ -95,7 +95,7 @@ public class Components { public static final BiConsumer MATERIAL_VERTEX = SourceChecks.checkFunctionArity("flw_materialVertex", 0); public static final BiConsumer MATERIAL_FRAGMENT = SourceChecks.checkFunctionArity("flw_materialFragment", 0); public static final BiConsumer CONTEXT_VERTEX = SourceChecks.checkFunctionArity("flw_contextVertex", 0); - public static final BiConsumer CONTEXT_FRAGMENT = SourceChecks.checkFunctionArity("flw_contextFragment", 0); + public static final BiConsumer CONTEXT_FRAGMENT = SourceChecks.checkFunctionArity("flw_contextFragment", 0).andThen(SourceChecks.checkFunctionArity("flw_initFragment", 0)); } public static class Names { diff --git a/src/main/java/com/jozufozu/flywheel/core/Materials.java b/src/main/java/com/jozufozu/flywheel/core/Materials.java index 7748be35d..82b1a01b4 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/core/Materials.java @@ -10,7 +10,7 @@ import net.minecraft.resources.ResourceLocation; public class Materials { private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png"); - public static final Material DEFAULT = ComponentRegistry.register(new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, RenderType.solid(), Components.Files.DEFAULT_VERTEX, Components.Files.DEFAULT_FRAGMENT)); + public static final Material DEFAULT = ComponentRegistry.register(new SimpleMaterial(RenderStage.AFTER_SOLID_TERRAIN, RenderType.cutout(), Components.Files.SHADED_VERTEX, Components.Files.DEFAULT_FRAGMENT)); public static final Material CHEST = ComponentRegistry.register(new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, Sheets.chestSheet(), Components.Files.SHADED_VERTEX, Components.Files.DEFAULT_FRAGMENT)); public static final Material SHULKER = ComponentRegistry.register(new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, RenderType.entityCutoutNoCull(Sheets.SHULKER_SHEET), Components.Files.SHADED_VERTEX, Components.Files.DEFAULT_FRAGMENT)); public static final Material BELL = ComponentRegistry.register(new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, Sheets.solidBlockSheet(), Components.Files.SHADED_VERTEX, Components.Files.DEFAULT_FRAGMENT)); diff --git a/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java b/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java index ec7d3470c..13bab6021 100644 --- a/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java +++ b/src/main/java/com/jozufozu/flywheel/core/compile/FragmentCompiler.java @@ -54,9 +54,11 @@ public class FragmentCompiler extends Memoizer> checks = new ArrayList<>(); private final ResourceLocation fileLoc; + private final boolean weak; private SourceFile file; - FileResolution(ResourceLocation fileLoc) { + private FileResolution(ResourceLocation fileLoc, boolean weak) { this.fileLoc = fileLoc; + this.weak = weak; } public static FileResolution get(ResourceLocation file) { if (!tooLate) { - return ALL.computeIfAbsent(file, FileResolution::new); + return ALL.computeIfAbsent(file, loc -> new FileResolution(loc, false)); } else { // Lock the map after resolution has run. FileResolution fileResolution = ALL.get(file); @@ -71,7 +73,7 @@ public class FileResolution { return fileResolution; } // never too late for weak resolutions. - return WEAK.computeIfAbsent(file, FileResolution::new); + return WEAK.computeIfAbsent(file, loc -> new FileResolution(loc, true)); } /** @@ -134,6 +136,10 @@ public class FileResolution { return file; } + public boolean isWeak() { + return weak; + } + /** * Store the given span so this resolution can know all the places that reference the file. * diff --git a/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java b/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java index 43f95c6a3..4e63ef409 100644 --- a/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java +++ b/src/main/java/com/jozufozu/flywheel/core/source/SourceFile.java @@ -15,6 +15,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.jozufozu.flywheel.core.source.error.ErrorReporter; import com.jozufozu.flywheel.core.source.parse.Import; +import com.jozufozu.flywheel.core.source.parse.ShaderField; import com.jozufozu.flywheel.core.source.parse.ShaderFunction; import com.jozufozu.flywheel.core.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.span.ErrorSpan; diff --git a/src/main/java/com/jozufozu/flywheel/core/source/ShaderField.java b/src/main/java/com/jozufozu/flywheel/core/source/parse/ShaderField.java similarity index 89% rename from src/main/java/com/jozufozu/flywheel/core/source/ShaderField.java rename to src/main/java/com/jozufozu/flywheel/core/source/parse/ShaderField.java index d4fdf6ef2..39289ff22 100644 --- a/src/main/java/com/jozufozu/flywheel/core/source/ShaderField.java +++ b/src/main/java/com/jozufozu/flywheel/core/source/parse/ShaderField.java @@ -1,10 +1,9 @@ -package com.jozufozu.flywheel.core.source; +package com.jozufozu.flywheel.core.source.parse; import java.util.regex.Pattern; import org.jetbrains.annotations.Nullable; -import com.jozufozu.flywheel.core.source.parse.AbstractShaderElement; import com.jozufozu.flywheel.core.source.span.Span; public class ShaderField extends AbstractShaderElement { diff --git a/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitWriterUnsafe.java b/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitWriterUnsafe.java index 9e6d4bac0..985fc7046 100644 --- a/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitWriterUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/structs/ColoredLitWriterUnsafe.java @@ -16,8 +16,8 @@ public abstract class ColoredLitWriterUnsafe extends U @Override protected void writeInternal(D d) { long ptr = writePointer; - MemoryUtil.memPutByte(ptr, (byte) (d.blockLight << 4)); - MemoryUtil.memPutByte(ptr + 1, (byte) (d.skyLight << 4)); + MemoryUtil.memPutByte(ptr, d.blockLight); + MemoryUtil.memPutByte(ptr + 1, d.skyLight); MemoryUtil.memPutByte(ptr + 2, d.r); MemoryUtil.memPutByte(ptr + 3, d.g); MemoryUtil.memPutByte(ptr + 4, d.b); diff --git a/src/main/java/com/jozufozu/flywheel/core/structs/oriented/OrientedPart.java b/src/main/java/com/jozufozu/flywheel/core/structs/oriented/OrientedPart.java index 5608a9c34..969b2efc7 100644 --- a/src/main/java/com/jozufozu/flywheel/core/structs/oriented/OrientedPart.java +++ b/src/main/java/com/jozufozu/flywheel/core/structs/oriented/OrientedPart.java @@ -108,4 +108,3 @@ public class OrientedPart extends ColoredLitPart { return out; } } - diff --git a/src/main/java/com/jozufozu/flywheel/core/uniform/FogProvider.java b/src/main/java/com/jozufozu/flywheel/core/uniform/FogProvider.java index 80c875a2f..9a7586c41 100644 --- a/src/main/java/com/jozufozu/flywheel/core/uniform/FogProvider.java +++ b/src/main/java/com/jozufozu/flywheel/core/uniform/FogProvider.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.core.uniform; -import java.nio.ByteBuffer; - import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.api.uniform.UniformProvider; diff --git a/src/main/java/com/jozufozu/flywheel/core/uniform/UniformBuffer.java b/src/main/java/com/jozufozu/flywheel/core/uniform/UniformBuffer.java index fc6b00603..5f3b10bb7 100644 --- a/src/main/java/com/jozufozu/flywheel/core/uniform/UniformBuffer.java +++ b/src/main/java/com/jozufozu/flywheel/core/uniform/UniformBuffer.java @@ -4,7 +4,6 @@ import java.nio.ByteBuffer; import java.util.BitSet; import java.util.Collection; import java.util.List; -import java.util.concurrent.atomic.AtomicLongArray; import org.lwjgl.opengl.GL32; import org.lwjgl.system.MemoryUtil; diff --git a/src/main/java/com/jozufozu/flywheel/core/uniform/ViewProvider.java b/src/main/java/com/jozufozu/flywheel/core/uniform/ViewProvider.java index d91322976..1d5535b6d 100644 --- a/src/main/java/com/jozufozu/flywheel/core/uniform/ViewProvider.java +++ b/src/main/java/com/jozufozu/flywheel/core/uniform/ViewProvider.java @@ -1,7 +1,5 @@ package com.jozufozu.flywheel.core.uniform; -import java.nio.ByteBuffer; - import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.api.uniform.UniformProvider; diff --git a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockWriterUnsafe.java b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockWriterUnsafe.java index b67149e18..212c7c2eb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/vertex/BlockWriterUnsafe.java +++ b/src/main/java/com/jozufozu/flywheel/core/vertex/BlockWriterUnsafe.java @@ -46,7 +46,7 @@ public class BlockWriterUnsafe extends VertexWriterUnsafe { MemoryUtil.memPutByte(ptr + 15, a); MemoryUtil.memPutFloat(ptr + 16, u); MemoryUtil.memPutFloat(ptr + 20, v); - MemoryUtil.memPutInt(ptr + 24, light << 8); // light is packed in the low byte of each short + MemoryUtil.memPutInt(ptr + 24, (light >> 4) & 0xF000F); MemoryUtil.memPutByte(ptr + 28, RenderMath.nb(nX)); MemoryUtil.memPutByte(ptr + 29, RenderMath.nb(nY)); MemoryUtil.memPutByte(ptr + 30, RenderMath.nb(nZ)); diff --git a/src/main/java/com/jozufozu/flywheel/util/MatrixWrite.java b/src/main/java/com/jozufozu/flywheel/util/MatrixWrite.java index 5b29338a7..e5455dad5 100644 --- a/src/main/java/com/jozufozu/flywheel/util/MatrixWrite.java +++ b/src/main/java/com/jozufozu/flywheel/util/MatrixWrite.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.util; import java.nio.ByteBuffer; -import com.mojang.math.Matrix3f; import com.mojang.math.Matrix4f; /** diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java index cc2a24e0d..f8cc6ff99 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestInstance.java @@ -7,7 +7,6 @@ import java.util.function.BiFunction; import org.jetbrains.annotations.NotNull; -import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.instancer.InstancerManager; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java index af0bd1bdd..ca56fed30 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartInstance.java @@ -2,7 +2,6 @@ package com.jozufozu.flywheel.vanilla; import org.jetbrains.annotations.NotNull; -import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.TickableInstance; import com.jozufozu.flywheel.api.instancer.InstancerManager; diff --git a/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl b/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl index ee9cf8489..4b652fa18 100644 --- a/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl +++ b/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl @@ -1,6 +1,7 @@ in vec4 flw_vertexPos; in vec4 flw_vertexColor; in vec2 flw_vertexTexCoord; +flat in ivec2 flw_vertexOverlay; in vec2 flw_vertexLight; in vec3 flw_vertexNormal; @@ -10,3 +11,11 @@ in vec4 flw_var0; in vec4 flw_var1; in vec4 flw_var2; in vec4 flw_var3; + +// + +/*const*/ vec4 flw_sampleColor; + +vec4 flw_fragColor; +ivec2 flw_fragOverlay; +vec2 flw_fragLight; diff --git a/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl b/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl index 11ab56206..c5d670ec3 100644 --- a/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl +++ b/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl @@ -1,6 +1,7 @@ out vec4 flw_vertexPos; out vec4 flw_vertexColor; out vec2 flw_vertexTexCoord; +flat out ivec2 flw_vertexOverlay; out vec2 flw_vertexLight; out vec3 flw_vertexNormal; diff --git a/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag b/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag index 942cb70d8..a6dbf8caa 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag +++ b/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag @@ -2,7 +2,7 @@ #use "flywheel:util/fog.glsl" #use "flywheel:uniform/fog.glsl" -uniform sampler2D uCrumblingTex; +uniform sampler2D flw_diffuseTex; out vec4 fragColor; @@ -25,8 +25,16 @@ vec2 flattenedPos(vec3 pos, vec3 normal) { return (transpose(tbn) * pos).xy + vec2(0.5); } +void flw_initFragment() { + flw_sampleColor = texture(flw_diffuseTex, flattenedPos(flw_vertexPos.xyz, flw_vertexNormal)); + // Crumbling ignores vertex colors + flw_fragColor = flw_sampleColor; + flw_fragOverlay = flw_vertexOverlay; + flw_fragLight = flw_vertexLight; +} + void flw_contextFragment() { - vec4 color = texture(uCrumblingTex, flattenedPos(flw_vertexPos.xyz, flw_vertexNormal)); + vec4 color = flw_fragColor; #ifdef ALPHA_DISCARD if (color.a < ALPHA_DISCARD) { diff --git a/src/main/resources/assets/flywheel/flywheel/context/world.frag b/src/main/resources/assets/flywheel/flywheel/context/world.frag index 8f53b158b..7de6a2698 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/world.frag +++ b/src/main/resources/assets/flywheel/flywheel/context/world.frag @@ -9,15 +9,26 @@ layout (depth_greater) out float gl_FragDepth; #endif #endif -uniform sampler2D uBlockAtlas; -uniform sampler2D uLightMap; +uniform sampler2D flw_diffuseTex; +uniform sampler2D flw_overlayTex; +uniform sampler2D flw_lightTex; out vec4 fragColor; +void flw_initFragment() { + flw_sampleColor = texture(flw_diffuseTex, flw_vertexTexCoord); + flw_fragColor = flw_vertexColor * flw_sampleColor; + flw_fragOverlay = flw_vertexOverlay; + flw_fragLight = flw_vertexLight; +} + void flw_contextFragment() { - vec4 texColor = texture(uBlockAtlas, flw_vertexTexCoord); - vec4 lightColor = texture(uLightMap, flw_vertexLight); - vec4 color = flw_vertexColor * vec4(texColor.rgb * lightColor.rgb, texColor.a); + vec4 overlayColor = texelFetch(flw_overlayTex, flw_fragOverlay, 0); + vec4 lightColor = texture(flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0); + + vec4 color = flw_fragColor; + color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); + color *= lightColor; #ifdef ALPHA_DISCARD if (color.a < ALPHA_DISCARD) { diff --git a/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert b/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert index fdff61295..46594fb28 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert +++ b/src/main/resources/assets/flywheel/flywheel/instance/oriented.vert @@ -1,8 +1,7 @@ #use "flywheel:api/vertex.glsl" -#use "flywheel:util/light.glsl" #use "flywheel:util/quaternion.glsl" -layout(location = 0) in vec2 oriented_light; +layout(location = 0) in vec2 oriented_light; // TODO: switch to ivec2 layout(location = 1) in vec4 oriented_color; layout(location = 2) in vec3 oriented_pos; layout(location = 3) in vec3 oriented_pivot; @@ -12,5 +11,5 @@ void flw_instanceVertex() { flw_vertexPos = vec4(rotateVertexByQuat(flw_vertexPos.xyz - oriented_pivot, oriented_rotation) + oriented_pivot + oriented_pos, 1.0); flw_vertexNormal = rotateVertexByQuat(flw_vertexNormal, oriented_rotation); flw_vertexColor = oriented_color; - flw_vertexLight = shiftLight(oriented_light); + flw_vertexLight = oriented_light / 15.0; } diff --git a/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert b/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert index 535136c71..72931d407 100644 --- a/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert +++ b/src/main/resources/assets/flywheel/flywheel/instance/transformed.vert @@ -1,7 +1,6 @@ #use "flywheel:api/vertex.glsl" -#use "flywheel:util/light.glsl" -layout(location = 0) in vec2 transformed_light; +layout(location = 0) in vec2 transformed_light; // TODO: switch to ivec2 layout(location = 1) in vec4 transformed_color; layout(location = 2) in mat4 transformed_pose; layout(location = 6) in mat3 transformed_normal; @@ -10,5 +9,5 @@ void flw_instanceVertex() { flw_vertexPos = transformed_pose * flw_vertexPos; flw_vertexNormal = transformed_normal * flw_vertexNormal; flw_vertexColor = transformed_color; - flw_vertexLight = shiftLight(transformed_light); + flw_vertexLight = transformed_light / 15.0; } diff --git a/src/main/resources/assets/flywheel/flywheel/layout/block.vert b/src/main/resources/assets/flywheel/flywheel/layout/block.vert index d4175c75c..865578d63 100644 --- a/src/main/resources/assets/flywheel/flywheel/layout/block.vert +++ b/src/main/resources/assets/flywheel/flywheel/layout/block.vert @@ -1,16 +1,16 @@ #use "flywheel:api/vertex.glsl" -#use "flywheel:util/light.glsl" layout(location = 0) in vec3 _flw_v_pos; layout(location = 1) in vec4 _flw_v_color; layout(location = 2) in vec2 _flw_v_texCoord; -layout(location = 3) in vec2 _flw_v_light; +layout(location = 3) in vec2 _flw_v_light; // TODO: switch to ivec2 layout(location = 4) in vec3 _flw_v_normal; void flw_layoutVertex() { flw_vertexPos = vec4(_flw_v_pos, 1.0); flw_vertexColor = _flw_v_color; flw_vertexTexCoord = _flw_v_texCoord; - flw_vertexLight = shiftLight(_flw_v_light); + flw_vertexOverlay = ivec2(0, 10); + flw_vertexLight = _flw_v_light / 15.0; flw_vertexNormal = _flw_v_normal; } diff --git a/src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert b/src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert index 36a17186e..4ecfb2c3c 100644 --- a/src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert +++ b/src/main/resources/assets/flywheel/flywheel/layout/pos_tex_normal.vert @@ -8,6 +8,7 @@ void flw_layoutVertex() { flw_vertexPos = vec4(_flw_v_pos, 1.0); flw_vertexColor = vec4(1.0); flw_vertexTexCoord = _flw_v_texCoord; - flw_vertexLight = vec2(0.0); + flw_vertexOverlay = ivec2(0, 10); + flw_vertexLight = vec2(1.0); flw_vertexNormal = _flw_v_normal; } diff --git a/src/main/resources/assets/flywheel/flywheel/uniform/view.glsl b/src/main/resources/assets/flywheel/flywheel/uniform/view.glsl index 4def2de12..52170bccd 100644 --- a/src/main/resources/assets/flywheel/flywheel/uniform/view.glsl +++ b/src/main/resources/assets/flywheel/flywheel/uniform/view.glsl @@ -1,4 +1,3 @@ - layout(std140, binding = 0) uniform flw_view { mat4 flw_viewProjection; vec4 flw_cameraPos; diff --git a/src/main/resources/assets/flywheel/flywheel/util/light.glsl b/src/main/resources/assets/flywheel/flywheel/util/light.glsl deleted file mode 100644 index f8cd2089e..000000000 --- a/src/main/resources/assets/flywheel/flywheel/util/light.glsl +++ /dev/null @@ -1,4 +0,0 @@ -// Adjust the [0,1] normalized lightmap value based on the texture matrix from LightTexture#enableLightmap -vec2 shiftLight(vec2 lm) { - return lm * 0.99609375 + 0.03125; // * 255/256 + 1/32 -}