mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 08:27:03 +01:00
Shader sanity
- Keeping up with Flywheel changes
This commit is contained in:
parent
33d0f8c352
commit
2b6348855a
11 changed files with 46 additions and 137 deletions
|
@ -7,6 +7,8 @@ import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.RenderLayer;
|
import com.jozufozu.flywheel.backend.RenderLayer;
|
||||||
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
import com.jozufozu.flywheel.backend.gl.GlStateTracker;
|
||||||
import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
|
import com.jozufozu.flywheel.backend.gl.GlTextureUnit;
|
||||||
|
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
||||||
|
import com.jozufozu.flywheel.core.Formats;
|
||||||
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
|
import com.jozufozu.flywheel.core.virtual.VirtualRenderWorld;
|
||||||
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
import com.jozufozu.flywheel.event.RenderLayerEvent;
|
||||||
import com.jozufozu.flywheel.util.Textures;
|
import com.jozufozu.flywheel.util.Textures;
|
||||||
|
@ -47,7 +49,7 @@ public class FlwContraptionManager extends ContraptionRenderingWorld<FlwContrapt
|
||||||
|
|
||||||
Textures.bindActiveTextures();
|
Textures.bindActiveTextures();
|
||||||
|
|
||||||
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.STRUCTURE);
|
ContraptionProgram structureShader = CreateContexts.STRUCTURE.getProgram(AllProgramSpecs.PASSTHRU, Formats.BLOCK);
|
||||||
|
|
||||||
structureShader.bind();
|
structureShader.bind();
|
||||||
structureShader.uploadViewProjection(event.viewProjection);
|
structureShader.uploadViewProjection(event.viewProjection);
|
||||||
|
|
|
@ -6,11 +6,11 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
public class AllProgramSpecs {
|
public class AllProgramSpecs {
|
||||||
|
|
||||||
|
public static final ResourceLocation PASSTHRU = asResource("passthru");
|
||||||
public static final ResourceLocation ROTATING = asResource("rotating");
|
public static final ResourceLocation ROTATING = asResource("rotating");
|
||||||
public static final ResourceLocation CHROMATIC = asResource("chromatic");
|
public static final ResourceLocation CHROMATIC = asResource("chromatic");
|
||||||
public static final ResourceLocation BELT = asResource("belt");
|
public static final ResourceLocation BELT = asResource("belt");
|
||||||
public static final ResourceLocation FLAPS = asResource("flap");
|
public static final ResourceLocation FLAPS = asResource("flap");
|
||||||
public static final ResourceLocation STRUCTURE = asResource("contraption_structure");
|
|
||||||
public static final ResourceLocation ACTOR = asResource("contraption_actor");
|
public static final ResourceLocation ACTOR = asResource("contraption_actor");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,11 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.Backend;
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
import com.jozufozu.flywheel.backend.GameStateRegistry;
|
import com.jozufozu.flywheel.backend.GameStateRegistry;
|
||||||
import com.jozufozu.flywheel.backend.pipeline.InstancingTemplate;
|
|
||||||
import com.jozufozu.flywheel.backend.pipeline.OneShotTemplate;
|
|
||||||
import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline;
|
import com.jozufozu.flywheel.backend.pipeline.ShaderPipeline;
|
||||||
import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline;
|
import com.jozufozu.flywheel.backend.pipeline.WorldShaderPipeline;
|
||||||
import com.jozufozu.flywheel.backend.source.FileResolution;
|
import com.jozufozu.flywheel.backend.source.FileResolution;
|
||||||
import com.jozufozu.flywheel.backend.source.Resolver;
|
import com.jozufozu.flywheel.backend.source.Resolver;
|
||||||
|
import com.jozufozu.flywheel.core.Templates;
|
||||||
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.jozufozu.flywheel.util.ResourceUtil;
|
import com.jozufozu.flywheel.util.ResourceUtil;
|
||||||
|
@ -33,14 +32,14 @@ public class CreateContexts {
|
||||||
GameStateRegistry.register(RainbowDebugStateProvider.INSTANCE);
|
GameStateRegistry.register(RainbowDebugStateProvider.INSTANCE);
|
||||||
FileResolution header = Resolver.INSTANCE.findShader(ResourceUtil.subPath(CONTRAPTION, ".glsl"));
|
FileResolution header = Resolver.INSTANCE.findShader(ResourceUtil.subPath(CONTRAPTION, ".glsl"));
|
||||||
|
|
||||||
ShaderPipeline<ContraptionProgram> instancing = new WorldShaderPipeline<>(ContraptionProgram::new, InstancingTemplate.INSTANCE, header);
|
ShaderPipeline<ContraptionProgram> instancing = new WorldShaderPipeline<>(ContraptionProgram::new, Templates.INSTANCING, header);
|
||||||
ShaderPipeline<ContraptionProgram> structure = new WorldShaderPipeline<>(ContraptionProgram::new, OneShotTemplate.INSTANCE, header);
|
ShaderPipeline<ContraptionProgram> structure = new WorldShaderPipeline<>(ContraptionProgram::new, Templates.ONE_SHOT, header);
|
||||||
|
|
||||||
CWORLD = backend.register(WorldContext.builder(backend, CONTRAPTION)
|
CWORLD = backend.register(WorldContext.builder(backend, CONTRAPTION)
|
||||||
.build(instancing));
|
.build(instancing));
|
||||||
|
|
||||||
STRUCTURE = backend.register(WorldContext.builder(backend, CONTRAPTION)
|
STRUCTURE = backend.register(WorldContext.builder(backend, CONTRAPTION)
|
||||||
.setSpecStream(() -> Stream.of(AllProgramSpecs.STRUCTURE))
|
.setSpecStream(() -> Stream.of(AllProgramSpecs.PASSTHRU))
|
||||||
.build(structure));
|
.build(structure));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"source": "create:contraption_structure.vert",
|
"source": "create:passthru.vert",
|
||||||
"states": [
|
"states": [
|
||||||
{
|
{
|
||||||
"when": {
|
"when": {
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#use "flywheel:core/quaternion.glsl"
|
#use "flywheel:core/quaternion.glsl"
|
||||||
#use "flywheel:core/matutils.glsl"
|
#use "flywheel:core/matutils.glsl"
|
||||||
#use "flywheel:core/diffuse.glsl"
|
|
||||||
|
|
||||||
struct Belt {
|
struct Belt {
|
||||||
vec2 light;
|
vec2 light;
|
||||||
|
@ -16,36 +15,22 @@ struct Belt {
|
||||||
float scrollMult;
|
float scrollMult;
|
||||||
};
|
};
|
||||||
|
|
||||||
#use "flywheel:data/modelvertex.glsl"
|
|
||||||
#use "flywheel:block.frag"
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
#if defined(VERTEX_SHADER)
|
#if defined(VERTEX_SHADER)
|
||||||
BlockFrag vertex(Vertex v, Belt instance) {
|
void vertex(inout Vertex v, Belt instance) {
|
||||||
vec3 rotated = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
|
v.pos = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5;
|
||||||
|
|
||||||
vec4 worldPos = vec4(rotated, 1.);
|
v.normal = rotateVertexByQuat(v.normal, instance.rotation);
|
||||||
|
|
||||||
vec3 norm = rotateVertexByQuat(v.normal, instance.rotation);
|
|
||||||
|
|
||||||
FLWFinalizeWorldPos(worldPos);
|
|
||||||
FLWFinalizeNormal(norm);
|
|
||||||
|
|
||||||
float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
|
float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y;
|
||||||
float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
|
float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult;
|
||||||
|
|
||||||
BlockFrag b;
|
v.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
|
||||||
b.diffuse = diffuse(norm);
|
v.light = instance.light;
|
||||||
b.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll);
|
|
||||||
b.light = instance.light;
|
|
||||||
|
|
||||||
#if defined(DEBUG_RAINBOW)
|
#if defined(DEBUG_RAINBOW)
|
||||||
b.color = instance.color;
|
v.color = instance.color;
|
||||||
#elif defined(DEBUG_NORMAL)
|
|
||||||
b.color = vec4(norm, 1.);
|
|
||||||
#else
|
|
||||||
b.color = vec4(1.);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#use "flywheel:context/fog.glsl"
|
#use "flywheel:context/fog.glsl"
|
||||||
|
#use "flywheel:core/diffuse.glsl"
|
||||||
|
|
||||||
uniform sampler3D uLightVolume;
|
uniform sampler3D uLightVolume;
|
||||||
|
|
||||||
|
@ -13,26 +14,25 @@ uniform float uTime;
|
||||||
uniform mat4 uViewProjection;
|
uniform mat4 uViewProjection;
|
||||||
uniform vec3 uCameraPos;
|
uniform vec3 uCameraPos;
|
||||||
|
|
||||||
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)
|
#if defined(VERTEX_SHADER)
|
||||||
|
|
||||||
out vec3 BoxCoord;
|
out vec3 BoxCoord;
|
||||||
|
|
||||||
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
vec4 FLWVertex(inout Vertex v) {
|
||||||
worldPos = uModel * worldPos;
|
vec4 worldPos = uModel * vec4(v.pos, 1.);
|
||||||
|
|
||||||
BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
|
BoxCoord = (worldPos.xyz - uLightBoxMin) / uLightBoxSize;
|
||||||
|
|
||||||
FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
|
FragDistance = max(length(worldPos.xz), abs(worldPos.y)); // cylindrical fog
|
||||||
|
|
||||||
gl_Position = uViewProjection * worldPos;
|
mat3 m;
|
||||||
|
m[0] = uModel[0].xyz;
|
||||||
|
m[1] = uModel[1].xyz;
|
||||||
|
m[2] = uModel[2].xyz;
|
||||||
|
v.normal = m * v.normal;
|
||||||
|
|
||||||
|
v.pos = worldPos.xyz;
|
||||||
|
return uViewProjection * worldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(FRAGMENT_SHADER)
|
#elif defined(FRAGMENT_SHADER)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#use "flywheel:core/matutils.glsl"
|
#use "flywheel:core/matutils.glsl"
|
||||||
#use "flywheel:core/quaternion.glsl"
|
#use "flywheel:core/quaternion.glsl"
|
||||||
#use "flywheel:core/diffuse.glsl"
|
|
||||||
|
|
||||||
struct Actor {
|
struct Actor {
|
||||||
vec3 pos;
|
vec3 pos;
|
||||||
|
@ -14,34 +13,18 @@ struct Actor {
|
||||||
float speed;
|
float speed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#use "flywheel:data/modelvertex.glsl"
|
|
||||||
#use "flywheel:block.frag"
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
#if defined(VERTEX_SHADER)
|
#if defined(VERTEX_SHADER)
|
||||||
BlockFrag vertex(Vertex v, Actor instance) {
|
void vertex(inout 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.;
|
||||||
|
|
||||||
vec4 kineticRot = quat(instance.axis, degrees);
|
vec4 kineticRot = quat(instance.axis, degrees);
|
||||||
vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
|
vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter;
|
||||||
|
|
||||||
vec4 worldPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.);
|
v.pos = rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5;
|
||||||
vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
|
v.normal = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation);
|
||||||
|
v.light = instance.light;
|
||||||
FLWFinalizeWorldPos(worldPos);
|
|
||||||
FLWFinalizeNormal(norm);
|
|
||||||
|
|
||||||
BlockFrag b;
|
|
||||||
b.diffuse = diffuse(norm);
|
|
||||||
b.texCoords = v.texCoords;
|
|
||||||
b.light = instance.light;
|
|
||||||
|
|
||||||
#if defined(DEBUG_NORMAL)
|
|
||||||
b.color = vec4(norm, 1.);
|
|
||||||
#else
|
|
||||||
b.color = vec4(1.);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
#define PI 3.1415926538
|
|
||||||
|
|
||||||
#use "flywheel:core/matutils.glsl"
|
|
||||||
#use "flywheel:core/diffuse.glsl"
|
|
||||||
|
|
||||||
struct Vertex {
|
|
||||||
vec3 pos;
|
|
||||||
vec4 color;
|
|
||||||
vec2 texCoords;
|
|
||||||
vec2 modelLight;
|
|
||||||
vec3 normal;
|
|
||||||
};
|
|
||||||
|
|
||||||
#use "flywheel:block.frag"
|
|
||||||
|
|
||||||
#if defined(VERTEX_SHADER)
|
|
||||||
BlockFrag vertex(Vertex v) {
|
|
||||||
vec4 worldPos = vec4(v.pos, 1.);
|
|
||||||
vec3 norm = v.normal;
|
|
||||||
|
|
||||||
FLWFinalizeWorldPos(worldPos);
|
|
||||||
FLWFinalizeNormal(norm);
|
|
||||||
|
|
||||||
BlockFrag b;
|
|
||||||
b.diffuse = diffuse(norm);
|
|
||||||
b.texCoords = v.texCoords;
|
|
||||||
b.light = v.modelLight;
|
|
||||||
|
|
||||||
#if defined(DEBUG_NORMAL)
|
|
||||||
b.color = vec4(norm, 1.);
|
|
||||||
#else
|
|
||||||
b.color = v.color;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#use "flywheel:core/matutils.glsl"
|
#use "flywheel:core/matutils.glsl"
|
||||||
#use "flywheel:core/quaternion.glsl"
|
#use "flywheel:core/quaternion.glsl"
|
||||||
#use "flywheel:core/diffuse.glsl"
|
|
||||||
|
|
||||||
struct Flap {
|
struct Flap {
|
||||||
vec3 instancePos;
|
vec3 instancePos;
|
||||||
|
@ -15,7 +14,6 @@ struct Flap {
|
||||||
float flapness;
|
float flapness;
|
||||||
};
|
};
|
||||||
|
|
||||||
#use "flywheel:data/modelvertex.glsl"
|
|
||||||
#use "flywheel:block.frag"
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
#if defined(VERTEX_SHADER)
|
#if defined(VERTEX_SHADER)
|
||||||
|
@ -37,7 +35,7 @@ float getFlapAngle(float flapness, float intensity, float scale) {
|
||||||
return degrees;
|
return degrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockFrag vertex(Vertex v, Flap flap) {
|
void vertex(inout 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);
|
||||||
|
@ -46,21 +44,8 @@ BlockFrag vertex(Vertex v, Flap flap) {
|
||||||
vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
|
vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset;
|
||||||
rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
|
rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5;
|
||||||
|
|
||||||
vec4 worldPos = vec4(rotated, 1.);
|
v.pos = rotated;
|
||||||
vec3 norm = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
|
v.normal = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation);
|
||||||
|
v.light = flap.light;
|
||||||
FLWFinalizeWorldPos(worldPos);
|
|
||||||
FLWFinalizeNormal(norm);
|
|
||||||
|
|
||||||
BlockFrag b;
|
|
||||||
b.diffuse = diffuse(norm);
|
|
||||||
b.texCoords = v.texCoords;
|
|
||||||
b.light = flap.light;
|
|
||||||
#if defined(DEBUG_NORMAL)
|
|
||||||
b.color = vec4(norm, 1.);
|
|
||||||
#else
|
|
||||||
b.color = vec4(1.);
|
|
||||||
#endif
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
|
#if defined(VERTEX_SHADER)
|
||||||
|
void vertex(inout Vertex v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -1,7 +1,6 @@
|
||||||
#define PI 3.1415926538
|
#define PI 3.1415926538
|
||||||
|
|
||||||
#use "flywheel:core/matutils.glsl"
|
#use "flywheel:core/matutils.glsl"
|
||||||
#use "flywheel:core/diffuse.glsl"
|
|
||||||
|
|
||||||
struct Rotating {
|
struct Rotating {
|
||||||
vec2 light;
|
vec2 light;
|
||||||
|
@ -12,7 +11,6 @@ struct Rotating {
|
||||||
vec3 axis;
|
vec3 axis;
|
||||||
};
|
};
|
||||||
|
|
||||||
#use "flywheel:data/modelvertex.glsl"
|
|
||||||
#use "flywheel:block.frag"
|
#use "flywheel:block.frag"
|
||||||
|
|
||||||
mat4 kineticRotation(float offset, float speed, vec3 axis) {
|
mat4 kineticRotation(float offset, float speed, vec3 axis) {
|
||||||
|
@ -23,30 +21,17 @@ mat4 kineticRotation(float offset, float speed, vec3 axis) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(VERTEX_SHADER)
|
#if defined(VERTEX_SHADER)
|
||||||
BlockFrag vertex(Vertex v, Rotating instance) {
|
void vertex(inout 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.);
|
||||||
worldPos += vec4(instance.pos + .5, 0.);
|
v.pos = worldPos.xyz + instance.pos + .5;
|
||||||
|
|
||||||
vec3 norm = modelToNormal(spin) * v.normal;
|
v.normal = modelToNormal(spin) * v.normal;
|
||||||
|
v.light = instance.light;
|
||||||
FLWFinalizeWorldPos(worldPos);
|
|
||||||
FLWFinalizeNormal(norm);
|
|
||||||
|
|
||||||
BlockFrag b;
|
|
||||||
b.diffuse = diffuse(norm);
|
|
||||||
b.texCoords = v.texCoords;
|
|
||||||
b.light = instance.light;
|
|
||||||
|
|
||||||
#if defined(DEBUG_RAINBOW)
|
#if defined(DEBUG_RAINBOW)
|
||||||
b.color = instance.color;
|
v.color = instance.color;
|
||||||
#elif defined(DEBUG_NORMAL)
|
|
||||||
b.color = vec4(norm, 1.);
|
|
||||||
#else
|
|
||||||
b.color = vec4(1.);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue