Exemple #1
0
    void setup() {
        ofEnableDepthTest();
        ofDisableArbTex();

        img.loadImage("img1.jpg");
        env.loadImage("env.jpg");
        env1.loadImage("env1.jpg");


        shader.load("material.vert","material.frag");
	model.loadModel("wolf.dae", true);
    }
Exemple #2
0
    void draw() {
        ofBackgroundGradient(64, 0);

	if(reflect || sreflect) 
		env.draw(0,0,env.getWidth()/8,env.getHeight()/8);
	if(sreflect) 
		env1.draw(env.getWidth()/8,0,env1.getWidth()/8,env1.getHeight()/8);

	ofEnableDepthTest();
        cam.begin();
        shader.begin();

	if(sreflect){
//        	shader.setUniform3f("CameraPos",cam.getGlobalPosition().x, cam.getGlobalPosition().y, cam.getGlobalPosition().z);
//		shader.setUniformMatrix4f("ModelWorld4x4",cam.getGlobalTransformMatrix());
        	shader.setUniform3f("CameraPos",cam.getPosition().x, cam.getPosition().y, cam.getPosition().z);
		shader.setUniformMatrix4f("ModelWorld4x4",cam.getModelViewMatrix());//getLocalTransformMatrix());
	        shader.setUniformTexture("frontMap",  env,1);
	        shader.setUniformTexture("backMap",  env1,2);
	}

	if(reflect){
        	shader.setUniformTexture("colorMap",env1,1);
	        shader.setUniformTexture("envMap",  env,2);
	}else if(sreflect==false){
        	shader.setUniformTexture("texture", img, 1);
        	shader.setUniform1f("time", ofGetElapsedTimef());
	}

	if(cube)
		ofDrawBox(200);
	else {
		ofTranslate(0,-150,0);
		ofRotateX(-90);
		ofRotateY(-90);
		ofRotateZ(45);
		model.drawFaces();
	}

        shader.end();
        cam.end();
	ofDisableDepthTest();

        ofDrawBitmapString(ofToString((int) ofGetFrameRate()), 10, 20);
    }
Exemple #3
0
		void draw() {
			ofBackground(25);

			fbo.begin();
			ofClear(0,0,0,0);
			ofEnableDepthTest();
			camera.begin();
			    glPushMatrix();

			    glEnable(GL_BLEND);
		        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
		        glEnable(GL_ALPHA_TEST);
		        glAlphaFunc(GL_GREATER, 0);

		        if(dvel) draw_velocity();
		        if(dden){
                        draw_density();
                }

                glDisable(GL_BLEND);
		        glDisable(GL_ALPHA_TEST);

		        glPopMatrix();
                if( drawAxis ){	ofDrawAxis(15); }

			camera.end();
			ofDisableDepthTest();
			fbo.end();

            shader.begin();
            shader.setUniformTexture("tex",fbo.getTextureReference(),0);
            shader.setUniform2f("resolution",dw,dh);
            shader.setUniform1f("timer",ofGetElapsedTimef());

            fbo.draw(0,0);

            shader.end();
			gui.draw();
		}
void ofxRGBDRenderer::setupProjectionUniforms(ofShader& theShader){

    rgbMatrix = (depthToRGBView * rgbProjection);
    ofVec2f dims = ofVec2f(currentRGBImage->getTextureReference().getWidth(), 
                           currentRGBImage->getTextureReference().getHeight());
    theShader.setUniform2f("fudge", xmult, ymult);
    theShader.setUniform2f("dim", dims.x, dims.y);
    
    glMatrixMode(GL_TEXTURE);
    glPushMatrix();
    glLoadMatrixf(rgbMatrix.getPtr());
    glMatrixMode(GL_MODELVIEW);      
}
void SPECTRUM_INDICATOR__TYPE_POINT::draw(ofShader& shader, float *spectrum)
{
	/********************
	********************/
	shader.setUniform4f("BaseColor", IndicatorColor);
	
	/********************
	********************/
	ofPushMatrix();
	ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
	
	float spectrum_out = spectrum[NUM_DISP_SPECTRUMS - 1];
	
	for(int id = 0; id < NUM_DISP_SPECTRUMS; id++){
		int x = (int)(id * IndicatorHoriSpace);
		
		spectrum_out = FreqFilter_k * spectrum[id] + (1 - FreqFilter_k) * spectrum_out;
		shader.setUniform1f( "DispTextureSize", IndicatorTextureSize + IndicatorGainSize * spectrum_out ); // 描画サイズ
		// shader.setUniform1f( "TextureSize", IndicatorTextureSize ); // 描画サイズ
		for(int y = 0; y <= ofGetHeight()/2; y+= IndicatorVertSpace){
			/********************
			********************/
			vbo_drawPoint(ofVec3f(x, y, 0));
			if(y != 0) vbo_drawPoint(ofVec3f(x, -y, 0));
			
			/********************
			********************/
			if(x != 0){
				vbo_drawPoint(ofVec3f(-x, y, 0));
				if(y != 0) vbo_drawPoint(ofVec3f(-x, -y, 0));
			}
		}
	}
	
	ofPopMatrix();
}
Exemple #6
0
void Dude::updateRenderer( ofShader & shader )
{
    // update the rendering matrices
    renderMats = animSys.getBoneMatrices();
    std::vector<float> boneLengths = animSys.getBoneLengths();
    
    for( int i = 0; i < animSys.getNumBones(); i++ )
    {
        renderMats[i].scale(1,1,boneLengths[i]);
        //renderMats[i].preTranslate(position);
        renderMats[i].invert();
    }
    
    // prepare rendering steer matrix
    renderSteerMatrix.identity();
    renderSteerMatrix.translate(position);
    renderSteerMatrix *= steerMatrix;
    //renderSteerMatrix.translate(-position);

    // set it up
    shader.setUniformMatrix4f("steerMatrix",ofMatrix4x4((float*)renderSteerMatrix.inverse()));
    shader.setUniform1f("blend_k",blend_k);
    shader.setUniformMatrix4f("box_mats", (ofMatrix4x4&) renderMats[0], renderMats.size());//
}
Exemple #7
0
		void setup() {
            ofSetFrameRate(60);
            ofSetVerticalSync(true);

            dw=ofGetScreenWidth();
			dh=ofGetScreenHeight();
			ofDisableArbTex();
            fbo.allocate(dw,dh);
            shader.load("shaders/fluid.vert","shaders/fluid.frag");

			camera.setFarClip(100000);
			camera.setNearClip(.1);
            if ( !allocate_data () ){
                    cout<<"error allocate!"<<endl;
                    exit();
			}
            clear_data ();

			gui.setup();
            gui.setPosition(ofPoint(10,10));

			gui.add(size_cube.setup("size box", 100.0f,0.0f,255.0f));
            gui.add(dvel.setup("draw velocity", true));
            gui.add(dden.setup("draw density",  false));

			gui.add(TaddSource.setup("add source",false));
			gui.add(Bclear.setup("clear source",false));

			gui.add(addX.setup("add x",false));
			gui.add(addY.setup("add y",false));
			gui.add(addZ.setup("add z",false));
			gui.add(dt.setup("time delta", 0.9f,0.0f,25.0f));
			gui.add(diff.setup("diffuse",  0.0f,0.0f,25.0f));
			gui.add(visc.setup("viscosity", 0.0f,0.0f,25.0f));
			gui.add(force.setup("add force",30.0f,0.0f,60.0f));
			gui.add(source.setup("density", 200.0f,0.0f,600.0f));
			gui.add(source_alpha.setup("alpha",0.05,0.0,1.0));
			gui.add(drawAbstacle.setup("draw abstacle",false));
			gui.add(drawAxis.setup("draw Axis",true));

			gui.add(sourcePosX.setup("source posX", 0,-10,SIZE));
			gui.add(sourcePosY.setup("source posY", 0,-10,SIZE));
			gui.add(sourcePosZ.setup("source posZ", 0,-10,SIZE));
		}
Exemple #8
0
 void setupFromXml(string filename) {
     size = ofVec2f(ofGetWidth(), ofGetHeight());
     if (xml.load(filename)) {
         xml.setTo("STAR[0]");
         do {
             xml.setTo("POSITION");
             int x = xml.getValue<float>("X");
             int y = xml.getValue<float>("Y");
             xml.setToParent();
             int m = xml.getValue<int>("MAGNITUDE");
             int id = xml.getValue<int>("ID");
             
             BPStar s;
             s.setPosition(x, y);
             s.setMagnitude(m);
             s.setId(id);
             stars.push_back(s);
         }while( xml.setToSibling() ); // go to next STAR
     } else {
         
     }
     shader.load("","SkyShader.frag");
     skyShader.setup();
 }
Exemple #9
0
    void keyPressed(int key) {
	if(key == '1') { model.loadModel("wolf.dae"); cube=false; }
	if(key == '2') { model.loadModel("elephant.dae"); cube=false; }
	if(key == '3') { model.loadModel("alduin.obj"); cube=false; }
	if(key == '4') cube=!cube;


	if(key == ' ') ofToggleFullscreen();

	if(key == 'q') { shader.load("material.vert","material.frag"); reflect=false; sreflect=false; }
	if(key == 'w') { shader.load("material.vert","material1.frag"); reflect=false; sreflect=false; }
	if(key == 'e') { shader.load("material.vert","material2.frag"); reflect=false; sreflect=false; }
	if(key == 'r') { shader.load("material.vert","material3.frag"); reflect=false; sreflect=false; }
	if(key == 't') { shader.load("material.vert","material4.frag"); reflect=false; sreflect=false; }
	if(key == 'y') { shader.load("material.vert","material5.frag"); reflect=false; sreflect=false; }

	if(key == 'u') { shader.load("material.vert","material6.frag"); reflect=false; sreflect=false; }
	if(key == 'i') { shader.load("material.vert","material7.frag"); reflect=false; sreflect=false; }
	if(key == 'o') { shader.load("material.vert","material8.frag"); reflect=false; sreflect=false; }
	if(key == 'p') { shader.load("material.vert","material9.frag"); reflect=false; sreflect=false; }
	if(key == 'a') { shader.load("material.vert","material10.frag"); reflect=false; sreflect=false; }
	if(key == 's') { shader.load("material.vert","material11.frag"); reflect=false; sreflect=false; }
	if(key == 'd') { shader.load("material.vert","material12.frag"); reflect=false; sreflect=false; }
	if(key == 'f') { shader.load("material.vert","material13.frag"); reflect=false; sreflect=false; }
	if(key == 'g') { shader.load("material.vert","material14.frag"); reflect=false; sreflect=false; }
	if(key == 'h') { shader.load("material.vert","material15.frag"); reflect=false; sreflect=false; }
	if(key == 'j') { shader.load("material.vert","material16.frag"); reflect=false; sreflect=false; }
	if(key == 'k') { shader.load("material.vert","material17.frag"); reflect=false; sreflect=false; }
	if(key == 'l') { shader.load("material.vert","material18.frag"); reflect=false; sreflect=false; }
	if(key == 'z') { shader.load("material.vert","material19.frag"); reflect=false; sreflect=false; }
	if(key == 'x') { shader.load("material.vert","material20.frag"); reflect=false; sreflect=false; }

	if(key == 'c') { shader.load("material_reflect.vert","material_reflect.frag"); reflect=true; sreflect=false; }
	if(key == 'v') { shader.load("material_reflect_1.vert","material_reflect_1.frag"); reflect=true; sreflect=false; }
	if(key == 'b') { shader.load("material_reflect_2.vert","material_reflect_2.frag"); sreflect=true; reflect=false; }
    }
Exemple #10
0
void helix::drawCenteredForDOF( ofShader & dofShader, bool bDrawInner, bool bDrawOuter ){
        
               
        GLint sideLocation = dofShader.getAttributeLocation("side");
        GLint nextLocation = dofShader.getAttributeLocation("next");
        
        
        
        ofPoint midPt;
        int count = 0;
        
        for (int i = 0; i < helix0.size(); i++){
            midPt += helix0[i];
            count++;
        }
        
        for (int i = 0; i < helix1.size(); i++){
            midPt += helix1[i];
            count++;
        }
        
        for (int i = 0; i < lines.size(); i++){
            midPt += lines[i].a;
            midPt += lines[i].b;
            count += 2;
        }
        
        midPt /= (float)count;
        
        
    
    
        ofPushMatrix();
        ofTranslate(-midPt.x, -midPt.y, -midPt.z);
    
    
    if (bDrawOuter){
        glBegin(GL_TRIANGLE_STRIP);
        
        for (int i = 0; i < helix0.size()-1; i++){
            ofPoint cur = helix0[i];
            ofPoint next = helix0[i+1];
            
            ofPoint temp0 = cur;
            ofPoint temp1 = next;
            temp0.normalize();
            temp1.normalize();
            ofPoint normal = temp0.cross(temp1).normalize();
            
            
            dofShader.setAttribute1f(sideLocation, -.5);
            dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
            
            //glNormal3f(normal.x, normal.y, normal.y);
            glVertex3f(cur.x, cur.y, cur.z);
            
            dofShader.setAttribute1f(sideLocation, +.5);
            dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
            
            //glNormal3f(normal.x, normal.y, normal.y);
            glVertex3f(cur.x, cur.y, cur.z);
            
        }
        
        
        glEnd();
        
        glBegin(GL_TRIANGLE_STRIP);
        
        for (int i = 0; i < helix1.size()-1; i++){
            ofPoint cur = helix1[i];
            ofPoint next = helix1[i+1];
            
            ofPoint temp0 = cur;
            ofPoint temp1 = next;
            temp0.normalize();
            temp1.normalize();
            ofPoint normal = temp0.cross(temp1).normalize();
            
            
            dofShader.setAttribute1f(sideLocation, -.5);
            dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
            //glNormal3f(normal.x, normal.y, normal.y);
            
            glVertex3f(cur.x, cur.y, cur.z);
            
            dofShader.setAttribute1f(sideLocation, +.5);
            dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
            //glNormal3f(normal.x, normal.y, normal.y);
            
            glVertex3f(cur.x, cur.y, cur.z);
            
        }
        
        glEnd();
    }
    
        if (bDrawInner)
        for (int i = 0; i < lines.size(); i++){
            
            int divisions = 20;
            
            glBegin(GL_TRIANGLE_STRIP);
            
            
            for (int j = 0; j < 20; j++){
                
                
                ofPoint cur = lines[i].a + ((lines[i].b - lines[i].a)/(float)19) * j;
                ofPoint next = lines[i].a + ((lines[i].b - lines[i].a)/(float)19) * (j+1);
                
                dofShader.setAttribute1f(sideLocation, -.5);
                dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
                glVertex3f(cur.x, cur.y, cur.z);
                glTexCoord2d( ofRandom(0,50), ofRandom(0,50));
                
                
                
                dofShader.setAttribute1f(sideLocation, +.5);
                dofShader.setAttribute3f(nextLocation, next.x, next.y, next.z);
                glVertex3f(cur.x, cur.y, cur.z);
                glTexCoord2d(ofRandom(0,50), ofRandom(0,50));
                
                
                
                
                
            }
            
            glEnd();
            
            
        }
    
    
    
     ofPopMatrix();
        
        
}
Exemple #11
0
void ofBaseMaterial::uploadMatrices(const ofShader & shader,ofGLProgrammableRenderer & renderer) const{
	const ofMatrix4x4 & normalMatrix = renderer.getCurrentNormalMatrix();
	shader.setUniformMatrix4f("normalMatrix",normalMatrix);
}
Exemple #12
0
void meshView::render(ofxControlPanel& panel, ofLight& light, ofShader& shader, ofTexture* texture) 
//void meshView::render(ofxControlPanel& panel, ofLight& light, ofShader& shader, ofImage& customPicture, ofVideoPlayer& mappingMovie) 
{
	ofPushStyle();
	ofSetLineWidth(panel.getValueI("lineWidth"));
	if(panel.getValueB("useSmoothing")) {
		ofEnableSmoothing();
	} else {
		ofDisableSmoothing();
	}
	int shading = panel.getValueI("shading");
	bool useLights = shading == 1;
	bool useShader = shading == 2;
	if(useLights) {
		light.enable();
		ofEnableLighting();
		glShadeModel(GL_SMOOTH);
		glEnable(GL_NORMALIZE);
	}
	
	if(panel.getValueB("highlight")) {
		objectMesh->clearColors();
		int n = objectMesh->getNumVertices();
		float highlightPosition = panel.getValueF("highlightPosition");
		float highlightOffset = panel.getValueF("highlightOffset");
		for(int i = 0; i < n; i++) {
			int lower = ofMap(highlightPosition - highlightOffset, 0, 1, 0, n);
			int upper = ofMap(highlightPosition + highlightOffset, 0, 1, 0, n);
			ofColor cur = (lower < i && i < upper) ? ofColor::white : ofColor::black;
			objectMesh->addColor(cur);
		}
	}
	
	ofSetColor(255);
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glEnable(GL_DEPTH_TEST);
	if(useShader) {
		shader.begin();
		shader.setUniform1f("elapsedTime", ofGetElapsedTimef());
		shader.end();
	}
	int nrOfMeshes = 0;

	ofColor transparentBlack(0, 0, 0, 0);
	switch(panel.getValueI("drawMode")) {
		case 0: // faces
			{
			if(useShader) shader.begin();
			glEnable(GL_CULL_FACE);
			glCullFace(GL_BACK);
			objectMesh->drawFaces();
			if(useShader) shader.end();
	
// use the default implementation from ofxAssimpModelLoader
//			model.drawFaces();

			break;
			}
		case 1: // fullWireframe
			{
			if(useShader) shader.begin();
			objectMesh->drawWireframe();
			if(useShader) shader.end();
			break;
			}
		case 2: // outlineWireframe
			{
			LineArt::draw(*objectMesh, true, transparentBlack, useShader ? &shader : NULL);
			break;
			}
		case 3: // occludedWireframe
			{
			LineArt::draw(*objectMesh, false, transparentBlack, useShader ? &shader : NULL);
			break;
			}
		case 4: // texture
			{
				if(texture != NULL)
				{
					//ofTexture& pictureTexture = customPicture.getTextureReference();
					//pictureTexture.bind();
					//drawModel(OF_MESH_FILL, &pictureTexture);
					//pictureTexture.unbind();
					texture->bind();
					drawModel(OF_MESH_FILL, texture);
					texture->unbind();
				}
			}
			break;

		//case 5: // video
		//	{
		//	// use our custom version that supports video textures and stuff
		//	ofTexture& videoTexture = mappingMovie.getTextureReference();
		//	videoTexture.bind();
		//	drawModel(OF_MESH_FILL, &videoTexture);
		//	videoTexture.unbind();
		//	break;
		//	}
	}
	glPopAttrib();
	if(useLights) {
		ofDisableLighting();
	}
	ofPopStyle();
}
void ofMaterial::updateLights(const ofShader & shader,ofGLProgrammableRenderer & renderer) const{
	for(size_t i=0;i<ofLightsData().size();i++){
		string idx = ofToString(i);
		shared_ptr<ofLight::Data> light = ofLightsData()[i].lock();
		if(!light || !light->isEnabled){
			shader.setUniform1f("lights["+idx+"].enabled",0);
			continue;
		}
		auto lightEyePosition = renderer.getCurrentViewMatrix() * light->position;
		shader.setUniform1f("lights["+idx+"].enabled",1);
		shader.setUniform1f("lights["+idx+"].type", light->lightType);
		shader.setUniform4f("lights["+idx+"].position", lightEyePosition);
		shader.setUniform4f("lights["+idx+"].ambient", light->ambientColor);
		shader.setUniform4f("lights["+idx+"].specular", light->specularColor);
		shader.setUniform4f("lights["+idx+"].diffuse", light->diffuseColor);

		if(light->lightType!=OF_LIGHT_DIRECTIONAL){
			shader.setUniform1f("lights["+idx+"].constantAttenuation", light->attenuation_constant);
			shader.setUniform1f("lights["+idx+"].linearAttenuation", light->attenuation_linear);
			shader.setUniform1f("lights["+idx+"].quadraticAttenuation", light->attenuation_quadratic);
		}

		if(light->lightType==OF_LIGHT_SPOT){
			auto direction = toGlm(light->position).xyz() + light->direction;
			auto direction4 = renderer.getCurrentViewMatrix() * glm::vec4(direction,1.0);
			direction = direction4.xyz() / direction4.w;
			direction = direction - lightEyePosition.xyz();
			shader.setUniform3f("lights["+idx+"].spotDirection", glm::normalize(direction));
			shader.setUniform1f("lights["+idx+"].spotExponent", light->exponent);
			shader.setUniform1f("lights["+idx+"].spotCutoff", light->spotCutOff);
			shader.setUniform1f("lights["+idx+"].spotCosCutoff", cos(ofDegToRad(light->spotCutOff)));
		}else if(light->lightType==OF_LIGHT_DIRECTIONAL){
			auto halfVector = glm::normalize(glm::vec4(0.f, 0.f, 1.f, 0.f) + lightEyePosition);
			shader.setUniform3f("lights["+idx+"].halfVector", halfVector.xyz());
		}else if(light->lightType==OF_LIGHT_AREA){
			shader.setUniform1f("lights["+idx+"].width", light->width);
			shader.setUniform1f("lights["+idx+"].height", light->height);
			auto direction = light->position.xyz() + light->direction;
			auto direction4 = renderer.getCurrentViewMatrix() * glm::vec4(direction, 1.0);
			direction = direction4.xyz() / direction4.w;
			direction = direction - lightEyePosition.xyz();
			shader.setUniform3f("lights["+idx+"].spotDirection", glm::normalize(direction));
			auto right = toGlm(light->position).xyz() + light->right;
			auto right4 = renderer.getCurrentViewMatrix() * glm::vec4(right, 1.0);
			right = right4.xyz() / right4.w;
			right = right - lightEyePosition.xyz();
			auto up = glm::cross(toGlm(right), direction);
			shader.setUniform3f("lights["+idx+"].right", glm::normalize(toGlm(right)));
			shader.setUniform3f("lights["+idx+"].up", glm::normalize(up));
		}
	}
}
Exemple #14
0
	//--------------------------------------------------------------
	void SnapshotRamses::update(ofShader& shader)
	{
		shader.setUniformTexture("uTransform", m_bufferTexture, 0);
	}
void ofMaterial::updateMaterial(const ofShader & shader,ofGLProgrammableRenderer & renderer) const{
	shader.setUniform4fv("mat_ambient", &data.ambient.r);
	shader.setUniform4fv("mat_diffuse", &data.diffuse.r);
	shader.setUniform4fv("mat_specular", &data.specular.r);
	shader.setUniform4fv("mat_emissive", &data.emissive.r);
	shader.setUniform4fv("global_ambient", &ofGetGlobalAmbientColor().r);
	shader.setUniform1f("mat_shininess",data.shininess);
	for(auto & uniform: uniforms1f){
		shader.setUniform1f(uniform.first, uniform.second);
	}
	for (auto & uniform : uniforms2f) {
		shader.setUniform2f(uniform.first, uniform.second);
	}
	for (auto & uniform : uniforms3f) {
		shader.setUniform3f(uniform.first, uniform.second);
	}
	for (auto & uniform : uniforms4f) {
		shader.setUniform4f(uniform.first, uniform.second);
	}
	for (auto & uniform : uniforms1i) {
		shader.setUniform1i(uniform.first, uniform.second);
	}
	for (auto & uniform : uniforms2i) {
		shader.setUniform2i(uniform.first, uniform.second.x, uniform.second.y);
	}
	for (auto & uniform : uniforms3i) {
		shader.setUniform3i(uniform.first, uniform.second.x, uniform.second.y, uniform.second.z);
	}
	for (auto & uniform : uniforms4i) {
		shader.setUniform4i(uniform.first, uniform.second.x, uniform.second.y, uniform.second.z, uniform.second.w);
	}
	for (auto & uniform : uniformstex) {
		shader.setUniformTexture(uniform.first,
								 uniform.second.textureTarget,
								 uniform.second.textureID,
								 uniform.second.textureLocation);
	}
}
//--------------------------------------------------------------- ACTIONS
void CloudsRGBDVideoPlayer::setupProjectionUniforms(ofShader& shader){
    
	if(!getPlayer().isLoaded() || !getTextureReference().isAllocated()){
		//ofLogWarning() << " CloudsRGBDVideoPlayer::setupProjectionUniforms -- player is not ready";
		return;
	}
	
	if(playingVO){
		return;
	}

    shader.setUniformTexture("rgbdTexture", getTextureReference(), 1);
    shader.setUniform2f("textureSize",  getPlayer().getWidth(), getPlayer().getHeight());
    
    shader.setUniform4f("colorRect", colorRect.x, colorRect.y, colorRect.width, colorRect.height);
    shader.setUniform2f("colorScale", colorScale.x, colorScale.y);
    
    shader.setUniform2f("colorFOV", colorFOV.x, colorFOV.y );
    shader.setUniform2f("colorPP", colorPrincipalPoint.x, colorPrincipalPoint.y);
    shader.setUniform3f("dK", distortionK.x, distortionK.y, distortionK.z);
    shader.setUniform2f("dP", distortionP.x, distortionP.y);
    
	ofMatrix4x4 adjustmentMatrix;
	adjustmentMatrix.rotate(adjustRotate.x, 0, 1, 0);
	adjustmentMatrix.rotate(adjustRotate.y, 1, 0, 0);
	adjustmentMatrix.translate(adjustTranslate.x, adjustTranslate.y, adjustTranslate.z);

	shader.setUniformMatrix4f("extrinsics", extrinsics * adjustmentMatrix );
    
    shader.setUniform4f("depthRect", depthRect.x, depthRect.y, depthRect.width, depthRect.height);
	shader.setUniform2f("depthPP", depthPrincipalPoint.x, depthPrincipalPoint.y);
	shader.setUniform2f("depthFOV", depthFOV.x, depthFOV.y);
    
    shader.setUniform4f("normalRect", normalRect.x, normalRect.y, normalRect.width, normalRect.height);
    shader.setUniform4f("faceFeatureRect", faceFeatureRect.x, faceFeatureRect.y, faceFeatureRect.width, faceFeatureRect.height);
    shader.setUniform4f("deltaChangeRect", deltaChangeRect.x, deltaChangeRect.y, deltaChangeRect.width, deltaChangeRect.height);
	
	shader.setUniform1f("farClip", farClip);
    shader.setUniform1f("nearClip", nearClip);
	shader.setUniform1f("edgeClip", edgeClip);

	shader.setUniform1f("minDepth", minDepth);
    shader.setUniform1f("maxDepth", maxDepth);
	
	shader.setUniform3f("skinSampleColor",skinSampleColor.r,skinSampleColor.g,skinSampleColor.b);
	shader.setUniform3f("skinWeights", skinWeights.x,skinWeights.y,skinWeights.z);
	shader.setUniform2f("skinThreshold", skinThreshold.min, skinThreshold.max);

	shader.setUniform3f("headPosition",headPosition.x,-headPosition.y,headPosition.z);
	
	shader.setUniform1f("flowPosition", flowPosition);
}
Exemple #17
0
	void update() {
#ifdef INSTALL
		if(cam.update()) {
			ofPixels& pixels = cam.getColorPixels();
#else
		cam.update();
		if(cam.isFrameNew()) {
			ofPixels& pixels = cam.getPixelsRef();
#endif
			// next two could be replaced with one line
			ofxCv::rotate90(pixels, rotated, rotate ? 270 : 0);
			ofxCv:flip(rotated, rotated, 1);
			Mat rotatedMat = toCv(rotated);
			if(tracker.update(rotatedMat))  {
				ofVec2f position = tracker.getPosition();
				vector<FaceTrackerData*> neighbors = data.getNeighborsCount(position, neighborCount);
				FaceTrackerData curData;
				curData.load(tracker);
				if(!neighbors.empty()) {
					nearestData = *faceCompare.nearest(curData, neighbors);
					if(nearestData.label != lastLabel) {
						similar.loadImage(nearestData.getImageFilename());
#ifdef INSTALL
						whitePoint = getWhitePoint(similar);
#else
						whitePoint.set(1, 1, 1);
#endif
					}
					lastLabel = nearestData.label;
				}
				if(faceCompare.different(curData, currentData) && faceCompare.different(curData, neighbors)) {
					saveFace(curData, rotated);
					currentData.push_back(pair<ofVec2f, FaceTrackerData>(position, curData));
				}
			}
			presence.update(tracker.getFound());
			if(presence.wasTriggered()) {
				presenceFade.stop();
			}
			if(presence.wasUntriggered()) {
				for(int i = 0; i < currentData.size(); i++) {
					data.add(currentData[i].first, currentData[i].second);
				}
				currentData.clear();
				presenceFade.start();
			}
		}
	}
	void draw() {
		ofBackground(255);
		CGDisplayHideCursor(NULL);
		ofSetColor(255);
		if(similar.isAllocated()) {
			shader.begin();
			shader.setUniformTexture("tex", similar, 0);
			shader.setUniform3fv("whitePoint", (float*) &whitePoint);
			similar.draw(0, 0);
			shader.end();
		}
		ofPushStyle();
		if(presenceFade.getActive()) {
			ofSetColor(0, ofMap(presenceFade.get(), 0, 1, 0, 128));
			ofFill();
			ofRect(0, 0, ofGetWidth(), ofGetHeight());
			ofSetColor(255, ofMap(presenceFade.get(), 0, 1, 0, 32));
			data.drawBins();
			ofSetColor(255, ofMap(presenceFade.get(), 0, 1, 0, 64));
			data.drawData();
		}
		ofSetColor(255, 64);
		ofNoFill();
		if(!tracker.getFound()) {
			ofCircle(tracker.getPosition(), 10);
		}
		tracker.draw();
		ofPopStyle();
		
#ifndef INSTALL
		drawFramerate();
#endif
	}
//--------------------------------------------------------------- ACTIONS
void CloudsRGBDVideoPlayer::setupProjectionUniforms(ofShader& shader){
    
	if(!getPlayer().isLoaded()){
		ofLogWarning() << " CloudsRGBDVideoPlayer::setupProjectionUniforms -- player is not ready";
		return;
	}
	
    shader.setUniformTexture("rgbdTexture", getPlayer().getTextureReference(), 0);
    shader.setUniform2f("textureSize",  getPlayer().getWidth(), getPlayer().getHeight());
    
    shader.setUniform4f("colorRect", colorRect.x, colorRect.y, colorRect.width, colorRect.height);
    shader.setUniform2f("colorScale", colorScale.x, colorScale.y);
    
    shader.setUniform2f("colorFOV", colorFOV.x, colorFOV.y );
    shader.setUniform2f("colorPP", colorPrincipalPoint.x, colorPrincipalPoint.y);
    shader.setUniform3f("dK", distortionK.x, distortionK.y, distortionK.z);
    shader.setUniform2f("dP", distortionP.x, distortionP.y);
    
	ofMatrix4x4 adjustmentMatrix;
	adjustmentMatrix.rotate(adjustRotate.x, 0, 1, 0);
	adjustmentMatrix.rotate(adjustRotate.y, 1, 0, 0);
	adjustmentMatrix.translate(adjustTranslate.x, adjustTranslate.y, adjustTranslate.z);

	shader.setUniformMatrix4f("extrinsics", extrinsics * adjustmentMatrix );
    
    shader.setUniform4f("depthRect", depthRect.x, depthRect.y, depthRect.width, depthRect.height);
	shader.setUniform2f("depthPP", depthPrincipalPoint.x, depthPrincipalPoint.y);
	shader.setUniform2f("depthFOV", depthFOV.x, depthFOV.y);
    
    shader.setUniform4f("normalRect", normalRect.x, normalRect.y, normalRect.width, normalRect.height);
    shader.setUniform4f("faceFeatureRect", faceFeatureRect.x, faceFeatureRect.y, faceFeatureRect.width, faceFeatureRect.height);
    shader.setUniform4f("deltaChangeRect", deltaChangeRect.x, deltaChangeRect.y, deltaChangeRect.width, deltaChangeRect.height);

	shader.setUniform1i("useFaces", useFaces ? 1 : 0);
	shader.setUniform1f("flowPosition", flowPosition);
	
	shader.setUniform1f("farClip", farClip);
    shader.setUniform1f("nearClip", nearClip);
	shader.setUniform1f("edgeClip", edgeClip);

	shader.setUniform1f("minDepth", minDepth);
    shader.setUniform1f("maxDepth", maxDepth);

}
Exemple #19
0
void BGNode::drawFace(ofShader & mEyeShader) {

/*
    int n = neighbours.size();
    ofVec2f toVector(1,0);
    if(n > 0)
        toVector = (neighbours[0]->position - position).normalize();


    ofVec2f perpVec(-toVector.y, toVector.x);
*/

    ofSetColor(255);

    float offset = .05 * nodeRadius;
    float perpOffset = .6 * nodeRadius;
    float eyeRadius = .6 * nodeRadius;

    ofVec2f toVector = mSurfaceNormal;
    ofVec2f perpVec(-toVector.y, toVector.x);

    ofVec2f goalPos = position;
    if(neighbours.size() > 0)
        goalPos = neighbours[0]->position;

    float texFactor = .6 * nodeRadius;

    for(int i=0; i<2; ++i) {

        int factor = i == 0 ? 1 : -1;
        ofVec2f pos = position + toVector * offset + factor * perpVec * perpOffset;

        ofMesh eyeMesh;
        eyeMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);

        for(int j=0; j<4; ++j) {

            ofVec2f texPos(j % 2, j / 2);

            ofVec2f vPos = pos + (texPos.x - .5) * texFactor * perpVec + (texPos.y - .5) * texFactor * toVector;

            eyeMesh.addVertex(ofVec3f(vPos.x, vPos.y, 0));
            eyeMesh.addTexCoord(texPos);
        }

        ofVec2f goalPos = position;
        if(neighbours.size() > 0)
            goalPos = neighbours[0]->position;

        ofVec2f toGoal = goalPos - pos;
        float toGoalLength = toGoal.length();
        ofVec2f pupilPos = pos;
        if(toGoalLength > 0.01)
            pupilPos = pos + .25 * eyeRadius / toGoalLength * toGoal;

        mEyeShader.begin();
        mEyeShader.setUniform2f("uCenter", pos.x, pos.y);
        mEyeShader.setUniform2f("uFocusPoint", goalPos.x, goalPos.y);
        mEyeShader.setUniform2f("uPupilLoc", pupilPos.x, pupilPos.y);
        mEyeShader.setUniform1i("uFlipHorizontally", i > 0);
        
        eyeMesh.draw();
        mEyeShader.end();
    }

    ofMesh mouthMesh;
    mouthMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);

    for(int i=0; i<21; ++i) {
        float t = i / 20.0;
        float x = .6 * (t - .5) * nodeRadius;
        float yVar = 2 * abs(t - .5);
        float y = (-yVar * yVar * (1 - yVar) * .6 - .3) * nodeRadius;

        for(int it=0; it<2; ++it) {
            mouthMesh.addVertex(position + y * toVector + x * perpVec);
            mouthMesh.addColor(ofColor(0));
            y -= 3;
        }

    }

    mouthMesh.draw();
}