Nouveau shader pour les barres de progression qui donne un aspect "tube"

This commit is contained in:
Antoine 2021-06-17 14:34:52 +02:00
parent d587940b45
commit ec45df9c5e
4 changed files with 49 additions and 2 deletions

View File

@ -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);
}
}
}

View File

@ -9,13 +9,15 @@ public class HorizontalProgressBar extends ObjectGl {
private float max; private float max;
private float current; private float current;
private int leftToRight; private int leftToRight;
private boolean useHeight;
public HorizontalProgressBar(float z, float w, float h, float size, float current, float max, boolean leftToRight) { 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)); super(z, w, h, size, null, new Vector3f(0f, 1f, 0f));
this.max = max; this.max = max;
this.current = current; this.current = current;
this.leftToRight = leftToRight ? 1 : 0; 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) { public void setCurrent(float newCurrent) {
@ -26,6 +28,10 @@ public class HorizontalProgressBar extends ObjectGl {
this.max = newMax; this.max = newMax;
} }
public void setUseHeight(boolean b){
this.useHeight = b;
}
protected void uniformInjection() { protected void uniformInjection() {
if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime()); 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())); 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.setUniform1i("leftToRight", this.leftToRight);
this.shader.setUniformMat4f("projection", projection); this.shader.setUniformMat4f("projection", projection);

View File

@ -190,7 +190,8 @@ public class match {
engine.add_uiElement(coordP2); engine.add_uiElement(coordP2);
// Barre de vie // Barre de vie
healthBarP1Obj = new HorizontalProgressBar(80f, 8.5f, 0.4f, 100f, p1.getCurrentHP(), p1.getMaxHP(), false); 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); healthBarP1 = new UIElement(healthBarP1Obj, 0.0138f, 0.980f, engine);
healthBarP2Obj = new HorizontalProgressBar(80f, 8.5f, 0.4f, 100f, p2.getCurrentHP(), p2.getMaxHP(), true); 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)); healthBarP2Obj.setColorVerticalGradient(new Vector3f(39f/255f, 201f/255f, 30f/255f), new Vector3f(19f/255f, 89f/255f, 15f/255f));