Ignore:
Timestamp:
10/19/06 15:27:47 (18 years ago)
Author:
igarcia
Message:
 
Location:
GTP/trunk/Lib/Illum/GPUObscurancesGT/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Illum/GPUObscurancesGT/src/MyFrame.cpp

    r953 r1648  
    226226        float r_float; 
    227227 
    228         for (i = 0, j = 0; i < (res * res * 4); i += 4, j += 3) 
     228        i = 0; 
     229        j = 0;   
     230        while (i < (res * res * 4)) 
    229231        { 
    230232                r_float = ObscuranceMap[i] * 255; 
     
    234236                r_float = ObscuranceMap[i+2] * 255; 
    235237                bmp[j + 2] = uchar(r_float); 
     238 
     239                j += 3; 
     240                i += 4; 
    236241        } 
    237242 
  • GTP/trunk/Lib/Illum/GPUObscurancesGT/src/vcObscuranceMap.cpp

    r930 r1648  
    77#pragma warning(disable:4244) 
    88// Includes 
     9#define GLEW_STATIC 1 
    910#include "glew.h" 
    1011#include <glut.h> 
     12//#include <iostream> 
    1113#include "stdlib.h" 
     14#include "time.h" 
    1215 
    1316// Includes 
    1417#include "CMesh.h" 
    1518#include "vcObscuranceMap.h" 
    16  
    17 //progress bar 
    18 #include <wx/progdlg.h> 
    1919 
    2020#define ROUND(x) (floor(x+0.5)) 
     
    5757//Lightmap Normalization Step. 
    5858GLint TexturaNormalize; 
     59GLint ResolutionNormalize; 
    5960 
    6061// Global variables 
     
    6768static int Res2X;               //Resolution 
    6869static int Res2Y;               //Resolution 
    69  
    7070 
    7171//RenderTexture *ob=NULL;                                                               // RenderTexture for the Obscurances. 
     
    121121} 
    122122 
     123float vdc(int i, int base) 
     124{ 
     125        float prec = 1.0 / (float)base; 
     126        float f = 0.0; 
     127        while(i!=0) 
     128        { 
     129                f += (float)(prec * (i % base)); 
     130                i /= base; 
     131                prec /= base; 
     132        } 
     133        return f; 
     134} 
    123135 
    124136// Returns a random point in the surface of the sphere 
    125 CVert ranpoint(float r, CVert c) 
     137CVert ranpoint(float r, CVert c, int &count) 
    126138{ 
    127         double ale1, ale2; 
     139        float ale1, ale2; 
    128140        CVert p; 
    129141        float alfa,beta; 
    130142 
    131         ale1= (float)rand()/(float)RAND_MAX;  
    132         ale2= (float)rand()/(float)RAND_MAX; 
     143        count++; 
     144        ale1 = vdc(count, 2); 
     145        ale2 = vdc(count, 3); 
     146//      ale1= (float)rand()/(float)RAND_MAX;  
     147//      ale2= (float)rand()/(float)RAND_MAX; 
    133148  
    134149    alfa=1.0-2.0*ale1;  /* real between -1 and 1 */ 
     
    146161// Function to find a point in the sphere in the direction that goes from the point in the surface of the sphere 
    147162// to the center of the sphere. First it gets the random point in the surface. 
    148 void BuscarDireccio() 
     163void BuscarDireccio(int &count) 
    149164{ 
    150165        Esfera.center.x = 0.0; 
     
    153168        Esfera.radius = sqrt(12.0)/2.0; 
    154169 
    155         Primer = ranpoint(Esfera.radius,Esfera.center); 
     170        Primer = ranpoint(Esfera.radius, Esfera.center, count); 
    156171        Vertex.x = Primer.x + (Esfera.center.x-Primer.x) * ((float)rand()/(float)RAND_MAX)*2.0; 
    157172        Vertex.y = Primer.y + (Esfera.center.y-Primer.y) * ((float)rand()/(float)RAND_MAX)*2.0; 
     
    160175 
    161176// Function that renders the depth peeling geometry planes and stores them in PBOs. 
    162 void RenderProjeccions(void) 
     177void RenderProjeccions(int buffer, int first) 
    163178{ 
     179        int i, j, e; 
     180 
    164181                glUseProgram(pProjection); 
    165182                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2); 
    166183 
    167                 int i, j, e; 
    168184                changeSize(ResX, ResY); 
    169                 glClearColor(0.0,0.0,1.0,1.0); 
    170                 glClearDepth(1.0); 
    171                 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    172185                glEnable (GL_DEPTH_TEST);                                                                       // Enable Depth Testing 
    173186                glDepthFunc(GL_LESS); 
     
    188201 
    189202                glUniform1f(SizeProjection, (float)ResX); 
    190                 glUniform1f(FirstProjection, 1.0); 
     203                glUniform1f(FirstProjection, (float)first); 
     204 
     205                int other = ((buffer == 1)? 0:1); 
     206                if(first == 0) 
     207                { 
     208                        glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[other] );                     // Bind The Buffer 
     209                        glBindTexture(GL_TEXTURE_2D,texName[0]); 
     210                        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, ResX, ResY); 
     211                        glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );                 // Bind The Buffer 
     212                        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     213 
     214                        glActiveTexture(GL_TEXTURE0); 
     215                        glBindTexture(GL_TEXTURE_2D, texName[0]); 
     216                        glUniform1i(TexturaDepthProjection, 0); 
     217                } 
    191218 
    192219                // Enable Pointers 
     
    214241                } 
    215242 
    216                 //Copy the color buffer to PBO. 
    217                 glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[1] );                 // Bind The Buffer 
    218                 glReadPixels(0, 0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0)); 
    219                 glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0); 
    220  
    221                 //Render the following layers. 
    222                 glUniform1f(FirstProjection, 0.0); 
    223  
    224                 e = 1; 
    225  
    226                 for(e = 1; e < MAX_LAYERS; e++) 
    227                 { 
    228                         glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[e] );                 // Bind The Buffer 
    229                         glBindTexture(GL_TEXTURE_2D,texName[0]); 
    230                         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, ResX, ResY); 
    231                         glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );                 // Bind The Buffer 
    232                         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    233  
    234                         glActiveTexture(GL_TEXTURE0); 
    235                         glBindTexture(GL_TEXTURE_2D, texName[0]); 
    236                         glUniform1i(TexturaDepthProjection, 0); 
    237  
    238                         for(i=0; i<g_pMesh.m_pObject._numGeos;i++) 
    239                         { 
    240                                 for(j=0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++) 
    241                                 { 
    242                                         // Set Pointers To Our Data 
    243                                         glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices ); 
    244                                         glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );               // Set The Vertex Pointer To The Vertex Buffer 
    245                                         glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords ); 
    246                                         glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );             // Set The TexCoord Pointer To The TexCoord Buffer 
    247                                         glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals ); 
    248                                         glNormalPointer( GL_FLOAT, 0, (char *) NULL );          // Set The TexCoord Pointer To The TexCoord Buffer 
    249                                         glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs ); 
    250  
    251                                         glDrawElements( GL_TRIANGLES, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris*3,GL_UNSIGNED_INT,BUFFER_OFFSET(0) );       // Draw All Of The Quads At Once 
    252                                 }                                
    253                         } 
    254  
    255                         glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[e+1] );                       // Bind The Buffer 
    256                         glReadPixels(0, 0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0)); 
    257                         glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0); 
    258                 } 
    259  
    260243                glDisableClientState( GL_VERTEX_ARRAY );                                        // Disable Vertex Arrays 
    261244                glDisableClientState( GL_TEXTURE_COORD_ARRAY );                         // Disable Texture Coord Arrays 
    262245                glDisableClientState( GL_NORMAL_ARRAY );                                // Disable Texture Coord Arrays 
    263246 
     247                //Copy the color buffer to PBO. 
     248                glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[buffer] );                    // Bind The Buffer 
     249                glReadPixels(0, 0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0)); 
     250                glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0); 
     251 
    264252                glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    265253                glUseProgram(0); 
     
    267255 
    268256// Function that calculates the lightmap using the neighbouring projections. 
    269 void RenderTransfer(void) 
     257void RenderTransfer(int buffer, int first) 
    270258{ 
    271259        glUseProgram(pTransfer); 
    272260        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3); 
    273261 
     262                int other = ((buffer == 1)? 0:1); 
     263 
    274264                glBlendFunc(GL_ONE, GL_ONE); 
    275265 
     
    287277 
    288278                glUniform1f(DmaxTransfer, (GLfloat)0.3); 
    289                 glUniform1f(DirectionTransfer, 0.0); 
    290279                glActiveTexture(GL_TEXTURE0); 
    291280                glBindTexture(GL_TEXTURE_2D, texReflect[0]); 
    292281                glUniform1i(TexturaReflectTransfer, 0); 
    293282                 
    294                 //First Render 
    295                 glEnableClientState( GL_VERTEX_ARRAY );                                         // Enable Vertex Arrays 
    296                 glUniform1f(DirectionTransfer, 1.0); 
    297                 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[1] ); 
    298                 glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );               // Set The Vertex Pointer To The Vertex Buffer 
    299  
    300                 glEnableClientState( GL_TEXTURE_COORD_ARRAY );                          // Enable Texture Coord Arrays 
    301                 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[0] ); 
    302                 glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );             // Set The TexCoord Pointer To The TexCoord Buffer 
    303  
    304                 glDrawArrays(GL_POINTS, 0, ResX*ResY ); 
    305                  
    306                 for(int e=0;e<MAX_LAYERS-1;e++) 
     283                if(first == 1) 
     284                { 
     285                        //First Render 
     286                        glUniform1f(DirectionTransfer, (float)buffer); 
     287                        glEnableClientState( GL_VERTEX_ARRAY );                                         // Enable Vertex Arrays 
     288                        glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] ); 
     289                        glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );               // Set The Vertex Pointer To The Vertex Buffer 
     290 
     291                        glEnableClientState( GL_TEXTURE_COORD_ARRAY );                          // Enable Texture Coord Arrays 
     292                        glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] ); 
     293                        glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );             // Set The TexCoord Pointer To The TexCoord Buffer 
     294 
     295                        glDrawArrays(GL_POINTS, 0, ResX*ResY ); 
     296                } 
     297                else 
    307298                { 
    308299                        glUniform1f(DirectionTransfer, 0.0); 
    309300 
    310                         glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[e+1] ); 
     301                        glEnableClientState( GL_VERTEX_ARRAY );                                         // Enable Vertex Arrays 
     302                        glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] ); 
    311303                        glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );               // Set The Vertex Pointer To The Vertex Buffer 
    312304 
    313                         glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[e+2] ); 
     305                        glEnableClientState( GL_TEXTURE_COORD_ARRAY );                          // Enable Texture Coord Arrays 
     306                        glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] ); 
    314307                        glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );             // Set The TexCoord Pointer To The TexCoord Buffer 
    315308 
     
    318311                        glUniform1f(DirectionTransfer, 1.0); 
    319312 
    320                         glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[e+2] ); 
     313                        glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] ); 
    321314                        glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );               // Set The Vertex Pointer To The Vertex Buffer 
    322315 
    323                         glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[e+1] ); 
     316                        glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] ); 
    324317                        glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );             // Set The TexCoord Pointer To The TexCoord Buffer 
    325318 
    326319                        glDrawArrays(GL_POINTS, 0, ResX*ResY ); 
    327320                } 
    328  
    329                 glUniform1f(DirectionTransfer, 0.0); 
    330                 glEnableClientState( GL_VERTEX_ARRAY );                                         // Enable Vertex Arrays 
    331                 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[MAX_LAYERS] ); 
    332                 glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );               // Set The Vertex Pointer To The Vertex Buffer 
    333  
    334                 glEnableClientState( GL_TEXTURE_COORD_ARRAY );                          // Enable Texture Coord Arrays 
    335                 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[MAX_LAYERS+1] ); 
    336                 glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );             // Set The TexCoord Pointer To The TexCoord Buffer 
    337  
    338                 glDrawArrays(GL_POINTS, 0, ResX*ResY ); 
    339  
    340321 
    341322                glDisableClientState( GL_VERTEX_ARRAY );                                        // Disable Vertex Arrays 
     
    473454                glActiveTexture(GL_TEXTURE0); 
    474455                glBindTexture(GL_TEXTURE_2D, texCopy[0]); 
    475                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    476                 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    477                 glUniform1i(TextureCopy, 0); 
     456                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     457                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     458                glUniform1i(TexturaNormalize, 0); 
     459                glUniform1f(ResolutionNormalize, Res2X); 
    478460 
    479461                //Draw the geometry.  
     
    489471        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    490472        glUseProgram(0); 
     473 
    491474} 
    492475 
    493476// Function that updates the lightmap.  
    494477// The number of directions used to calculate the lightmap is iterations * steps 
    495 void UpdateTexture(int iterations, int steps) 
     478void UpdateTexture(int iterations, int steps, int &count) 
    496479{ 
    497480        const int range = ((steps * 100) / steps) + ((iterations) * 100)/(steps * iterations); 
     
    506489 
    507490        bool cont = true; 
    508          
     491 
     492        count = 0; 
    509493        printf("\nIteracions: %d => Steps: %d\n", iterations, steps); 
    510494        for(int i = 0; (i < steps) && cont; i++) 
     
    513497                { 
    514498                        cont = dialog.Update(i*100/steps + j*100/(steps*iterations)); 
    515                         BuscarDireccio();                               // Find a random direction 
    516                         RenderProjeccions(); 
    517                         RenderTransfer(); 
     499                        BuscarDireccio(count);                          // Find a random direction 
     500                        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2); 
     501                                glClearColor(0.0,0.0,1.0,1.0); 
     502                                glClearDepth(1.0); 
     503                                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     504                        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
     505                        glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[0] );                 // Bind The Buffer 
     506                        glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY ); 
     507                        glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );                  
     508                        RenderProjeccions(1,1); 
     509                        RenderTransfer(1,1); 
     510                        int l = 0; 
     511                        for(int k=1; k < MAX_LAYERS; k++) 
     512                        { 
     513                                RenderProjeccions(l,0); 
     514                                l = (l == 0)? 1:0; 
     515                                RenderTransfer(l,0); 
     516                        } 
     517                        glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[l] );                 // Bind The Buffer 
     518                        glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY ); 
     519                        glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );                  
     520                        l = (l = 0)? 1:0; 
     521                        RenderTransfer(l,1); 
    518522                } 
    519523                CopyTexture(); 
    520524        } 
    521525        printf("\r100%% Done!!!!"); 
     526 
    522527        NormalizeLightmap(); 
    523528} 
     
    602607void init2(char *argv) 
    603608{        
     609        int count; 
     610 
     611        srand ( time(NULL) ); 
     612 
    604613        g_pMesh.LoadMesh(argv); 
    605614 
     
    741750        //GLSL 
    742751        //Projection Shaders 
     752//      char *vsProjection = NULL, *fsProjection = NULL; 
    743753         
    744754        vProjection = glCreateShader(GL_VERTEX_SHADER); 
    745755        fProjection = glCreateShader(GL_FRAGMENT_SHADER); 
    746756 
     757//      vsProjection = textFileRead("projection.vert"); 
     758//      fsProjection = textFileRead("projection.frag"); 
     759         
     760//      const char *vvProjection = vsProjection; 
    747761        static const char *vvProjection = 
    748762        "                                                                                                                                                               \n" 
     
    759773        "                                                                                                                                                               \n"; 
    760774 
     775//      const char *ffProjection = fsProjection; 
    761776        static const char *ffProjection = 
    762777        "                                                                                                                                                               \n" 
     
    784799        glShaderSource(fProjection, 1, &ffProjection, NULL); 
    785800 
     801//      free(vsProjection); free(fsProjection); 
     802 
    786803        glCompileShader(vProjection); 
    787804        glCompileShader(fProjection); 
     
    802819 
    803820        //Reflect Shaders 
     821//      char *vsReflect = NULL, *fsReflect = NULL; 
    804822         
    805823        vReflect = glCreateShader(GL_VERTEX_SHADER); 
    806824        fReflect = glCreateShader(GL_FRAGMENT_SHADER); 
    807825 
     826//      vsReflect = textFileRead("reflect.vert"); 
     827//      fsReflect = textFileRead("reflect.frag"); 
     828         
     829//      const char *vvReflect = vsReflect; 
    808830        static const char *vvReflect = 
    809831        "                                                                                                                               \n" 
     
    818840        "       }                                                                                                                       \n"; 
    819841 
     842//      const char *ffReflect = fsReflect; 
    820843        static const char *ffReflect = 
    821844        "                                                               \n" 
     
    831854        glShaderSource(fReflect, 1, &ffReflect, NULL); 
    832855 
     856//      free(vsReflect); free(fsReflect); 
     857 
    833858        glCompileShader(vReflect); 
    834859        glCompileShader(fReflect); 
     
    840865        glLinkProgram(pReflect); 
    841866 
     867//      glUseProgram(pReflect); 
    842868        glUseProgram(0); 
    843869 
    844870        //Texture Copy Shaders 
     871//      char *vsCopy = NULL, *fsCopy = NULL; 
    845872         
    846873        vCopy = glCreateShader(GL_VERTEX_SHADER); 
    847874        fCopy = glCreateShader(GL_FRAGMENT_SHADER); 
    848875 
     876//      vsCopy = textFileRead("copy.vert"); 
     877//      fsCopy = textFileRead("copy.frag"); 
     878         
     879//      const char *vvCopy = vsCopy; 
    849880        static const char *vvCopy = 
    850881        "                                                                                                                               \n" 
     
    859890        "       }                                                                                                                       \n"; 
    860891 
     892//      const char *ffCopy = fsCopy; 
    861893        static const char *ffCopy = 
    862894        "                                                                                                                                                       \n" 
     
    874906        glShaderSource(fCopy, 1, &ffCopy, NULL); 
    875907 
     908//      free(vsCopy); free(fsCopy); 
     909 
    876910        glCompileShader(vCopy); 
    877911        glCompileShader(fCopy); 
     
    889923 
    890924        //Lightmap Normalization Shaders 
     925//      char *vsNormalize = NULL, *fsNormalize = NULL; 
    891926         
    892927        vNormalize = glCreateShader(GL_VERTEX_SHADER); 
    893928        fNormalize = glCreateShader(GL_FRAGMENT_SHADER); 
    894929 
     930//      vsNormalize = textFileRead("normalize.vert"); 
     931//      fsNormalize = textFileRead("normalize.frag"); 
     932         
     933//      const char *vvNormalize = vsNormalize; 
    895934        static const char *vvNormalize = 
    896935        "                                                                                                                               \n" 
     
    905944        "       }                                                                                                                       \n"; 
    906945 
     946//      const char *ffNormalize = fsNormalize; 
    907947        static const char *ffNormalize = 
    908         "                                                                                                                                                       \n" 
    909         "       uniform sampler2D texture;                                                                                              \n" 
    910         "                                                                                                                                                       \n" 
    911         "       varying vec2 texCoord;                                                                                                  \n" 
    912         "                                                                                                                                                       \n" 
    913         "       void main()                                                                                                                             \n" 
    914         "       {                                                                                                                                               \n" 
    915         "               float res = 256.0;                                                                                                      \n" 
    916         "               float dif = 1.0/res;                                                                                            \n" 
    917         "               vec4 aux1 = tex2D(texture,texCoord);                                                            \n" 
    918         "               vec4 aux2 = tex2D(texture,vec2(texCoord.r+dif,texCoord.g));                     \n" 
    919         "               vec4 aux3 = tex2D(texture,vec2(texCoord.r+dif,texCoord.g+dif));         \n" 
    920         "               vec4 aux4 = tex2D(texture,vec2(texCoord.r,texCoord.g+dif));                     \n" 
    921         "               float counter = 0.0;                                                                                            \n" 
    922         "               vec4 aux = vec4(0.0,0.0,0.0,0.0);                                                                       \n" 
    923         "               if(aux1.a>0.0)                                                                                                          \n" 
    924         "               {                                                                                                                                       \n" 
    925         "                       aux += vec4(aux1.rgb/aux1.a,1.0);                                                               \n" 
    926         "                       counter += 1.0;                                                                                                 \n" 
    927         "               }                                                                                                                                       \n" 
    928         "               if(aux2.a>0.0)                                                                                                          \n" 
    929         "               {                                                                                                                                       \n" 
    930         "                       aux += vec4(aux2.rgb/aux2.a,1.0);                                                               \n" 
    931         "                       counter += 1.0;                                                                                                 \n" 
    932         "               }                                                                                                                                       \n" 
    933         "               if(aux3.a>0.0)                                                                                                          \n" 
    934         "               {                                                                                                                                       \n" 
    935         "                       aux += vec4(aux3.rgb/aux3.a,1.0);                                                               \n" 
    936         "                       counter += 1.0;                                                                                                 \n" 
    937         "               }                                                                                                                                       \n" 
    938         "               if(aux4.a>0.0)                                                                                                          \n" 
    939         "               {                                                                                                                                       \n" 
    940         "                       aux += vec4(aux4.rgb/aux4.a,1.0);                                                               \n" 
    941         "                       counter += 1.0;                                                                                                 \n" 
    942         "               }                                                                                                                                       \n" 
    943         "               if(counter < 1.0) gl_FragColor = vec4(0.0,0.0,0.0,0.0);                         \n" 
    944         "               else                                                                                                                            \n" 
    945         "               {                                                                                                                                       \n" 
    946         "                       aux /= counter;                                                                                                 \n" 
    947         "                       gl_FragColor = aux;                                                                                             \n" 
    948         "               }                                                                                                                                       \n" 
    949         "       }                                                                                                                                               \n"; 
     948        "                                                                                                                                                               \n" 
     949        "       uniform sampler2D texture;                                                                                                      \n" 
     950        "       uniform float res;                                                                                                                      \n" 
     951        "                                                                                                                                                               \n" 
     952        "       varying vec2 texCoord;                                                                                                          \n" 
     953        "                                                                                                                                                               \n" 
     954        "       void main()                                                                                                                                     \n" 
     955        "       {                                                                                                                                                       \n" 
     956        "               vec4 aux1 = tex2D(texture,texCoord);                                                                    \n" 
     957        "               if(aux1.a > 10.0)                                                                                                               \n" 
     958        "               {                                                                                                                                               \n" 
     959        "                       gl_FragColor = vec4(aux1.rgb/aux1.a,1.0);                                                       \n" 
     960        "               }                                                                                                                                               \n" 
     961        "               else                                                                                                                                    \n" 
     962        "               {                                                                                                                                               \n" 
     963//      "                       float res = 256.0;                                                                                                      \n" 
     964        "                       float dif = 1.0/res;                                                                                            \n" 
     965        "                                                                                                                                                               \n" 
     966        "                       float counter = 0.0;                                                                                            \n" 
     967        "                       vec4 aux = vec4(0.0,0.0,0.0,0.0);                                                                       \n" 
     968        "                                                                                                                                                               \n" 
     969        "                       vec4 aux2 = tex2D(texture,vec2(texCoord.r+dif,texCoord.g));                     \n" 
     970        "                       vec4 aux3 = tex2D(texture,vec2(texCoord.r+dif,texCoord.g+dif));         \n" 
     971        "                       vec4 aux4 = tex2D(texture,vec2(texCoord.r,texCoord.g+dif));                     \n" 
     972        "                       vec4 aux5 = tex2D(texture,vec2(texCoord.r-dif,texCoord.g+dif));         \n" 
     973        "                       vec4 aux6 = tex2D(texture,vec2(texCoord.r-dif,texCoord.g));                     \n" 
     974        "                       vec4 aux7 = tex2D(texture,vec2(texCoord.r-dif,texCoord.g-dif));         \n" 
     975        "                       vec4 aux8 = tex2D(texture,vec2(texCoord.r,texCoord.g-dif));                     \n" 
     976        "                       vec4 aux9 = tex2D(texture,vec2(texCoord.r+dif,texCoord.g-dif));         \n" 
     977//      "                       if(aux1.a>0.0)                                                                                                          \n" 
     978//      "                       {                                                                                                                                       \n" 
     979//      "                               aux += aux1;                                                                                                    \n" 
     980//      "                               counter += 1.0;                                                                                                 \n" 
     981//      "                       }                                                                                                                                       \n" 
     982        "                       if(aux2.a>10.0)                                                                                                         \n" 
     983        "                       {                                                                                                                                       \n" 
     984        "                               aux += aux2;                                                                                                    \n" 
     985        "                               counter += 1.0;                                                                                                 \n" 
     986        "                       }                                                                                                                                       \n" 
     987        "                       if(aux3.a>10.0)                                                                                                         \n" 
     988        "                       {                                                                                                                                       \n" 
     989        "                               aux += aux3;                                                                                                    \n" 
     990        "                               counter += 1.0;                                                                                                 \n" 
     991        "                       }                                                                                                                                       \n" 
     992        "                       if(aux4.a>10.0)                                                                                                         \n" 
     993        "                       {                                                                                                                                       \n" 
     994        "                               aux += aux4;                                                                                                    \n" 
     995        "                               counter += 1.0;                                                                                                 \n" 
     996        "                       }                                                                                                                                       \n" 
     997        "                       if(aux5.a>10.0)                                                                                                         \n" 
     998        "                       {                                                                                                                                       \n" 
     999        "                               aux += aux5;                                                                                                    \n" 
     1000        "                               counter += 1.0;                                                                                                 \n" 
     1001        "                       }                                                                                                                                       \n" 
     1002        "                       if(aux6.a>10.0)                                                                                                         \n" 
     1003        "                       {                                                                                                                                       \n" 
     1004        "                               aux += aux6;                                                                                                    \n" 
     1005        "                               counter += 1.0;                                                                                                 \n" 
     1006        "                       }                                                                                                                                       \n" 
     1007        "                       if(aux7.a>10.0)                                                                                                         \n" 
     1008        "                       {                                                                                                                                       \n" 
     1009        "                               aux += aux7;                                                                                                    \n" 
     1010        "                               counter += 1.0;                                                                                                 \n" 
     1011        "                       }                                                                                                                                       \n" 
     1012        "                       if(aux8.a>10.0)                                                                                                         \n" 
     1013        "                       {                                                                                                                                       \n" 
     1014        "                               aux += aux8;                                                                                                    \n" 
     1015        "                               counter += 1.0;                                                                                                 \n" 
     1016        "                       }                                                                                                                                       \n" 
     1017        "                       if(aux9.a>10.0)                                                                                                         \n" 
     1018        "                       {                                                                                                                                       \n" 
     1019        "                               aux += aux9;                                                                                                    \n" 
     1020        "                               counter += 1.0;                                                                                                 \n" 
     1021        "                       }                                                                                                                                       \n" 
     1022        "                       if(counter < 1.0) gl_FragColor = vec4(0.0,0.0,0.0,0.0);                         \n" 
     1023        "                       else                                                                                                                            \n" 
     1024        "                       {                                                                                                                                       \n" 
     1025        "                               aux /= counter;                                                                                                 \n" 
     1026        "                               gl_FragColor = vec4(aux.rgb/aux.a,1.0);                                                 \n" 
     1027        "                       };                                                                                                                                      \n" 
     1028        "               }                                                                                                                                               \n" 
     1029        "       }                                                                                                                                                       \n"; 
    9501030 
    9511031        glShaderSource(vNormalize, 1, &vvNormalize, NULL); 
    9521032        glShaderSource(fNormalize, 1, &ffNormalize, NULL); 
     1033 
     1034//      free(vsNormalize); free(fsNormalize); 
    9531035 
    9541036        glCompileShader(vNormalize); 
     
    9631045        glUseProgram(pNormalize); 
    9641046        TexturaNormalize = glGetUniformLocation(pNormalize, "texture"); 
     1047        ResolutionNormalize = glGetUniformLocation(pNormalize, "res"); 
    9651048        glUseProgram(0); 
    9661049 
    9671050        //Energy Transfer Shaders 
     1051//      char *vsTransfer = NULL, *fsTransfer = NULL; 
    9681052         
    9691053        vTransfer = glCreateShader(GL_VERTEX_SHADER); 
    9701054        fTransfer = glCreateShader(GL_FRAGMENT_SHADER); 
    9711055 
     1056//      vsTransfer = textFileRead("transfer.vert"); 
     1057//      fsTransfer = textFileRead("transfer.frag"); 
     1058         
     1059//      const char *vvTransfer = vsTransfer; 
    9721060        static const char *vvTransfer = 
    9731061        "                                                                                                                                                                                                                                                       \n" 
     
    10031091        "       }                                                                                                                                                                                                                                               \n"; 
    10041092 
     1093//      const char *ffTransfer = fsTransfer; 
    10051094        static const char *ffTransfer = 
    10061095        "                                                                                                                                                               \n" 
     
    10221111        glShaderSource(fTransfer, 1, &ffTransfer, NULL); 
    10231112 
     1113//      free(vsTransfer); free(fsTransfer); 
     1114 
    10241115        glCompileShader(vTransfer); 
    10251116        glCompileShader(fTransfer); 
     
    10441135        RenderReflect(); 
    10451136 
    1046         UpdateTexture(60,3);     
     1137        UpdateTexture(60, 3, count);     
    10471138 
    10481139} 
    10491140 
    1050 // Function that interfaces with the VisualCAD. 
     1141//Interface of the Obscurance Module 
    10511142int vcObscurerGenerateImage(CMesh &geom, char *argv, int quality, int *imgUsize, int *imgVsize, float **imgRgbBuffer) 
    10521143{ 
     
    10591150        float a; 
    10601151 
    1061  
    10621152        glutCreateWindow("T"); 
    1063          
     1153 
    10641154        glerror = glewInit(); 
    10651155 
    10661156        FILE *file = NULL; 
    10671157 
    1068         file = fopen("tmp.txt", "w"); 
    1069  
    1070         if (glerror != GLEW_OK) fprintf(file, "\nError initializing glew library, %s", glewGetErrorString(glerror)); 
    1071         else fprintf(file, "\nTot Correcte!\n"); 
     1158        file = fopen("GPUObscurancesLog.txt", "w"); 
     1159 
     1160        if ((!file) || (glerror != GLEW_OK)) 
     1161        { 
     1162                fprintf(file, "GPUObscurancesLog: Error initializing glew library"); 
     1163                exit(-1); 
     1164        } 
     1165        else 
     1166                fprintf(file, "GPUObscurancesLog: glew library correctly initialized"); 
    10721167 
    10731168        fclose(file); 
     
    11081203        init2(argv); 
    11091204  
     1205        //->g_pMesh.FreeMem(); 
     1206 
    11101207        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb5); 
    11111208        glReadPixels(0,0,Res2X,Res2Y,GL_RGBA,GL_FLOAT,dadesf); 
    11121209        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
    11131210 
     1211/*      for(int i=0; i<Res2X*Res2Y; i++) 
     1212        { 
     1213                divisor = dadesf[4*i+3]; 
     1214                if(divisor>15) 
     1215                { 
     1216                        dadesf[4*i] = (dadesf[4*i]/divisor); 
     1217                        dadesf[4*i+1] = (dadesf[4*i+1]/divisor); 
     1218                        dadesf[4*i+2] = (dadesf[4*i+2]/divisor); 
     1219                        dadesf[4*i+3] = 1.0; 
     1220                } 
     1221                else 
     1222                { 
     1223                        a=0; 
     1224                        aux[0] = 0.0; 
     1225                        aux[1] = 0.0; 
     1226                        aux[2] = 0.0; 
     1227                        aux[3] = 0.0; 
     1228                        if(i/Res2X > 0) 
     1229                        { 
     1230                                if(i/Res2X < Res2Y-1) 
     1231                                { 
     1232                                        if(i%Res2X !=0) 
     1233                                        { 
     1234                                                if(dadesf[4*(i-Res2X)-1]>15)    //ul(); 
     1235                                                { 
     1236                                                        aux[0] += (dadesf[4*(i-Res2X)-4]/dadesf[4*(i-Res2X)-1]); 
     1237                                                        aux[1] += (dadesf[4*(i-Res2X)-3]/dadesf[4*(i-Res2X)-1]); 
     1238                                                        aux[2] += (dadesf[4*(i-Res2X)-2]/dadesf[4*(i-Res2X)-1]); 
     1239                                                        aux[3] += 1.0; 
     1240                                                        a =+ 1.0;; 
     1241                                                } 
     1242                                                if(dadesf[4*i-1]>15)    //l(); 
     1243                                                { 
     1244                                                        aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]); 
     1245                                                        aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]); 
     1246                                                        aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]); 
     1247                                                        aux[3] += 1.0; 
     1248                                                        a =+ 1.0;; 
     1249                                                } 
     1250                                                if(dadesf[4*(i+Res2X)-1]>15)    //dl(); 
     1251                                                { 
     1252                                                        aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]); 
     1253                                                        aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]); 
     1254                                                        aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]); 
     1255                                                        aux[3] += 1.0; 
     1256                                                        a =+ 1.0;; 
     1257                                                } 
     1258                                        } 
     1259                                        if(dadesf[4*(i+Res2X)+3]>15)    //d(); 
     1260                                        { 
     1261                                                aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]); 
     1262                                                aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]); 
     1263                                                aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]); 
     1264                                                aux[3] += 1.0; 
     1265                                                a =+ 1.0;; 
     1266                                        } 
     1267                                        if(i%Res2X!=Res2X-1) 
     1268                                        { 
     1269                                                if(dadesf[4*(i-Res2X)+7]>15)    //ur(); 
     1270                                                { 
     1271                                                        aux[0] += (dadesf[4*(i-Res2X)+4]/dadesf[4*(i-Res2X)+7]); 
     1272                                                        aux[1] += (dadesf[4*(i-Res2X)+5]/dadesf[4*(i-Res2X)+7]); 
     1273                                                        aux[2] += (dadesf[4*(i-Res2X)+6]/dadesf[4*(i-Res2X)+7]); 
     1274                                                        aux[3] += 1.0; 
     1275                                                        a =+ 1.0;; 
     1276                                                } 
     1277                                                if(dadesf[4*i+7]>15)    //r(); 
     1278                                                { 
     1279                                                        aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]); 
     1280                                                        aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]); 
     1281                                                        aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]); 
     1282                                                        aux[3] += 1.0; 
     1283                                                        a =+ 1.0;; 
     1284                                                } 
     1285                                                if(dadesf[4*(i+Res2X)+7]>15)    //dr(); 
     1286                                                { 
     1287                                                        aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]); 
     1288                                                        aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]); 
     1289                                                        aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]); 
     1290                                                        aux[3] += 1.0; 
     1291                                                        a =+ 1.0;; 
     1292                                                } 
     1293                                        } 
     1294                                        if(dadesf[4*(i-Res2X)+3]>15)    //u(); 
     1295                                        { 
     1296                                                aux[0] += (dadesf[4*(i-Res2X)]/dadesf[4*(i-Res2X)+3]); 
     1297                                                aux[1] += (dadesf[4*(i-Res2X)+1]/dadesf[4*(i-Res2X)+3]); 
     1298                                                aux[2] += (dadesf[4*(i-Res2X)+2]/dadesf[4*(i-Res2X)+3]); 
     1299                                                aux[3] += 1.0; 
     1300                                                a =+ 1.0;; 
     1301                                        } 
     1302                                } 
     1303                        } 
     1304                        else 
     1305                        { 
     1306                                if(i%Res2X !=0) 
     1307                                { 
     1308                                        if(dadesf[4*i-1]>15)    //l(); 
     1309                                        { 
     1310                                                aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]); 
     1311                                                aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]); 
     1312                                                aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]); 
     1313                                                aux[3] += 1.0; 
     1314                                                a =+ 1.0;; 
     1315                                        } 
     1316                                        if(dadesf[4*(i+Res2X)-1]>15)    //dl(); 
     1317                                        { 
     1318                                                aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]); 
     1319                                                aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]); 
     1320                                                aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]); 
     1321                                                aux[3] = 1.0; 
     1322                                                a =+ 1.0;; 
     1323                                        } 
     1324                                } 
     1325                                if(i%Res2X!=Res2X-1) 
     1326                                { 
     1327                                        if(dadesf[4*i+7]>15)    //r(); 
     1328                                        { 
     1329                                                aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]); 
     1330                                                aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]); 
     1331                                                aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]); 
     1332                                                aux[3] += 1.0; 
     1333                                                a =+ 1.0;; 
     1334                                        } 
     1335                                        if(dadesf[4*(i+Res2X)+7]>15)    //dr(); 
     1336                                        { 
     1337                                                aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]); 
     1338                                                aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]); 
     1339                                                aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]); 
     1340                                                aux[3] += 1.0; 
     1341                                                a =+ 1.0;; 
     1342                                        } 
     1343                                } 
     1344                                if(dadesf[4*(i+Res2X)+3]>15)    //d(); 
     1345                                { 
     1346                                                aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]); 
     1347                                                aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]); 
     1348                                                aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]); 
     1349                                                aux[3] += 1.0; 
     1350                                                a =+ 1.0;; 
     1351                                } 
     1352                        } 
     1353                        if(a > 0.0) 
     1354                        { 
     1355                                dadesf[4*i] = aux[0]/aux[3]; 
     1356                                dadesf[4*i+1] = aux[1]/aux[3]; 
     1357                                dadesf[4*i+2] = aux[2]/aux[3]; 
     1358                                dadesf[4*i+3] = 1.0; 
     1359                        } 
     1360                        else 
     1361                        { 
     1362                                dadesf[4*i] = 0.0; 
     1363                                dadesf[4*i+1] = 0.0; 
     1364                                dadesf[4*i+2] = 0.0; 
     1365                                dadesf[4*i+3] = 0.0; 
     1366                        } 
     1367                } 
     1368                dadesi[4*i] = (int)(255.0*dadesf[4*i]); 
     1369                dadesi[4*i+1] = (int)(255.0*dadesf[4*i+1]); 
     1370                dadesi[4*i+2] = (int)(255.0*dadesf[4*i+2]); 
     1371                dadesi[4*i+3] = (int)(255.0*dadesf[4*i+3]); 
     1372 
     1373        } 
     1374*/ 
    11141375        *imgRgbBuffer = dadesf; 
    11151376 
Note: See TracChangeset for help on using the changeset viewer.