mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-14 22:44:07 +01:00
More simplification
- Move more stuff to the flywheel namespace - Give up on ShaderConstants, there's a better way to do it - A semblance of better crash reports
This commit is contained in:
parent
fd6e06b487
commit
4d755dc506
6
src/main/java/com/jozufozu/flywheel/Flywheel.java
Normal file
6
src/main/java/com/jozufozu/flywheel/Flywheel.java
Normal file
@ -0,0 +1,6 @@
|
||||
package com.jozufozu.flywheel;
|
||||
|
||||
public class Flywheel {
|
||||
|
||||
public static final String ID = "flywheel";
|
||||
}
|
@ -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<P extends GlProgram> {
|
||||
|
||||
public final Map<ProgramSpec, IMultiProgram<P>> programs = new HashMap<>();
|
||||
|
||||
public final ResourceLocation root;
|
||||
protected final ShaderSpecLoader<P> specLoader;
|
||||
protected ShaderTransformer transformer = new ShaderTransformer();
|
||||
|
||||
public ShaderContext(ResourceLocation root, ShaderSpecLoader<P> specLoader) {
|
||||
this.root = root;
|
||||
public ShaderContext(ShaderSpecLoader<P> specLoader) {
|
||||
this.specLoader = specLoader;
|
||||
}
|
||||
|
||||
@ -37,24 +33,29 @@ public abstract class ShaderContext<P extends GlProgram> {
|
||||
|
||||
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<String> 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<P extends GlProgram> {
|
||||
return programs.get(spec).get();
|
||||
}
|
||||
|
||||
public ResourceLocation getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<ResourceLocation, String> shaderSource = new HashMap<>();
|
||||
|
||||
private boolean shouldCrash;
|
||||
|
||||
void onResourceManagerReload(IResourceManager manager, Predicate<IResourceType> 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) {
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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<P extends BasicProgram> extends ShaderContext<P> {
|
||||
private static final String declaration = "#flwbuiltins";
|
||||
private static final Pattern builtinPattern = Pattern.compile(declaration);
|
||||
|
||||
public static final WorldContext<BasicProgram> INSTANCE = new WorldContext<>(new ResourceLocation("create", "context/world"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new));
|
||||
public static final WorldContext<CrumblingProgram> CRUMBLING = new WorldContext<>(new ResourceLocation("create", "context/crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new));
|
||||
|
||||
final Map<ShaderType, ResourceLocation> builtins;
|
||||
final Map<ShaderType, String> builtinSources;
|
||||
public static final WorldContext<BasicProgram> INSTANCE = new WorldContext<>(new ResourceLocation(Flywheel.ID, "context/world"), new FogSensitiveProgram.SpecLoader<>(BasicProgram::new));
|
||||
public static final WorldContext<CrumblingProgram> CRUMBLING = new WorldContext<>(new ResourceLocation(Flywheel.ID, "context/crumbling"), new FogSensitiveProgram.SpecLoader<>(CrumblingProgram::new));
|
||||
|
||||
protected ProgramTemplate template;
|
||||
protected final ResourceLocation name;
|
||||
protected final Supplier<Stream<ProgramSpec>> specStream;
|
||||
protected final TemplateFactory templateFactory;
|
||||
|
||||
private final Map<ShaderType, ResourceLocation> builtins = new EnumMap<>(ShaderType.class);
|
||||
private final Map<ShaderType, String> builtinSources = new EnumMap<>(ShaderType.class);
|
||||
|
||||
public WorldContext(ResourceLocation root, ShaderSpecLoader<P> loader) {
|
||||
this(root, loader, () -> Backend.allMaterials()
|
||||
.stream()
|
||||
@ -47,11 +50,10 @@ public class WorldContext<P extends BasicProgram> extends ShaderContext<P> {
|
||||
}
|
||||
|
||||
public WorldContext(ResourceLocation root, ShaderSpecLoader<P> loader, Supplier<Stream<ProgramSpec>> 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<P extends BasicProgram> extends ShaderContext<P> {
|
||||
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<P extends BasicProgram> extends ShaderContext<P> {
|
||||
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 {
|
||||
|
@ -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<P extends GlProgram> implements IMultiProgram<P> {
|
||||
|
||||
private final Map<GlFogMode, P> programs;
|
||||
private final List<P> debugPrograms;
|
||||
|
||||
public FogSensitiveProgram(Map<GlFogMode, P> programs) {
|
||||
public FogSensitiveProgram(Map<GlFogMode, P> programs, List<P> debugPrograms) {
|
||||
this.programs = programs;
|
||||
this.debugPrograms = debugPrograms;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,25 +42,31 @@ public class FogSensitiveProgram<P extends GlProgram> implements IMultiProgram<P
|
||||
|
||||
@Override
|
||||
public IMultiProgram<P> create(ShaderLoader loader, ShaderContext<P> ctx, ProgramSpec spec) {
|
||||
List<P> 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<GlFogMode, P> 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 extends GlProgram> {
|
||||
|
||||
P create(ResourceLocation name, int handle, ProgramFogMode.Factory fogFactory);
|
||||
P create(Program program, ProgramFogMode.Factory fogFactory);
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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<ResourceLocation> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<String> 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<String> defines) {
|
||||
this.defines.addAll(defines);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayList<String> getDefines() {
|
||||
return defines;
|
||||
}
|
||||
|
||||
public Stream<String> 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<String> map = Stream.of(line);
|
||||
|
||||
if (line.startsWith("#version")) {
|
||||
map = Stream.concat(map, directives());
|
||||
}
|
||||
|
||||
return map;
|
||||
}).collect(Collectors.joining("\n")));
|
||||
}
|
||||
}
|
@ -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<P extends GlProgram> implements IMultiProgram<P> {
|
||||
final P program;
|
||||
|
||||
@ -32,14 +30,12 @@ public class SingleProgram<P extends GlProgram> implements IMultiProgram<P> {
|
||||
|
||||
@Override
|
||||
public IMultiProgram<P> create(ShaderLoader loader, ShaderContext<P> 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 extends GlProgram> {
|
||||
P create(ResourceLocation name, int handle);
|
||||
P create(Program program);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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<String> 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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<SphereFilterProgram> {
|
||||
|
||||
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
|
||||
|
@ -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);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#version 140
|
||||
|
||||
#flwinclude <"create:core/color.glsl">
|
||||
#flwinclude <"flywheel:core/color.glsl">
|
||||
|
||||
in vec2 ScreenCoord;
|
||||
in vec3 WorldDir;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -1 +0,0 @@
|
||||
#flwinclude <"create:context/world/builtin.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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#flwbuiltins
|
||||
|
||||
#flwinclude <"create:data/blockfragment.glsl">
|
||||
#flwinclude <"flywheel:data/blockfragment.glsl">
|
||||
|
||||
void FLWMain(BlockFrag r) {
|
||||
vec4 tex = FLWBlockTexture(r.texCoords);
|
@ -1,4 +1,4 @@
|
||||
#flwinclude <"create:context/world/fog.glsl">
|
||||
#flwinclude <"flywheel:context/world/fog.glsl">
|
||||
|
||||
uniform vec2 uTextureScale;
|
||||
uniform sampler2D uBlockAtlas;
|
@ -0,0 +1 @@
|
||||
#flwinclude <"flywheel:context/world/builtin.vert">
|
@ -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;
|
@ -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;
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user