Skip to content

Instantly share code, notes, and snippets.

@Liareth
Created March 27, 2023 11:35
Show Gist options
  • Save Liareth/08a64f1d7459810be50cc6b8009f7f32 to your computer and use it in GitHub Desktop.
Save Liareth/08a64f1d7459810be50cc6b8009f7f32 to your computer and use it in GitHub Desktop.
#MAXMODEL ASCII
newmodel pnl_hpbar
classification CHARACTER
setsupermodel pnl_hpbar NULL
setanimationscale 1
#MAXGEOM ASCII
beginmodelgeom pnl_hpbar
node dummy pnl_hpbar
parent NULL
position 0 -0.3 0
endnode
node trimesh background
parent pnl_hpbar
materialname uihpbarbg
verts 4
-0.5 0.1 0
-0.5 -0.1 0
0.5 0.1 0
0.5 -0.1 0
tverts 4
0 1 0
0 0 0
1 1 0
1 0 0
faces 2
0 1 2 1 0 1 2 1
3 2 1 1 3 2 1 1
endnode
node trimesh foreground
parent pnl_hpbar
materialname uihpbar
verts 4
-0.48 0.09 0
-0.48 -0.09 0
0.48 0.09 0
0.48 -0.09 0
tverts 4
0 1 0
0 0 0
1 1 0
1 0 0
faces 2
0 1 2 1 0 1 2 1
3 2 1 1 3 2 1 1
endnode
endmodelgeom pnl_hpbar
donemodel pnl_hpbar
customshaderVS uihpbarvs
customshaderGS uihpbargs
customshaderFS uihpbarfs
texture0 uihpbar
parameter float hpPercent 100.0
customshaderVS uihpbarbgvs
customshaderFS uihpbarbgfs
texture0 uihpbarbg
parameter int aiStateReaction 0
#define AISTATEREACTION_NEUTRAL 0
#define AISTATEREACTION_FRIENDLY 1
#define AISTATEREACTION_HOSTILE 2
uniform sampler2D texUnit0;
uniform int aiStateReaction;
in vec2 vTcOut;
void main()
{
vec4 texData = texture2D(texUnit0, vTcOut);
if (texData.a == 1.0)
{
vec3 col = vec3(0.5, 0.5, 0.5);
if (aiStateReaction == AISTATEREACTION_FRIENDLY)
{
col = vec3(0.0, 0.5, 0.0);
}
else if (aiStateReaction == AISTATEREACTION_HOSTILE)
{
col = vec3(0.5, 0.0, 0.0);
}
gl_FragColor = vec4(col, 1.0);
}
else
{
gl_FragColor = vec4(texData.rgb, 1.0);
}
}
uniform mat4 m_mvp;
attribute vec3 vPos;
attribute vec2 vTcIn;
out vec2 vTcOut;
void main()
{
gl_Position = m_mvp * vec4(vPos, 1.0);
vTcOut = vTcIn;
}
uniform float hpPercent;
uniform sampler2D texUnit0;
in vec2 gTcOut;
void main()
{
float percentNorm = min(1.0, (1.0 - hpPercent / 100.0) + 0.2);
vec3 col = vec3(2.0 * percentNorm, 2.0f * (1.0 - percentNorm), 0);
vec3 diffuse = texture2D(texUnit0, gTcOut).rgb * col * 2.0f;
gl_FragColor = vec4(diffuse, 0.4);
}
layout (triangles) in;
layout (triangle_strip) out;
layout (max_vertices = 3) out;
in vec2 vTcOut[];
out vec2 gTcOut;
uniform float hpPercent;
void main (void)
{
int i;
float minX = 2;
float maxX = -2;
for (i = 0; i < gl_in.length(); i++)
{
float x = gl_in[i].gl_Position.x;
minX = min(minX, x);
maxX = max(maxX, x);
}
float maxDiff = (maxX - minX) * hpPercent / 100.0;
for (i = 0; i < gl_in.length(); i++)
{
vec4 pos = gl_in[i].gl_Position;
float xDiff = min(pos.x - minX, maxDiff);
gl_Position = vec4(minX + xDiff, pos.y, pos.z, pos.w);
gTcOut = vTcOut[i];
EmitVertex();
}
EndPrimitive();
};
uniform mat4 m_mvp;
attribute vec3 vPos;
attribute vec2 vTcIn;
out vec2 vTcOut;
void main()
{
gl_Position = m_mvp * vec4(vPos, 1.0);
vTcOut = vTcIn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment