From ec45df9c5e5f64c8a75c388d9aebba6a87d177c1 Mon Sep 17 00:00:00 2001 From: Antoine Date: Thu, 17 Jun 2021 14:34:52 +0200 Subject: [PATCH] Nouveau shader pour les barres de progression qui donne un aspect "tube" --- ...ar.glsl => HorizontalProgressBarFrag.glsl} | 0 ...rizontalProgressBarGradientSquareFrag.glsl | 36 +++++++++++++++++++ src/engine/object/HorizontalProgressBar.java | 12 ++++++- src/gameplay/match/match.java | 3 +- 4 files changed, 49 insertions(+), 2 deletions(-) rename shaders/StylishShaders/{HorizontalProgressBar.glsl => HorizontalProgressBarFrag.glsl} (100%) create mode 100644 shaders/StylishShaders/HorizontalProgressBarGradientSquareFrag.glsl diff --git a/shaders/StylishShaders/HorizontalProgressBar.glsl b/shaders/StylishShaders/HorizontalProgressBarFrag.glsl similarity index 100% rename from shaders/StylishShaders/HorizontalProgressBar.glsl rename to shaders/StylishShaders/HorizontalProgressBarFrag.glsl diff --git a/shaders/StylishShaders/HorizontalProgressBarGradientSquareFrag.glsl b/shaders/StylishShaders/HorizontalProgressBarGradientSquareFrag.glsl new file mode 100644 index 0000000..8719613 --- /dev/null +++ b/shaders/StylishShaders/HorizontalProgressBarGradientSquareFrag.glsl @@ -0,0 +1,36 @@ +#version 410 + +in vec4 color; +in vec2 fragCoord; + +out vec4 FragColor; + +uniform float time; +uniform float fill; +uniform bool leftToRight; +uniform float height; + +void main() +{ //Rectangle plus large que haut + vec4 colorTemp = color; + float ouverture = 0.8f; + float lum = -pow(fragCoord.y + height/2f, 2f) * 5f /height + ouverture; + colorTemp.xyz *= lum; + if (leftToRight){ + if (fill > fragCoord.x){ + FragColor = colorTemp; + } + else { + FragColor = vec4(0f); + } + } else { + if (fill < fragCoord.x){ + FragColor = colorTemp; + } + else { + FragColor = vec4(0f); + } + } + + +} \ No newline at end of file diff --git a/src/engine/object/HorizontalProgressBar.java b/src/engine/object/HorizontalProgressBar.java index 2ff24aa..8d870e7 100644 --- a/src/engine/object/HorizontalProgressBar.java +++ b/src/engine/object/HorizontalProgressBar.java @@ -9,13 +9,15 @@ public class HorizontalProgressBar extends ObjectGl { private float max; private float current; private int leftToRight; + private boolean useHeight; public HorizontalProgressBar(float z, float w, float h, float size, float current, float max, boolean leftToRight) { super(z, w, h, size, null, new Vector3f(0f, 1f, 0f)); this.max = max; this.current = current; this.leftToRight = leftToRight ? 1 : 0; - this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/HorizontalProgressBar.glsl"); + this.useHeight = false; + this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/HorizontalProgressBarFrag.glsl"); } public void setCurrent(float newCurrent) { @@ -26,6 +28,10 @@ public class HorizontalProgressBar extends ObjectGl { this.max = newMax; } + public void setUseHeight(boolean b){ + this.useHeight = b; + } + protected void uniformInjection() { if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime()); @@ -35,6 +41,10 @@ public class HorizontalProgressBar extends ObjectGl { this.shader.setUniform1f("fill", Math.abs(((this.current / this.max) * this.getWidth()) - this.getWidth())); } + if (this.useHeight) { + this.shader.setUniform1f("height", this.height); + } + this.shader.setUniform1i("leftToRight", this.leftToRight); this.shader.setUniformMat4f("projection", projection); diff --git a/src/gameplay/match/match.java b/src/gameplay/match/match.java index 5446658..835af2a 100644 --- a/src/gameplay/match/match.java +++ b/src/gameplay/match/match.java @@ -190,7 +190,8 @@ public class match { engine.add_uiElement(coordP2); // Barre de vie healthBarP1Obj = new HorizontalProgressBar(80f, 8.5f, 0.4f, 100f, p1.getCurrentHP(), p1.getMaxHP(), false); - healthBarP1Obj.setColorVerticalGradient(new Vector3f(39f/255f, 201f/255f, 30f/255f), new Vector3f(19f/255f, 89f/255f, 15f/255f)); + healthBarP1Obj.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/HorizontalProgressBarGradientSquareFrag.glsl"); + healthBarP1Obj.setUseHeight(true); healthBarP1 = new UIElement(healthBarP1Obj, 0.0138f, 0.980f, engine); healthBarP2Obj = new HorizontalProgressBar(80f, 8.5f, 0.4f, 100f, p2.getCurrentHP(), p2.getMaxHP(), true); healthBarP2Obj.setColorVerticalGradient(new Vector3f(39f/255f, 201f/255f, 30f/255f), new Vector3f(19f/255f, 89f/255f, 15f/255f));