updated conway example

This commit is contained in:
codeanticode
2014-03-31 09:41:05 -04:00
parent 8a203e93f9
commit ef4a5089bf
2 changed files with 12 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
// GLSL version of Conway's game of life, ported from GLSL sandbox:
// http://glsl.heroku.com/e#207.3
// Exemplifies the use of the buffer uniform in the shader, that gives
// access to the previous frame.
// Exemplifies the use of the ppixels uniform in the shader, that gives
// access to the pixels of the previous frame.
PShader conway;
PGraphics pg;

View File

@@ -9,7 +9,7 @@ precision highp float;
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
uniform sampler2D buffer;
uniform sampler2D ppixels;
vec4 live = vec4(0.5,1.0,0.7,1.);
vec4 dead = vec4(0.,0.,0.,1.);
@@ -28,15 +28,15 @@ void main( void ) {
}
} else {
float sum = 0.;
sum += texture2D(buffer, position + pixel * vec2(-1., -1.)).g;
sum += texture2D(buffer, position + pixel * vec2(-1., 0.)).g;
sum += texture2D(buffer, position + pixel * vec2(-1., 1.)).g;
sum += texture2D(buffer, position + pixel * vec2(1., -1.)).g;
sum += texture2D(buffer, position + pixel * vec2(1., 0.)).g;
sum += texture2D(buffer, position + pixel * vec2(1., 1.)).g;
sum += texture2D(buffer, position + pixel * vec2(0., -1.)).g;
sum += texture2D(buffer, position + pixel * vec2(0., 1.)).g;
vec4 me = texture2D(buffer, position);
sum += texture2D(ppixels, position + pixel * vec2(-1., -1.)).g;
sum += texture2D(ppixels, position + pixel * vec2(-1., 0.)).g;
sum += texture2D(ppixels, position + pixel * vec2(-1., 1.)).g;
sum += texture2D(ppixels, position + pixel * vec2(1., -1.)).g;
sum += texture2D(ppixels, position + pixel * vec2(1., 0.)).g;
sum += texture2D(ppixels, position + pixel * vec2(1., 1.)).g;
sum += texture2D(ppixels, position + pixel * vec2(0., -1.)).g;
sum += texture2D(ppixels, position + pixel * vec2(0., 1.)).g;
vec4 me = texture2D(ppixels, position);
if (me.g <= 0.1) {
if ((sum >= 2.9) && (sum <= 3.1)) {