Browse Source

cool cellular shader things

master
Joshua Moerman 14 years ago
parent
commit
829679073c
  1. 41
      App.h
  2. 3
      main.cpp
  3. 14
      resources/myHBlurShader.frag
  4. 3
      resources/myTextureShader.frag
  5. 5
      resources/myVBlurShader.frag
  6. 18
      shader.h

41
App.h

@ -40,8 +40,7 @@ class App {
shader mshader;
shader clear_shader;
shader texture_shader;
shader blur_shader1;
shader blur_shader2;
shader blur_shader;
fbo fbo1;
fbo fbo2;
@ -59,8 +58,7 @@ public:
mshader("resources/myTeaShader.vert", "resources/myTeaShader.frag"),
clear_shader("resources/myClearShader.vert", "resources/myClearShader.frag"),
texture_shader("resources/myTextureShader.vert", "resources/myTextureShader.frag"),
blur_shader1("resources/myHBlurShader.vert", "resources/myHBlurShader.frag"),
blur_shader2("resources/myVBlurShader.vert", "resources/myVBlurShader.frag"),
blur_shader("resources/myHBlurShader.vert", "resources/myHBlurShader.frag"),
fbo1(width, height),
fbo2(width, height),
lines(),
@ -96,24 +94,36 @@ public:
void draw() {
fbo & read_fbo = (counter % 2) ? fbo1 : fbo2;
fbo & draw_fbo = (counter % 2) ? fbo2 : fbo1;
shader & blur_shader = (counter % 2) ? blur_shader1 : blur_shader2;
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
draw_fbo.begin();
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
blur_shader.begin();
texture(read_fbo);
blur_shader.set_uniform("offset", (float) cos(counter) / width, (float) sin(counter) / height);
if(true){
blur_shader.set_uniform("fade", 0.75f);
blur_shader.set_uniform("inter", 0.55f);
} else {
blur_shader.set_uniform("fade", 0.96f);
blur_shader.set_uniform("inter", 0.9f);
}
texture(blur_shader, read_fbo);
mshader.begin();
glBlendFunc(GL_ONE, GL_ONE);
scene();
draw_fbo.end();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
texture_shader.begin();
texture(draw_fbo);
texture(texture_shader, draw_fbo);
//save_screen();
//if(counter % 4 == 0)
// save_screen();
}
void fade() {
@ -125,9 +135,8 @@ public:
glDisableClientState(GL_VERTEX_ARRAY);
}
void texture(fbo const & read_fbo) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
texture_shader.set_texture("tex", GL_TEXTURE_2D, read_fbo.texture_id, 0);
void texture(shader const & tex_shader, fbo const & read_fbo) {
tex_shader.set_texture("tex", GL_TEXTURE_2D, read_fbo.texture_id, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
@ -139,19 +148,13 @@ public:
}
void scene() {
glBlendFunc(GL_ONE, GL_ONE);
mshader.set_uniform("steps", counter/10);
glRotatef(0.05, std::sin(counter/13370.0), 1.0, 0.0);
const unsigned int part = 8;
glRotatef(0.09, std::sin(counter/13370.0), 1.0, 0.0);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &lines[0]);
glPointSize(3.0);
glDrawArrays(GL_POINTS, 0, number_of_vertices/part);
glPointSize(1.0);
glDrawArrays(GL_POINTS, number_of_vertices/part, (part-1)*number_of_vertices/part);
glDrawArrays(GL_POINTS, 0, number_of_vertices);
glDisableClientState(GL_VERTEX_ARRAY);
}

3
main.cpp

@ -11,7 +11,7 @@
App* app_ptr = 0;
unsigned int const frames_per_second = 60.0;
unsigned int const frames_per_second = 200.0;
typedef std::chrono::high_resolution_clock clock_type;
@ -62,7 +62,6 @@ int main(int argc, char** argv) {
//glFlush();
++frame_count;
if(frame_count == 7400) exit(0);
previous_timepoint = current_timepoint-(difference%time_step);
} else {

14
resources/myHBlurShader.frag

@ -1,12 +1,20 @@
uniform sampler2D tex;
uniform vec2 offset;
uniform float inter;
uniform float fade;
vec2 offset = vec2(0.0, 1.0/600.0);
//vec2 offset = vec2(0.0, 1.0/600.0);
//float inter = 0.2;
void main( void ) {
gl_FragColor = texture2D(tex, gl_TexCoord[0].st + offset);
gl_FragColor += texture2D(tex, gl_TexCoord[0].st - offset);
gl_FragColor = normalize(gl_FragColor) + 0.5*gl_FragColor;
gl_FragColor *= 0.56;
gl_FragColor = inter*normalize(gl_FragColor) + (1.0 - inter)*gl_FragColor;
gl_FragColor *= fade;
//gl_FragColor = sin(gl_FragColor*3.0);
gl_FragColor -= 0.033*texture2D(tex, gl_TexCoord[0].st + 30.0*offset);
gl_FragColor -= 0.033*texture2D(tex, gl_TexCoord[0].st - 30.0*offset);
gl_FragColor.a = 1.0;
}

3
resources/myTextureShader.frag

@ -3,6 +3,7 @@ uniform sampler2D tex;
void main( void ) {
gl_FragColor = texture2D(tex, gl_TexCoord[0].st);
//gl_FragColor = sin(gl_FragColor*3.0);
//gl_FragColor -= texture2D(tex, gl_TexCoord[0].st + vec2(0.0, 0.005));
//gl_FragColor = gl_FragColor*2.0 + 0.5;
gl_FragColor.a = 1.0;
}

5
resources/myVBlurShader.frag

@ -1,12 +1,13 @@
uniform sampler2D tex;
vec2 offset = vec2(1.0/800.0, 0.0);
float inter = 0.2;
void main( void ) {
gl_FragColor = texture2D(tex, gl_TexCoord[0].st + offset);
gl_FragColor += texture2D(tex, gl_TexCoord[0].st - offset);
gl_FragColor = normalize(gl_FragColor) + 0.5*gl_FragColor;
gl_FragColor *= 0.56;
gl_FragColor = inter*normalize(gl_FragColor) + (1.0 - inter)*gl_FragColor;
gl_FragColor *= 0.57;
//gl_FragColor = sin(gl_FragColor*3.0);
gl_FragColor.a = 1.0;
}

18
shader.h

@ -60,39 +60,39 @@ public:
glUseProgram(0);
}
void set_uniform(char const* name, float x) {
void set_uniform(char const* name, float x) const {
glUniform1f(glGetUniformLocation(program, name), x);
}
void set_uniform(char const* name, float x, float y) {
void set_uniform(char const* name, float x, float y) const {
glUniform2f(glGetUniformLocation(program, name), x, y);
}
void set_uniform(char const* name, float x, float y, float z) {
void set_uniform(char const* name, float x, float y, float z) const {
glUniform3f(glGetUniformLocation(program, name), x, y, z);
}
void set_uniform(char const* name, float x, float y, float z, float w) {
void set_uniform(char const* name, float x, float y, float z, float w) const {
glUniform4f(glGetUniformLocation(program, name), x, y, z, w);
}
void set_uniform(char const* name, int x) {
void set_uniform(char const* name, int x) const {
glUniform1i(glGetUniformLocation(program, name), x);
}
void set_uniform(char const* name, int x, int y) {
void set_uniform(char const* name, int x, int y) const {
glUniform2i(glGetUniformLocation(program, name), x, y);
}
void set_uniform(char const* name, int x, int y, int z) {
void set_uniform(char const* name, int x, int y, int z) const {
glUniform3i(glGetUniformLocation(program, name), x, y, z);
}
void set_uniform(char const* name, int x, int y, int z, int w) {
void set_uniform(char const* name, int x, int y, int z, int w) const {
glUniform4i(glGetUniformLocation(program, name), x, y, z, w);
}
void set_texture(const char* name, GLenum target, GLuint tex, int textureLocation) {
void set_texture(const char* name, GLenum target, GLuint tex, int textureLocation) const {
glActiveTexture(GL_TEXTURE0 + textureLocation);
glBindTexture(target, tex);
set_uniform(name, textureLocation);