mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 03:53:12 +01:00
Reload
- Redo shader loading - Now loads an immutable SourceFile containing some metadata - Replace legacy compilation pipeline with improved new one using new api - Builtins are defined in one file, now "header" - New ErrorReporter/ErrorBuilder methods - Fancier shader loading errors
This commit is contained in:
parent
5555f9e6bb
commit
cb47ca8452
10 changed files with 127 additions and 116 deletions
|
@ -4,10 +4,10 @@ import java.util.List;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL20;
|
import org.lwjgl.opengl.GL20;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.loading.Program;
|
|
||||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||||
import com.jozufozu.flywheel.core.shader.extension.IProgramExtension;
|
import com.jozufozu.flywheel.core.shader.extension.IProgramExtension;
|
||||||
|
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.vector.Matrix4f;
|
import net.minecraft.util.math.vector.Matrix4f;
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ public class ContraptionProgram extends WorldProgram {
|
||||||
|
|
||||||
protected int uLightVolume;
|
protected int uLightVolume;
|
||||||
|
|
||||||
public ContraptionProgram(Program program, List<IProgramExtension> extensions) {
|
public ContraptionProgram(ResourceLocation name, int handle, List<IProgramExtension> extensions) {
|
||||||
super(program, extensions);
|
super(name, handle, extensions);
|
||||||
uLightBoxSize = getUniformLocation("uLightBoxSize");
|
uLightBoxSize = getUniformLocation("uLightBoxSize");
|
||||||
uLightBoxMin = getUniformLocation("uLightBoxMin");
|
uLightBoxMin = getUniformLocation("uLightBoxMin");
|
||||||
uModel = getUniformLocation("uModel");
|
uModel = getUniformLocation("uModel");
|
||||||
|
|
|
@ -2,10 +2,17 @@ package com.simibubi.create.foundation.render;
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL46;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
|
import com.jozufozu.flywheel.backend.FileResolution;
|
||||||
|
import com.jozufozu.flywheel.backend.ResourceUtil;
|
||||||
import com.jozufozu.flywheel.backend.SpecMetaRegistry;
|
import com.jozufozu.flywheel.backend.SpecMetaRegistry;
|
||||||
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
|
import com.jozufozu.flywheel.backend.pipeline.IShaderPipeline;
|
||||||
import com.jozufozu.flywheel.backend.loading.ModelTemplate;
|
import com.jozufozu.flywheel.backend.pipeline.ITemplate;
|
||||||
|
import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate;
|
||||||
|
import com.jozufozu.flywheel.backend.pipeline.OneShotTemplate;
|
||||||
|
import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline;
|
||||||
import com.jozufozu.flywheel.core.WorldContext;
|
import com.jozufozu.flywheel.core.WorldContext;
|
||||||
import com.jozufozu.flywheel.event.GatherContextEvent;
|
import com.jozufozu.flywheel.event.GatherContextEvent;
|
||||||
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram;
|
import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionProgram;
|
||||||
|
@ -26,16 +33,18 @@ public class CreateContexts {
|
||||||
|
|
||||||
SpecMetaRegistry.register(RainbowDebugStateProvider.INSTANCE);
|
SpecMetaRegistry.register(RainbowDebugStateProvider.INSTANCE);
|
||||||
|
|
||||||
CWORLD = backend.register(contraptionContext(backend));
|
CWORLD = backend.register(contraptionContext(backend, InstancingTemplate.INSTANCE));
|
||||||
STRUCTURE = backend.register(contraptionContext(backend)
|
STRUCTURE = backend.register(contraptionContext(backend, OneShotTemplate.INSTANCE)
|
||||||
.withSpecStream(() -> Stream.of(AllProgramSpecs.STRUCTURE))
|
.withSpecStream(() -> Stream.of(AllProgramSpecs.STRUCTURE)));
|
||||||
.withTemplateFactory(ModelTemplate::new));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WorldContext<ContraptionProgram> contraptionContext(Backend backend) {
|
private static WorldContext<ContraptionProgram> contraptionContext(Backend backend, ITemplate template) {
|
||||||
return new WorldContext<>(backend, ContraptionProgram::new)
|
|
||||||
.withName(CONTRAPTION)
|
FileResolution header = backend.sources.resolveFile(ResourceUtil.subPath(CONTRAPTION, ".glsl"));
|
||||||
.withBuiltin(ShaderType.FRAGMENT, CONTRAPTION, "/builtin.frag")
|
|
||||||
.withBuiltin(ShaderType.VERTEX, CONTRAPTION, "/builtin.vert");
|
IShaderPipeline<ContraptionProgram> worldPipeline = new WorldShaderPipeline<>(backend.sources, ContraptionProgram::new, template, header);
|
||||||
|
|
||||||
|
return new WorldContext<>(backend, worldPipeline)
|
||||||
|
.withName(CONTRAPTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#define PI 3.1415926538
|
#define PI 3.1415926538
|
||||||
|
|
||||||
#flwbuiltins
|
#use "flywheel:core/quaternion.glsl"
|
||||||
#flwinclude <"flywheel:core/quaternion.glsl">
|
#use "flywheel:core/matutils.glsl"
|
||||||
#flwinclude <"flywheel:core/matutils.glsl">
|
#use "flywheel:core/diffuse.glsl"
|
||||||
#flwinclude <"flywheel:core/diffuse.glsl">
|
|
||||||
|
|
||||||
#[InstanceData]
|
|
||||||
struct Belt {
|
struct Belt {
|
||||||
vec2 light;
|
vec2 light;
|
||||||
vec4 color;
|
vec4 color;
|
||||||
|
@ -18,10 +16,11 @@ struct Belt {
|
||||||
float scrollMult;
|
float scrollMult;
|
||||||
};
|
};
|
||||||
|
|
||||||
#flwinclude <"flywheel:data/modelvertex.glsl">
|
#use "flywheel:data/modelvertex.glsl"
|
||||||
#flwinclude <"flywheel:data/blockfragment.glsl">
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
BlockFrag FLWMain(Vertex v, Belt instance) {
|
#if defined(VERTEX_SHADER)
|
||||||
|
BlockFrag vertex(Vertex v, Belt instance) {
|
||||||
vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
|
vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
|
||||||
|
|
||||||
vec4 worldPos = vec4(rotated, 1.);
|
vec4 worldPos = vec4(rotated, 1.);
|
||||||
|
@ -49,3 +48,4 @@ BlockFrag FLWMain(Vertex v, Belt instance) {
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
#use "flywheel:context/fog.glsl"
|
||||||
|
|
||||||
|
varying vec3 BoxCoord;
|
||||||
|
|
||||||
|
uniform sampler3D uLightVolume;
|
||||||
|
|
||||||
|
uniform sampler2D uBlockAtlas;
|
||||||
|
uniform sampler2D uLightMap;
|
||||||
|
|
||||||
|
uniform vec3 uLightBoxSize;
|
||||||
|
uniform vec3 uLightBoxMin;
|
||||||
|
uniform mat4 uModel;
|
||||||
|
|
||||||
|
uniform float uTime;
|
||||||
|
uniform mat4 uViewProjection;
|
||||||
|
uniform vec3 uCameraPos;
|
||||||
|
|
||||||
|
uniform vec2 uWindowSize;
|
||||||
|
|
||||||
|
void FLWFinalizeNormal(inout vec3 normal) {
|
||||||
|
mat3 m;
|
||||||
|
m[0] = uModel[0].xyz;
|
||||||
|
m[1] = uModel[1].xyz;
|
||||||
|
m[2] = uModel[2].xyz;
|
||||||
|
normal = m * normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(VERTEX_SHADER)
|
||||||
|
|
||||||
|
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
||||||
|
worldPos = uModel * worldPos;
|
||||||
|
|
||||||
|
BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
|
||||||
|
|
||||||
|
#if defined(USE_FOG)
|
||||||
|
FragDistance = length(worldPos.xyz);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gl_Position = uViewProjection * worldPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(FRAGMENT_SHADER)
|
||||||
|
#use "flywheel:core/lightutil.glsl"
|
||||||
|
|
||||||
|
vec4 FLWBlockTexture(vec2 texCoords) {
|
||||||
|
return texture2D(uBlockAtlas, texCoords);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FLWFinalizeColor(vec4 color) {
|
||||||
|
#if defined(USE_FOG)
|
||||||
|
float a = color.a;
|
||||||
|
float fog = clamp(FLWFogFactor(), 0., 1.);
|
||||||
|
|
||||||
|
color = mix(uFogColor, color, fog);
|
||||||
|
color.a = a;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 FLWLight(vec2 lightCoords) {
|
||||||
|
lightCoords = max(lightCoords, texture3D(uLightVolume, BoxCoord).rg);
|
||||||
|
|
||||||
|
return texture2D(uLightMap, shiftLight(lightCoords));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,31 +0,0 @@
|
||||||
#flwinclude <"flywheel:context/world/fog.glsl">
|
|
||||||
#flwinclude <"flywheel:core/lightutil.glsl">
|
|
||||||
|
|
||||||
varying vec3 BoxCoord;
|
|
||||||
varying vec2 BoxLight;
|
|
||||||
uniform sampler3D uLightVolume;
|
|
||||||
|
|
||||||
uniform sampler2D uBlockAtlas;
|
|
||||||
uniform sampler2D uLightMap;
|
|
||||||
|
|
||||||
vec4 FLWBlockTexture(vec2 texCoords) {
|
|
||||||
return texture2D(uBlockAtlas, texCoords);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FLWFinalizeColor(vec4 color) {
|
|
||||||
#if defined(USE_FOG)
|
|
||||||
float a = color.a;
|
|
||||||
float fog = clamp(FLWFogFactor(), 0., 1.);
|
|
||||||
|
|
||||||
color = mix(uFogColor, color, fog);
|
|
||||||
color.a = a;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gl_FragColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 FLWLight(vec2 lightCoords) {
|
|
||||||
lightCoords = max(lightCoords, texture3D(uLightVolume, BoxCoord).rg);
|
|
||||||
|
|
||||||
return texture2D(uLightMap, shiftLight(lightCoords));
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
#if defined(USE_FOG)
|
|
||||||
varying float FragDistance;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
varying vec3 BoxCoord;
|
|
||||||
|
|
||||||
uniform vec3 uLightBoxSize;
|
|
||||||
uniform vec3 uLightBoxMin;
|
|
||||||
uniform mat4 uModel;
|
|
||||||
|
|
||||||
uniform float uTime;
|
|
||||||
uniform mat4 uViewProjection;
|
|
||||||
uniform vec3 uCameraPos;
|
|
||||||
|
|
||||||
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
|
||||||
worldPos = uModel * worldPos;
|
|
||||||
|
|
||||||
BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
|
|
||||||
|
|
||||||
#if defined(USE_FOG)
|
|
||||||
FragDistance = length(worldPos.xyz);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gl_Position = uViewProjection * worldPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FLWFinalizeNormal(inout vec3 normal) {
|
|
||||||
mat3 m;
|
|
||||||
m[0] = uModel[0].xyz;
|
|
||||||
m[1] = uModel[1].xyz;
|
|
||||||
m[2] = uModel[2].xyz;
|
|
||||||
normal = m * normal;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#define PI 3.1415926538
|
#define PI 3.1415926538
|
||||||
|
|
||||||
#flwbuiltins
|
#use "flywheel:core/matutils.glsl"
|
||||||
#flwinclude <"flywheel:core/matutils.glsl">
|
#use "flywheel:core/quaternion.glsl"
|
||||||
#flwinclude <"flywheel:core/quaternion.glsl">
|
#use "flywheel:core/diffuse.glsl"
|
||||||
#flwinclude <"flywheel:core/diffuse.glsl">
|
|
||||||
|
|
||||||
#[InstanceData]
|
|
||||||
struct Actor {
|
struct Actor {
|
||||||
vec3 pos;
|
vec3 pos;
|
||||||
vec2 light;
|
vec2 light;
|
||||||
|
@ -16,10 +14,11 @@ struct Actor {
|
||||||
float speed;
|
float speed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#flwinclude <"flywheel:data/modelvertex.glsl">
|
#use "flywheel:data/modelvertex.glsl"
|
||||||
#flwinclude <"flywheel:data/blockfragment.glsl">
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
BlockFrag FLWMain(Vertex v, Actor instance) {
|
#if defined(VERTEX_SHADER)
|
||||||
|
BlockFrag vertex(Vertex v, Actor instance) {
|
||||||
float degrees = instance.offset + uTime * instance.speed / 20.;
|
float degrees = instance.offset + uTime * instance.speed / 20.;
|
||||||
//float angle = fract(degrees / 360.) * PI * 2.;
|
//float angle = fract(degrees / 360.) * PI * 2.;
|
||||||
|
|
||||||
|
@ -45,3 +44,4 @@ BlockFrag FLWMain(Vertex v, Actor instance) {
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#define PI 3.1415926538
|
#define PI 3.1415926538
|
||||||
|
|
||||||
#flwbuiltins
|
#use "flywheel:core/matutils.glsl"
|
||||||
#flwinclude <"flywheel:core/matutils.glsl">
|
#use "flywheel:core/diffuse.glsl"
|
||||||
#flwinclude <"flywheel:core/diffuse.glsl">
|
|
||||||
|
|
||||||
#[VertexData]
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
vec3 pos;
|
vec3 pos;
|
||||||
vec3 normal;
|
vec3 normal;
|
||||||
|
@ -13,9 +11,10 @@ struct Vertex {
|
||||||
vec2 modelLight;
|
vec2 modelLight;
|
||||||
};
|
};
|
||||||
|
|
||||||
#flwinclude <"flywheel:data/blockfragment.glsl">
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
BlockFrag FLWMain(Vertex v) {
|
#if defined(VERTEX_SHADER)
|
||||||
|
BlockFrag vertex(Vertex v) {
|
||||||
vec4 worldPos = vec4(v.pos, 1.);
|
vec4 worldPos = vec4(v.pos, 1.);
|
||||||
vec3 norm = v.normal;
|
vec3 norm = v.normal;
|
||||||
|
|
||||||
|
@ -35,3 +34,4 @@ BlockFrag FLWMain(Vertex v) {
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#define PI 3.1415926538
|
#define PI 3.1415926538
|
||||||
|
|
||||||
#flwbuiltins
|
#use "flywheel:core/matutils.glsl"
|
||||||
#flwinclude <"flywheel:core/matutils.glsl">
|
#use "flywheel:core/quaternion.glsl"
|
||||||
#flwinclude <"flywheel:core/quaternion.glsl">
|
#use "flywheel:core/diffuse.glsl"
|
||||||
#flwinclude <"flywheel:core/diffuse.glsl">
|
|
||||||
|
|
||||||
#[InstanceData]
|
|
||||||
struct Flap {
|
struct Flap {
|
||||||
vec3 instancePos;
|
vec3 instancePos;
|
||||||
vec2 light;
|
vec2 light;
|
||||||
|
@ -17,9 +15,10 @@ struct Flap {
|
||||||
float flapness;
|
float flapness;
|
||||||
};
|
};
|
||||||
|
|
||||||
#flwinclude <"flywheel:data/modelvertex.glsl">
|
#use "flywheel:data/modelvertex.glsl"
|
||||||
#flwinclude <"flywheel:data/blockfragment.glsl">
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
|
#if defined(VERTEX_SHADER)
|
||||||
|
|
||||||
float toRad(float degrees) {
|
float toRad(float degrees) {
|
||||||
return fract(degrees / 360.) * PI * 2.;
|
return fract(degrees / 360.) * PI * 2.;
|
||||||
|
@ -38,7 +37,7 @@ float getFlapAngle(float flapness, float intensity, float scale) {
|
||||||
return degrees;
|
return degrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockFrag FLWMain(Vertex v, Flap flap) {
|
BlockFrag vertex(Vertex v, Flap flap) {
|
||||||
float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
|
float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale);
|
||||||
|
|
||||||
vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
|
vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle);
|
||||||
|
@ -64,3 +63,4 @@ BlockFrag FLWMain(Vertex v, Flap flap) {
|
||||||
#endif
|
#endif
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#define PI 3.1415926538
|
#define PI 3.1415926538
|
||||||
|
|
||||||
#flwbuiltins
|
#use "flywheel:core/matutils.glsl"
|
||||||
#flwinclude <"flywheel:core/matutils.glsl">
|
#use "flywheel:core/diffuse.glsl"
|
||||||
#flwinclude <"flywheel:core/diffuse.glsl">
|
|
||||||
|
|
||||||
#[InstanceData]
|
|
||||||
struct Rotating {
|
struct Rotating {
|
||||||
vec2 light;
|
vec2 light;
|
||||||
vec4 color;
|
vec4 color;
|
||||||
|
@ -14,8 +12,8 @@ struct Rotating {
|
||||||
vec3 axis;
|
vec3 axis;
|
||||||
};
|
};
|
||||||
|
|
||||||
#flwinclude <"flywheel:data/modelvertex.glsl">
|
#use "flywheel:data/modelvertex.glsl"
|
||||||
#flwinclude <"flywheel:data/blockfragment.glsl">
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
mat4 kineticRotation(float offset, float speed, vec3 axis) {
|
mat4 kineticRotation(float offset, float speed, vec3 axis) {
|
||||||
float degrees = offset + uTime * speed * 3./10.;
|
float degrees = offset + uTime * speed * 3./10.;
|
||||||
|
@ -24,7 +22,8 @@ mat4 kineticRotation(float offset, float speed, vec3 axis) {
|
||||||
return rotate(axis, angle);
|
return rotate(axis, angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockFrag FLWMain(Vertex v, Rotating instance) {
|
#if defined(VERTEX_SHADER)
|
||||||
|
BlockFrag vertex(Vertex v, Rotating instance) {
|
||||||
mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
|
mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis);
|
||||||
|
|
||||||
vec4 worldPos = spin * vec4(v.pos - .5, 1.);
|
vec4 worldPos = spin * vec4(v.pos - .5, 1.);
|
||||||
|
@ -50,3 +49,4 @@ BlockFrag FLWMain(Vertex v, Rotating instance) {
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue