Beispiel #1
0
void LoadPoint(FILE *f, vcg::Point3f &p){
  LoadFloat(f,  p.X() ); 
  LoadFloat(f,  p.Z() );
  LoadFloat(f,  p.Y() ); 
  
  //printf("(%f,%f,%f) ",p[0],p[1],p[2]);
}
Beispiel #2
0
static void norm2int(vcg::Point3f  res, Byte &zenb,Byte &azib){

  double zen = atan2(res.Z(), res.X() );
  double azi = acos(res.Y() );

  int zeni = int( zen / (2 * M_PI ) * 255.0);
  int azii = int( azi / (2 * M_PI ) * 255.0);
  if (zeni>255) zeni -= 255;
  if (zeni<0)   zeni += 255;
  if (azii>255) azii -= 255;
  if (azii<0)   azii += 255;

  zenb = zeni;
  azib = azii;
}
Beispiel #3
0
void SdfGpuPlugin::calculateObscurance(FramebufferObject* fboFront, FramebufferObject* fboBack, FramebufferObject* nextBack, const vcg::Point3f& cameraDir, float bbDiag)
{
    mFboResult->bind();

    glEnable(GL_SCISSOR_TEST);
    glScissor(0,0,mResTextureDim,mNumberOfTexRows);

    GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };
    glDrawBuffers(2, buffers);

    glViewport(0, 0, mResTextureDim, mResTextureDim);

    GLfloat mv_pr_Matrix_f[16];  // modelview-projection matrix

    glGetFloatv(GL_MODELVIEW_MATRIX, mv_pr_Matrix_f);
    glMatrixMode(GL_PROJECTION);
    glMultMatrixf(mv_pr_Matrix_f);
    glGetFloatv(GL_PROJECTION_MATRIX, mv_pr_Matrix_f);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glDepthMask(GL_FALSE);
    glDisable(GL_DEPTH_TEST);

    glEnable (GL_BLEND);
    glBlendFunc (GL_ONE, GL_ONE);
    glBlendEquation(GL_FUNC_ADD);


    glUseProgram(mObscuranceProgram->id());
    assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)==GL_FRAMEBUFFER_COMPLETE_EXT && "before draw");


    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, fboFront->getAttachedId(GL_DEPTH_ATTACHMENT));
    mObscuranceProgram->setUniform1i("depthTextureFront",0);

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, fboBack->getAttachedId(GL_DEPTH_ATTACHMENT));
    mObscuranceProgram->setUniform1i("depthTextureBack",1);

    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, mVertexCoordsTexture->id());
    mObscuranceProgram->setUniform1i("vTexture",2);

    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, mVertexNormalsTexture->id());
    mObscuranceProgram->setUniform1i("nTexture",3);

    //next depth layer, see TraceRays function for an explanation
    if(nextBack != NULL)
    {
        glActiveTexture(GL_TEXTURE4);
        glBindTexture(GL_TEXTURE_2D, nextBack->getAttachedId(GL_DEPTH_ATTACHMENT));
        mObscuranceProgram->setUniform1i("depthTextureNextBack",4);
    }

    // Set view direction
    mObscuranceProgram->setUniform3f("viewDirection", cameraDir.X(), cameraDir.Y(), cameraDir.Z());

    // Set ModelView-Projection Matrix
    mObscuranceProgram->setUniformMatrix4fv( "mvprMatrix", mv_pr_Matrix_f, 1, GL_FALSE );

    // Set texture Size
    mObscuranceProgram->setUniform1f("texSize", mPeelingTextureSize);

    // Set viewport Size
    mObscuranceProgram->setUniform1f("viewpSize", mResTextureDim );

    mObscuranceProgram->setUniform1f("tau", mTau);

    mObscuranceProgram->setUniform1f("maxDist", bbDiag);

    //just a flag to know how many layers to use for z-fighting removal
    if(nextBack == NULL)
        mObscuranceProgram->setUniform1i("firstRendering",1);
    else
         mObscuranceProgram->setUniform1i("firstRendering",0);

    // Screen-aligned Quad
    glBegin(GL_QUADS);
            glVertex3f(-1.0f, -1.0f, 0.0f); //L-L
            glVertex3f( 1.0f, -1.0f, 0.0f); //L-R
            glVertex3f( 1.0f,  1.0f, 0.0f); //U-R
            glVertex3f(-1.0f,  1.0f, 0.0f); //U-L
    glEnd();

    assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)==GL_FRAMEBUFFER_COMPLETE_EXT && "after draw");

    mFboResult->unbind();

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDisable(GL_BLEND);
    glDisable(GL_SCISSOR_TEST);
}
Beispiel #4
0
void SdfGpuPlugin::calculateSdfHW(FramebufferObject* fboFront, FramebufferObject* fboBack, FramebufferObject* fboPrevBack, const vcg::Point3f& cameraDir)
{
    mFboResult->bind();

    glEnable(GL_SCISSOR_TEST);
    glScissor(0,0,mResTextureDim,mNumberOfTexRows);

    GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT };
    glDrawBuffers(2, buffers);

    glViewport(0, 0, mResTextureDim, mResTextureDim);
    GLfloat mv_pr_Matrix_f[16];  // modelview-projection matrix

    glGetFloatv(GL_MODELVIEW_MATRIX, mv_pr_Matrix_f);
    glMatrixMode(GL_PROJECTION);
    glMultMatrixf(mv_pr_Matrix_f);
    glGetFloatv(GL_PROJECTION_MATRIX, mv_pr_Matrix_f);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glDisable(GL_DEPTH_TEST);
   // glDepthMask(GL_FALSE);

    glEnable (GL_BLEND);
    glBlendFunc (GL_ONE, GL_ONE);
    glBlendEquation(GL_FUNC_ADD);


    glUseProgram(mSDFProgram->id());

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, fboFront->getAttachedId(GL_DEPTH_ATTACHMENT));
    mSDFProgram->setUniform1i("depthTextureFront",0);

    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, fboBack->getAttachedId(GL_DEPTH_ATTACHMENT));
    mSDFProgram->setUniform1i("depthTextureBack",1);

    glActiveTexture(GL_TEXTURE2);
    glBindTexture(GL_TEXTURE_2D, fboBack->getAttachedId(GL_COLOR_ATTACHMENT0));
    mSDFProgram->setUniform1i("normalTextureBack",2);

    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, mVertexCoordsTexture->id());
    mSDFProgram->setUniform1i("vTexture",3);

    glActiveTexture(GL_TEXTURE4);
    glBindTexture(GL_TEXTURE_2D, mVertexNormalsTexture->id());
    mSDFProgram->setUniform1i("nTexture",4);

    //previous depth layer, see TraceRays function for an explanation
    if(fboPrevBack)
    {
        glActiveTexture(GL_TEXTURE5);
        glBindTexture(GL_TEXTURE_2D, fboPrevBack->getAttachedId(GL_DEPTH_ATTACHMENT));
        mSDFProgram->setUniform1i("depthTexturePrevBack",5);

    }



    // Set view direction
    mSDFProgram->setUniform3f("viewDirection", cameraDir.X(), cameraDir.Y(), cameraDir.Z());

    // Set ModelView-Projection Matrix
    mSDFProgram->setUniformMatrix4fv( "mvprMatrix", mv_pr_Matrix_f, 1, GL_FALSE );

    vcg::Matrix44f mvprINV(mv_pr_Matrix_f);
    mvprINV.transposeInPlace();
    vcg::Invert(mvprINV);
    mSDFProgram->setUniformMatrix4fv( "mvprMatrixINV", mvprINV.V(), 1, GL_TRUE );


    // Set texture Size
    mSDFProgram->setUniform1f("texSize", mPeelingTextureSize);

    // Set viewport Size
    mSDFProgram->setUniform1f("viewpSize", mResTextureDim );

    mSDFProgram->setUniform1f("minCos", mMinCos);

    //just a flag to know how many layers to use for z-fighting removal
    if(fboPrevBack == NULL)
        mSDFProgram->setUniform1i("firstRendering",1);
    else
         mSDFProgram->setUniform1i("firstRendering",0);

    if(mRemoveFalse)
        mSDFProgram->setUniform1i("removeFalse",1);
    else
         mSDFProgram->setUniform1i("removeFalse",0);

    if(mRemoveOutliers)
        mSDFProgram->setUniform1i("removeOutliers",1);
    else
        mSDFProgram->setUniform1i("removeOutliers",0);

    // Screen-aligned Quad
    glBegin(GL_QUADS);
            glVertex3f(-1.0f, -1.0f, 0.0f); //L-L
            glVertex3f( 1.0f, -1.0f, 0.0f); //L-R
            glVertex3f( 1.0f,  1.0f, 0.0f); //U-R
            glVertex3f(-1.0f,  1.0f, 0.0f); //U-L
    glEnd();

    mFboResult->unbind();
    glEnable(GL_DEPTH_TEST);
  //  glDepthMask(GL_TRUE);
    glDisable(GL_BLEND);
      glDisable(GL_SCISSOR_TEST);

}
Beispiel #5
0
void SavePoint16(FILE *f, vcg::Point3f p) {
  SaveShort(f,  int(p.X()*RATIO*64) );
  SaveShort(f,  int(p.Z()*RATIO*64) );
  SaveShort(f,  int(p.Y()*RATIO*64) );
}
Beispiel #6
0
int RGBPtm::createImage(unsigned char** buffer, int& width, int& height, const vcg::Point3f& light, const QRectF& rect, int level, int mode)
{
#ifdef PRINT_DEBUG
	QTime first = QTime::currentTime();
#endif

	// Computes height and width of the texture.
	width = ceil(rect.width());
	height = ceil(rect.height());
	int offx = rect.x();
	int offy = rect.y();
    if (currentRendering != DETAIL_ENHANCEMENT || mode == LUMR_MODE || mode == LUMG_MODE || mode == LUMB_MODE)
    {
		for (int i = 0; i < level; i++)
		{
			width = ceil(width/2.0);
			height = ceil(height/2.0);
			offx = offx/2;
			offy = offy/2;
		}
	}

	(*buffer) = new unsigned char[width*height*4];
	int offsetBuf = 0;
	
    if (mode == LUMR_MODE || mode == LUMG_MODE || mode == LUMB_MODE)
	{
		// Creates map of the RGB component.
		const PTMCoefficient* coeffPtr = NULL;
		switch(mode)
		{
			case LUMR_MODE:
				coeffPtr = redCoefficients.getLevel(level); break;
			case LUMB_MODE:
				coeffPtr = greenCoefficients.getLevel(level); break;
			case LUMG_MODE:
				coeffPtr = blueCoefficients.getLevel(level); break;
		}
		for (int y = offy; y < offy + height; y++)
		{
			for (int x = offx; x < offx + width; x++)
			{
				int offset = y * mipMapSize[level].width() + x;
				unsigned char c = tobyte(evalPoly((int*)&(coeffPtr[offset][0]), light.X(), light.Y()));
				(*buffer)[offsetBuf + 0] = c;
				(*buffer)[offsetBuf + 1] = c;
				(*buffer)[offsetBuf + 2] = c;
				(*buffer)[offsetBuf + 3] = 255;
				offsetBuf += 4;
			}
		}

	}
	else
	{
		// Applies the current rendering mode.
		RenderingInfo info = {offx, offy, height, width, level, mode, light, 6};
		list->value(currentRendering)->applyPtmRGB(redCoefficients, greenCoefficients, blueCoefficients, mipMapSize, normals, info, (*buffer));
	}
	
#ifdef PRINT_DEBUG
	QTime second = QTime::currentTime();
	double diff = first.msecsTo(second) / 1000.0;
	if (mode == DEFAULT_MODE)
	{
		switch(currentRendering)
		{
                        case DEFAULT: printf("Default rendering: %.5f s\n", diff); break;
                        case NORMALS: printf("Normals: %.5f s\n", diff); break;
                        case DIFFUSE_GAIN: printf("Diffuse gain: %.5f s\n", diff); break;
                        case SPECULAR_ENHANCEMENT: printf("Specular enhancement: %.5f s\n", diff); break;
                        case NORMAL_ENHANCEMENT: printf("Normal enhancement: %.5f s\n", diff); break;
                        case UNSHARP_MASKING_IMG: printf("Unsharp masking image: %.5f s\n", diff); break;
                        case UNSHARP_MASKING_LUM: printf("Unsharp masking luminance: %.5f s\n", diff); break;
                        case COEFF_ENHANCEMENT: printf("Coefficient enhancement: %.5f s\n", diff); break;
                        case DETAIL_ENHANCEMENT: printf("Detail enhancement: %.5f s\n", diff); break;
                        case DYN_DETAIL_ENHANCEMENT: printf("Dynamic detail enhancement: %.5f s\n", diff); break;
		}
	}
	else
                printf("Browing mode: %.5f s\n", diff);
#endif
	return 0;
}
Beispiel #7
0
void SavePoint(FILE *f, vcg::Point3f p) {
  SaveFloat(f,  p.X() ); 
  SaveFloat(f,  p.Z() );
  SaveFloat(f,  p.Y() ); 
}
Beispiel #8
0
static void setMatrices(vcg::Point3f L, int screensize, int screensizeHard, bool sx){
  // orthonormal basis
  L.Normalize();
  Point3f ax,ay,az=L;
  ax=az^Point3f(1,0,0);
  if (ax.SquaredNorm()<0.1) ax=az^Point3f(0,1,0);
  ax=ax.Normalize();
  ay=(az^ax).Normalize();

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
/*  if (!sx) {
    glScalef(1,1,-1);
  }*/

  
	GLfloat nearPlane = 1.0;
	GLfloat farPlane = 201;
  glOrtho(-1,+1,-1,+1, nearPlane, farPlane);

  glMatrixMode(GL_MODELVIEW);
  
  // PREPARE MATRIX for shadow test...
  
  glPushMatrix();
  glLoadIdentity();
  glOrtho(-1,+1,-1,+1, nearPlane, farPlane);
  
  gluLookAt(0,0,-4,   0,0,0,   0,1,0);    
  gluLookAt( az[0],az[1],az[2],  0,0,0, ay[0], ay[1], ay[2] );

  float r=shadowmap.m.r;
  float px=shadowmap.m.px;
  float py=shadowmap.m.py;
  float pz=shadowmap.m.pz;
  glScalef(1/r,1/r,1/r);
  glTranslatef(-px,-py,-pz);
  
  glGetFloatv(GL_MODELVIEW_MATRIX, &(matSM[0][0]));
  
  // ...done!
  
  glLoadIdentity();
  gluLookAt(0,0,-4,   0,0,0,   0,1,0);    
  gluLookAt( az[0],az[1],az[2],  0,0,0, ay[0], ay[1], ay[2] );

  //shadowScaleFactor=extractCurrentScaleFactor()/r;
  
  glGetIntegerv(GL_VIEWPORT, lastviewport);
  
  if (sx) {
    glViewport(0,0,screensize,screensize);
    glEnable(GL_SCISSOR_TEST);
    glScissor(0,0,screensize,screensize);
  }
  else {
    glViewport(screensize,0,screensize,screensize);
    glEnable(GL_SCISSOR_TEST);
    glScissor(screensize,0,screensize,screensize);
  }

  HSratio = float(screensize) / float(screensizeHard) ;
  //for (int i=0; i<4; i++)
  //for (int j=0; j<2; j++) matSM[i][j] /=ratio;
  
}