Changeset 1648 for GTP/trunk/Lib/Illum/GPUObscurancesGT/src
- Timestamp:
- 10/19/06 15:27:47 (18 years ago)
- Location:
- GTP/trunk/Lib/Illum/GPUObscurancesGT/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Illum/GPUObscurancesGT/src/MyFrame.cpp
r953 r1648 226 226 float r_float; 227 227 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)) 229 231 { 230 232 r_float = ObscuranceMap[i] * 255; … … 234 236 r_float = ObscuranceMap[i+2] * 255; 235 237 bmp[j + 2] = uchar(r_float); 238 239 j += 3; 240 i += 4; 236 241 } 237 242 -
GTP/trunk/Lib/Illum/GPUObscurancesGT/src/vcObscuranceMap.cpp
r930 r1648 7 7 #pragma warning(disable:4244) 8 8 // Includes 9 #define GLEW_STATIC 1 9 10 #include "glew.h" 10 11 #include <glut.h> 12 //#include <iostream> 11 13 #include "stdlib.h" 14 #include "time.h" 12 15 13 16 // Includes 14 17 #include "CMesh.h" 15 18 #include "vcObscuranceMap.h" 16 17 //progress bar18 #include <wx/progdlg.h>19 19 20 20 #define ROUND(x) (floor(x+0.5)) … … 57 57 //Lightmap Normalization Step. 58 58 GLint TexturaNormalize; 59 GLint ResolutionNormalize; 59 60 60 61 // Global variables … … 67 68 static int Res2X; //Resolution 68 69 static int Res2Y; //Resolution 69 70 70 71 71 //RenderTexture *ob=NULL; // RenderTexture for the Obscurances. … … 121 121 } 122 122 123 float 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 } 123 135 124 136 // Returns a random point in the surface of the sphere 125 CVert ranpoint(float r, CVert c )137 CVert ranpoint(float r, CVert c, int &count) 126 138 { 127 doubleale1, ale2;139 float ale1, ale2; 128 140 CVert p; 129 141 float alfa,beta; 130 142 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; 133 148 134 149 alfa=1.0-2.0*ale1; /* real between -1 and 1 */ … … 146 161 // Function to find a point in the sphere in the direction that goes from the point in the surface of the sphere 147 162 // to the center of the sphere. First it gets the random point in the surface. 148 void BuscarDireccio( )163 void BuscarDireccio(int &count) 149 164 { 150 165 Esfera.center.x = 0.0; … … 153 168 Esfera.radius = sqrt(12.0)/2.0; 154 169 155 Primer = ranpoint(Esfera.radius, Esfera.center);170 Primer = ranpoint(Esfera.radius, Esfera.center, count); 156 171 Vertex.x = Primer.x + (Esfera.center.x-Primer.x) * ((float)rand()/(float)RAND_MAX)*2.0; 157 172 Vertex.y = Primer.y + (Esfera.center.y-Primer.y) * ((float)rand()/(float)RAND_MAX)*2.0; … … 160 175 161 176 // Function that renders the depth peeling geometry planes and stores them in PBOs. 162 void RenderProjeccions( void)177 void RenderProjeccions(int buffer, int first) 163 178 { 179 int i, j, e; 180 164 181 glUseProgram(pProjection); 165 182 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2); 166 183 167 int i, j, e;168 184 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);172 185 glEnable (GL_DEPTH_TEST); // Enable Depth Testing 173 186 glDepthFunc(GL_LESS); … … 188 201 189 202 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 } 191 218 192 219 // Enable Pointers … … 214 241 } 215 242 216 //Copy the color buffer to PBO.217 glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[1] ); // Bind The Buffer218 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 Buffer229 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 Buffer232 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 Data243 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 Buffer245 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 Buffer247 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 Buffer249 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 Once252 }253 }254 255 glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[e+1] ); // Bind The Buffer256 glReadPixels(0, 0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));257 glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);258 }259 260 243 glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays 261 244 glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays 262 245 glDisableClientState( GL_NORMAL_ARRAY ); // Disable Texture Coord Arrays 263 246 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 264 252 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 265 253 glUseProgram(0); … … 267 255 268 256 // Function that calculates the lightmap using the neighbouring projections. 269 void RenderTransfer( void)257 void RenderTransfer(int buffer, int first) 270 258 { 271 259 glUseProgram(pTransfer); 272 260 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3); 273 261 262 int other = ((buffer == 1)? 0:1); 263 274 264 glBlendFunc(GL_ONE, GL_ONE); 275 265 … … 287 277 288 278 glUniform1f(DmaxTransfer, (GLfloat)0.3); 289 glUniform1f(DirectionTransfer, 0.0);290 279 glActiveTexture(GL_TEXTURE0); 291 280 glBindTexture(GL_TEXTURE_2D, texReflect[0]); 292 281 glUniform1i(TexturaReflectTransfer, 0); 293 282 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 307 298 { 308 299 glUniform1f(DirectionTransfer, 0.0); 309 300 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] ); 311 303 glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer 312 304 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] ); 314 307 glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer 315 308 … … 318 311 glUniform1f(DirectionTransfer, 1.0); 319 312 320 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[ e+2] );313 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] ); 321 314 glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer 322 315 323 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[ e+1] );316 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] ); 324 317 glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer 325 318 326 319 glDrawArrays(GL_POINTS, 0, ResX*ResY ); 327 320 } 328 329 glUniform1f(DirectionTransfer, 0.0);330 glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays331 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[MAX_LAYERS] );332 glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer333 334 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays335 glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[MAX_LAYERS+1] );336 glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer337 338 glDrawArrays(GL_POINTS, 0, ResX*ResY );339 340 321 341 322 glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays … … 473 454 glActiveTexture(GL_TEXTURE0); 474 455 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); 478 460 479 461 //Draw the geometry. … … 489 471 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 490 472 glUseProgram(0); 473 491 474 } 492 475 493 476 // Function that updates the lightmap. 494 477 // The number of directions used to calculate the lightmap is iterations * steps 495 void UpdateTexture(int iterations, int steps )478 void UpdateTexture(int iterations, int steps, int &count) 496 479 { 497 480 const int range = ((steps * 100) / steps) + ((iterations) * 100)/(steps * iterations); … … 506 489 507 490 bool cont = true; 508 491 492 count = 0; 509 493 printf("\nIteracions: %d => Steps: %d\n", iterations, steps); 510 494 for(int i = 0; (i < steps) && cont; i++) … … 513 497 { 514 498 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); 518 522 } 519 523 CopyTexture(); 520 524 } 521 525 printf("\r100%% Done!!!!"); 526 522 527 NormalizeLightmap(); 523 528 } … … 602 607 void init2(char *argv) 603 608 { 609 int count; 610 611 srand ( time(NULL) ); 612 604 613 g_pMesh.LoadMesh(argv); 605 614 … … 741 750 //GLSL 742 751 //Projection Shaders 752 // char *vsProjection = NULL, *fsProjection = NULL; 743 753 744 754 vProjection = glCreateShader(GL_VERTEX_SHADER); 745 755 fProjection = glCreateShader(GL_FRAGMENT_SHADER); 746 756 757 // vsProjection = textFileRead("projection.vert"); 758 // fsProjection = textFileRead("projection.frag"); 759 760 // const char *vvProjection = vsProjection; 747 761 static const char *vvProjection = 748 762 " \n" … … 759 773 " \n"; 760 774 775 // const char *ffProjection = fsProjection; 761 776 static const char *ffProjection = 762 777 " \n" … … 784 799 glShaderSource(fProjection, 1, &ffProjection, NULL); 785 800 801 // free(vsProjection); free(fsProjection); 802 786 803 glCompileShader(vProjection); 787 804 glCompileShader(fProjection); … … 802 819 803 820 //Reflect Shaders 821 // char *vsReflect = NULL, *fsReflect = NULL; 804 822 805 823 vReflect = glCreateShader(GL_VERTEX_SHADER); 806 824 fReflect = glCreateShader(GL_FRAGMENT_SHADER); 807 825 826 // vsReflect = textFileRead("reflect.vert"); 827 // fsReflect = textFileRead("reflect.frag"); 828 829 // const char *vvReflect = vsReflect; 808 830 static const char *vvReflect = 809 831 " \n" … … 818 840 " } \n"; 819 841 842 // const char *ffReflect = fsReflect; 820 843 static const char *ffReflect = 821 844 " \n" … … 831 854 glShaderSource(fReflect, 1, &ffReflect, NULL); 832 855 856 // free(vsReflect); free(fsReflect); 857 833 858 glCompileShader(vReflect); 834 859 glCompileShader(fReflect); … … 840 865 glLinkProgram(pReflect); 841 866 867 // glUseProgram(pReflect); 842 868 glUseProgram(0); 843 869 844 870 //Texture Copy Shaders 871 // char *vsCopy = NULL, *fsCopy = NULL; 845 872 846 873 vCopy = glCreateShader(GL_VERTEX_SHADER); 847 874 fCopy = glCreateShader(GL_FRAGMENT_SHADER); 848 875 876 // vsCopy = textFileRead("copy.vert"); 877 // fsCopy = textFileRead("copy.frag"); 878 879 // const char *vvCopy = vsCopy; 849 880 static const char *vvCopy = 850 881 " \n" … … 859 890 " } \n"; 860 891 892 // const char *ffCopy = fsCopy; 861 893 static const char *ffCopy = 862 894 " \n" … … 874 906 glShaderSource(fCopy, 1, &ffCopy, NULL); 875 907 908 // free(vsCopy); free(fsCopy); 909 876 910 glCompileShader(vCopy); 877 911 glCompileShader(fCopy); … … 889 923 890 924 //Lightmap Normalization Shaders 925 // char *vsNormalize = NULL, *fsNormalize = NULL; 891 926 892 927 vNormalize = glCreateShader(GL_VERTEX_SHADER); 893 928 fNormalize = glCreateShader(GL_FRAGMENT_SHADER); 894 929 930 // vsNormalize = textFileRead("normalize.vert"); 931 // fsNormalize = textFileRead("normalize.frag"); 932 933 // const char *vvNormalize = vsNormalize; 895 934 static const char *vvNormalize = 896 935 " \n" … … 905 944 " } \n"; 906 945 946 // const char *ffNormalize = fsNormalize; 907 947 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"; 950 1030 951 1031 glShaderSource(vNormalize, 1, &vvNormalize, NULL); 952 1032 glShaderSource(fNormalize, 1, &ffNormalize, NULL); 1033 1034 // free(vsNormalize); free(fsNormalize); 953 1035 954 1036 glCompileShader(vNormalize); … … 963 1045 glUseProgram(pNormalize); 964 1046 TexturaNormalize = glGetUniformLocation(pNormalize, "texture"); 1047 ResolutionNormalize = glGetUniformLocation(pNormalize, "res"); 965 1048 glUseProgram(0); 966 1049 967 1050 //Energy Transfer Shaders 1051 // char *vsTransfer = NULL, *fsTransfer = NULL; 968 1052 969 1053 vTransfer = glCreateShader(GL_VERTEX_SHADER); 970 1054 fTransfer = glCreateShader(GL_FRAGMENT_SHADER); 971 1055 1056 // vsTransfer = textFileRead("transfer.vert"); 1057 // fsTransfer = textFileRead("transfer.frag"); 1058 1059 // const char *vvTransfer = vsTransfer; 972 1060 static const char *vvTransfer = 973 1061 " \n" … … 1003 1091 " } \n"; 1004 1092 1093 // const char *ffTransfer = fsTransfer; 1005 1094 static const char *ffTransfer = 1006 1095 " \n" … … 1022 1111 glShaderSource(fTransfer, 1, &ffTransfer, NULL); 1023 1112 1113 // free(vsTransfer); free(fsTransfer); 1114 1024 1115 glCompileShader(vTransfer); 1025 1116 glCompileShader(fTransfer); … … 1044 1135 RenderReflect(); 1045 1136 1046 UpdateTexture(60, 3);1137 UpdateTexture(60, 3, count); 1047 1138 1048 1139 } 1049 1140 1050 // Function that interfaces with the VisualCAD.1141 //Interface of the Obscurance Module 1051 1142 int vcObscurerGenerateImage(CMesh &geom, char *argv, int quality, int *imgUsize, int *imgVsize, float **imgRgbBuffer) 1052 1143 { … … 1059 1150 float a; 1060 1151 1061 1062 1152 glutCreateWindow("T"); 1063 1153 1064 1154 glerror = glewInit(); 1065 1155 1066 1156 FILE *file = NULL; 1067 1157 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"); 1072 1167 1073 1168 fclose(file); … … 1108 1203 init2(argv); 1109 1204 1205 //->g_pMesh.FreeMem(); 1206 1110 1207 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb5); 1111 1208 glReadPixels(0,0,Res2X,Res2Y,GL_RGBA,GL_FLOAT,dadesf); 1112 1209 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 1113 1210 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 */ 1114 1375 *imgRgbBuffer = dadesf; 1115 1376
Note: See TracChangeset
for help on using the changeset viewer.