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
This commit is contained in:
PepperCode1 2022-07-23 17:53:57 -07:00
parent 1a03b63406
commit dd33c6f444
38 changed files with 88 additions and 66 deletions

View file

@ -11,7 +11,12 @@ import com.jozufozu.flywheel.backend.model.MeshPool;
import com.jozufozu.flywheel.config.BackendTypeArgument; import com.jozufozu.flywheel.config.BackendTypeArgument;
import com.jozufozu.flywheel.config.FlwCommands; import com.jozufozu.flywheel.config.FlwCommands;
import com.jozufozu.flywheel.config.FlwConfig; 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.compile.ProgramCompiler;
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer; import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider; import com.jozufozu.flywheel.core.shader.NormalDebugStateProvider;

View file

@ -2,7 +2,6 @@ package com.jozufozu.flywheel.api.material;
import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.RenderStage;
import com.jozufozu.flywheel.core.source.FileResolution; import com.jozufozu.flywheel.core.source.FileResolution;
import com.jozufozu.flywheel.core.source.SourceFile;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.gl; package com.jozufozu.flywheel.backend.gl;
// TODO: support glVertexAttribIPointer
/** /**
* A bindable attribute in a vertex array. * A bindable attribute in a vertex array.
* *

View file

@ -14,7 +14,6 @@ import com.jozufozu.flywheel.util.WorldAttached;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;

View file

@ -8,18 +8,13 @@ import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import com.jozufozu.flywheel.api.RenderStage; import com.jozufozu.flywheel.api.RenderStage;
import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.instancer.InstancedPart;
import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.struct.StructType; import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.api.vertex.VertexType; 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.Engine;
import com.jozufozu.flywheel.backend.instancing.InstanceManager; 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.instancing.TaskEngine;
import com.jozufozu.flywheel.backend.model.MeshPool; import com.jozufozu.flywheel.backend.model.MeshPool;
import com.jozufozu.flywheel.core.CoreShaderInfoMap.CoreShaderInfo; import com.jozufozu.flywheel.core.CoreShaderInfoMap.CoreShaderInfo;

View file

@ -26,20 +26,26 @@ public enum BackendType {
static { static {
lookup = new HashMap<>(); lookup = new HashMap<>();
for (BackendType value : values()) { for (BackendType value : values()) {
lookup.put(value.name().toLowerCase(Locale.ROOT), value); lookup.put(value.getShortName(), value);
} }
} }
private final String properName; private final String properName;
private final String shortName;
BackendType(String properName) { BackendType(String properName) {
this.properName = properName; this.properName = properName;
shortName = name().toLowerCase(Locale.ROOT);
} }
public String getProperName() { public String getProperName() {
return properName; return properName;
} }
public String getShortName() {
return shortName;
}
@Nullable @Nullable
public static BackendType byName(String name) { public static BackendType byName(String name) {
return lookup.get(name); return lookup.get(name);

View file

@ -12,7 +12,6 @@ import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.api.uniform.UniformProvider; import com.jozufozu.flywheel.api.uniform.UniformProvider;
import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.core.compile.ContextShader; import com.jozufozu.flywheel.core.compile.ContextShader;
import com.jozufozu.flywheel.core.vertex.BlockVertex;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;

View file

@ -95,7 +95,7 @@ public class Components {
public static final BiConsumer<ErrorReporter, SourceFile> MATERIAL_VERTEX = SourceChecks.checkFunctionArity("flw_materialVertex", 0); public static final BiConsumer<ErrorReporter, SourceFile> MATERIAL_VERTEX = SourceChecks.checkFunctionArity("flw_materialVertex", 0);
public static final BiConsumer<ErrorReporter, SourceFile> MATERIAL_FRAGMENT = SourceChecks.checkFunctionArity("flw_materialFragment", 0); public static final BiConsumer<ErrorReporter, SourceFile> MATERIAL_FRAGMENT = SourceChecks.checkFunctionArity("flw_materialFragment", 0);
public static final BiConsumer<ErrorReporter, SourceFile> CONTEXT_VERTEX = SourceChecks.checkFunctionArity("flw_contextVertex", 0); public static final BiConsumer<ErrorReporter, SourceFile> CONTEXT_VERTEX = SourceChecks.checkFunctionArity("flw_contextVertex", 0);
public static final BiConsumer<ErrorReporter, SourceFile> CONTEXT_FRAGMENT = SourceChecks.checkFunctionArity("flw_contextFragment", 0); public static final BiConsumer<ErrorReporter, SourceFile> CONTEXT_FRAGMENT = SourceChecks.checkFunctionArity("flw_contextFragment", 0).andThen(SourceChecks.checkFunctionArity("flw_initFragment", 0));
} }
public static class Names { public static class Names {

View file

@ -10,7 +10,7 @@ import net.minecraft.resources.ResourceLocation;
public class Materials { public class Materials {
private static final ResourceLocation MINECART_LOCATION = new ResourceLocation("textures/entity/minecart.png"); 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 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 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)); public static final Material BELL = ComponentRegistry.register(new SimpleMaterial(RenderStage.AFTER_BLOCK_ENTITIES, Sheets.solidBlockSheet(), Components.Files.SHADED_VERTEX, Components.Files.DEFAULT_FRAGMENT));

View file

@ -54,9 +54,11 @@ public class FragmentCompiler extends Memoizer<FragmentCompiler.Context, GlShade
protected String generateFooter() { protected String generateFooter() {
return """ return """
void main() { void main() {
flw_initFragment();
flw_materialFragment(); flw_materialFragment();
flw_contextFragment(); flw_contextFragment();
} }
"""; """;
} }

View file

@ -1,8 +1,5 @@
package com.jozufozu.flywheel.core.compile; package com.jozufozu.flywheel.core.compile;
import java.util.ArrayList;
import java.util.List;
import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.vertex.VertexType; import com.jozufozu.flywheel.api.vertex.VertexType;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram; import com.jozufozu.flywheel.backend.gl.shader.GlProgram;

View file

@ -9,8 +9,8 @@ import com.jozufozu.flywheel.backend.gl.shader.GlShader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType; import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.core.shader.StateSnapshot; import com.jozufozu.flywheel.core.shader.StateSnapshot;
import com.jozufozu.flywheel.core.source.CompilationContext; import com.jozufozu.flywheel.core.source.CompilationContext;
import com.jozufozu.flywheel.core.source.ShaderField;
import com.jozufozu.flywheel.core.source.SourceFile; import com.jozufozu.flywheel.core.source.SourceFile;
import com.jozufozu.flywheel.core.source.parse.ShaderField;
import com.jozufozu.flywheel.core.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
import com.jozufozu.flywheel.util.Pair; import com.jozufozu.flywheel.util.Pair;

View file

@ -5,14 +5,12 @@ import com.jozufozu.flywheel.core.shader.WorldProgram;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class CrumblingProgram extends WorldProgram { public class CrumblingProgram extends WorldProgram {
protected int uCrumblingTex;
public CrumblingProgram(ResourceLocation name, int handle) { public CrumblingProgram(ResourceLocation name, int handle) {
super(name, handle); super(name, handle);
} }
@Override @Override
protected void registerSamplers() { protected void registerSamplers() {
uCrumblingTex = setSamplerBinding("uCrumblingTex", 0); diffuseTex = setSamplerBinding("flw_diffuseTex", 0);
} }
} }

View file

@ -17,7 +17,6 @@ import com.jozufozu.flywheel.core.RenderContext;
import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent;
import com.jozufozu.flywheel.mixin.LevelRendererAccessor; import com.jozufozu.flywheel.mixin.LevelRendererAccessor;
import com.jozufozu.flywheel.util.Lazy; import com.jozufozu.flywheel.util.Lazy;
import com.mojang.math.Matrix4f;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;

View file

@ -15,8 +15,8 @@ public class CommonItems {
public static final PrimitiveItem RGBA = new PrimitiveItem(GlNumericType.UBYTE, 4, true); public static final PrimitiveItem RGBA = new PrimitiveItem(GlNumericType.UBYTE, 4, true);
public static final PrimitiveItem RGB = new PrimitiveItem(GlNumericType.UBYTE, 3, true); public static final PrimitiveItem RGB = new PrimitiveItem(GlNumericType.UBYTE, 3, true);
public static final PrimitiveItem LIGHT = new PrimitiveItem(GlNumericType.UBYTE, 2, true); public static final PrimitiveItem LIGHT = new PrimitiveItem(GlNumericType.UBYTE, 2, false);
public static final PrimitiveItem LIGHT_SHORT = new PrimitiveItem(GlNumericType.USHORT, 2, true); public static final PrimitiveItem LIGHT_SHORT = new PrimitiveItem(GlNumericType.USHORT, 2, false);
public static final PrimitiveItem NORMALIZED_BYTE = new PrimitiveItem(GlNumericType.BYTE, 1, true); public static final PrimitiveItem NORMALIZED_BYTE = new PrimitiveItem(GlNumericType.BYTE, 1, true);

View file

@ -7,8 +7,9 @@ import net.minecraft.resources.ResourceLocation;
public class WorldProgram extends GlProgram { public class WorldProgram extends GlProgram {
// TODO: sampler registry? // TODO: sampler registry?
protected int uBlockAtlas; protected int diffuseTex;
protected int uLightMap; protected int overlayTex;
protected int lightTex;
public WorldProgram(ResourceLocation name, int handle) { public WorldProgram(ResourceLocation name, int handle) {
super(name, handle); super(name, handle);
@ -19,7 +20,8 @@ public class WorldProgram extends GlProgram {
} }
protected void registerSamplers() { protected void registerSamplers() {
uBlockAtlas = setSamplerBinding("uBlockAtlas", 0); diffuseTex = setSamplerBinding("flw_diffuseTex", 0);
uLightMap = setSamplerBinding("uLightMap", 2); overlayTex = setSamplerBinding("flw_overlayTex", 1);
lightTex = setSamplerBinding("flw_lightTex", 2);
} }
} }

View file

@ -34,16 +34,18 @@ public class FileResolution {
private final List<BiConsumer<ErrorReporter, SourceFile>> checks = new ArrayList<>(); private final List<BiConsumer<ErrorReporter, SourceFile>> checks = new ArrayList<>();
private final ResourceLocation fileLoc; private final ResourceLocation fileLoc;
private final boolean weak;
private SourceFile file; private SourceFile file;
FileResolution(ResourceLocation fileLoc) { private FileResolution(ResourceLocation fileLoc, boolean weak) {
this.fileLoc = fileLoc; this.fileLoc = fileLoc;
this.weak = weak;
} }
public static FileResolution get(ResourceLocation file) { public static FileResolution get(ResourceLocation file) {
if (!tooLate) { if (!tooLate) {
return ALL.computeIfAbsent(file, FileResolution::new); return ALL.computeIfAbsent(file, loc -> new FileResolution(loc, false));
} else { } else {
// Lock the map after resolution has run. // Lock the map after resolution has run.
FileResolution fileResolution = ALL.get(file); FileResolution fileResolution = ALL.get(file);
@ -71,7 +73,7 @@ public class FileResolution {
return fileResolution; return fileResolution;
} }
// never too late for weak resolutions. // 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; return file;
} }
public boolean isWeak() {
return weak;
}
/** /**
* Store the given span so this resolution can know all the places that reference the file. * Store the given span so this resolution can know all the places that reference the file.
* *

View file

@ -15,6 +15,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.jozufozu.flywheel.core.source.error.ErrorReporter; import com.jozufozu.flywheel.core.source.error.ErrorReporter;
import com.jozufozu.flywheel.core.source.parse.Import; 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.ShaderFunction;
import com.jozufozu.flywheel.core.source.parse.ShaderStruct; import com.jozufozu.flywheel.core.source.parse.ShaderStruct;
import com.jozufozu.flywheel.core.source.span.ErrorSpan; import com.jozufozu.flywheel.core.source.span.ErrorSpan;

View file

@ -1,10 +1,9 @@
package com.jozufozu.flywheel.core.source; package com.jozufozu.flywheel.core.source.parse;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.core.source.parse.AbstractShaderElement;
import com.jozufozu.flywheel.core.source.span.Span; import com.jozufozu.flywheel.core.source.span.Span;
public class ShaderField extends AbstractShaderElement { public class ShaderField extends AbstractShaderElement {

View file

@ -16,8 +16,8 @@ public abstract class ColoredLitWriterUnsafe<D extends ColoredLitPart> extends U
@Override @Override
protected void writeInternal(D d) { protected void writeInternal(D d) {
long ptr = writePointer; long ptr = writePointer;
MemoryUtil.memPutByte(ptr, (byte) (d.blockLight << 4)); MemoryUtil.memPutByte(ptr, d.blockLight);
MemoryUtil.memPutByte(ptr + 1, (byte) (d.skyLight << 4)); MemoryUtil.memPutByte(ptr + 1, d.skyLight);
MemoryUtil.memPutByte(ptr + 2, d.r); MemoryUtil.memPutByte(ptr + 2, d.r);
MemoryUtil.memPutByte(ptr + 3, d.g); MemoryUtil.memPutByte(ptr + 3, d.g);
MemoryUtil.memPutByte(ptr + 4, d.b); MemoryUtil.memPutByte(ptr + 4, d.b);

View file

@ -108,4 +108,3 @@ public class OrientedPart extends ColoredLitPart {
return out; return out;
} }
} }

View file

@ -1,7 +1,5 @@
package com.jozufozu.flywheel.core.uniform; package com.jozufozu.flywheel.core.uniform;
import java.nio.ByteBuffer;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.uniform.UniformProvider; import com.jozufozu.flywheel.api.uniform.UniformProvider;

View file

@ -4,7 +4,6 @@ import java.nio.ByteBuffer;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicLongArray;
import org.lwjgl.opengl.GL32; import org.lwjgl.opengl.GL32;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;

View file

@ -1,7 +1,5 @@
package com.jozufozu.flywheel.core.uniform; package com.jozufozu.flywheel.core.uniform;
import java.nio.ByteBuffer;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.api.uniform.UniformProvider; import com.jozufozu.flywheel.api.uniform.UniformProvider;

View file

@ -46,7 +46,7 @@ public class BlockWriterUnsafe extends VertexWriterUnsafe<BlockVertex> {
MemoryUtil.memPutByte(ptr + 15, a); MemoryUtil.memPutByte(ptr + 15, a);
MemoryUtil.memPutFloat(ptr + 16, u); MemoryUtil.memPutFloat(ptr + 16, u);
MemoryUtil.memPutFloat(ptr + 20, v); 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 + 28, RenderMath.nb(nX));
MemoryUtil.memPutByte(ptr + 29, RenderMath.nb(nY)); MemoryUtil.memPutByte(ptr + 29, RenderMath.nb(nY));
MemoryUtil.memPutByte(ptr + 30, RenderMath.nb(nZ)); MemoryUtil.memPutByte(ptr + 30, RenderMath.nb(nZ));

View file

@ -2,7 +2,6 @@ package com.jozufozu.flywheel.util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f; import com.mojang.math.Matrix4f;
/** /**

View file

@ -7,7 +7,6 @@ import java.util.function.BiFunction;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import com.jozufozu.flywheel.api.RenderStage;
import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.DynamicInstance;
import com.jozufozu.flywheel.api.instancer.InstancedPart; import com.jozufozu.flywheel.api.instancer.InstancedPart;
import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.api.instancer.InstancerManager;

View file

@ -2,7 +2,6 @@ package com.jozufozu.flywheel.vanilla;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import com.jozufozu.flywheel.api.RenderStage;
import com.jozufozu.flywheel.api.instance.DynamicInstance; import com.jozufozu.flywheel.api.instance.DynamicInstance;
import com.jozufozu.flywheel.api.instance.TickableInstance; import com.jozufozu.flywheel.api.instance.TickableInstance;
import com.jozufozu.flywheel.api.instancer.InstancerManager; import com.jozufozu.flywheel.api.instancer.InstancerManager;

View file

@ -1,6 +1,7 @@
in vec4 flw_vertexPos; in vec4 flw_vertexPos;
in vec4 flw_vertexColor; in vec4 flw_vertexColor;
in vec2 flw_vertexTexCoord; in vec2 flw_vertexTexCoord;
flat in ivec2 flw_vertexOverlay;
in vec2 flw_vertexLight; in vec2 flw_vertexLight;
in vec3 flw_vertexNormal; in vec3 flw_vertexNormal;
@ -10,3 +11,11 @@ in vec4 flw_var0;
in vec4 flw_var1; in vec4 flw_var1;
in vec4 flw_var2; in vec4 flw_var2;
in vec4 flw_var3; in vec4 flw_var3;
//
/*const*/ vec4 flw_sampleColor;
vec4 flw_fragColor;
ivec2 flw_fragOverlay;
vec2 flw_fragLight;

View file

@ -1,6 +1,7 @@
out vec4 flw_vertexPos; out vec4 flw_vertexPos;
out vec4 flw_vertexColor; out vec4 flw_vertexColor;
out vec2 flw_vertexTexCoord; out vec2 flw_vertexTexCoord;
flat out ivec2 flw_vertexOverlay;
out vec2 flw_vertexLight; out vec2 flw_vertexLight;
out vec3 flw_vertexNormal; out vec3 flw_vertexNormal;

View file

@ -2,7 +2,7 @@
#use "flywheel:util/fog.glsl" #use "flywheel:util/fog.glsl"
#use "flywheel:uniform/fog.glsl" #use "flywheel:uniform/fog.glsl"
uniform sampler2D uCrumblingTex; uniform sampler2D flw_diffuseTex;
out vec4 fragColor; out vec4 fragColor;
@ -25,8 +25,16 @@ vec2 flattenedPos(vec3 pos, vec3 normal) {
return (transpose(tbn) * pos).xy + vec2(0.5); 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() { void flw_contextFragment() {
vec4 color = texture(uCrumblingTex, flattenedPos(flw_vertexPos.xyz, flw_vertexNormal)); vec4 color = flw_fragColor;
#ifdef ALPHA_DISCARD #ifdef ALPHA_DISCARD
if (color.a < ALPHA_DISCARD) { if (color.a < ALPHA_DISCARD) {

View file

@ -9,15 +9,26 @@ layout (depth_greater) out float gl_FragDepth;
#endif #endif
#endif #endif
uniform sampler2D uBlockAtlas; uniform sampler2D flw_diffuseTex;
uniform sampler2D uLightMap; uniform sampler2D flw_overlayTex;
uniform sampler2D flw_lightTex;
out vec4 fragColor; 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() { void flw_contextFragment() {
vec4 texColor = texture(uBlockAtlas, flw_vertexTexCoord); vec4 overlayColor = texelFetch(flw_overlayTex, flw_fragOverlay, 0);
vec4 lightColor = texture(uLightMap, flw_vertexLight); vec4 lightColor = texture(flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0);
vec4 color = flw_vertexColor * vec4(texColor.rgb * lightColor.rgb, texColor.a);
vec4 color = flw_fragColor;
color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a);
color *= lightColor;
#ifdef ALPHA_DISCARD #ifdef ALPHA_DISCARD
if (color.a < ALPHA_DISCARD) { if (color.a < ALPHA_DISCARD) {

View file

@ -1,8 +1,7 @@
#use "flywheel:api/vertex.glsl" #use "flywheel:api/vertex.glsl"
#use "flywheel:util/light.glsl"
#use "flywheel:util/quaternion.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 = 1) in vec4 oriented_color;
layout(location = 2) in vec3 oriented_pos; layout(location = 2) in vec3 oriented_pos;
layout(location = 3) in vec3 oriented_pivot; 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_vertexPos = vec4(rotateVertexByQuat(flw_vertexPos.xyz - oriented_pivot, oriented_rotation) + oriented_pivot + oriented_pos, 1.0);
flw_vertexNormal = rotateVertexByQuat(flw_vertexNormal, oriented_rotation); flw_vertexNormal = rotateVertexByQuat(flw_vertexNormal, oriented_rotation);
flw_vertexColor = oriented_color; flw_vertexColor = oriented_color;
flw_vertexLight = shiftLight(oriented_light); flw_vertexLight = oriented_light / 15.0;
} }

View file

@ -1,7 +1,6 @@
#use "flywheel:api/vertex.glsl" #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 = 1) in vec4 transformed_color;
layout(location = 2) in mat4 transformed_pose; layout(location = 2) in mat4 transformed_pose;
layout(location = 6) in mat3 transformed_normal; layout(location = 6) in mat3 transformed_normal;
@ -10,5 +9,5 @@ void flw_instanceVertex() {
flw_vertexPos = transformed_pose * flw_vertexPos; flw_vertexPos = transformed_pose * flw_vertexPos;
flw_vertexNormal = transformed_normal * flw_vertexNormal; flw_vertexNormal = transformed_normal * flw_vertexNormal;
flw_vertexColor = transformed_color; flw_vertexColor = transformed_color;
flw_vertexLight = shiftLight(transformed_light); flw_vertexLight = transformed_light / 15.0;
} }

View file

@ -1,16 +1,16 @@
#use "flywheel:api/vertex.glsl" #use "flywheel:api/vertex.glsl"
#use "flywheel:util/light.glsl"
layout(location = 0) in vec3 _flw_v_pos; layout(location = 0) in vec3 _flw_v_pos;
layout(location = 1) in vec4 _flw_v_color; layout(location = 1) in vec4 _flw_v_color;
layout(location = 2) in vec2 _flw_v_texCoord; 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; layout(location = 4) in vec3 _flw_v_normal;
void flw_layoutVertex() { void flw_layoutVertex() {
flw_vertexPos = vec4(_flw_v_pos, 1.0); flw_vertexPos = vec4(_flw_v_pos, 1.0);
flw_vertexColor = _flw_v_color; flw_vertexColor = _flw_v_color;
flw_vertexTexCoord = _flw_v_texCoord; 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; flw_vertexNormal = _flw_v_normal;
} }

View file

@ -8,6 +8,7 @@ void flw_layoutVertex() {
flw_vertexPos = vec4(_flw_v_pos, 1.0); flw_vertexPos = vec4(_flw_v_pos, 1.0);
flw_vertexColor = vec4(1.0); flw_vertexColor = vec4(1.0);
flw_vertexTexCoord = _flw_v_texCoord; 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; flw_vertexNormal = _flw_v_normal;
} }

View file

@ -1,4 +1,3 @@
layout(std140, binding = 0) uniform flw_view { layout(std140, binding = 0) uniform flw_view {
mat4 flw_viewProjection; mat4 flw_viewProjection;
vec4 flw_cameraPos; vec4 flw_cameraPos;

View file

@ -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
}