|
From: Lasse Kärkkäi. <tr...@us...> - 2011-02-06 21:02:17
|
Module: performous
Branch: opengl2
Commit: 7045ca120773edff9e494dc08637675a70abef15
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Feb 6 22:02:05 2011 +0100
Fix dance mode. Shader slightly optimized.
---
game/dancegraph.cc | 19 ++++++++++-
game/video_driver.cc | 4 ++
themes/default/shaders/dancenote.frag | 30 +++++++++++++++++
themes/default/shaders/dancenote.vert | 56 +++++++++++++++++++++++++++++++++
4 files changed, 107 insertions(+), 2 deletions(-)
diff --git a/game/dancegraph.cc b/game/dancegraph.cc
index 2cf3d9f..ee29f98 100644
--- a/game/dancegraph.cc
+++ b/game/dancegraph.cc
@@ -392,7 +392,8 @@ namespace {
/// Draw a dance pad icon using the given texture
void DanceGraph::drawArrow(int arrow_i, Texture& tex, float ty1, float ty2) {
- UseTexture tblock(tex);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(tex.type(), tex.id());
glutil::VertexArray va;
vertexPair(va, arrow_i, -arrowSize, ty1);
vertexPair(va, arrow_i, arrowSize, ty2);
@@ -426,8 +427,14 @@ void DanceGraph::draw(double time) {
// Arrows on cursor
{
+ UseShader us(getShader("dancenote"));
+ us().setUniform("clock", float(time))
+ .setUniform("noteType", 0)
+ .setUniform("scale", getScale());
for (int arrow_i = 0; arrow_i < m_pads; ++arrow_i) {
float l = m_pressed_anim[arrow_i].get();
+ us().setUniform("hitAnim", l)
+ .setUniform("position", panel2x(arrow_i), time2y(0.0));
drawArrow(arrow_i, m_arrows_cursor);
}
}
@@ -483,6 +490,11 @@ void DanceGraph::drawNote(DanceNote& note, double time) {
double glow = note.hitAnim.get();
{
+ UseShader us(getShader("dancenote"));
+ us().setUniform("hitAnim", float(glow))
+ .setUniform("clock", float(time))
+ .setUniform("scale", getScale());
+
if (yEnd - yBeg > arrowSize) {
// Draw holds
if (note.isHit && note.releaseTime <= 0) { // The note is being held down
@@ -490,10 +502,12 @@ void DanceGraph::drawNote(DanceNote& note, double time) {
yEnd = std::max(time2y(0.0), yEnd);
}
if (note.releaseTime > 0) yBeg = time2y(note.releaseTime - time); // Oh noes, it got released!
+ us().setUniform("noteType", 2).setUniform("position", x, yBeg);
// Draw begin
drawArrow(arrow_i, m_arrows_hold, 0.0f, 1.0f/3.0f);
if (yEnd - yBeg > 0) {
- UseTexture tblock(m_arrows_hold);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(m_arrows_hold.type(), m_arrows_hold.id());
glutil::VertexArray va;
// Middle
vertexPair(va, arrow_i, arrowSize, 1.0f/3.0f);
@@ -507,6 +521,7 @@ void DanceGraph::drawNote(DanceNote& note, double time) {
} else {
// Draw short note
if (mine && note.isHit) yBeg = time2y(0.0);
+ us().setUniform("noteType", (mine ? 3 : 1)).setUniform("position", x, yBeg);
drawArrow((mine ? -1 : arrow_i), (mine ? m_mine : m_arrows));
}
}
diff --git a/game/video_driver.cc b/game/video_driver.cc
index ea238da..3c8a3fc 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -87,6 +87,10 @@ Window::Window(unsigned int width, unsigned int height, bool fs): m_windowW(widt
.compileFile(getThemePath("shaders/3dobject.vert"))
.compileFile(getThemePath("shaders/3dobject.frag"))
.link();
+ shader("dancenote")
+ .compileFile(getThemePath("shaders/dancenote.vert"))
+ .compileFile(getThemePath("shaders/dancenote.frag"))
+ .link();
}
Window::~Window() { }
diff --git a/themes/default/shaders/dancenote.frag b/themes/default/shaders/dancenote.frag
new file mode 100644
index 0000000..d60579d
--- /dev/null
+++ b/themes/default/shaders/dancenote.frag
@@ -0,0 +1,30 @@
+#extension GL_ARB_texture_rectangle : enable
+
+uniform sampler2D tex;
+uniform int noteType;
+uniform float hitAnim;
+uniform float clock;
+uniform float scale;
+
+
+void colorGlow(inout vec4 c) {
+ c = vec4(
+ min(c.r + hitAnim *.5, 1.0),
+ min(c.g + hitAnim *.5, 1.0),
+ min(c.b + hitAnim *.5, 1.0),
+ max(c.a - hitAnim, 0.0));
+}
+
+
+void main()
+{
+ vec4 texel;
+
+ texel = texture2D(tex, gl_TexCoord[0].st).rgba;
+
+ // Regular arrows or holds
+ if (noteType == 1 || noteType == 2) colorGlow(texel);
+
+ gl_FragColor = texel;
+}
+
diff --git a/themes/default/shaders/dancenote.vert b/themes/default/shaders/dancenote.vert
new file mode 100644
index 0000000..3573391
--- /dev/null
+++ b/themes/default/shaders/dancenote.vert
@@ -0,0 +1,56 @@
+uniform int noteType;
+uniform float hitAnim;
+uniform float clock;
+uniform float scale;
+uniform vec2 position;
+
+#define deg2rad 0.0174532925
+
+mat4 scaleMat(in float sc) {
+ return mat4(sc, 0, 0, 0,
+ 0, sc, 0, 0,
+ 0, 0, sc, 0,
+ 0, 0, 0, 1);
+}
+
+mat4 rotMat(in float ang) {
+ float ca = cos(ang);
+ float sa = sin(ang);
+ return mat4(ca, -sa, 0, 0,
+ sa, ca, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+}
+
+
+void main()
+{
+ gl_FrontColor = gl_Color;
+ gl_BackColor = gl_Color;
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+
+ mat4 trans = scaleMat(scale);
+
+ // Cursor arrows
+ if (noteType == 0) {
+ trans *= scaleMat(1.0 - hitAnim * .5);
+
+ // Regular arrows
+ } else if (noteType == 1) {
+ trans *= scaleMat(1.0 + hitAnim);
+
+ // Holds
+ } else if (noteType == 2) {
+ trans *= scaleMat(1.0 + hitAnim);
+
+ // Mines
+ } else if (noteType == 3) {
+ trans *= scaleMat(1.0 + hitAnim);
+ float r = float(mod(int(clock*360.0), 360)) * deg2rad; // They rotate!
+ trans *= rotMat(r);
+ }
+
+ gl_Position = gl_ModelViewProjectionMatrix * trans * gl_Vertex;
+ gl_Position += gl_ModelViewProjectionMatrix * vec4(position.xy, 0, 0);
+}
+
|