Permalink
Browse files

adding scenes demo app and shaders

  • Loading branch information...
1 parent 43b83b5 commit 880780f2e77d060a8b4b249b47cc393e92d2e84f @kylemcdonald kylemcdonald committed Oct 30, 2011
View
@@ -0,0 +1,9 @@
+//THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
+//THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
+OF_PATH = ../../..
+
+//THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
+#include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
+
+OTHER_LDFLAGS = $(OF_CORE_LIBS)
+HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.openFrameworks</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+</dict>
+</plist>
View
@@ -0,0 +1,8 @@
+#include "testApp.h"
+#include "ofAppGlutWindow.h"
+
+int main() {
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, 1024, 1024, OF_WINDOW);
+ ofRunApp(new testApp());
+}
View
@@ -0,0 +1,64 @@
+#include "testApp.h"
+
+void testApp::setup() {
+ ofSetWindowPosition((ofGetScreenWidth() - ofGetWidth()) / 2, 0);
+ ofSetBackgroundAuto(false);
+ //ofSetVerticalSync(true);
+ scenes.push_back(new OrigScene());
+ scenes.push_back(new GridScene());
+ scenes.push_back(new LensScene());
+ scenes.push_back(new BallScene());
+ scenes.push_back(new VoroScene());
+ scenes.push_back(new FracScene());
+ scenes.push_back(new WindScene());
+ scenes.push_back(new BoidScene());
+ scenes.push_back(new DotsScene());
+ scenes.push_back(new WallScene());
+ scenes.push_back(new RectScene());
+ for(int i = 0; i < scenes.size(); i++) {
+ scenes[i]->setSize(ofGetWidth(), ofGetHeight());
+ scenes[i]->setup();
+ }
+ curScene = 0;
+}
+
+void testApp::update() {
+ vector<ofVec2f> touches;
+ ofSeedRandom(0);
+ for(int i = 0; i < 1; i++) {
+ float f = .1;
+ touches.push_back(
+ ofVec2f(
+ ofGetWidth() * ofNoise(ofGetElapsedTimef() * f + ofRandom(1024)),
+ ofGetHeight() * ofNoise(ofGetElapsedTimef() * f + ofRandom(1024))));
+ }
+ if(ofGetMousePressed()) {
+ touches.push_back(ofVec2f(mouseX, mouseY));
+ }
+ scenes[curScene]->setTouches(touches);
+ scenes[curScene]->update();
+}
+
+void testApp::draw() {
+ ofPushMatrix();
+ //ofPushStyle();
+ scenes[curScene]->draw();
+ //ofPopStyle();
+ ofPopMatrix();
+
+ if(ofGetMousePressed()) {
+ int frameLength = 1000 * ofGetLastFrameTime();
+ ofSetColor(frameLength > 10 ? ofColor::red : ofColor::green);
+ ofDrawBitmapString(ofToString(frameLength) + " ms", 10, 20);
+ }
+}
+
+void testApp::keyPressed(int key) {
+ if(key == OF_KEY_UP) {
+ curScene--;
+ }
+ if(key == OF_KEY_DOWN) {
+ curScene++;
+ }
+ curScene = ofClamp(curScene, 0, scenes.size() - 1);
+}
View
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "ofMain.h"
+
+#include "OrigScene.h"
+#include "GridScene.h"
+#include "LensScene.h"
+#include "BallScene.h"
+#include "VoroScene.h"
+#include "FracScene.h"
+#include "WindScene.h"
+#include "BoidScene.h"
+#include "WallScene.h"
+#include "RectScene.h"
+#include "DotsScene.h"
+
+class testApp : public ofBaseApp {
+public:
+ void setup();
+ void update();
+ void draw();
+ void keyPressed(int key);
+
+ vector<Scene*> scenes;
+ int curScene;
+};
@@ -0,0 +1,33 @@
+uniform sampler2DRect points;
+uniform int count;
+
+const int subdivisions = 16;
+const float lineWidth = .5;
+
+const float TWO_PI = 6.28318531;
+// res has to be an integer divided by TWO_PI
+// it can be scaled by count, but has to be scaled using an integer divide
+const float res = float(subdivisions) / TWO_PI;
+
+vec4 getPoint(int i) {
+ // need .5 offset to lookup the middle of the bin
+ vec2 st = vec2(.5 + float(i), 0.);
+ return texture2DRect(points, st);
+}
+
+float xorMix(bool a, bool b) {
+ return a ? (b ? .5 : 1.) : (b ? 0. : .5);
+}
+
+void main(void) {
+ vec2 xy = gl_TexCoord[0].xy;
+ vec2 field = vec2(0, 0);
+ for(int i = 0; i < count; i++) {
+ vec2 d = xy - getPoint(i).xy;
+ field.x += atan(d.y, d.x);
+ field.y += log(length(d));
+ }
+ vec2 mfield = mod(field * res, 1.);
+ float b = xorMix(mfield.x < lineWidth, mfield.y < lineWidth);
+ gl_FragColor = vec4(b, b, b, 1.);
+}
@@ -0,0 +1,20 @@
+uniform sampler2DRect tex;
+uniform float radius;
+
+const float total = (1. + 8. + 28. + 56.) * 2. + 70.;
+
+void main(void) {
+ vec2 st = gl_TexCoord[0].st;
+
+ gl_FragColor = (1. / total) * texture2DRect(tex, st - radius * vec2(4. / 4., 0.));
+ gl_FragColor += (8. / total) * texture2DRect(tex, st - radius * vec2(3. / 4., 0.));
+ gl_FragColor += (28. / total) * texture2DRect(tex, st - radius * vec2(2. / 4., 0.));
+ gl_FragColor += (56. / total) * texture2DRect(tex, st - radius * vec2(1. / 4., 0.));
+
+ gl_FragColor += (70. / total) * texture2DRect(tex, st);
+
+ gl_FragColor += (1. / total) * texture2DRect(tex, st + radius * vec2(4. / 4., 0.));
+ gl_FragColor += (8. / total) * texture2DRect(tex, st + radius * vec2(3. / 4., 0.));
+ gl_FragColor += (28. / total) * texture2DRect(tex, st + radius * vec2(2. / 4., 0.));
+ gl_FragColor += (56. / total) * texture2DRect(tex, st + radius * vec2(1. / 4., 0.));
+}
@@ -0,0 +1,49 @@
+uniform sampler2DRect points;
+uniform int count;
+
+const float TWO_PI = 6.28318530;
+
+const float spacing = .1;
+const float lineWidth = .5;
+const float strength = .01;
+const float cutoff = spacing * lineWidth;
+const float offset = (spacing + cutoff) / 2.;
+
+vec4 getPoint(int i) {
+ // need .5 offset to lookup the middle of the bin
+ vec2 st = vec2(.5 + float(i), 0.);
+ return texture2DRect(points, st);
+}
+
+float xorMix(bool a, bool b) {
+ return a ? (b ? .5 : 1.) : (b ? 0. : .5);
+}
+
+void main(void) {
+ vec2 st = gl_TexCoord[0].st;
+ vec2 sto = st;
+
+ for(int i = 0; i < count; i++) {
+ vec4 cur = getPoint(i);
+ vec2 d = cur.st - st;
+
+ // euclidian distance
+ float distance = sqrt(d.x * d.x + d.y * d.y);
+ // manhattan distance
+ //float distance = abs(d.x) + abs(d.y);
+ // psychedelic distance
+ //float distance = sin((sin(TWO_PI * d.x) + sin(TWO_PI * d.y)) * TWO_PI);
+
+ float displacement = strength / (distance * distance);
+ if(displacement < distance) {
+ sto += normalize(d) * displacement;
+ } else {
+ gl_FragColor = vec4(0., 0., 0., 1.);
+ return;
+ }
+ }
+
+ vec2 m = mod(sto + offset, spacing);
+ float b = xorMix(m.x < cutoff, m.y < cutoff);
+ gl_FragColor = vec4(b, b, b, 1.);
+}
@@ -0,0 +1,13 @@
+uniform sampler2DRect lut, source;
+
+const float lutSize = 256.;
+
+void main(void) {
+ vec2 st = gl_TexCoord[0].st;
+ vec4 c = texture2DRect(source, st);
+ gl_FragColor = vec4(
+ texture2DRect(lut, vec2(lutSize * c.r, 0.)).r,
+ texture2DRect(lut, vec2(lutSize * c.g, 0.)).g,
+ texture2DRect(lut, vec2(lutSize * c.b, 0.)).b,
+ c.a);
+}
@@ -0,0 +1,39 @@
+uniform sampler2DRect points;
+uniform int count;
+
+const float banding = 10.;
+const float lineWidth = .33;
+
+vec2 getPoint(int i) {
+ // need .5 offset to lookup the middle of the bin
+ vec2 st = vec2(.5 + float(i), 0.);
+ return texture2DRect(points, st).xy;
+}
+
+float xorMix(bool a, bool b) {
+ return a ? (b ? .5 : 1.) : (b ? 0. : .5);
+}
+
+void main(void) {
+ vec2 p = gl_TexCoord[0].xy;
+
+ vec2 start, end;
+ float t;
+
+ end = getPoint(0);
+ for(int i = 1; i < count; i++) {
+ start = end;
+ end = getPoint(i);
+ vec2 b = end - start;
+ vec2 c = p - start;
+ if((b.x * c.y) - (b.y * c.x) > 0.) {
+ continue;
+ }
+ t = dot(b, c) / dot(b, b);
+ p = (b * t + start) * 2. - p;
+ }
+
+ p = mod(p * banding, 1.);
+ float b = xorMix(p.x < lineWidth, p.y < lineWidth);
+ gl_FragColor = vec4(b, b, b, 1.);
+}
@@ -0,0 +1,32 @@
+uniform sampler2DRect remap, scene, shoji, lut;
+uniform float weight;
+uniform vec2 sceneOffset;
+uniform float sceneScale;
+
+const float topBoundary = 2.; // ignore the top couple pixels
+const vec2 remapSize = vec2(1., .75);
+const vec2 sceneSize = vec2(1024., 1024.);
+const float lutSize = 256.;
+
+void main(void) {
+ vec2 target = (texture2DRect(remap, gl_TexCoord[0].st).rg * remapSize - sceneOffset) / sceneScale;
+ if(target.x > 1. || target.x < 0. ||
+ target.y > 1. || target.y < 0. ||
+ gl_TexCoord[0].t < topBoundary) {
+ gl_FragColor = vec4(0, 0, 0, 1);
+ } else {
+ target *= sceneSize;
+ vec4 mul;
+ if(weight > 0.) {
+ mul = texture2DRect(shoji, target);
+ } else {
+ mul = 1. - texture2DRect(shoji, target);
+ }
+ gl_FragColor = texture2DRect(scene, target) * mul;
+ gl_FragColor = vec4(
+ texture2DRect(lut, vec2(lutSize * gl_FragColor.r, 0.)).r,
+ texture2DRect(lut, vec2(lutSize * gl_FragColor.g, 0.)).g,
+ texture2DRect(lut, vec2(lutSize * gl_FragColor.b, 0.)).b,
+ 1.);
+ }
+}
@@ -0,0 +1,20 @@
+uniform sampler2DRect tex;
+uniform float radius;
+
+const float total = (1. + 8. + 28. + 56.) * 2. + 70.;
+
+void main(void) {
+ vec2 st = gl_TexCoord[0].st;
+
+ gl_FragColor = (1. / total) * texture2DRect(tex, st - radius * vec2(0., 4. / 4.));
+ gl_FragColor += (8. / total) * texture2DRect(tex, st - radius * vec2(0., 3. / 4.));
+ gl_FragColor += (28. / total) * texture2DRect(tex, st - radius * vec2(0., 2. / 4.));
+ gl_FragColor += (56. / total) * texture2DRect(tex, st - radius * vec2(0., 1. / 4.));
+
+ gl_FragColor += (70. / total) * texture2DRect(tex, st);
+
+ gl_FragColor += (1. / total) * texture2DRect(tex, st + radius * vec2(0., 4. / 4.));
+ gl_FragColor += (8. / total) * texture2DRect(tex, st + radius * vec2(0., 3. / 4.));
+ gl_FragColor += (28. / total) * texture2DRect(tex, st + radius * vec2(0., 2. / 4.));
+ gl_FragColor += (56. / total) * texture2DRect(tex, st + radius * vec2(0., 1. / 4.));
+}
@@ -0,0 +1,40 @@
+uniform sampler2DRect points;
+uniform int count;
+const float TWO_PI = 6.283185;
+
+vec4 getPoint(int i) {
+ // need .5 offset to lookup the middle of the bin
+ vec2 st = vec2(.5 + float(i), 0.);
+ return texture2DRect(points, st);
+}
+
+void main(void) {
+ vec2 st = gl_TexCoord[0].st;
+ int minIndex = 0;
+ float minDistance = 0.;
+ for(int i = 0; i < count; i++) {
+ vec4 cur = getPoint(i);
+ float dx = cur.x - st.x;
+ float dy = cur.y - st.y;
+
+ // euclidian distance
+ float distance = dx * dx + dy * dy;
+ // manhattan distance
+ //float distance = abs(dx) + abs(dy);
+ // psychedelic distance
+ //float distance = sin((sin(TWO_PI * dx) + sin(TWO_PI * dy)) * TWO_PI);
+
+ if(i == 0 || distance < minDistance) {
+ minDistance = distance;
+ minIndex = i;
+ }
+ }
+ float b = getPoint(minIndex).b;
+
+ // standard shading
+ gl_FragColor = vec4(b, b, b, 1);
+ // circular patterns
+ //gl_FragColor = vec4(mod(st.x + st.y + mod(minDistance * 100., 1.) + b, 1.));
+ // crazy colors
+ //gl_FragColor = vec4(st.x, mod(minDistance * 10., 1.), b, 1);
+}

0 comments on commit 880780f

Please sign in to comment.