diff options
| -rw-r--r-- | gui/.DS_Store | bin | 8196 -> 8196 bytes | |||
| -rw-r--r-- | keyshade/bin/data/shader.frag | 21 | ||||
| -rw-r--r-- | keyshade/bin/data/shader.vert | 7 | ||||
| -rw-r--r-- | keyshade/src/ofApp.cpp | 15 | ||||
| -rw-r--r-- | keyshade/src/ofApp.h | 11 |
5 files changed, 32 insertions, 22 deletions
diff --git a/gui/.DS_Store b/gui/.DS_Store Binary files differindex c14ff44..db06893 100644 --- a/gui/.DS_Store +++ b/gui/.DS_Store diff --git a/keyshade/bin/data/shader.frag b/keyshade/bin/data/shader.frag index 7dbf468..560766b 100644 --- a/keyshade/bin/data/shader.frag +++ b/keyshade/bin/data/shader.frag @@ -3,13 +3,15 @@ uniform vec4 keyColour; uniform float keyMinDist; uniform float keyMaxDist; +uniform float time; // these are our textures uniform sampler2DRect backgroundTex; uniform sampler2DRect foregroundTex; // this comes from the vertex shader -in vec2 texCoordVarying; +in vec2 texCoordVarying1; +in vec2 texCoordVarying2; @@ -19,20 +21,13 @@ out vec4 outputColor; void main() { // Get color values from the background and foreground - vec4 back = texture(backgroundTex, texCoordVarying); - vec4 fore = texture(foregroundTex, texCoordVarying); + vec4 back = texture(backgroundTex, (texCoordVarying1 - 0.5) * time + (0.5 * time) ); + vec4 fore = texture(foregroundTex, texCoordVarying1); - // get alpha from mask - float mask = texture(backgroundTex, texCoordVarying).r; - - vec4 delta = back - keyColour; + vec4 delta = fore - keyColour; float distance2 = dot( delta, delta ); - float weight = clamp( (distance2 - keyMinDist) / (keyMaxDist - keyMinDist) ,0.0,1.0); - - //float4 transparent = IN.color; - //transparent.w = 0; - //OUT.color = lerp( transparent, IN.color, weight ); + float weight = clamp( (distance2 - keyMinDist) / (keyMaxDist - keyMinDist), 0.0, 1.0); //mix colors from background and foreground based on the mask value - outputColor = mix(fore , back, weight); + outputColor = mix(back, fore, weight); } diff --git a/keyshade/bin/data/shader.vert b/keyshade/bin/data/shader.vert index 0e63995..df91b35 100644 --- a/keyshade/bin/data/shader.vert +++ b/keyshade/bin/data/shader.vert @@ -7,10 +7,13 @@ in vec4 position; in vec2 texcoord; // texture coordinates are sent to fragment shader -out vec2 texCoordVarying; +out vec2 texCoordVarying1; +out vec2 texCoordVarying2; void main() { - texCoordVarying = texcoord; + texCoordVarying1 = texcoord; + //texCoordVarying = (texcoord - 0.5); ///(2.0f+sin(time)); + //texCoords = (texCoords - 0.5) * scale + (0.5 * scale); gl_Position = modelViewProjectionMatrix * position; }
\ No newline at end of file diff --git a/keyshade/src/ofApp.cpp b/keyshade/src/ofApp.cpp index 9adae87..588557a 100644 --- a/keyshade/src/ofApp.cpp +++ b/keyshade/src/ofApp.cpp @@ -4,7 +4,7 @@ void ofApp::setup(){ shader.load("shader"); backgroundImage.load("../../../gui/bin/data/funfair/IMG_2893.JPG"); - foregroundImage.load("../../../gui/bin/data/funfair/IMG_2894.JPG"); + foregroundImage.load("../../../gui/bin/data/funfair/IMG_2890.JPG"); maskFbo.allocate(ofGetWidth(), ofGetHeight()); @@ -14,8 +14,8 @@ void ofApp::setup(){ ofClear(0,0,0,255); maskFbo.end(); - keyMinDist=0.2f; - keyMaxDist=0.3f; + keyMinDist=0.1f; + keyMaxDist=0.2f; keyColour=ofColor(200,40,0); } @@ -34,7 +34,8 @@ void ofApp::draw(){ shader.begin(); shader.setUniform4f("keyColour",keyColour); shader.setUniform1f("keyMinDist",keyMinDist); - shader.setUniform4f("keyMaxDist",keyMaxDist); + shader.setUniform1f("keyMaxDist",keyMaxDist); + shader.setUniform1f("time",2.0f+sin(ofGetElapsedTimef())); shader.setUniformTexture("backgroundTex", backgroundImage.getTexture(), 1 ); shader.setUniformTexture("foregroundTex", foregroundImage.getTexture(), 2 ); @@ -65,9 +66,9 @@ void ofApp::mouseDragged(int x, int y, int button){ //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ - keyColour = backgroundImage.getColor( - x*(backgroundImage.getWidth()/ofGetWidth()), - y*(backgroundImage.getHeight()/ofGetHeight()) + keyColour = foregroundImage.getColor( + x*(foregroundImage.getWidth()/ofGetWidth()), + y*(foregroundImage.getHeight()/ofGetHeight()) ); } diff --git a/keyshade/src/ofApp.h b/keyshade/src/ofApp.h index 8774291..b9c5f19 100644 --- a/keyshade/src/ofApp.h +++ b/keyshade/src/ofApp.h @@ -5,6 +5,17 @@ /* click on the image to choose a colour (maybe draw a line or outline a range of colours?) +works really well. now, how to appy a transform + +this approach maps the whole image onto the whole screen. +the texcoords come from the vertex shader? +I suppose that it's necessary to add extra transforms and extract +extra texcoords from the vertex shader + +although it'd be possible to use a simplistic shader in this way +and create the scaled textures normally as Fbos + +need a tutorial on transforming textures using the GPU */ class ofApp : public ofBaseApp{ |
