From 9a858d769bd31036a7ac1d7d9d8cdaba070a7373 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 14 Dec 2024 14:22:53 +0100 Subject: [PATCH] Add proper lsd effects --- .../client/render/shader/GeometryShader.java | 6 ++++++ .../psychedelicraft/entity/drug/Drug.java | 1 + .../drug/hallucination/HallucinationManager.java | 3 +++ .../entity/drug/type/LsdDrug.java | 1 + .../psychedelicraft/shaders/geometry/basic.gfsh | 16 ++++++++++++++++ .../psychedelicraft/shaders/geometry/basic.gvsh | 8 ++++++-- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/ivorius/psychedelicraft/client/render/shader/GeometryShader.java b/src/main/java/ivorius/psychedelicraft/client/render/shader/GeometryShader.java index 9b47c5be..37d3947f 100644 --- a/src/main/java/ivorius/psychedelicraft/client/render/shader/GeometryShader.java +++ b/src/main/java/ivorius/psychedelicraft/client/render/shader/GeometryShader.java @@ -108,6 +108,12 @@ public void addUniforms(ShaderProgramSetupView program, Consumer regi register.accept(new BoundUniform("PS_FractalFractureStrength", GlUniform.getTypeIndex("float"), 1, program, uniform -> { uniform.set(isWorld() ? ShaderContext.hallucinations().get(Drug.SHATTERING_WAVES) : 0F); })); + register.accept(new BoundUniform("PS_lsdBlendRatio", GlUniform.getTypeIndex("float"), 1, program, uniform -> { + uniform.set(isWorld() && RenderPhase.current() != RenderPhase.CLOUDS + ? ShaderContext.modifier(Drug.RAINBOW_WAVES) + : RenderPhase.current() == RenderPhase.SKY ? ShaderContext.modifier(Drug.RAINBOW_WAVES) * 1.1F + : 0F); + })); } public Map> getSamplers() { diff --git a/src/main/java/ivorius/psychedelicraft/entity/drug/Drug.java b/src/main/java/ivorius/psychedelicraft/entity/drug/Drug.java index 01889900..db22ac8a 100644 --- a/src/main/java/ivorius/psychedelicraft/entity/drug/Drug.java +++ b/src/main/java/ivorius/psychedelicraft/entity/drug/Drug.java @@ -60,6 +60,7 @@ public interface Drug extends NbtSerialisable { Attribute BUBBLING_WAVES = new Attribute("bubbling_waves", 0, Combiner.SUM); Attribute SHATTERING_WAVES = new Attribute("shattering_waves", 0, Combiner.SUM); Attribute FRACTALS = new Attribute("fractals", 0, Combiner.SUM); + Attribute RAINBOW_WAVES = new Attribute("rainbow_waves", 0, Combiner.SUM); Function CONTRAST_COLORIZATION = Attribute.createColorModification(Drug::applyContrastColorization); Function BLOOM = Attribute.createColorModification(Drug::applyColorBloom); diff --git a/src/main/java/ivorius/psychedelicraft/entity/drug/hallucination/HallucinationManager.java b/src/main/java/ivorius/psychedelicraft/entity/drug/hallucination/HallucinationManager.java index 6f810b3f..a3cc409c 100644 --- a/src/main/java/ivorius/psychedelicraft/entity/drug/hallucination/HallucinationManager.java +++ b/src/main/java/ivorius/psychedelicraft/entity/drug/hallucination/HallucinationManager.java @@ -89,6 +89,9 @@ public BlockState getFractalAppearance() { } public Vector4f getPulseColor(float tickDelta, boolean sky) { + if (sky) { + return MathUtils.TEMP_VECTOR.set(pulseColor.getColor(tickDelta), ShaderContext.modifier(Drug.RAINBOW_WAVES)); + } float alpha = MathHelper.clamp(visualisations.getMultiplier(HallucinationTypes.PULSES), 0, 1); if (alpha == 0) { return MathUtils.ZERO; diff --git a/src/main/java/ivorius/psychedelicraft/entity/drug/type/LsdDrug.java b/src/main/java/ivorius/psychedelicraft/entity/drug/type/LsdDrug.java index 4adbe5c8..3e1248bf 100644 --- a/src/main/java/ivorius/psychedelicraft/entity/drug/type/LsdDrug.java +++ b/src/main/java/ivorius/psychedelicraft/entity/drug/type/LsdDrug.java @@ -36,6 +36,7 @@ public class LsdDrug extends SimpleDrug { + Math.abs(MathHelper.sin(ShaderContext.ticks() / 30F) * 0.02F * MathUtils.project(f, 0, 0.3F)) + Math.abs(MathHelper.cos((ShaderContext.ticks() + 15) / 30F) * 0.02F * MathUtils.project(f, 0, 0.3F)) ) + .put(RAINBOW_WAVES, 1) .build(); public LsdDrug(DrugType type, double decSpeed, double decSpeedPlus) { diff --git a/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gfsh b/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gfsh index 922459f1..6cbcf3f7 100644 --- a/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gfsh +++ b/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gfsh @@ -1,10 +1,14 @@ uniform float PS_WorldTicks; uniform vec4 PS_Pulses; +uniform float PS_lsdBlendRatio; ps_in float vertexDistance; ps_in vec4 vertexColor; +ps_in float psyColorMultiplier; +ps_in float lsdBlendRatio; + ps_out vec4 fragColor; void main() { @@ -13,6 +17,7 @@ void main() { i_parent_shaders_main(); float worldTicks = PS_WorldTicks; + float lsdBlendRatio = PS_lsdBlendRatio; float fogFragCoord = vertexDistance; float unusedbecausemacisgarbage = vertexColor.r; @@ -29,4 +34,15 @@ void main() { fragColor = vec4(outcolor, fragColor.a); } + + if (lsdBlendRatio > 0) { + lsdBlendRatio *= (vertexDistance <= 0 ? 1 : vertexDistance / 9) * (sin(worldTicks / 100) * 0.5); + fragColor = vec4( + vec3( + fragColor.r * (sin((psyColorMultiplier + 90) * 1.18)), + fragColor.g * (cos(psyColorMultiplier * 1.18)), + fragColor.b * (sin(psyColorMultiplier * 1.18)) + ) * lsdBlendRatio + (fragColor.rgb * (1 - lsdBlendRatio)) + , fragColor.a); + } } diff --git a/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gvsh b/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gvsh index 77422761..3d10301c 100644 --- a/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gvsh +++ b/src/main/resources/assets/psychedelicraft/shaders/geometry/basic.gvsh @@ -16,6 +16,8 @@ ps_out vec4 vertexColor; ps_out float vertexDistance; +ps_out float psyColorMultiplier; + float PHI = 1.61803398874989484820459; float TAU = 6.283185307; @@ -56,8 +58,8 @@ void main() { if (smallWaves > 0.0) { float w1 = 8.0; - gl_Position[1] += sin((vertexPosition.x + worldTicks / 5.0) / w1 * TAU) * sin((vertexPosition.z + worldTicks / 5.0) / w1 * TAU) * smallWaves * 1.5; - gl_Position[1] -= sin((playerPos.x + worldTicks / 5.0) / w1 * TAU) * sin((playerPos.z + worldTicks / 5.0) / w1 * TAU) * smallWaves * 1.5; + gl_Position.y += sin((vertexPosition.x + worldTicks / 5.0) / w1 * TAU) * sin((vertexPosition.z + worldTicks / 5.0) / w1 * TAU) * smallWaves * 1.5; + gl_Position.y -= sin((playerPos.x + worldTicks / 5.0) / w1 * TAU) * sin((playerPos.z + worldTicks / 5.0) / w1 * TAU) * smallWaves * 1.5; float w2 = 16.0; @@ -133,4 +135,6 @@ void main() { gl_Position.w += sin(gl_Position.x * 0.124 * sin(worldTicks * 0.00184298) + worldTicks * 0.018394082) * 0.05 * inf6 * pMul; } } + + psyColorMultiplier = (vertexPosition.x + vertexPosition.y + vertexPosition.z) + worldTicks * 0.1 + sin(gl_Position.x + worldTicks * 0.1); }