Permalink
Browse files

Updated shaders.

  • Loading branch information...
1 parent 41e3afb commit 4918444fedc6ac04851a89c4e329f8ea345c251e @minimoog committed Jun 17, 2012
Showing with 112 additions and 14 deletions.
  1. +11 −3 eval.fsh
  2. +94 −4 glwindow.cpp
  3. +4 −0 glwindow.h
  4. +3 −7 simple.vsh
View
@@ -1,9 +1,17 @@
uniform sampler2D texUnit0;
uniform highp float width;
uniform highp float height;
-uniform highp float k1;
-uniform highp float k2;
-uniform highp float k3;
+
+const highp float d = 0.1;
+const highp float t = 1.3;
+const highp float c = 0.05;
+const highp float mu = 0.05;
+
+const highp float f1 = c * c * t * t / (d * d);
+const highp float f2 = 1.0 / (mu * t + 2.0);
+const highp float k1 = (4.0 - 8.0 * f1) * f2;
+const highp float k2 = (mu * t - 2.0) * f2;
+const highp float k3 = 2.0 * f1 * f2;
highp vec2 step_w = vec2(1.0 / float(width), 0.0);
highp vec2 step_h = vec2(0.0, 1.0 / float(height));
View
@@ -25,9 +25,20 @@
#include <QX11Info>
#endif
+#define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i))
+
//#include <qmeegographicssystemhelper.h>
#include "glwindow.h"
+static const float s_vertices[]= {
+ -1.0f, -1.0f, 0.0f,
+ 1.0f, -1.0f, 0.0f,
+ -1.0f, 1.0f, 0.0f,
+ -1.0f, 1.0f, 0.0f,
+ 1.0f, -1.0f, 0.0f,
+ 1.0f, 1.0f, 0.0f
+};
+
GLWindow::GLWindow(QWidget *parent)
: QWidget(parent),
m_previousTime(0),
@@ -116,7 +127,7 @@ void GLWindow::resume()
return;
m_paused = false;
- m_timerID = startTimer(0);
+ m_timerID = startTimer(17);
}
bool GLWindow::eventFilter(QObject *object, QEvent *event)
@@ -398,6 +409,22 @@ void GLWindow::glError(const char *file, int line)
}
}
+void GLWindow::mousePressEvent(QMouseEvent *event)
+{
+ qDebug() << event->x() << event->y();
+
+ char exc[4] = { 0, 255, 1, 1};
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, m_renderTexture[0]);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 300, 200, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, exc);
+
+ glBindTexture(GL_TEXTURE_2D, m_renderTexture[1]);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 300, 200, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, exc);
+}
+
void GLWindow::initializeGL()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
@@ -434,7 +461,6 @@ void GLWindow::initializeGL()
//vertex array stuff
glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
//shader stuff
@@ -448,7 +474,6 @@ void GLWindow::initializeGL()
glAttachShader(m_programEval, m_fsEval);
glBindAttribLocation(m_programEval, 0, "vertexPos");
- glBindAttribLocation(m_programEval, 1, "vertexTexCoord");
glLinkProgram(m_programEval);
checkProgram(m_programEval);
@@ -460,18 +485,83 @@ void GLWindow::initializeGL()
glAttachShader(m_programRender, m_fsRender);
glBindAttribLocation(m_programRender, 0, "vertexPos");
- glBindAttribLocation(m_programRender, 1, "vertexTexCoord");
glLinkProgram(m_programRender);
checkProgram(m_programRender);
//texture
m_texture = loadTexture("/opt/fluid/bin/Trees.jpg");
+
+ //vbo
+ glGenBuffers(1, &m_vbo);
+ glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(s_vertices), s_vertices, GL_STATIC_DRAW);
+
+ //viewport
+ glViewport(0, 0, 854, 480);
+
+ //uniforms, eval
+ glUseProgram(m_programEval);
+
+ int texUnit0Index = glGetUniformLocation(m_programEval, "texUnit0");
+ glUniform1i(texUnit0Index, 0);
+
+ int widthIndex = glGetUniformLocation(m_programEval, "width");
+ glUniform1f(widthIndex, (float)854);
+
+ int heightIndex = glGetUniformLocation(m_programEval, "height");
+ glUniform1f(heightIndex, (float)480);
+
+ //uniform, render
+ glUseProgram(m_programRender);
+ texUnit0Index = glGetUniformLocation(m_programRender, "texUnit0");
+ glUniform1i(texUnit0Index, 0);
+
+ int texUnit1Index = glGetUniformLocation(m_programRender, "texUnit1");
+ glUniform1i(texUnit1Index, 1);
+
+ widthIndex = glGetUniformLocation(m_programRender, "width");
+ glUniform1f(widthIndex, (float)854);
+
+ heightIndex = glGetUniformLocation(m_programRender, "height");
+ glUniform1f(heightIndex, (float)480);
+}
+
+void GLWindow::eval()
+{
+ glBindFramebuffer(GL_FRAMEBUFFER, m_renderTexture[1 - m_whichRenderTarget]);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, m_renderTexture[m_whichRenderTarget]);
+
+ glUseProgram(m_programEval);
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
+
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+
+ m_whichRenderTarget = 1 - m_whichRenderTarget;
}
void GLWindow::renderGL()
{
+ eval();
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, m_renderTexture[0]);
+ glActiveTexture(GL_TEXTURE1);
+ glBindTexture(GL_TEXTURE_2D, m_texture);
+
+ glUseProgram(m_programRender);
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
+
+ glDrawArrays(GL_TRIANGLES, 0, 6);
}
void GLWindow::resizeGL(int w, int h)
View
@@ -55,6 +55,7 @@ public slots:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
void timerEvent(QTimerEvent *event);
+ void mousePressEvent(QMouseEvent *event);
virtual void initializeGL();
virtual void renderGL();
@@ -64,6 +65,7 @@ public slots:
void createEGL();
//void reinitEGL();
void render();
+ void eval();
void cleanupAndExit(EGLDisplay eglDisplay);
EGLNativeWindowType getWindow();
@@ -90,6 +92,8 @@ public slots:
GLuint m_fsRender;
GLuint m_texture;
+
+ GLuint m_vbo;
};
#endif // GLWINDOW_H
View
@@ -1,14 +1,10 @@
attribute highp vec3 vertexPos;
-attribute highp vec2 vertexTexCoord;
-
-//uniform highp mat4 viewMatrix;
-uniform highp mat4 projectionMatrix;
varying highp vec2 texCoordOutput;
void main(void)
-{
- texCoordOutput = vertexTexCoord;
+{
+ texCoordOutput = (vec2(vertexPos.x, vertexPos.y) + vec2(1.0)) * 0.5;
- gl_Position = projectionMatrix * vec4(vertexPos, 1);
+ gl_Position = vec4(vertexPos, 1);
}

0 comments on commit 4918444

Please sign in to comment.