diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java
new file mode 100644
index 000000000..45cff0f46
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java
@@ -0,0 +1,6 @@
+package com.jozufozu.flywheel;
+
+public class Flywheel {
+
+ public static final String ID = "flywheel";
+}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java
index dd4e6a5a3..70f774155 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderContext.java
@@ -1,30 +1,26 @@
package com.jozufozu.flywheel.backend;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
import com.jozufozu.flywheel.backend.gl.shader.IMultiProgram;
import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec;
-import com.jozufozu.flywheel.backend.gl.shader.ShaderConstants;
import com.jozufozu.flywheel.backend.gl.shader.ShaderSpecLoader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.loading.Program;
import com.jozufozu.flywheel.backend.loading.Shader;
import com.jozufozu.flywheel.backend.loading.ShaderTransformer;
-import net.minecraft.util.ResourceLocation;
-
public abstract class ShaderContext
{
public final Map> programs = new HashMap<>();
- public final ResourceLocation root;
protected final ShaderSpecLoader specLoader;
protected ShaderTransformer transformer = new ShaderTransformer();
- public ShaderContext(ResourceLocation root, ShaderSpecLoader
specLoader) {
- this.root = root;
+ public ShaderContext(ShaderSpecLoader
specLoader) {
this.specLoader = specLoader;
}
@@ -37,24 +33,29 @@ public abstract class ShaderContext
{
public void loadProgramFromSpec(ShaderLoader loader, ProgramSpec programSpec) {
- programs.put(programSpec, specLoader.create(loader, this, programSpec));
+ try {
+ programs.put(programSpec, specLoader.create(loader, this, programSpec));
- Backend.log.debug("Loaded program {}", programSpec.name);
+ Backend.log.debug("Loaded program {}", programSpec.name);
+ } catch (Exception e) {
+ Backend.log.error("program '{}': {}", programSpec.name, e.getMessage());
+ loader.notifyError();
+ }
}
- public Program loadProgram(ProgramSpec spec, ShaderConstants defines, ShaderLoader loader) {
- if (defines != null)
- transformer.pushStage(defines);
-
+ public Program loadProgram(ShaderLoader loader, ProgramSpec spec, Collection defines) {
Shader vertexFile = loader.source(spec.vert, ShaderType.VERTEX);
Shader fragmentFile = loader.source(spec.frag, ShaderType.FRAGMENT);
transformer.transformSource(vertexFile);
transformer.transformSource(fragmentFile);
+ if (defines != null) {
+ vertexFile.defineAll(defines);
+ fragmentFile.defineAll(defines);
+ }
+
Program program = loader.loadProgram(spec.name, vertexFile, fragmentFile);
- if (defines != null)
- transformer.popStage();
preLink(program);
@@ -69,8 +70,4 @@ public abstract class ShaderContext {
return programs.get(spec).get();
}
- public ResourceLocation getRoot() {
- return root;
- }
-
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java
index 569e2f3f4..2dbf1a100 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/ShaderLoader.java
@@ -5,7 +5,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
-import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
@@ -23,6 +22,8 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.annotation.Nonnull;
+
import org.lwjgl.system.MemoryUtil;
import com.google.common.collect.Lists;
@@ -31,6 +32,7 @@ import com.jozufozu.flywheel.backend.gl.shader.GlShader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import com.jozufozu.flywheel.backend.loading.Program;
import com.jozufozu.flywheel.backend.loading.Shader;
+import com.jozufozu.flywheel.backend.loading.ShaderLoadingException;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.resources.IResource;
@@ -49,6 +51,8 @@ public class ShaderLoader {
private final Map shaderSource = new HashMap<>();
+ private boolean shouldCrash;
+
void onResourceManagerReload(IResourceManager manager, Predicate predicate) {
if (predicate.test(VanillaResourceType.SHADERS)) {
OptifineHandler.refresh();
@@ -56,12 +60,19 @@ public class ShaderLoader {
if (Backend.gl20()) {
shaderSource.clear();
+
+ shouldCrash = false;
+
loadShaderSources(manager);
for (ShaderContext> context : Backend.contexts) {
context.load(this);
}
+ if (shouldCrash) {
+ throw new ShaderLoadingException("could not load all shaders, see log for details");
+ }
+
Backend.log.info("Loaded all shader programs.");
// no need to hog all that memory
@@ -70,8 +81,19 @@ public class ShaderLoader {
}
}
+ public void notifyError() {
+ shouldCrash = true;
+ }
+
+ @Nonnull
public String getShaderSource(ResourceLocation loc) {
- return shaderSource.get(loc);
+ String source = shaderSource.get(loc);
+
+ if (source == null) {
+ throw new ShaderLoadingException(String.format("shader '%s' does not exist", loc));
+ }
+
+ return source;
}
private void loadShaderSources(IResourceManager manager) {
@@ -158,12 +180,13 @@ public class ShaderLoader {
ResourceLocation include = new ResourceLocation(includeName);
if (seen.add(include)) {
- String includeSource = getShaderSource(include);
-
- if (includeSource != null) {
- return includeRecursive(includeSource, seen);
+ try {
+ return includeRecursive(getShaderSource(include), seen);
+ } catch (ShaderLoadingException e) {
+ throw new ShaderLoadingException("could not resolve import: " + e.getMessage());
}
}
+
}
return Stream.of(line);
@@ -181,7 +204,7 @@ public class ShaderLoader {
try {
bytebuffer = readToBuffer(is);
int i = bytebuffer.position();
- ((Buffer) bytebuffer).rewind();
+ bytebuffer.rewind();
return MemoryUtil.memASCII(bytebuffer, i);
} catch (IOException e) {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/BasicProgram.java b/src/main/java/com/jozufozu/flywheel/backend/core/BasicProgram.java
index 80e554f39..cae17d565 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/core/BasicProgram.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/core/BasicProgram.java
@@ -8,7 +8,6 @@ import com.jozufozu.flywheel.backend.gl.shader.ProgramFogMode;
import com.jozufozu.flywheel.backend.loading.Program;
import com.simibubi.create.foundation.utility.AnimationTickHolder;
-import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
public class BasicProgram extends GlProgram {
@@ -21,12 +20,8 @@ public class BasicProgram extends GlProgram {
protected int uBlockAtlas;
protected int uLightMap;
- public BasicProgram(Program builder, ProgramFogMode.Factory fogFactory) {
- this(builder.name, builder.program, fogFactory);
- }
-
- public BasicProgram(ResourceLocation name, int handle, ProgramFogMode.Factory fogFactory) {
- super(name, handle);
+ public BasicProgram(Program program, ProgramFogMode.Factory fogFactory) {
+ super(program);
uTime = getUniformLocation("uTime");
uViewProjection = getUniformLocation("uViewProjection");
uCameraPos = getUniformLocation("uCameraPos");
diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java b/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java
index e25feeee4..417ae135c 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/core/CrumblingProgram.java
@@ -3,15 +3,14 @@ package com.jozufozu.flywheel.backend.core;
import static org.lwjgl.opengl.GL20.glUniform2f;
import com.jozufozu.flywheel.backend.gl.shader.ProgramFogMode;
-
-import net.minecraft.util.ResourceLocation;
+import com.jozufozu.flywheel.backend.loading.Program;
public class CrumblingProgram extends BasicProgram {
protected final int uTextureScale;
protected int uCrumbling;
- public CrumblingProgram(ResourceLocation name, int handle, ProgramFogMode.Factory fogFactory) {
- super(name, handle, fogFactory);
+ public CrumblingProgram(Program program, ProgramFogMode.Factory fogFactory) {
+ super(program, fogFactory);
uTextureScale = getUniformLocation("uTextureScale");
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java b/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java
index c2fbdcdbb..f3b1dada0 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/core/WorldContext.java
@@ -7,6 +7,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
+import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.ResourceUtil;
import com.jozufozu.flywheel.backend.ShaderContext;
@@ -21,6 +22,7 @@ import com.jozufozu.flywheel.backend.loading.InstancedArraysTemplate;
import com.jozufozu.flywheel.backend.loading.Program;
import com.jozufozu.flywheel.backend.loading.ProgramTemplate;
import com.jozufozu.flywheel.backend.loading.Shader;
+import com.jozufozu.flywheel.backend.loading.ShaderLoadingException;
import com.jozufozu.flywheel.backend.loading.ShaderTransformer;
import net.minecraft.util.ResourceLocation;
@@ -30,16 +32,17 @@ public class WorldContext extends ShaderContext
{
private static final String declaration = "#flwbuiltins";
private static final Pattern builtinPattern = Pattern.compile(declaration);
- public static final WorldContext INSTANCE = new WorldContext<>(new ResourceLocation("create", "context/world"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new));
- public static final WorldContext CRUMBLING = new WorldContext<>(new ResourceLocation("create", "context/crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new));
-
- final Map builtins;
- final Map builtinSources;
+ public static final WorldContext INSTANCE = new WorldContext<>(new ResourceLocation(Flywheel.ID, "context/world"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new));
+ public static final WorldContext CRUMBLING = new WorldContext<>(new ResourceLocation(Flywheel.ID, "context/crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new));
protected ProgramTemplate template;
+ protected final ResourceLocation name;
protected final Supplier> specStream;
protected final TemplateFactory templateFactory;
+ private final Map builtins = new EnumMap<>(ShaderType.class);
+ private final Map builtinSources = new EnumMap<>(ShaderType.class);
+
public WorldContext(ResourceLocation root, ShaderSpecLoader loader) {
this(root, loader, () -> Backend.allMaterials()
.stream()
@@ -47,11 +50,10 @@ public class WorldContext
extends ShaderContext
{
}
public WorldContext(ResourceLocation root, ShaderSpecLoader
loader, Supplier> specStream, TemplateFactory templateFactory) {
- super(root, loader);
+ super(loader);
+ this.name = root;
this.specStream = specStream;
this.templateFactory = templateFactory;
- builtins = new EnumMap<>(ShaderType.class);
- builtinSources = new EnumMap<>(ShaderType.class);
builtins.put(ShaderType.FRAGMENT, ResourceUtil.subPath(root, "/builtin.frag"));
builtins.put(ShaderType.VERTEX, ResourceUtil.subPath(root, "/builtin.vert"));
}
@@ -61,7 +63,17 @@ public class WorldContext extends ShaderContext
{
programs.values().forEach(IMultiProgram::delete);
programs.clear();
- builtins.forEach((type, resourceLocation) -> builtinSources.put(type, loader.getShaderSource(resourceLocation)));
+ Backend.log.info("loading context '{}'", name);
+
+ try {
+ builtins.forEach((type, resourceLocation) -> builtinSources.put(type, loader.getShaderSource(resourceLocation)));
+ } catch (ShaderLoadingException e) {
+ loader.notifyError();
+
+ Backend.log.error(String.format("could not find builtin: %s", e.getMessage()));
+
+ return;
+ }
template = templateFactory.create(loader);
transformer = new ShaderTransformer()
@@ -88,7 +100,7 @@ public class WorldContext
extends ShaderContext
{
if (matcher.find())
shader.setSource(matcher.replaceFirst(builtinSources.get(shader.type)));
else
- throw new RuntimeException(String.format("%s shader '%s' is missing %s, cannot use in World Context", shader.type.name, shader.name, declaration));
+ throw new ShaderLoadingException(String.format("%s is missing %s, cannot use in World Context", shader.type.name, declaration));
}
public interface TemplateFactory {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/FogSensitiveProgram.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/FogSensitiveProgram.java
index 7aa8ef21d..f54e699cc 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/FogSensitiveProgram.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/FogSensitiveProgram.java
@@ -1,6 +1,9 @@
package com.jozufozu.flywheel.backend.gl.shader;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.EnumMap;
+import java.util.List;
import java.util.Map;
import com.jozufozu.flywheel.backend.ShaderContext;
@@ -9,14 +12,14 @@ import com.jozufozu.flywheel.backend.gl.GlFog;
import com.jozufozu.flywheel.backend.gl.GlFogMode;
import com.jozufozu.flywheel.backend.loading.Program;
-import net.minecraft.util.ResourceLocation;
-
public class FogSensitiveProgram
implements IMultiProgram
{
private final Map programs;
+ private final List debugPrograms;
- public FogSensitiveProgram(Map programs) {
+ public FogSensitiveProgram(Map programs, List debugPrograms) {
this.programs = programs;
+ this.debugPrograms = debugPrograms;
}
@Override
@@ -39,25 +42,31 @@ public class FogSensitiveProgram
implements IMultiProgram
create(ShaderLoader loader, ShaderContext
ctx, ProgramSpec spec) {
+ List
debugModes = new ArrayList<>(2);
+
+ String[] modes = new String[]{"NORMAL_DEBUG", "RAINBOW_DEBUG"};
+
+ for (String mode : modes) {
+ Program builder = ctx.loadProgram(loader, spec, Collections.singletonList(mode));
+
+ debugModes.add(fogProgramLoader.create(builder, GlFogMode.NONE.getFogFactory()));
+ }
+
Map programs = new EnumMap<>(GlFogMode.class);
for (GlFogMode fogMode : GlFogMode.values()) {
- ShaderConstants defines = new ShaderConstants(spec.defines);
+ Program builder = ctx.loadProgram(loader, spec, fogMode.getDefines());
- defines.defineAll(fogMode.getDefines());
-
- Program builder = ctx.loadProgram(spec, defines, loader);
-
- programs.put(fogMode, fogProgramLoader.create(builder.name, builder.program, fogMode.getFogFactory()));
+ programs.put(fogMode, fogProgramLoader.create(builder, fogMode.getFogFactory()));
}
- return new FogSensitiveProgram<>(programs);
+ return new FogSensitiveProgram<>(programs, debugModes);
}
}
public interface FogProgramLoader {
- P create(ResourceLocation name, int handle, ProgramFogMode.Factory fogFactory);
+ P create(Program program, ProgramFogMode.Factory fogFactory);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java
index 65e284062..e62ba84df 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/GlProgram.java
@@ -8,6 +8,7 @@ import static org.lwjgl.opengl.GL20.glUseProgram;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.GlObject;
+import com.jozufozu.flywheel.backend.loading.Program;
import com.jozufozu.flywheel.util.RenderUtil;
import net.minecraft.util.ResourceLocation;
@@ -17,9 +18,9 @@ public abstract class GlProgram extends GlObject {
public final ResourceLocation name;
- protected GlProgram(ResourceLocation name, int handle) {
- setHandle(handle);
- this.name = name;
+ protected GlProgram(Program program) {
+ setHandle(program.program);
+ this.name = program.name;
}
public void bind() {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ProgramSpec.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ProgramSpec.java
index 247662d22..a7f686fff 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ProgramSpec.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ProgramSpec.java
@@ -1,5 +1,8 @@
package com.jozufozu.flywheel.backend.gl.shader;
+import java.util.ArrayList;
+import java.util.List;
+
import net.minecraft.util.ResourceLocation;
public class ProgramSpec {
@@ -8,48 +11,12 @@ public class ProgramSpec {
public final ResourceLocation vert;
public final ResourceLocation frag;
- public final ShaderConstants defines;
+ public final List debugModes = new ArrayList<>();
- public static Builder builder(ResourceLocation name) {
- return new Builder(name);
- }
-
- public ProgramSpec(ResourceLocation name, ResourceLocation vert, ResourceLocation frag, ShaderConstants defines) {
+ public ProgramSpec(ResourceLocation name, ResourceLocation vert, ResourceLocation frag) {
this.name = name;
this.vert = vert;
this.frag = frag;
- this.defines = defines;
- }
-
- public static class Builder {
- private ResourceLocation vert;
- private ResourceLocation frag;
- private ShaderConstants defines = ShaderConstants.EMPTY;
-
- private final ResourceLocation name;
-
- public Builder(ResourceLocation name) {
- this.name = name;
- }
-
- public Builder setVert(ResourceLocation vert) {
- this.vert = vert;
- return this;
- }
-
- public Builder setFrag(ResourceLocation frag) {
- this.frag = frag;
- return this;
- }
-
- public Builder setDefines(ShaderConstants defines) {
- this.defines = defines;
- return this;
- }
-
- public ProgramSpec build() {
- return new ProgramSpec(name, vert, frag, defines);
- }
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ShaderConstants.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ShaderConstants.java
deleted file mode 100644
index 5119310f7..000000000
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/ShaderConstants.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.jozufozu.flywheel.backend.gl.shader;
-
-import java.io.BufferedReader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import com.google.common.collect.Lists;
-import com.jozufozu.flywheel.backend.loading.ProcessingStage;
-import com.jozufozu.flywheel.backend.loading.Shader;
-
-public class ShaderConstants implements ProcessingStage {
- public static final ShaderConstants EMPTY = new ShaderConstants();
-
- private final ArrayList defines;
-
- public ShaderConstants() {
- defines = new ArrayList<>();
- }
-
- public ShaderConstants(ShaderConstants other) {
- this.defines = Lists.newArrayList(other.defines);
- }
-
- public static ShaderConstants define(String def) {
- return new ShaderConstants().def(def);
- }
-
- public ShaderConstants def(String def) {
- defines.add(def);
- return this;
- }
-
- public ShaderConstants defineAll(Collection defines) {
- this.defines.addAll(defines);
- return this;
- }
-
- public ArrayList getDefines() {
- return defines;
- }
-
- public Stream directives() {
- return defines.stream().map(it -> "#define " + it);
- }
-
- @Override
- public void process(Shader shader) {
- shader.setSource(new BufferedReader(new StringReader(shader.getSource())).lines().flatMap(line -> {
- Stream map = Stream.of(line);
-
- if (line.startsWith("#version")) {
- map = Stream.concat(map, directives());
- }
-
- return map;
- }).collect(Collectors.joining("\n")));
- }
-}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/SingleProgram.java b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/SingleProgram.java
index a957d24b6..d66f10bb6 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/gl/shader/SingleProgram.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/gl/shader/SingleProgram.java
@@ -4,8 +4,6 @@ import com.jozufozu.flywheel.backend.ShaderContext;
import com.jozufozu.flywheel.backend.ShaderLoader;
import com.jozufozu.flywheel.backend.loading.Program;
-import net.minecraft.util.ResourceLocation;
-
public class SingleProgram implements IMultiProgram
{
final P program;
@@ -32,14 +30,12 @@ public class SingleProgram
implements IMultiProgram
{
@Override
public IMultiProgram
create(ShaderLoader loader, ShaderContext
ctx, ProgramSpec spec) {
- Program builder = ctx.loadProgram(spec, spec.defines, loader);
-
- return new SingleProgram<>(factory.create(builder.name, builder.program));
+ return new SingleProgram<>(factory.create(ctx.loadProgram(loader, spec, null)));
}
}
@FunctionalInterface
public interface ProgramFactory
{
- P create(ResourceLocation name, int handle);
+ P create(Program program);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/loading/InstancedArraysTemplate.java b/src/main/java/com/jozufozu/flywheel/backend/loading/InstancedArraysTemplate.java
index 1314e66b9..6f3c6cd84 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/loading/InstancedArraysTemplate.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/loading/InstancedArraysTemplate.java
@@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.loading;
+import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.ShaderLoader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
@@ -18,8 +19,8 @@ public class InstancedArraysTemplate extends ProgramTemplate {
public static final String[] requiredFrag = {fragment};
- public static final ResourceLocation vert = new ResourceLocation("create", "template/instanced/instanced.vert");
- public static final ResourceLocation frag = new ResourceLocation("create", "template/instanced/instanced.frag");
+ public static final ResourceLocation vert = new ResourceLocation(Flywheel.ID, "template/instanced/instanced.vert");
+ public static final ResourceLocation frag = new ResourceLocation(Flywheel.ID, "template/instanced/instanced.frag");
public InstancedArraysTemplate(ShaderLoader loader) {
super(loader);
diff --git a/src/main/java/com/jozufozu/flywheel/backend/loading/ModelTemplate.java b/src/main/java/com/jozufozu/flywheel/backend/loading/ModelTemplate.java
index ffa650c73..5e12d8652 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/loading/ModelTemplate.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/loading/ModelTemplate.java
@@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.loading;
+import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.ShaderLoader;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
@@ -15,8 +16,8 @@ public class ModelTemplate extends ProgramTemplate {
public static final String[] requiredFrag = {fragment};
- public static final ResourceLocation vert = new ResourceLocation("create", "template/model/model.vert");
- public static final ResourceLocation frag = new ResourceLocation("create", "template/model/model.frag");
+ public static final ResourceLocation vert = new ResourceLocation(Flywheel.ID, "template/model/model.vert");
+ public static final ResourceLocation frag = new ResourceLocation(Flywheel.ID, "template/model/model.frag");
public ModelTemplate(ShaderLoader loader) {
super(loader);
diff --git a/src/main/java/com/jozufozu/flywheel/backend/loading/Shader.java b/src/main/java/com/jozufozu/flywheel/backend/loading/Shader.java
index aa70847b8..250172968 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/loading/Shader.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/loading/Shader.java
@@ -1,17 +1,20 @@
package com.jozufozu.flywheel.backend.loading;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
import net.minecraft.util.ResourceLocation;
public class Shader {
+ public static final Pattern versionDetector = Pattern.compile("#version[^\\n]*");
private static final Pattern decorator = Pattern.compile("#\\[([\\w_]*)]");
public final ResourceLocation name;
@@ -54,6 +57,21 @@ public class Shader {
}
}
+ public void defineAll(Collection defines) {
+ Matcher matcher = versionDetector.matcher(source);
+
+ if (matcher.find()) {
+ StringBuffer sourceWithDefines = new StringBuffer();
+ String lines = defines.stream().map(it -> "#define " + it).collect(Collectors.joining("\n"));
+
+ matcher.appendReplacement(sourceWithDefines, matcher.group() + '\n' + lines);
+
+ matcher.appendTail(sourceWithDefines);
+
+ source = sourceWithDefines.toString();
+ }
+ }
+
public void parseStructs() {
Matcher structMatcher = TaggedStruct.taggedStruct.matcher(source);
diff --git a/src/main/java/com/jozufozu/flywheel/backend/loading/ShaderLoadingException.java b/src/main/java/com/jozufozu/flywheel/backend/loading/ShaderLoadingException.java
new file mode 100644
index 000000000..5c32c7d98
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/loading/ShaderLoadingException.java
@@ -0,0 +1,22 @@
+package com.jozufozu.flywheel.backend.loading;
+
+public class ShaderLoadingException extends RuntimeException {
+ public ShaderLoadingException() {
+ }
+
+ public ShaderLoadingException(String message) {
+ super(message);
+ }
+
+ public ShaderLoadingException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ShaderLoadingException(Throwable cause) {
+ super(cause);
+ }
+
+ public ShaderLoadingException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java
index 868c121ab..b5952789a 100644
--- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java
+++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionProgram.java
@@ -4,30 +4,30 @@ import org.lwjgl.opengl.GL20;
import com.jozufozu.flywheel.backend.core.BasicProgram;
import com.jozufozu.flywheel.backend.gl.shader.ProgramFogMode;
+import com.jozufozu.flywheel.backend.loading.Program;
-import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.vector.Matrix4f;
public class ContraptionProgram extends BasicProgram {
- protected final int uLightBoxSize;
- protected final int uLightBoxMin;
- protected final int uModel;
+ protected final int uLightBoxSize;
+ protected final int uLightBoxMin;
+ protected final int uModel;
- protected int uLightVolume;
+ protected int uLightVolume;
- public ContraptionProgram(ResourceLocation name, int handle, ProgramFogMode.Factory fogFactory) {
- super(name, handle, fogFactory);
- uLightBoxSize = getUniformLocation("uLightBoxSize");
- uLightBoxMin = getUniformLocation("uLightBoxMin");
- uModel = getUniformLocation("uModel");
- }
+ public ContraptionProgram(Program program, ProgramFogMode.Factory fogFactory) {
+ super(program, fogFactory);
+ uLightBoxSize = getUniformLocation("uLightBoxSize");
+ uLightBoxMin = getUniformLocation("uLightBoxMin");
+ uModel = getUniformLocation("uModel");
+ }
- @Override
- protected void registerSamplers() {
- super.registerSamplers();
- uLightVolume = setSamplerBinding("uLightVolume", 4);
- }
+ @Override
+ protected void registerSamplers() {
+ super.registerSamplers();
+ uLightVolume = setSamplerBinding("uLightVolume", 4);
+ }
public void bind(Matrix4f model, AxisAlignedBB lightVolume) {
double sizeX = lightVolume.maxX - lightVolume.minX;
diff --git a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java
index bf67269e3..a08553039 100644
--- a/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java
+++ b/src/main/java/com/simibubi/create/foundation/render/AllProgramSpecs.java
@@ -2,8 +2,8 @@ package com.simibubi.create.foundation.render;
import static com.jozufozu.flywheel.backend.Backend.register;
+import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.backend.gl.shader.ProgramSpec;
-import com.jozufozu.flywheel.backend.gl.shader.ShaderConstants;
import com.simibubi.create.Create;
import net.minecraft.util.ResourceLocation;
@@ -13,55 +13,20 @@ public class AllProgramSpecs {
// noop, make sure the static field are loaded.
}
- public static final ProgramSpec CHROMATIC = register(builder("chromatic")
- .setVert(Locations.EFFECT_VERT)
- .setFrag(Locations.EFFECT_FRAG)
- .build());
-
- public static final ProgramSpec MODEL = register(builder("model")
- .setVert(Locations.MODEL_VERT)
- .setFrag(Locations.BLOCK)
- .build());
-
- public static final ProgramSpec ORIENTED = register(builder("oriented")
- .setVert(Locations.ORIENTED)
- .setFrag(Locations.BLOCK)
- .build());
-
- public static final ProgramSpec ROTATING = register(builder("rotating")
- .setVert(Locations.ROTATING)
- .setFrag(Locations.BLOCK)
- .build());
-
- public static final ProgramSpec BELT = register(builder("belt")
- .setVert(Locations.BELT)
- .setFrag(Locations.BLOCK)
- .build());
-
- public static final ProgramSpec FLAPS = register(builder("flap")
- .setVert(Locations.FLAP)
- .setFrag(Locations.BLOCK)
- .build());
- public static final ProgramSpec STRUCTURE = register(builder("contraption_structure")
- .setVert(Locations.CONTRAPTION_STRUCTURE)
- .setFrag(Locations.BLOCK)
- .setDefines(ShaderConstants.define("CONTRAPTION"))
- .build());
- public static final ProgramSpec ACTOR = register(builder("contraption_actor")
- .setVert(Locations.CONTRAPTION_ACTOR)
- .setFrag(Locations.BLOCK)
- .setDefines(ShaderConstants.define("CONTRAPTION"))
- .build());
-
- public static ProgramSpec.Builder builder(String name) {
- return ProgramSpec.builder(new ResourceLocation(Create.ID, name));
- }
+ public static final ProgramSpec CHROMATIC = register(new ProgramSpec(loc("chromatic"), Locations.EFFECT_VERT, Locations.EFFECT_FRAG));
+ public static final ProgramSpec MODEL = register(new ProgramSpec(new ResourceLocation(Flywheel.ID, "model"), Locations.MODEL_VERT, Locations.BLOCK));
+ public static final ProgramSpec ORIENTED = register(new ProgramSpec(new ResourceLocation(Flywheel.ID, "oriented"), Locations.ORIENTED, Locations.BLOCK));
+ public static final ProgramSpec ROTATING = register(new ProgramSpec(loc("rotating"), Locations.ROTATING, Locations.BLOCK));
+ public static final ProgramSpec BELT = register(new ProgramSpec(loc("belt"), Locations.BELT, Locations.BLOCK));
+ public static final ProgramSpec FLAPS = register(new ProgramSpec(loc("flap"), Locations.FLAP, Locations.BLOCK));
+ public static final ProgramSpec STRUCTURE = register(new ProgramSpec(loc("contraption_structure"), Locations.CONTRAPTION_STRUCTURE, Locations.BLOCK));
+ public static final ProgramSpec ACTOR = register(new ProgramSpec(loc("contraption_actor"), Locations.CONTRAPTION_ACTOR, Locations.BLOCK));
public static class Locations {
- public static final ResourceLocation BLOCK = loc("block.frag");
+ public static final ResourceLocation BLOCK = new ResourceLocation(Flywheel.ID, "block.frag");
- public static final ResourceLocation MODEL_VERT = loc("model.vert");
- public static final ResourceLocation ORIENTED = loc("oriented.vert");
+ public static final ResourceLocation MODEL_VERT = new ResourceLocation(Flywheel.ID, "model.vert");
+ public static final ResourceLocation ORIENTED = new ResourceLocation(Flywheel.ID, "oriented.vert");
public static final ResourceLocation ROTATING = loc("rotating.vert");
public static final ResourceLocation BELT = loc("belt.vert");
@@ -71,9 +36,9 @@ public class AllProgramSpecs {
public static final ResourceLocation EFFECT_VERT = loc("area_effect.vert");
public static final ResourceLocation EFFECT_FRAG = loc("area_effect.frag");
+ }
- private static ResourceLocation loc(String name) {
- return new ResourceLocation(Create.ID, name);
- }
+ private static ResourceLocation loc(String name) {
+ return new ResourceLocation(Create.ID, name);
}
}
diff --git a/src/main/java/com/simibubi/create/foundation/render/effects/EffectsContext.java b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsContext.java
index f02261b66..5771e712e 100644
--- a/src/main/java/com/simibubi/create/foundation/render/effects/EffectsContext.java
+++ b/src/main/java/com/simibubi/create/foundation/render/effects/EffectsContext.java
@@ -6,14 +6,12 @@ import com.jozufozu.flywheel.backend.gl.shader.SingleProgram;
import com.jozufozu.flywheel.backend.loading.ShaderTransformer;
import com.simibubi.create.foundation.render.AllProgramSpecs;
-import net.minecraft.util.ResourceLocation;
-
public class EffectsContext extends ShaderContext {
public static final EffectsContext INSTANCE = new EffectsContext();
public EffectsContext() {
- super(new ResourceLocation("create", "effects"), new SingleProgram.SpecLoader<>(SphereFilterProgram::new));
+ super(new SingleProgram.SpecLoader<>(SphereFilterProgram::new));
}
@Override
diff --git a/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java b/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java
index a431579b2..80c4b5b67 100644
--- a/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java
+++ b/src/main/java/com/simibubi/create/foundation/render/effects/SphereFilterProgram.java
@@ -9,8 +9,8 @@ import com.jozufozu.flywheel.backend.gl.buffer.GlBuffer;
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
import com.jozufozu.flywheel.backend.gl.buffer.MappedBuffer;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
+import com.jozufozu.flywheel.backend.loading.Program;
-import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3d;
@@ -41,14 +41,14 @@ public class SphereFilterProgram extends GlProgram {
protected final int uCameraPos;
- public SphereFilterProgram(ResourceLocation name, int handle) {
- super(name, handle);
+ public SphereFilterProgram(Program program) {
+ super(program);
effectsUBO = new GlBuffer(GlBufferType.UNIFORM_BUFFER);
- uniformBlock = GL31.glGetUniformBlockIndex(handle, "Filters");
+ uniformBlock = GL31.glGetUniformBlockIndex(program.program, "Filters");
- GL31.glUniformBlockBinding(handle, uniformBlock, UBO_BINDING);
+ GL31.glUniformBlockBinding(program.program, uniformBlock, UBO_BINDING);
effectsUBO.bind();
effectsUBO.alloc(BUFFER_SIZE);
diff --git a/src/main/resources/assets/create/flywheel/shaders/area_effect.frag b/src/main/resources/assets/create/flywheel/shaders/area_effect.frag
index e2e99fc66..6c34704ce 100644
--- a/src/main/resources/assets/create/flywheel/shaders/area_effect.frag
+++ b/src/main/resources/assets/create/flywheel/shaders/area_effect.frag
@@ -1,6 +1,6 @@
#version 140
-#flwinclude <"create:core/color.glsl">
+#flwinclude <"flywheel:core/color.glsl">
in vec2 ScreenCoord;
in vec3 WorldDir;
diff --git a/src/main/resources/assets/create/flywheel/shaders/belt.vert b/src/main/resources/assets/create/flywheel/shaders/belt.vert
index 5d94c0f35..ce8ec2d5e 100644
--- a/src/main/resources/assets/create/flywheel/shaders/belt.vert
+++ b/src/main/resources/assets/create/flywheel/shaders/belt.vert
@@ -1,9 +1,9 @@
#define PI 3.1415926538
#flwbuiltins
-#flwinclude <"create:core/quaternion.glsl">
-#flwinclude <"create:core/matutils.glsl">
-#flwinclude <"create:core/diffuse.glsl">
+#flwinclude <"flywheel:core/quaternion.glsl">
+#flwinclude <"flywheel:core/matutils.glsl">
+#flwinclude <"flywheel:core/diffuse.glsl">
#[InstanceData]
struct Belt {
@@ -18,8 +18,8 @@ struct Belt {
float scrollMult;
};
-#flwinclude <"create:data/modelvertex.glsl">
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/modelvertex.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
BlockFrag FLWMain(Vertex v, Belt instance) {
vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
@@ -41,6 +41,8 @@ BlockFrag FLWMain(Vertex v, Belt instance) {
#if defined(RAINBOW_DEBUG)
b.color = instance.color;
+ #elif defined(NORMAL_DEBUG)
+ b.color = vec4(norm, 1.);
#else
b.color = vec4(1.);
#endif
diff --git a/src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.frag b/src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.frag
index 6a211bc46..43197a6c0 100644
--- a/src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.frag
+++ b/src/main/resources/assets/create/flywheel/shaders/context/contraption/builtin.frag
@@ -1,5 +1,5 @@
-#flwinclude <"create:context/world/fog.glsl">
-#flwinclude <"create:core/lightutil.glsl">
+#flwinclude <"flywheel:context/world/fog.glsl">
+#flwinclude <"flywheel:core/lightutil.glsl">
varying vec3 BoxCoord;
uniform sampler3D uLightVolume;
diff --git a/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.vert b/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.vert
deleted file mode 100644
index 8b61a3168..000000000
--- a/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.vert
+++ /dev/null
@@ -1 +0,0 @@
-#flwinclude <"create:context/world/builtin.vert">
diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert b/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert
index 6fe9b3ac4..b075730b9 100644
--- a/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert
+++ b/src/main/resources/assets/create/flywheel/shaders/contraption_actor.vert
@@ -1,9 +1,9 @@
#define PI 3.1415926538
#flwbuiltins
-#flwinclude <"create:core/matutils.glsl">
-#flwinclude <"create:core/quaternion.glsl">
-#flwinclude <"create:core/diffuse.glsl">
+#flwinclude <"flywheel:core/matutils.glsl">
+#flwinclude <"flywheel:core/quaternion.glsl">
+#flwinclude <"flywheel:core/diffuse.glsl">
#[InstanceData]
struct Actor {
@@ -16,8 +16,8 @@ struct Actor {
float speed;
};
-#flwinclude <"create:data/modelvertex.glsl">
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/modelvertex.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
BlockFrag FLWMain(Vertex v, Actor instance) {
float degrees = instance.offset + uTime * instance.speed / 20.;
@@ -36,7 +36,12 @@ BlockFrag FLWMain(Vertex v, Actor instance) {
b.diffuse = diffuse(norm);
b.texCoords = v.texCoords;
b.light = instance.light;
+
+ #if defined(NORMAL_DEBUG)
+ b.color = vec4(norm, 1.);
+ #else
b.color = vec4(1.);
+ #endif
return b;
}
diff --git a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert
index cac2956a0..fb3e66070 100644
--- a/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert
+++ b/src/main/resources/assets/create/flywheel/shaders/contraption_structure.vert
@@ -1,8 +1,8 @@
#define PI 3.1415926538
#flwbuiltins
-#flwinclude <"create:core/matutils.glsl">
-#flwinclude <"create:core/diffuse.glsl">
+#flwinclude <"flywheel:core/matutils.glsl">
+#flwinclude <"flywheel:core/diffuse.glsl">
#[VertexData]
struct Vertex {
@@ -13,7 +13,7 @@ struct Vertex {
vec2 modelLight;
};
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
BlockFrag FLWMain(Vertex v) {
vec4 worldPos = vec4(v.pos, 1.);
@@ -24,9 +24,14 @@ BlockFrag FLWMain(Vertex v) {
BlockFrag b;
b.diffuse = diffuse(norm);
- b.color = v.color / diffuse(v.normal);
b.texCoords = v.texCoords;
b.light = v.modelLight;
+ #if defined(NORMAL_DEBUG)
+ b.color = vec4(norm, 1.);
+ #else
+ b.color = v.color / diffuse(v.normal);
+ #endif
+
return b;
}
diff --git a/src/main/resources/assets/create/flywheel/shaders/flap.vert b/src/main/resources/assets/create/flywheel/shaders/flap.vert
index 1f5c973ad..047455554 100644
--- a/src/main/resources/assets/create/flywheel/shaders/flap.vert
+++ b/src/main/resources/assets/create/flywheel/shaders/flap.vert
@@ -1,9 +1,9 @@
#define PI 3.1415926538
#flwbuiltins
-#flwinclude <"create:core/matutils.glsl">
-#flwinclude <"create:core/quaternion.glsl">
-#flwinclude <"create:core/diffuse.glsl">
+#flwinclude <"flywheel:core/matutils.glsl">
+#flwinclude <"flywheel:core/quaternion.glsl">
+#flwinclude <"flywheel:core/diffuse.glsl">
#[InstanceData]
struct Flap {
@@ -17,8 +17,8 @@ struct Flap {
float flapness;
};
-#flwinclude <"create:data/modelvertex.glsl">
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/modelvertex.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
float toRad(float degrees) {
@@ -57,6 +57,10 @@ BlockFrag FLWMain(Vertex v, Flap flap) {
b.diffuse = diffuse(norm);
b.texCoords = v.texCoords;
b.light = flap.light;
+ #if defined(NORMAL_DEBUG)
+ b.color = vec4(norm, 1.);
+ #else
b.color = vec4(1.);
+ #endif
return b;
}
diff --git a/src/main/resources/assets/create/flywheel/shaders/rotating.vert b/src/main/resources/assets/create/flywheel/shaders/rotating.vert
index 5957c2752..f5fe07bde 100644
--- a/src/main/resources/assets/create/flywheel/shaders/rotating.vert
+++ b/src/main/resources/assets/create/flywheel/shaders/rotating.vert
@@ -1,8 +1,8 @@
#define PI 3.1415926538
#flwbuiltins
-#flwinclude <"create:core/matutils.glsl">
-#flwinclude <"create:core/diffuse.glsl">
+#flwinclude <"flywheel:core/matutils.glsl">
+#flwinclude <"flywheel:core/diffuse.glsl">
#[InstanceData]
struct Rotating {
@@ -14,24 +14,23 @@ struct Rotating {
vec3 axis;
};
-#flwinclude <"create:data/modelvertex.glsl">
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/modelvertex.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
mat4 kineticRotation(float offset, float speed, vec3 axis) {
- float degrees = offset + uTime * speed * -3./10.;
+ float degrees = offset + uTime * speed * 3./10.;
float angle = fract(degrees / 360.) * PI * 2.;
return rotate(axis, angle);
}
BlockFrag FLWMain(Vertex v, Rotating instance) {
- mat4 kineticRotation = kineticRotation(instance.offset, instance.speed, instance.axis);
+ mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
- vec4 worldPos = vec4(v.pos - .5, 1.);
- worldPos *= kineticRotation;
+ vec4 worldPos = spin * vec4(v.pos - .5, 1.);
worldPos += vec4(instance.pos + .5, 0.);
- vec3 norm = modelToNormal(kineticRotation) * v.normal;
+ vec3 norm = modelToNormal(spin) * v.normal;
FLWFinalizeWorldPos(worldPos);
FLWFinalizeNormal(norm);
@@ -43,6 +42,8 @@ BlockFrag FLWMain(Vertex v, Rotating instance) {
#if defined(RAINBOW_DEBUG)
b.color = instance.color;
+ #elif defined(NORMAL_DEBUG)
+ b.color = vec4(norm, 1.);
#else
b.color = vec4(1.);
#endif
diff --git a/src/main/resources/assets/create/flywheel/shaders/block.frag b/src/main/resources/assets/flywheel/flywheel/shaders/block.frag
similarity index 80%
rename from src/main/resources/assets/create/flywheel/shaders/block.frag
rename to src/main/resources/assets/flywheel/flywheel/shaders/block.frag
index e24666099..4b350cf60 100644
--- a/src/main/resources/assets/create/flywheel/shaders/block.frag
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/block.frag
@@ -1,6 +1,6 @@
#flwbuiltins
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
void FLWMain(BlockFrag r) {
vec4 tex = FLWBlockTexture(r.texCoords);
diff --git a/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.frag b/src/main/resources/assets/flywheel/flywheel/shaders/context/crumbling/builtin.frag
similarity index 92%
rename from src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.frag
rename to src/main/resources/assets/flywheel/flywheel/shaders/context/crumbling/builtin.frag
index 5bee49af8..3f68e588c 100644
--- a/src/main/resources/assets/create/flywheel/shaders/context/crumbling/builtin.frag
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/context/crumbling/builtin.frag
@@ -1,4 +1,4 @@
-#flwinclude <"create:context/world/fog.glsl">
+#flwinclude <"flywheel:context/world/fog.glsl">
uniform vec2 uTextureScale;
uniform sampler2D uBlockAtlas;
diff --git a/src/main/resources/assets/flywheel/flywheel/shaders/context/crumbling/builtin.vert b/src/main/resources/assets/flywheel/flywheel/shaders/context/crumbling/builtin.vert
new file mode 100644
index 000000000..730ca3556
--- /dev/null
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/context/crumbling/builtin.vert
@@ -0,0 +1 @@
+#flwinclude <"flywheel:context/world/builtin.vert">
diff --git a/src/main/resources/assets/create/flywheel/shaders/context/world/builtin.frag b/src/main/resources/assets/flywheel/flywheel/shaders/context/world/builtin.frag
similarity index 83%
rename from src/main/resources/assets/create/flywheel/shaders/context/world/builtin.frag
rename to src/main/resources/assets/flywheel/flywheel/shaders/context/world/builtin.frag
index 81e9a2be9..e8b615c75 100644
--- a/src/main/resources/assets/create/flywheel/shaders/context/world/builtin.frag
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/context/world/builtin.frag
@@ -1,5 +1,5 @@
-#flwinclude <"create:context/world/fog.glsl">
-#flwinclude <"create:core/lightutil.glsl">
+#flwinclude <"flywheel:context/world/fog.glsl">
+#flwinclude <"flywheel:core/lightutil.glsl">
uniform sampler2D uBlockAtlas;
uniform sampler2D uLightMap;
diff --git a/src/main/resources/assets/create/flywheel/shaders/context/world/builtin.vert b/src/main/resources/assets/flywheel/flywheel/shaders/context/world/builtin.vert
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/context/world/builtin.vert
rename to src/main/resources/assets/flywheel/flywheel/shaders/context/world/builtin.vert
diff --git a/src/main/resources/assets/create/flywheel/shaders/context/world/fog.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/context/world/fog.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/context/world/fog.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/context/world/fog.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/core/color.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/core/color.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/core/color.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/core/color.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/core/diffuse.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/core/diffuse.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/core/diffuse.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/core/diffuse.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/core/lightutil.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/core/lightutil.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/core/lightutil.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/core/lightutil.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/core/matutils.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/core/matutils.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/core/matutils.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/core/matutils.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/core/quaternion.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/core/quaternion.glsl
similarity index 60%
rename from src/main/resources/assets/create/flywheel/shaders/core/quaternion.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/core/quaternion.glsl
index cbfff38ee..fb3e1ae95 100644
--- a/src/main/resources/assets/create/flywheel/shaders/core/quaternion.glsl
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/core/quaternion.glsl
@@ -16,35 +16,6 @@ vec4 quatMult(vec4 q1, vec4 q2) {
return a + b + c + d;
}
-//
-//vec4 exp(vec4 q) {
-// vec3 i = q.xyz;
-// float r = sqrt(dot(i, i));
-// float et = exp(q.w);
-// float s = et * sin(r) / r;
-//
-// vec4 qr;
-// qr.w = et * cos(r);
-// qr.xyz = i * s;
-//
-// return qr;
-//}
-//
-//vec4 ln(vec4 q) {
-// vec3 i = q.xyz;
-// float r = sqrt(dot(i, i));
-// float t = atan(r, q.w) / r;
-//
-// vec4 qr;
-// qr.w = log(dot(q, q)) * 0.5;
-// qr.xyz = i * t;
-//
-// return qr;
-//}
-//
-//vec4 pow(vec4 q, float n) {
-// return exp(ln(q) * n);
-//}
vec3 rotateVertexByQuat(vec3 v, vec4 q) {
vec3 i = q.xyz;
@@ -53,4 +24,4 @@ vec3 rotateVertexByQuat(vec3 v, vec4 q) {
vec3 rotateAbout(vec3 v, vec3 axis, float angle) {
return rotateVertexByQuat(v, quat(axis, angle));
-}
\ No newline at end of file
+}
diff --git a/src/main/resources/assets/create/flywheel/shaders/data/blockfragment.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/data/blockfragment.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/data/blockfragment.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/data/blockfragment.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/data/modelvertex.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/data/modelvertex.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/data/modelvertex.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/data/modelvertex.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/model.vert b/src/main/resources/assets/flywheel/flywheel/shaders/model.vert
similarity index 69%
rename from src/main/resources/assets/create/flywheel/shaders/model.vert
rename to src/main/resources/assets/flywheel/flywheel/shaders/model.vert
index c9ca3fcea..d475c7a3b 100644
--- a/src/main/resources/assets/create/flywheel/shaders/model.vert
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/model.vert
@@ -1,5 +1,5 @@
#flwbuiltins
-#flwinclude <"create:core/diffuse.glsl">
+#flwinclude <"flywheel:core/diffuse.glsl">
#[InstanceData]
struct Instance {
@@ -9,8 +9,8 @@ struct Instance {
mat3 normalMat;
};
-#flwinclude <"create:data/modelvertex.glsl">
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/modelvertex.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
BlockFrag FLWMain(Vertex v, Instance i) {
vec4 worldPos = i.transform * vec4(v.pos, 1.);
@@ -26,6 +26,10 @@ BlockFrag FLWMain(Vertex v, Instance i) {
b.diffuse = diffuse(norm);
b.texCoords = v.texCoords;
b.light = i.light;
+ #if defined(NORMAL_DEBUG)
+ b.color = vec4(norm, 1.);
+ #else
b.color = i.color;
+ #endif
return b;
}
diff --git a/src/main/resources/assets/create/flywheel/shaders/oriented.vert b/src/main/resources/assets/flywheel/flywheel/shaders/oriented.vert
similarity index 63%
rename from src/main/resources/assets/create/flywheel/shaders/oriented.vert
rename to src/main/resources/assets/flywheel/flywheel/shaders/oriented.vert
index 6b978c08d..809e8fa92 100644
--- a/src/main/resources/assets/create/flywheel/shaders/oriented.vert
+++ b/src/main/resources/assets/flywheel/flywheel/shaders/oriented.vert
@@ -1,7 +1,7 @@
#flwbuiltins
-#flwinclude <"create:core/matutils.glsl">
-#flwinclude <"create:core/quaternion.glsl">
-#flwinclude <"create:core/diffuse.glsl">
+#flwinclude <"flywheel:core/matutils.glsl">
+#flwinclude <"flywheel:core/quaternion.glsl">
+#flwinclude <"flywheel:core/diffuse.glsl">
#[InstanceData]
struct Oriented {
@@ -12,8 +12,8 @@ struct Oriented {
vec4 rotation;
};
-#flwinclude <"create:data/modelvertex.glsl">
-#flwinclude <"create:data/blockfragment.glsl">
+#flwinclude <"flywheel:data/modelvertex.glsl">
+#flwinclude <"flywheel:data/blockfragment.glsl">
BlockFrag FLWMain(Vertex v, Oriented o) {
vec4 worldPos = vec4(rotateVertexByQuat(v.pos - o.pivot, o.rotation) + o.pivot + o.pos, 1.);
@@ -27,6 +27,10 @@ BlockFrag FLWMain(Vertex v, Oriented o) {
b.diffuse = diffuse(norm);
b.texCoords = v.texCoords;
b.light = o.light;
+ #if defined(NORMAL_DEBUG)
+ b.color = vec4(norm, 1.);
+ #else
b.color = o.color;
+ #endif
return b;
}
diff --git a/src/main/resources/assets/create/flywheel/shaders/template/instanced/instanced.frag b/src/main/resources/assets/flywheel/flywheel/shaders/template/instanced/instanced.frag
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/template/instanced/instanced.frag
rename to src/main/resources/assets/flywheel/flywheel/shaders/template/instanced/instanced.frag
diff --git a/src/main/resources/assets/create/flywheel/shaders/template/instanced/instanced.vert b/src/main/resources/assets/flywheel/flywheel/shaders/template/instanced/instanced.vert
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/template/instanced/instanced.vert
rename to src/main/resources/assets/flywheel/flywheel/shaders/template/instanced/instanced.vert
diff --git a/src/main/resources/assets/create/flywheel/shaders/template/meshlet/meshlet.glsl b/src/main/resources/assets/flywheel/flywheel/shaders/template/meshlet/meshlet.glsl
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/template/meshlet/meshlet.glsl
rename to src/main/resources/assets/flywheel/flywheel/shaders/template/meshlet/meshlet.glsl
diff --git a/src/main/resources/assets/create/flywheel/shaders/template/model/model.frag b/src/main/resources/assets/flywheel/flywheel/shaders/template/model/model.frag
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/template/model/model.frag
rename to src/main/resources/assets/flywheel/flywheel/shaders/template/model/model.frag
diff --git a/src/main/resources/assets/create/flywheel/shaders/template/model/model.vert b/src/main/resources/assets/flywheel/flywheel/shaders/template/model/model.vert
similarity index 100%
rename from src/main/resources/assets/create/flywheel/shaders/template/model/model.vert
rename to src/main/resources/assets/flywheel/flywheel/shaders/template/model/model.vert