From e892003eb574f50b682d977b5bdfdce667fb3b58 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Mon, 15 Jan 2024 16:25:15 -0800 Subject: [PATCH] Throwing shade - Actually register instance types. - Update instance shaders to compile with new flywheel. - Add cull shaders. - Update flywheel dep in mods.toml. - Bump flywheel build. --- gradle.properties | 2 +- .../com/simibubi/create/CreateClient.java | 3 ++ src/main/resources/META-INF/mods.toml | 4 +-- .../assets/create/flywheel/instance/belt.vert | 28 +++++---------- .../flywheel/instance/contraption_actor.vert | 27 +++++---------- .../create/flywheel/instance/cull/belt.glsl | 11 ++++++ .../instance/cull/contraption_actor.glsl | 14 ++++++++ .../create/flywheel/instance/cull/flap.glsl | 34 +++++++++++++++++++ .../flywheel/instance/cull/rotating.glsl | 20 +++++++++++ .../assets/create/flywheel/instance/flap.vert | 25 +++++--------- .../create/flywheel/instance/rotating.vert | 23 +++++-------- 11 files changed, 118 insertions(+), 73 deletions(-) create mode 100644 src/main/resources/assets/create/flywheel/instance/cull/belt.glsl create mode 100644 src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl create mode 100644 src/main/resources/assets/create/flywheel/instance/cull/flap.glsl create mode 100644 src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl diff --git a/gradle.properties b/gradle.properties index a13bd9319..e6819087c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ use_parchment = true # dependency versions registrate_version = MC1.20-1.3.3 flywheel_minecraft_version = 1.20.1 -flywheel_version = 1.0.0-alpha-11 +flywheel_version = 1.0.0-alpha-14 jei_minecraft_version = 1.20.1 jei_version = 15.2.0.22 curios_minecraft_version = 1.20.1 diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 89684cb99..ea5cb4b0a 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -18,6 +18,7 @@ import com.simibubi.create.foundation.blockEntity.behaviour.ValueSettingsClient; import com.simibubi.create.foundation.gui.UIRenderHelper; import com.simibubi.create.foundation.outliner.Outliner; import com.simibubi.create.foundation.ponder.element.WorldSectionElement; +import com.simibubi.create.foundation.render.AllInstanceTypes; import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.CreateContexts; import com.simibubi.create.foundation.render.SuperByteBufferCache; @@ -63,6 +64,8 @@ public class CreateClient { modEventBus.addListener(CreateClient::clientInit); modEventBus.addListener(AllParticleTypes::registerFactories); + AllInstanceTypes.init(); + MODEL_SWAPPER.registerListeners(modEventBus); ZAPPER_RENDER_HANDLER.registerListeners(forgeEventBus); diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index a5c47fedd..b9599d66e 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -5,7 +5,7 @@ license="MIT" [[mods]] modId="create" -# The Implementation-Version property in the jar's MANIFEST.MF file will be used as the mod version at runtime +# The Implementation-Version property in the jar's MANIFEST.MF file will be used as the mod version at runtime version="${file.jarVersion}" displayName="Create" #updateJSONURL="" @@ -33,6 +33,6 @@ Technology that empowers the player.''' [[dependencies.create]] modId="flywheel" mandatory=true - versionRange="[0.6.10,0.6.11)" + versionRange="[1.0.0-alpha,2.0)" ordering="AFTER" side="CLIENT" diff --git a/src/main/resources/assets/create/flywheel/instance/belt.vert b/src/main/resources/assets/create/flywheel/instance/belt.vert index 48cc0a83d..a42270e0f 100644 --- a/src/main/resources/assets/create/flywheel/instance/belt.vert +++ b/src/main/resources/assets/create/flywheel/instance/belt.vert @@ -1,33 +1,23 @@ #define PI 3.1415926538 -#include "flywheel:core/quaternion.glsl" -#include "flywheel:core/matutils.glsl" +#include "flywheel:util/quaternion.glsl" +#include "flywheel:util/matrix.glsl" -struct Belt { - vec2 light; - vec4 color; - vec3 pos; - float speed; - float offset; - vec4 rotation; - vec2 sourceTexture; - vec4 scrollTexture; - float scrollMult; -}; +const float uTime = 0.; -void vertex(inout Vertex v, Belt instance) { - v.pos = rotateVertexByQuat(v.pos - .5, instance.rotation) + instance.pos + .5; +void flw_instanceVertex(in FlwInstance instance) { + flw_vertexPos = vec4(rotateVertexByQuat(flw_vertexPos.xyz - .5, instance.rotation) + instance.pos + .5, 1.); - v.normal = rotateVertexByQuat(v.normal, instance.rotation); + flw_vertexNormal = rotateVertexByQuat(flw_vertexNormal, instance.rotation); float scrollSize = instance.scrollTexture.w - instance.scrollTexture.y; float scroll = fract(instance.speed * uTime / (31.5 * 16.) + instance.offset) * scrollSize * instance.scrollMult; - v.texCoords = v.texCoords - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll); - v.light = instance.light; + flw_vertexTexCoord = flw_vertexTexCoord - instance.sourceTexture + instance.scrollTexture.xy + vec2(0, scroll); + flw_vertexLight = instance.light; #if defined(DEBUG_RAINBOW) - v.color = instance.color; + flw_vertexColor = instance.color; #endif } diff --git a/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert b/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert index eca332180..676274e80 100644 --- a/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert +++ b/src/main/resources/assets/create/flywheel/instance/contraption_actor.vert @@ -1,26 +1,15 @@ -#define PI 3.1415926538 +#include "flywheel:util/matrix.glsl" +#include "flywheel:util/quaternion.glsl" -#include "flywheel:core/matutils.glsl" -#include "flywheel:core/quaternion.glsl" +const float uTime = 0.; -struct Actor { - vec3 pos; - vec2 light; - float offset; - vec3 axis; - vec4 rotation; - vec3 rotationCenter; - float speed; -}; - -void vertex(inout Vertex v, Actor instance) { +void flw_instanceVertex(in FlwInstance instance) { float degrees = instance.offset + uTime * instance.speed / 20.; - //float angle = fract(degrees / 360.) * PI * 2.; vec4 kineticRot = quat(instance.axis, degrees); - vec3 rotated = rotateVertexByQuat(v.pos - instance.rotationCenter, kineticRot) + instance.rotationCenter; + vec3 rotated = rotateVertexByQuat(flw_vertexPos.xyz - instance.rotationCenter, kineticRot) + instance.rotationCenter; - v.pos = rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5; - v.normal = rotateVertexByQuat(rotateVertexByQuat(v.normal, kineticRot), instance.rotation); - v.light = instance.light; + flw_vertexPos = vec4(rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5, 1.); + flw_vertexNormal = rotateVertexByQuat(rotateVertexByQuat(flw_vertexNormal, kineticRot), instance.rotation); + flw_vertexLight = instance.light; } diff --git a/src/main/resources/assets/create/flywheel/instance/cull/belt.glsl b/src/main/resources/assets/create/flywheel/instance/cull/belt.glsl new file mode 100644 index 000000000..0b638ab27 --- /dev/null +++ b/src/main/resources/assets/create/flywheel/instance/cull/belt.glsl @@ -0,0 +1,11 @@ +#define PI 3.1415926538 + +#include "flywheel:util/quaternion.glsl" +#include "flywheel:util/matrix.glsl" + +const float uTime = 0.; + +void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) { + // FIXME: this is incorrect, but it compiles + center = rotateVertexByQuat(center - .5, instance.rotation) + instance.pos + .5; +} diff --git a/src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl b/src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl new file mode 100644 index 000000000..a1c1aaff4 --- /dev/null +++ b/src/main/resources/assets/create/flywheel/instance/cull/contraption_actor.glsl @@ -0,0 +1,14 @@ +#include "flywheel:util/matrix.glsl" +#include "flywheel:util/quaternion.glsl" + +const float uTime = 0.; + +void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) { + // FIXME: this is incorrect, but it compiles + float degrees = instance.offset + uTime * instance.speed / 20.; + + vec4 kineticRot = quat(instance.axis, degrees); + vec3 rotated = rotateVertexByQuat(center - instance.rotationCenter, kineticRot) + instance.rotationCenter; + + center = rotateVertexByQuat(rotated - .5, instance.rotation) + instance.pos + .5; +} diff --git a/src/main/resources/assets/create/flywheel/instance/cull/flap.glsl b/src/main/resources/assets/create/flywheel/instance/cull/flap.glsl new file mode 100644 index 000000000..8a8ebeaa3 --- /dev/null +++ b/src/main/resources/assets/create/flywheel/instance/cull/flap.glsl @@ -0,0 +1,34 @@ +#define PI 3.1415926538 + +const float uTime = 0.; + +#include "flywheel:util/matrix.glsl" +#include "flywheel:util/quaternion.glsl" + +float toRad(float degrees) { + return fract(degrees / 360.) * PI * 2.; +} + +float getFlapAngle(float flapness, float intensity, float scale) { + float absFlap = abs(flapness); + + float angle = sin((1. - absFlap) * PI * intensity) * 30. * flapness * scale; + + float halfAngle = angle * 0.5; + + float which = step(0., flapness); // 0 if negative, 1 if positive + float degrees = which * halfAngle + (1. - which) * angle; // branchless conditional multiply + + return degrees; +} + +void flw_transformBoundingSphere(in FlwInstance flap, inout vec3 center, inout float radius) { + // FIXME: this is incorrect, but it compiles + float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale); + + vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle); + vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle); + + vec3 rotated = rotateVertexByQuat(center - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset; + center = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5; +} diff --git a/src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl b/src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl new file mode 100644 index 000000000..809a5679a --- /dev/null +++ b/src/main/resources/assets/create/flywheel/instance/cull/rotating.glsl @@ -0,0 +1,20 @@ +#define PI 3.1415926538 + +#include "flywheel:util/matrix.glsl" + +const float uTime = 0.; + +mat4 kineticRotation(float offset, float speed, vec3 axis) { + float degrees = offset + uTime * speed * 3./10.; + float angle = fract(degrees / 360.) * PI * 2.; + + return rotate(axis, angle); +} + +void flw_transformBoundingSphere(in FlwInstance instance, inout vec3 center, inout float radius) { + // FIXME: this is incorrect, but it compiles + mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis); + + vec4 worldPos = spin * vec4(center - .5, 1.); + center = worldPos.xyz + instance.pos + .5; +} diff --git a/src/main/resources/assets/create/flywheel/instance/flap.vert b/src/main/resources/assets/create/flywheel/instance/flap.vert index ea4ae6fb3..75a82a908 100644 --- a/src/main/resources/assets/create/flywheel/instance/flap.vert +++ b/src/main/resources/assets/create/flywheel/instance/flap.vert @@ -1,18 +1,9 @@ #define PI 3.1415926538 -#include "flywheel:core/matutils.glsl" -#include "flywheel:core/quaternion.glsl" +const float uTime = 0.; -struct Flap { - vec3 instancePos; - vec2 light; - vec3 segmentOffset; - vec3 pivot; - float horizontalAngle; - float intensity; - float flapScale; - float flapness; -}; +#include "flywheel:util/matrix.glsl" +#include "flywheel:util/quaternion.glsl" float toRad(float degrees) { return fract(degrees / 360.) * PI * 2.; @@ -31,16 +22,16 @@ float getFlapAngle(float flapness, float intensity, float scale) { return degrees; } -void vertex(inout Vertex v, Flap flap) { +void flw_instanceVertex(in FlwInstance flap) { float flapAngle = getFlapAngle(flap.flapness, flap.intensity, flap.flapScale); vec4 orientation = quat(vec3(0., 1., 0.), -flap.horizontalAngle); vec4 flapRotation = quat(vec3(1., 0., 0.), flapAngle); - vec3 rotated = rotateVertexByQuat(v.pos - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset; + vec3 rotated = rotateVertexByQuat(flw_vertexPos.xyz - flap.pivot, flapRotation) + flap.pivot + flap.segmentOffset; rotated = rotateVertexByQuat(rotated - .5, orientation) + flap.instancePos + .5; - v.pos = rotated; - v.normal = rotateVertexByQuat(rotateVertexByQuat(v.normal, flapRotation), orientation); - v.light = flap.light; + flw_vertexPos = vec4(rotated, 1.); + flw_vertexNormal = rotateVertexByQuat(rotateVertexByQuat(flw_vertexNormal, flapRotation), orientation); + flw_vertexLight = flap.light; } diff --git a/src/main/resources/assets/create/flywheel/instance/rotating.vert b/src/main/resources/assets/create/flywheel/instance/rotating.vert index e934b3e24..dd4d73ae1 100644 --- a/src/main/resources/assets/create/flywheel/instance/rotating.vert +++ b/src/main/resources/assets/create/flywheel/instance/rotating.vert @@ -1,15 +1,8 @@ #define PI 3.1415926538 -#include "flywheel:core/matutils.glsl" +#include "flywheel:util/matrix.glsl" -struct Rotating { - vec2 light; - vec4 color; - vec3 pos; - float speed; - float offset; - vec3 axis; -}; +const float uTime = 0.; mat4 kineticRotation(float offset, float speed, vec3 axis) { float degrees = offset + uTime * speed * 3./10.; @@ -18,16 +11,16 @@ mat4 kineticRotation(float offset, float speed, vec3 axis) { return rotate(axis, angle); } -void vertex(inout Vertex v, Rotating instance) { +void flw_instanceVertex(in FlwInstance instance) { mat4 spin = kineticRotation(instance.offset, instance.speed, instance.axis); - vec4 worldPos = spin * vec4(v.pos - .5, 1.); - v.pos = worldPos.xyz + instance.pos + .5; + vec4 worldPos = spin * vec4(flw_vertexPos.xyz - .5, 1.); + flw_vertexPos = vec4(worldPos.xyz + instance.pos + .5, 1.); - v.normal = modelToNormal(spin) * v.normal; - v.light = instance.light; + flw_vertexNormal = modelToNormal(spin) * flw_vertexNormal; + flw_vertexLight = instance.light; #if defined(DEBUG_RAINBOW) - v.color = instance.color; + flw_vertexColor = instance.color; #endif }