示例#1
0
ofxFluid::ofxFluid(){
    passes = 1;
    internalFormat = GL_RGBA;
    
    // ADVECT
    fragmentShader = STRINGIFY(uniform sampler2DRect tex0;         // Real obstacles
                               uniform sampler2DRect backbuffer;
                               uniform sampler2DRect VelocityTexture;
                               
                               uniform float TimeStep;
                               uniform float Dissipation;
                               
                               void main(){
                                   vec2 st = gl_TexCoord[0].st;
                                   
                                   float solid = texture2DRect(tex0, st).r;
                                   
                                   if (solid > 0.1) {
                                       gl_FragColor = vec4(0.0,0.0,0.0,0.0);
                                       return;
                                   }
                                   
                                   vec2 u = texture2DRect(VelocityTexture, st).rg;
                                   vec2 coord =  st - TimeStep * u;
                                   
                                   gl_FragColor = Dissipation * texture2DRect(backbuffer, coord);
                               } 
示例#2
0
//--------------------------------------------------------------
void testApp::setup(){
    cam.initGrabber(640, 480);
    
    string fragmentShader = STRINGIFY(
        uniform float time;
        uniform sampler2DRect tex0;

        uniform float brightness;
        uniform float rows;

        void main(void){
            vec2 st = gl_TexCoord[0].st;
            vec2 uv = 0.5 + (1.0/st-0.5)*( (1.0-brightness) + brightness*sin(0.2*time) );

            vec3 col;

            col.r = texture2DRect(tex0, vec2(st.x+0.003,st.y)).r;
            col.g = texture2DRect(tex0, vec2(st.x+0.000,st.y)).g;
            col.b = texture2DRect(tex0, vec2(st.x-0.003,st.y)).b;

            col = clamp(col * 0.5 + 0.5 * col * col * 1.2,0.0,1.0);

            col *= 0.5 + 0.5 * 16.0 * uv.x * uv.y * (1.0-uv.x) * (1.0-uv.y);

            col *= vec3(0.8,1.0,0.7);

            col *= 0.9 + 0.1 * sin(10.0 * time + st.y * rows);

            col *= 0.97 + 0.03 * sin(110.0 * time);

            gl_FragColor = vec4(col,1.0);
        }
示例#3
0
void testApp::setupGL(int width, int height) {



    // FBOs

    maskFbo.allocate(width, height, GL_RGBA);

    fbo.allocate(width, height, GL_RGBA);



    maskFbo.begin();

        ofClear(0,0,0,255);

    maskFbo.end();



    fbo.begin();

        ofClear(0,0,0,255);

    fbo.end();



    // SHADER

    string shaderProgram = "#version 120\n \

    #extension GL_ARB_texture_rectangle : enable\n \

    \

    uniform sampler2DRect tex0;\

    uniform sampler2DRect maskTex;\

    \

    void main (void){\

    vec2 pos = gl_TexCoord[0].st;\

    \

    vec3 src = texture2DRect(tex0, pos).rgb;\

    float mask = texture2DRect(maskTex, pos).r;\

    \

    gl_FragColor = vec4( src , mask);\

    }";
示例#4
0
void vboxCConv()
{
    vec2 clrCoordY = vec2(gl_TexCoord[0]);
    vec2 clrCoordV = vec2(gl_TexCoord[1]);
    int ixY = int(clrCoordY.x);
    vec2 coordY = vec2(float(ixY), clrCoordY.y);
    int ixV = int(clrCoordV.x);
    vec2 coordV = vec2(float(ixV), clrCoordV.y);
    vec4 clrY = texture2DRect(uSrcTex, coordY);
    vec4 clrV = texture2DRect(uVTex, coordV);
    vec4 clrU = texture2DRect(uUTex, coordV);
    float partY = clrCoordY.x - float(ixY);
    float partVU = clrCoordV.x - float(ixV);
    float y;
    float v;
    float u;
    if(partY < 0.25)
    {
        y = clrY.b;
    }
    else if(partY < 0.5)
    {
        y = clrY.g;
    }
    else if(partY < 0.75)
    {
        y = clrY.r;
    }
    else
    {
        y = clrY.a;
    }

    if(partVU < 0.25)
    {
        v = clrV.b;
        u = clrU.b;
    }
    else if(partVU < 0.5)
    {
        v = clrV.g;
        u = clrU.g;
    }
    else if(partVU < 0.75)
    {
        v = clrV.r;
        u = clrU.r;
    }
    else
    {
        v = clrV.a;
        u = clrU.a;
    }
    vboxCConvApplyAYUV(vec4(u, y, 0.0, v));
}
示例#5
0
void main() {\
vec2 pos = gl_TexCoord[0].st;	\
vec4 srcColorBlur = texture2DRect(srcBlur, pos);\
if(srcColorBlur.a > 0.) {\
vec3 srcColor = texture2DRect(src, pos).rgb;\
vec4 dstColorBlur = texture2DRect(dstBlur, pos);\
vec3 offset = (dstColorBlur.rgb - srcColorBlur.rgb);\
gl_FragColor = vec4(srcColor + offset, 1.);\
} else {\
gl_FragColor = vec4(0.);\
}\
}";
示例#6
0
void main(){
	vec2 pos = gl_TexCoord[0].xy;
	vec4 color0 = texture2DRect(texture0, pos);
	vec4 color1 = texture2DRect(texture1, pos);
	//Compute resulted color
	vec4 color;
	color.rgb = color0.rgb;
	color.a = color1.r;

	//Output of the shader
	gl_FragColor = color;
}
 void main(){
     vec2 st = gl_TexCoord[0].st;
     vec4 color = texture2DRect(prevTexture, st);
     
     if ( abs(st.x - offset) < dispersion ){
         vec2 srcSt = vec2(mouse.x,st.y);
         float noise = noise2f( vec2(st.x*time*0.3,st.y) * grainSize );
         srcSt.x += dispersion * noise*2.0;
         vec4 srcColor = texture2DRect(srcTexture, srcSt);
         color = mix(color,srcColor, noise );
     }
     
     gl_FragColor = color;
 });
示例#8
0
 void main(){
     vec2 st = gl_TexCoord[0].st;
     vec4 color = texture2DRect(backBuffer, st);
     
     if ( abs(st.x - dstHeader) < srcHeader.y ){
         vec2 srcSt = vec2(srcHeader.x,st.y);
         float noise = noise2f( vec2(st.x*abs(sin(time*0.061))*3.1,st.y) * grainSize );
         srcSt.x += srcHeader.y * noise*2.0;
         vec4 srcColor = texture2DRect(tex0, srcSt);
         color = mix(color,srcColor, noise );
     }
     
     gl_FragColor = color;
 });
示例#9
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofEnableAlphaBlending();
    int camWidth 		= 320;	// try to grab at this size. 
	int camHeight 		= 240;
    
    vidGrabber.setVerbose(true);
	vidGrabber.setup(camWidth,camHeight);
    
    fingerMovie.load("fingers.mov");
	fingerMovie.play();
    
    logoImg.load("colors.jpg");
    multimaskImg.load("mask.jpg");
    
    fbo.allocate(camWidth,camHeight);
    maskFbo.allocate(camWidth,camHeight);
    
    //ofSetWindowShape(camWidth, camHeight*2);
    
    // There are 3 of ways of loading a shader:
    //
    //  1 - Using just the name of the shader and ledding ofShader look for .frag and .vert: 
    //      Ex.: shader.load( "myShader");
    //
    //  2 - Giving the right file names for each one: 
    //      Ex.: shader.load( "myShader.vert","myShader.frag");
    //
    //  3 - And the third one is passing the shader programa on a single string;
    //      In this particular example we are using STRINGIFY which is a handy macro
    string shaderProgram = STRINGIFY(
                                     uniform sampler2DRect tex0;
                                     uniform sampler2DRect tex1;
                                     uniform sampler2DRect tex2;
                                     uniform sampler2DRect maskTex;

                                     void main (void){
                                         vec2 pos = gl_TexCoord[0].st;
                                         
                                         vec4 rTxt = texture2DRect(tex0, pos);
                                         vec4 gTxt = texture2DRect(tex1, pos);
                                         vec4 bTxt = texture2DRect(tex2, pos);
                                         vec4 mask = texture2DRect(maskTex, pos);
                                         
                                         vec4 color = vec4(0,0,0,0);
                                         color = mix(color, rTxt, mask.r );
                                         color = mix(color, gTxt, mask.g );
                                         color = mix(color, bTxt, mask.b );
                                         
                                         gl_FragColor = color;
                                     }
示例#10
0
文件: ofxWater.cpp 项目: hysysk/ofxFX
ofxWater::ofxWater(){
    passes = 1;
    internalFormat = GL_RGBA32F ;

    density = 0.995;
    
    fragmentShader = STRINGIFY(
    uniform sampler2DRect backbuffer;   // previus buffer
    uniform sampler2DRect tex0;         // actual buffer
                               
    //  This two are not going to be used in this shader
    //  but are need to tell ofxFXObject that need to create them
    //
    uniform sampler2DRect tex1;         // is going to be the background
    uniform sampler2DRect tex2;         // is going to be the render FBO
    
    uniform float damping;
    
    vec2 offset[4];
    
    void main(){
        vec2 st = gl_TexCoord[0].st;
        
        offset[0] = vec2(-1.0, 0.0);
        offset[1] = vec2(1.0, 0.0);
        offset[2] = vec2(0.0, 1.0);
        offset[3] = vec2(0.0, -1.0);
        
        //  Grab the information arround the active pixel
        //
        //      [3]
        //
        //  [0]  st  [1]
        //
        //      [2]
        
        vec3 sum = vec3(0.0, 0.0, 0.0);
        
        for (int i = 0; i < 4 ; i++){
            sum += texture2DRect(tex0, st + offset[i]).rgb;
        }
        
        //  make an average and substract the center value
        //
        sum = (sum / 2.0) - texture2DRect(backbuffer, st).rgb;
        sum *= damping;
        
        gl_FragColor = vec4(sum, 1.0);
    } );
 void main (void){
     vec2 pos = gl_TexCoord[0].st;
      
     vec4 rTxt = texture2DRect(tex0, pos);
     //vec4 gTxt = texture2DRect(tex1, pos);
    // vec4 bTxt = texture2DRect(tex2, pos);
     vec4 mask = texture2DRect(maskTex, pos);
      
     vec4 color = vec4(0,0,0,255);
     //color = mix(color, rTxt, mask );
     //color = mix(color, gTxt, mask.g );
     //color = mix(color, bTxt, mask.b );
      color = rTxt * mask;
     gl_FragColor = color;
 }
示例#12
0
string Threshold::getShaderCode() const
{
#define _S(src) #src
	
	const char *fs = _S(
						uniform sampler2DRect tex;
						uniform float near_value;
						uniform float far_value;
						uniform float left;
						uniform float right;
						uniform float top;
						uniform float bottom;
						
						void main()
						{
							vec2 coord = gl_TexCoord[0].st;
							if(coord.x < left || right <= coord.x || coord.y < top || bottom <= coord.y) {
								discard;
							}
							float c = texture2DRect(tex, coord).r;
							if(c < near_value || far_value <= c) {
								discard;
							}
							gl_FragColor = vec4(1.);
						}
 void main (void){
     vec2 pos = gl_TexCoord[0].st;
     pos += offset;
     pos *= scale;
     vec4 rTxt = texture2DRect(tex, pos);
     gl_FragColor = rTxt;
 }
示例#14
0
void main(){
	vec2 pos = gl_TexCoord[0].xy;
	
	vec4 color0 = texture2DRect(texture0, pos);
	vec4 color1 = texture2DRect(texture1, pos);
	
	vec4 color;
	/********************
	note that default value of "a" is zero.
	********************/
	// color = color0;
	color = (color0 + color1) / 2;
	// color.ba = color0.ba;

	//Output of the shader
	gl_FragColor = color;
}
示例#15
0
 void main( void ) {
     float c;
     vec2 p = (gl_FragCoord.xy - 0.5 * resolution.xy) / resolution.y;//-1~+1の座標系
     float s = sin(time * 2.75 + p.x * 10. * p.y);
     float ratio = resolution.x / resolution.y;
     float halfRatio = ratio / 2.;
     for(int i = 0; i < size; i++){
         vec4 o_s = texture2DRect(positionTexture_S, vec2(i + .5, 0.));
         vec4 o_l = texture2DRect(positionTexture_L, vec2(i + .5, 0.));
         vec4 o = vec4(vec2(o_s.xy + o_l.xy) / 2., o_s.z, o_s.w);
         o.x = o.x * ratio - halfRatio;
         o.y = (o.y - 0.5);
         float mag = o.z * 10.;
         c += (10. * o.z * o_s.w + 1) * 0.005 * 5./*mag*/ * (0.5 + 0.1 * s)  / length(p - o.xy);//dot(p - o.xy, p - o.xy);
     }
     gl_FragColor = vec4(c, c, c, c);
 });
示例#16
0
void main() {\
	vec2 pos = gl_TexCoord[0].st;\
	vec4 cur = texture2DRect(tex, pos);\
	if(cur.r * cur.g * cur.b == 1.) {\
		gl_FragColor = vec4(0.);\
	} else {\
		gl_FragColor = cur;\
	}\
}"; 
示例#17
0
 void main(void) {\
 vec2 st = gl_TexCoord[0].st;\
 vec4 color;\
 color += 1.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * 4.0));\
 color += 2.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * 3.0));\
 color += 3.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * 2.0));\
 color += 4.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * 1.0));\
 color += 5.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt) );\
 color += 4.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * -1.0));\
 color += 3.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * -2.0));\
 color += 2.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * -3.0));\
 color += 1.0 * texture2DRect(src_tex_unit0, st + vec2(0.0, amt * -4.0));\
 color /= 25.0;\
 gl_FragColor = color;\
 }";
 void main()\
 {\
     vec4 color;\
     color += 1.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * 4.0));\
     color += 2.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * 3.0));\
     color += 3.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * 2.0));\
     color += 4.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * 1.0));\
     color += 5.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt));\
     color += 4.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * -1.0));\
     color += 3.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * -2.0));\
     color += 2.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * -3.0));\
     color += 1.0 * texture2DRect(tex0, texCoordVarying + vec2(0.0, blurAmnt * -4.0));\
     color /= 25.0;\
     gl_FragColor = color;\
 }";
示例#19
0
void GreycGPU::InitShaders()
{
	bool bMissingAtan2 = false;
	if(IIRShader.m_iHandle == 0)
	{
		if(!gpu.TestCompileShader("atan2 test", "void main(void) { atan2(1.0, 1.0); }"))
		{
			bMissingAtan2 = true;
			printf("Enabling ATI atan2 workaround\n");
		}

		/*
		 * Implement:
		 * const float xc = img(x,y,z,v);
		 * const float xp = img(x-1, y,z,v);
		 * const float yp = prev(x-1,y,z,v);
		 * const float yb = prev(x-2,y,z,v);
		 * result = a0*xc + a1*xp - b1*yp - b2*yb;
		 *
		 * where prev is the output of the previous column.  This needs to be ping-ponged for
		 * each column.
		 *
		 * dir.xy is the step to the previous column (or row).  dir.zw = dir.xy * 2, to step
		 * to the column before that.
		 * w.xyzw = { a0, a1, b1, b2 }.
		 */

		string sIIRProgram =
"#extension GL_ARB_texture_rectangle : require\n"
"uniform sampler2DRect img; \
uniform sampler2DRect prev; \
uniform vec4 dir; \
uniform vec4 w; \
void main(void) \
{ \
	vec4 xc = texture2DRect(img, gl_TexCoord[0].xy); \
	vec4 xp = texture2DRect(img, gl_TexCoord[0].xy + dir.xy); \
	vec4 yp = texture2DRect(prev, gl_TexCoord[0].xy + dir.xy); \
	vec4 yb = texture2DRect(prev, gl_TexCoord[0].xy + dir.zw); \
	gl_FragColor = w.x*xc + w.y*xp - w.z*yp - w.w*yb; \
}";
		IIRShader.m_iHandle = gpu.CompileShader("IIR shader", sIIRProgram);
}
void main(){
	vec2 pos = gl_TexCoord[0].st;
	vec4 color = texture2DRect(texture, pos);
	
	// gl_FragColor = color;
	gl_FragColor = color * BaseColor;
	// gl_FragColor = BaseColor;
	
	// gl_FragColor = gl_Color;
}
示例#21
0
void main() {\
vec2 pos = gl_TexCoord[0].st;\
vec4 sum = texture2DRect(tex, pos);\
int i;\
for(i = 1; i < k; i++) {\
vec2 curOffset = float(i) * direction;\
vec4 leftMask = texture2DRect(mask, pos - curOffset);\
vec4 rightMask = texture2DRect(mask, pos + curOffset);\
bool valid = leftMask.r == 1. && rightMask.r == 1.;\
if(valid) {\
sum +=\
texture2DRect(tex, pos + curOffset) +\
texture2DRect(tex, pos - curOffset);\
} else {\
break;\
}\
}\
int samples = 1 + (i - 1) * 2;\
gl_FragColor = sum / float(samples);\
}";
示例#22
0
 void main()
 {
     vec4 col = texture2DRect(tex, gl_TexCoord[0].xy);
     float value = col.r;
     float low1 = 500.0;
     float high1 = 5000.0;
     float low2 = 1.0;
     float high2 = 0.0;
     float d = clamp(low2 + (value - low1) * (high2 - low2) / (high1 - low1), 0.0, 1.0);
     if (d == 1.0) {
         d = 0.0;
     }
     gl_FragColor = vec4(vec3(d), 1.0);
 }
示例#23
0
ofxShaderObj::ofxShaderObj():nTextures(0){
    // Simple effect just need this three variables
    // For something more complex that require another structure, logic or more shaders working together
    // think on making a new stand-alone class as the ofxBlur, ofxFluid, ofxGlow, etc ...
    // Collaborations are welcome

    passes.set("passes",1,1,20);
    passes = 1;                 // Number of itinerations needs. Default it´s 1;
    internalFormat = GL_RGBA;   // Tipe of GL textures

    // And the fragSahder it self. Note that are defaul variables:
    //
    // - time
    // - mouse position (normalized)
    // - resolution
    // - backbuffer texture
    // - tex0, tex1, tex2, ... : this are dynamicaly defined and allocated and can be
    //   filled with information by using .begin(0) and .end(0), or .begin(1) and .end(1), etc
    //
    // This dafault shader it's timer made of a mix on Ricardo Caballero's webGL Sandbox
    // http://mrdoob.com/projects/glsl_sandbox/
    //

    fragmentShader = "\n\
// \n\
// Empty Shader Patch for ofxComposer \n\
// by http://PatricioGonzalezVivo.com \n\
//\n\
// For quick GLSL prototyping this Patch have the next native variables\n\
//\n\
uniform sampler2DRect backbuffer;  // Previus frameBuffer \n\
uniform sampler2DRect tex0;        // Input texture number 0 \n\
                                   // You can add as many as you want\n\
                                   // just type name them 'tex'+ N\n\
\n\
uniform vec2  size0;               // tex0 resolution\n\
uniform vec2  resolution;          // Patch resolution\n\
uniform vec2  window;              // Window resolution\n\
uniform vec2  screen;              // Screen resolution\n\
uniform vec2  mouse;               // Mouse position on the screen\n\
uniform float time;                // seconds \n\
\n\
void main( void ){\n\
    vec2 st = gl_TexCoord[0].st;    // gl_FragCoord.st;\n\
    vec4 color = texture2DRect(tex0, st);\n\
    \n\
    gl_FragColor = vec4( color.rgb, color.a );\n\
}\n";
示例#24
0
void main(){

	//input line coordinates
	vec2 p0 = gl_PositionIn[0].xy; 
	vec2 p1 = gl_PositionIn[1].xy;

	//generate 50 lines and distort with perlin noise
	for (int i = 0; i < 50; i++){
		float x0 = snoise(vec4(p0 *3.0, time * 0.5 + 12.4, i));
		float y0 = snoise( vec4( p0 * 3.0, time * 0.5 + 304.2, i ) );
		float x1 = snoise( vec4( p1 * 3.0, time * 0.5 + 20.1,  i ) );
		float y1 = snoise( vec4( p1 * 3.0, time * 0.5 + 43.6,  i ) );
		vec2 q0 = p0 + vec2( x0, y0 ) * 25.0;
		vec2 q1 = p1 + vec2( x1, y1 ) * 25.0;

		//calculate color
		vec4 color = vec4(0.0);

		vec2 delta = q1 - q0;
		float len = distance( delta, vec2( 0.0 ) );
		if ( len > 0 ) {
			int n = int( len ) + 1;
			delta /= n;
			for (int i=0; i<n; i++) {
				color += texture2DRect( texture, q0 + delta * i );
			}
			color /= n;
		}

		color.a *= 0.4;	//Making output color transparent

		//output line
		gl_Position = gl_ModelViewProjectionMatrix * vec4(q0, 0.0, 1.0);	
		gl_FrontColor = color; 	//0 - left color, 1 - right color
		EmitVertex();

		gl_Position = gl_ModelViewProjectionMatrix * vec4(q1, 0.0, 1.0);	
		gl_FrontColor = color; 	//0 - left color, 1 - right color
		EmitVertex();
		EndPrimitive();
	}
		
}
示例#25
0
ofxShaderObj::ofxShaderObj():nTextures(0){
    // Simple effect just need this three variables
    // For something more complex that require another structure, logic or more shaders working together
    // think on making a new stand-alone class as the ofxBlur, ofxFluid, ofxGlow, etc ...
    // Collaborations are welcome
    
    passes = 1;                 // Number of itinerations needs. Default it´s 1;
    internalFormat = GL_RGBA;   // Tipe of GL textures 
    
    // And the fragSahder it self. Note that are defaul variables:
    //
    // - time
    // - mouse position (normalized)
    // - resolution
    // - backbuffer texture
    // - tex0, tex1, tex2, ... : this are dynamicaly defined and allocated and can be
    //   filled with information by using .begin(0) and .end(0), or .begin(1) and .end(1), etc 
    //
    // This dafault shader it´s timer made of a mix on Ricardo Caballero´s webGL Sandbox
    // http://mrdoob.com/projects/glsl_sandbox/
    //
    
    fragmentShader = "\n\
\n\
\n\
uniform float time;\n\
uniform vec2 mouse;\n\
uniform vec2 resolution;\n\
\n\
uniform sampler2DRect backbuffer;\n\
\n\
uniform sampler2DRect tex0;\n\
uniform vec2 size0;\n\
\n\
void main( void ){\n\
    vec2 st = (gl_FragCoord.xy / resolution.xy);\n\
    \n\
    vec4 color = texture2DRect(tex0, st);\n\
    \n\
    gl_FragColor = vec4( color.r, color.g, color.b, color.a );\n\
}\n\
示例#26
0
文件: ofApp.cpp 项目: firmread/parti
//--------------------------------------------------------------
void ofApp::setup() {
    ofSetFrameRate(60);
    posFbo.allocate(NUM_PARTICLES, 1, GL_RGB32F);
    for (int i = 0; i < NUM_PARTICLES; i ++) {
        pos[i].x = ofRandom(0, ofGetWidth());
        pos[i].y = ofRandom(0, ofGetHeight());
        float speed = ofRandom(0.5, 3.0);
        float angle = ofRandom(0.0, TWO_PI);
        vec[i].x = cos(angle) * speed;
        vec[i].y = sin(angle) * speed;
    }
    ofShader* shader;
    string shaderProgram;


    //--------------------------------------------------------------

    shader = new ofShader();
    shaderProgram = STRINGIFY(
                        uniform sampler2DRect tex0;
                        uniform sampler2DRect tex1;
                        uniform int numParticles;
                        uniform int width;
                        uniform int height;
    void main (void) {
        bool flag = false;
        for (int i = 0; i < numParticles; i ++) {
            vec2 posSample = texture2DRect(tex1, vec2(i, 0) + vec2(0.5, 0.5)).rg;
            posSample.r *= float(width);
            posSample.g *= float(height);
            float dist = distance(posSample, gl_TexCoord[0].st);
            if (dist < 3.0) {
                flag = true;
            }
        }
        gl_FragColor = (flag) ? vec4(1.0, 1.0, 0.0, 1.0) : vec4(0.0, 0.0, 0.0, 1.0);
    }
示例#27
0
//--------------------------------------------------------------
void ofApp::setup() {

    w = 640;
    h = 480;

    vidGrabber.setDeviceID(1);
    vidGrabber.setVerbose(true);
    vidGrabber.initGrabber(w, h);

    newTmpl.allocate(w, h);

    newTmplRect.allocate(w, h);

    newTmplRect.begin();
    ofClear(0, 0, 0, 0);
    newTmplRect.end();

    flagNewTmpl = false;

    newTmplX = -1;
    newTmplY = -1;
    newTmplXX = -1;
    newTmplYY = -1;

    n = 0;

    coeff = 0.5;

    coeffs = new float[num];

    for (int i = 0; i < num; ++i)
    {
        coeffs[i] = coeff * (0.6 + i * 0.4);
    }

    ww = w * coeff;
    hh = h * coeff;

    fbo.allocate(ww, hh);

    vidRect.allocate(w, h);

    vidRect.begin();
    ofClear(0, 0, 0, 0);
    vidRect.end();

    //////////////////////////////////////////////////////////////////////

    string shaderProgram = STRINGIFY(

                               uniform sampler2DRect map;
                               uniform sampler2DRect tmpl;

                               uniform float mat_y0;
                               uniform float mat_y1;
                               uniform float mat_y2;

                               uniform float w;
                               uniform float h;

                               uniform float ii;
                               uniform float ij;

    void main (void) {

        vec2 pos = gl_TexCoord[0].st;

        float mat_x0 = 0.0;
        float mat_x1 = 0.0;
        float mat_x2 = 0.0;

        int count = 0;

        for (int i = 0; i < int(w); i += int(ii) )
        {
            for (int j = 0; j < int(h); j+= int(ij) )
            {
                vec2 pos_rel = vec2(float(i), float(j));

                vec3 src_x = texture2DRect(map, vec2(pos + pos_rel)).rgb;
                vec4 src_y = texture2DRect(tmpl, pos_rel).rgba;

                mat_x0 += src_x[0];
                mat_x1 += src_x[1];
                mat_x2 += src_x[2];

                count ++;
            }
        }

        mat_x0 = mat_x0 / float(count);
        mat_x1 = mat_x1 / float(count);
        mat_x2 = mat_x2 / float(count);

        float c0 = 0.0;
        float c1 = 0.0;
        float c2 = 0.0;

        for (int i = 0; i < int(w); i += int(ii) )
        {
            for (int j = 0; j < int(h); j += int(ij) )
            {
                vec2 pos_rel = vec2(float(i), float(j));

                vec3 src_x = texture2DRect(map, vec2(pos + pos_rel)).rgb;
                vec4 src_y = texture2DRect(tmpl, pos_rel).rgba;

                float tmp_x0 = src_x[0] - mat_x0;
                float tmp_y0 = src_y[0] - mat_y0 / 255.0;

                float tmp_x1 = src_x[1] - mat_x1;
                float tmp_y1 = src_y[1] - mat_y1 / 255.0;

                float tmp_x2 = src_x[2] - mat_x2;
                float tmp_y2 = src_y[2] - mat_y2 / 255.0;

                c0 += tmp_x0 * tmp_y0 + tmp_x1 * tmp_y1 + tmp_x2 * tmp_y2;
                c1 += tmp_x0 * tmp_x0 + tmp_x1 * tmp_x1 + tmp_x2 * tmp_x2;
                c2 += tmp_y0 * tmp_y0 + tmp_y1 * tmp_y1 + tmp_y2 * tmp_y2;
            }

        }

        float corr = abs(c0) / sqrt(c1 * c2);

        gl_FragColor = vec4(corr, corr, corr, 1);
    }
示例#28
0
//--------------------------------------------------------------
void testApp::setup(){
    ofEnableAlphaBlending();
    ofSetVerticalSync(true);
    
    width = 640;
    height = 480;
    scale = 5;
    video.initGrabber(width, height);
    
    grayscale.allocate(width, height);
    blur.allocate(width, height);
    blur.setRadius(10);
    blur.setPasses(10);
    normals.allocate(width, height);
    
    timer = 0;
    
    for(int i = 0; i < 2; i++){
        pingpong[i].allocate(width,height);
        pingpong[i].begin();
        ofClear(0);
        pingpong[i].end();
    }
    
    string fragShader = STRINGIFY(uniform sampler2DRect backbuffer;
                                  uniform sampler2DRect normals;
                                  
                                  vec2 offset[9];
                                  
                                  void main(){
                                      vec2 st = gl_TexCoord[0].st;
                                      
                                      vec4 newFrame = texture2DRect(backbuffer, st);
                                      vec4 color = vec4(0,0,0,0);
                                      vec2 norm	= ( texture2DRect(normals, st).rg - 0.5 ) * 2.0;
                                      float inc	= ( abs(norm.x) + abs(norm.y) ) * 0.5;
                                      
                                      offset[0] = vec2(-1.0, -1.0);
                                      offset[1] = vec2(0.0, -1.0);
                                      offset[2] = vec2(1.0, -1.0);
                                      offset[3] = vec2(-1.0, 0.0);
                                      offset[4] = vec2(0.0, 0.0);
                                      offset[5] = vec2(1.0, 0.0);
                                      offset[6] = vec2(-1.0, 1.0);
                                      offset[7] = vec2(0.0, 1.0);
                                      offset[8] = vec2(1.0, 1.0);
                                      
                                      float sources = 0.0;
                                      for (int i = 0; i < 9; i++){
                                          if ( i != 4 ){
                                              vec4 goingTo = ( texture2DRect( normals, st + offset[i] ) - 0.5 ) * 2.0;
                                              vec2 match = vec2(goingTo.x + offset[9-i-1].x, goingTo.y + offset[9-i-1].y);
                                              
                                              if ( (match.x <= 1.0) && (match.x >= -1.0) && (match.y <= 1.0) && (match.y >= -1.0) ){
                                                  sources += 1.0;
                                                  color += texture2DRect(backbuffer, st + offset[i]);
                                              }
                                          }
                                      }
                                      
                                      color = color / sources;
                                      
                                      gl_FragColor = color*(1.0-inc) + newFrame*inc ;
                                  }
示例#29
0
//--------------------------------------------------------------
void ofApp::setup(){

    
    //for MBP 2014,front camera
    originCamWidth = 1280;
    originCamHeight = 720;
    
    //for MBA mid-2011,front camera
    originCamWidth = 640;
    originCamHeight = 480;

    
    camWidth = 240;
    camHeight = (int)camWidth * ((float)originCamHeight/(float)originCamWidth);
    

    displayscale = ofGetWindowWidth()/camWidth;
    
    ofBackground(0, 0, 0);
    ofShowCursor();
    
//    ofSetFrameRate(30);
//  ofSetVerticalSync(true);
    
//  cameraDeviceID(use another camera )
  vidGrabber.setDeviceID(0);
    
//    vidGrabber.setVerbose(true);
    vidGrabber.initGrabber(originCamWidth, originCamHeight);
    
    fbo.allocate(camWidth, camHeight, GL_RGB);
    
    
    //それぞれの映像情報の大きさを指定してあげます。
    colorImgHSV.allocate(camWidth, camHeight);
    
    hueImg.allocate(camWidth, camHeight);
    satImg.allocate(camWidth, camHeight);
    briImg.allocate(camWidth, camHeight);
    
    reds.allocate(camWidth, camHeight);
    
    //二値画像を作るための配列の大きさを指定
    colorTrackedPixelsRed =new unsigned char [camWidth*camHeight];
    
    //二値画像の大きさ
    trackedTextureRed.allocate(camWidth, camHeight, GL_LUMINANCE);
    


    smooth.set("smooth",5,1,91);
    threshold.set("threshold",0,0,256);
    mirror.set("mirror", true);
    
    displayset.setName("settings");
    displayset.add(smooth);
//    displayset.add(threshold);
    displayset.add(mirror);

    rangeset.setName("Ranges");
    rangeset.add(satMin[0].set("[0]satMin",24,0,255));
    rangeset.add(satMax[0].set("[0]satMax",200,0,255));
    rangeset.add(hueMin[0].set("[0]hueMin",12,0,255));
    rangeset.add(hueMax[0].set("[0]hueMax",12,0,255));

    rangeset.add(satMin[1].set("[1]satMin",24,0,255));
    rangeset.add(satMax[1].set("[1]satMax",200,0,255));
    rangeset.add(hueMin[1].set("[1]hueMin",12,0,255));
    rangeset.add(hueMax[1].set("[1]hueMax",12,0,255));
    

    
    colorset.setName("Pickup Color");
    colorset.add(track_hue[0].set("[0]trackhue",0,0,255));
    colorset.add(track_sat[0].set("[0]tracksat",0,0,255));
    colorset.add(track_bri[0].set("[0]trackbri",0,0,255));
    
    
    
    colorset.add(track_hue[1].set("[1]trackhue",0,0,255));
    colorset.add(track_sat[1].set("[1]tracksat",0,0,255));
    colorset.add(track_bri[1].set("[1]trackbri",0,0,255));
    
    displayset.add(rangeset);
    displayset.add(colorset);
    
    gui.setup(displayset);
    gui.setPosition(ofGetWindowWidth()- 200,0);
    gui.loadFromFile("settings.xml");
    
    
    

    /**
     * LightSaber Create
     */
    LightSaber l1,l2;
    ofColor c1,c2;
    
    c1.set(200, 200, 200);
    c2.set(200,20,20);
    

    l1.setup("LightSaber3.png",c1);
    l1.track.hue = track_hue[0];
    l1.track.sat = track_sat[0];
    l1.track.bri = track_bri[0];
    

    l2.setup("LightSaber3.png",c2);
    l2.track.hue = track_hue[1];
    l2.track.sat = track_sat[1];
    l2.track.bri = track_bri[1];
    
    
    ls.push_back(l1);
    ls.push_back(l2);
    
    

    
    SaberDelay _s;
    _s.pos1 = ofVec2f(0,0);
    _s.pos2 = ofVec2f(0,0);
    
    lostPosition.push_back(_s);
    lostPosition.push_back(_s);
    
    lostCount.push_back(0);
    lostCount.push_back(0);
    
    box.setup(camWidth * displayscale,camHeight * displayscale);
    for(int i = 0;i  <ls.size();i++){
        box.edges.push_back( ofPtr<ofxBox2dEdge>(new ofxBox2dEdge));
        box.edges.back().get()-> create(box.box2d.getWorld());
        box.edges.back().get()->setPhysics(0.0, 0.5, 0.5);
    }
    
    traceid = 0;
    


    
    
    
    // shader
    string shaderProgram = STRINGIFY(
                                     uniform sampler2DRect tex0; // これから描画するテクスチャが入っている
                                     uniform float brightness; // メインプログラムから渡された変数を受け取る
                                     
                                     void main (void){
                                         
                                         vec2 pos = gl_TexCoord[0].st; // テクスチャ上の座標を取得する
                                         
                                         float r = texture2DRect(tex0, pos).r;
                                         float g = texture2DRect(tex0, pos).g;
                                         float b = texture2DRect(tex0, pos).b;

                                         float a = texture2DRect(tex0, pos).a;
//                                         float h = texture2DRect(tex0,pos).hue;
  //                                       float s = texture2DRect(tex0,pos).sat;
    //                                     float b = texture2DRect(tex0,pos).bri*2;
                                         
                                         vec4 color = vec4(r,g,b,a);
                                         //vec4 color = vec4(h,s,b,a);

                                         
                                         gl_FragColor = color *brightness; // gl_FragColorの値が最終的に画面に出力される画素値になる。


                                     }
void FluidDynamicsApp::setup(ofFbo *fbo_) {

    setFBO(fbo_);
    
    _cloudBackground.setup(ofGetWidth(), ofGetHeight());
    
    OpenCVEngine::getInstance().setup();
    
    ofColor bg = ofColor(ofRandom(255), ofRandom(255), ofRandom(255));
    if (bg.getSaturation() < 127) bg.setSaturation(127);
//    bg.setSaturation(255);
    _colorManager.setBackground(bg);
    
    TrackedWall* wall = OpenCVEngine::getInstance().getWall(0);
    if (wall != NULL) _walls.push_back(wall);
    
    wall = OpenCVEngine::getInstance().getWall(1);
    if (wall != NULL) _walls.push_back(wall);
    
    _largeFbo.allocate(OpenCVEngine::getInstance().videoSourceWidth * 2, OpenCVEngine::getInstance().videoSourceHeight);
    _largeFbo.begin();
    ofClear(0, 0, 0, 0);
    ofSetColor(_colorManager.getBackground());
    ofRect(0, 0, _largeFbo.getWidth(), _largeFbo.getHeight());
    _largeFbo.end();
    
    _fluid.allocate(_largeFbo.getWidth(), _largeFbo.getHeight(), 0.5);
    
    _fluid.dissipation = 0.99;
    _fluid.velocityDissipation = 0.99;
    
    _fluid.setGravity(ofVec2f(0.0,0.0));
    
//    _fluid.begin();
//    ofSetColor(0,0);
//    ofSetColor(255);
//    ofCircle(width*0.5, height*0.35, 40);
//    _fluid.end();
    _fluid.setUseObstacles(false);
    
    ofFbo obstacleFbo;
    obstacleFbo.allocate(_largeFbo.getWidth(), _largeFbo.getHeight());
    obstacleFbo.begin();
    ofClear(0, 0, 0, 0);
    ofPushStyle();
    ofSetColor(255);
    ofRect(0, 0, _largeFbo.getWidth(), _largeFbo.getHeight());
    ofSetColor(0);
    int borderSize = 1;
    ofRect(borderSize, borderSize, _largeFbo.getWidth() - borderSize * 2, _largeFbo.getHeight() - borderSize * 2);
    ofPopStyle();
    obstacleFbo.end();
    
    _fluid.setObstacles(obstacleFbo);
    
    // Adding constant forces
    //    fluid.addConstantForce(ofPoint(width*0.15,height*0.5), ofPoint(2,0), ofFloatColor(0.5,0.1,0.0), 20.f);
    
//    fbo.allocate(width, height, GL_RGB, 4);
//    fbo.begin();
//    ofClear(0, 0, 0, 0);
//    fbo.end();
    
    // setup screen shader
    string shaderProgram = STRINGIFY(
                                     uniform sampler2DRect tex0; // this is how we receive the texture
                                     uniform vec4 blend;
                                     varying vec2 texCoordVarying;
                                     varying vec4 colorVarying;
                                     
                                     vec4 screen(vec4 base, vec4 blend) {
                                         return vec4(1.0) - (vec4(1.0) - blend) * (vec4(1.0) - base);
                                     }
                                     
                                     void main()
                                     {
                                         gl_FragColor = screen(texture2DRect(tex0, gl_TexCoord[0].st), blend);
                                     }