Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated to run with programmable renderer
- Loading branch information
1 parent
1e1f036
commit 3850e47
Showing
14 changed files
with
188 additions
and
55 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#version 330 | ||
|
||
out vec4 fragColor; | ||
|
||
void main() | ||
{ | ||
fragColor = vec4(1.0, 1.0, 1.0, 0.1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#version 330 | ||
|
||
uniform mat4 modelViewProjectionMatrix; | ||
uniform sampler2DRect particles0; | ||
uniform sampler2DRect particles1; | ||
|
||
in vec4 position; | ||
in vec2 texcoord; | ||
|
||
out vec2 texCoordVarying; | ||
|
||
void main() | ||
{ | ||
texCoordVarying = texcoord; | ||
gl_Position = modelViewProjectionMatrix * vec4(texture(particles0, texCoordVarying).xyz, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#version 330 | ||
|
||
// ping pong inputs | ||
uniform sampler2DRect particles0; | ||
uniform sampler2DRect particles1; | ||
|
||
uniform vec3 mouse; | ||
uniform float radiusSquared; | ||
uniform float elapsed; | ||
|
||
in vec2 texCoordVarying; | ||
|
||
layout(location = 0) out vec4 posOut; | ||
layout(location = 1) out vec4 velOut; | ||
|
||
void main() | ||
{ | ||
vec3 pos = texture(particles0, texCoordVarying.st).xyz; | ||
vec3 vel = texture(particles1, texCoordVarying.st).xyz; | ||
|
||
// mouse attraction | ||
vec3 direction = mouse - pos.xyz; | ||
float distSquared = dot(direction, direction); | ||
float magnitude = 500.0 * (1.0 - distSquared / radiusSquared); | ||
vec3 force = step(distSquared, radiusSquared) * magnitude * normalize(direction); | ||
|
||
// gravity | ||
force += vec3(0.0, -0.5, 0.0); | ||
|
||
// accelerate | ||
vel += elapsed * force; | ||
|
||
// bounce off the sides | ||
vel.x *= step(abs(pos.x), 512.0) * 2.0 - 1.0; | ||
vel.y *= step(abs(pos.y), 384.0) * 2.0 - 1.0; | ||
|
||
// damping | ||
vel *= 0.995; | ||
|
||
// move | ||
pos += elapsed * vel; | ||
|
||
posOut = vec4(pos, 1.0); | ||
velOut = vec4(vel, 0.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#version 330 | ||
|
||
in vec4 position; | ||
in vec2 texcoord; | ||
|
||
out vec2 texCoordVarying; | ||
|
||
void main() | ||
{ | ||
texCoordVarying = texcoord; | ||
gl_Position = position; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
#include "ofMain.h" | ||
#include "testApp.h" | ||
#include "ofApp.h" | ||
#include "ofAppGlutWindow.h" | ||
|
||
//======================================================================== | ||
int main( ){ | ||
|
||
int main() | ||
{ | ||
#ifdef _PROGRAMMABLE_RENDERER | ||
ofGLFWWindowSettings settings; | ||
settings.setGLVersion(4, 1); | ||
settings.width = 1024; | ||
settings.height = 768; | ||
ofCreateWindow(settings); | ||
#else | ||
ofAppGlutWindow window; | ||
ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context | ||
|
||
// this kicks off the running of my app | ||
// can be OF_WINDOW or OF_FULLSCREEN | ||
// pass in width and height too: | ||
ofRunApp( new testApp()); | ||
|
||
ofSetupOpenGL(&window, 1024,768, OF_WINDOW); | ||
#endif | ||
ofRunApp(new ofApp()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.