[930] | 1 | //========================================
|
---|
| 2 | // Class to interface the VisualCAD specifications.
|
---|
| 3 | // Nicolau Sunyer & Sergi Funtané (10/13/2005).
|
---|
| 4 | // Universitat de Girona.
|
---|
| 5 | //========================================
|
---|
| 6 |
|
---|
| 7 | #pragma warning(disable:4244) |
---|
| 8 | // Includes
|
---|
| 9 | #define GLEW_STATIC 1
|
---|
| 10 | #include "glew.h"
|
---|
| 11 | #include <iostream>
|
---|
| 12 | #include "textfile.h"
|
---|
| 13 |
|
---|
| 14 | // Includes
|
---|
| 15 | #include "CMesh.h"
|
---|
| 16 | #include "vcObscuranceMap.h"
|
---|
| 17 | #include <imdebug.h>
|
---|
| 18 | #include <imdebuggl.h>
|
---|
| 19 |
|
---|
| 20 | #ifndef M_PI
|
---|
| 21 | #define M_PI 3.14159265358979323846
|
---|
| 22 | #endif
|
---|
| 23 |
|
---|
| 24 | // DepthPeeling Layers.
|
---|
| 25 | #define MAX_LAYERS 12
|
---|
| 26 |
|
---|
| 27 | // To use Offsets in the PBOs.
|
---|
| 28 | #define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
---|
| 29 |
|
---|
| 30 | //GLSL
|
---|
| 31 | // Handlers
|
---|
| 32 | GLuint vProjection,fProjection,pProjection;
|
---|
| 33 | GLuint vReflect, fReflect, pReflect;
|
---|
| 34 | GLuint vCopy, fCopy, pCopy;
|
---|
| 35 | GLuint vTransfer, fTransfer, pTransfer;
|
---|
| 36 |
|
---|
| 37 | //Uniform Parameters
|
---|
| 38 | //Projection Step
|
---|
| 39 | GLint TexturaDepthProjection;
|
---|
| 40 | GLint SizeProjection;
|
---|
| 41 | GLint FirstProjection;
|
---|
| 42 |
|
---|
| 43 | //Reflectivity texture generation Step.
|
---|
| 44 |
|
---|
| 45 | //Texture Copy Step.
|
---|
| 46 | GLint TextureCopy;
|
---|
| 47 | GLint Texture2Copy;
|
---|
| 48 |
|
---|
| 49 | //Energy Transfer Step.
|
---|
| 50 | GLint TexturaReflectTransfer;
|
---|
| 51 | GLint DirectionTransfer;
|
---|
| 52 | GLint DmaxTransfer;
|
---|
| 53 |
|
---|
| 54 | // Global variables
|
---|
| 55 | CVert Vertex, Direccio, Increment, Primer, Ultim, Origin;
|
---|
| 56 |
|
---|
| 57 | static GLuint texName[3];
|
---|
| 58 |
|
---|
| 59 | static int ResX; //Resolution
|
---|
| 60 | static int ResY;
|
---|
| 61 | static int Res2X; //Resolution
|
---|
| 62 | static int Res2Y; //Resolution
|
---|
| 63 |
|
---|
| 64 | //RenderTexture *ob=NULL; // RenderTexture for the Obscurances.
|
---|
| 65 |
|
---|
| 66 | static GLuint texProjeccions[2]; //Texture name
|
---|
| 67 | static GLuint texTransfer[1];
|
---|
| 68 | static GLuint texReflect[1];
|
---|
| 69 | static GLuint texCopy[1];
|
---|
| 70 | static GLuint fb1; // Framebuffer Reflectivity
|
---|
| 71 | static GLuint fb2; // Framebuffer Projeccions
|
---|
| 72 | static GLuint fb3; // Framebuffer Transfer
|
---|
| 73 | static GLuint fb4; // Framebuffer Copy
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | GLenum glerror;
|
---|
| 78 |
|
---|
| 79 | GLfloat *m_pTextureImage;// Texture of diferent colors.
|
---|
| 80 | GLfloat *m_pTextureReflect; //Texture of reflectivitat.
|
---|
| 81 | GLfloat *m_pBlau;
|
---|
| 82 | GLfloat *m_pNegre;
|
---|
| 83 | int obs_global_cancelar;
|
---|
| 84 |
|
---|
| 85 | CMesh g_pMesh; // Mesh Data
|
---|
| 86 | static CSphere Esfera;
|
---|
| 87 |
|
---|
| 88 | static GLuint ProjectionsPBO[MAX_LAYERS+2]; // PBOs to store the projections.
|
---|
| 89 | static GLuint ObscurancesPBO; // PBOs to store the projections.
|
---|
| 90 | static GLuint ztex; //Texture with the depth.
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | // Function to use when the window is resized
|
---|
| 94 | void changeSize(int w, int h)
|
---|
| 95 | {
|
---|
| 96 |
|
---|
| 97 | if(h == 0)
|
---|
| 98 | h = 1;
|
---|
| 99 |
|
---|
| 100 | float ratio = 1.0 * (float)w / (float)h;
|
---|
| 101 |
|
---|
| 102 | //Camera Set up
|
---|
| 103 | glMatrixMode(GL_PROJECTION);
|
---|
| 104 | glLoadIdentity();
|
---|
| 105 | gluOrtho2D(-w,w,-h,h);
|
---|
| 106 |
|
---|
| 107 | glMatrixMode(GL_MODELVIEW);
|
---|
| 108 | glLoadIdentity();
|
---|
| 109 |
|
---|
| 110 | glViewport(0, 0, w, h);
|
---|
| 111 |
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | // Returns a random point in the surface of the sphere
|
---|
| 116 | CVert ranpoint(float r, CVert c)
|
---|
| 117 | {
|
---|
| 118 | double ale1, ale2;
|
---|
| 119 | CVert p;
|
---|
| 120 | float alfa,beta;
|
---|
| 121 |
|
---|
| 122 | ale1= (float)rand()/(float)RAND_MAX;
|
---|
| 123 | ale2= (float)rand()/(float)RAND_MAX;
|
---|
| 124 |
|
---|
| 125 | alfa=1.0-2.0*ale1; /* real between -1 and 1 */
|
---|
| 126 | alfa=acos(alfa); /* angle between 0 and PI */
|
---|
| 127 |
|
---|
| 128 | beta=2*M_PI*ale2; /* angle between 0 and 2*PI */
|
---|
| 129 |
|
---|
| 130 | p.x=c.x+r*sin(alfa)*cos(beta);
|
---|
| 131 | p.y=c.y+r*sin(alfa)*sin(beta);
|
---|
| 132 | p.z=c.z+r*cos(alfa);
|
---|
| 133 |
|
---|
| 134 | return p;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | // Function to find a point in the sphere in the direction that goes from the point in the surface of the sphere
|
---|
| 138 | // to the center of the sphere. First it gets the random point in the surface.
|
---|
| 139 | void BuscarDireccio()
|
---|
| 140 | {
|
---|
| 141 | Esfera.center.x = 0.0;
|
---|
| 142 | Esfera.center.y = 0.0;
|
---|
| 143 | Esfera.center.z = 0.0;
|
---|
| 144 | Esfera.radius = sqrt(12.0)/2.0;
|
---|
| 145 |
|
---|
| 146 | Primer = ranpoint(Esfera.radius,Esfera.center);
|
---|
| 147 | Vertex.x = Primer.x + (Esfera.center.x-Primer.x) * ((float)rand()/(float)RAND_MAX)*2.0;
|
---|
| 148 | Vertex.y = Primer.y + (Esfera.center.y-Primer.y) * ((float)rand()/(float)RAND_MAX)*2.0;
|
---|
| 149 | Vertex.z = Primer.z + (Esfera.center.z-Primer.z) * ((float)rand()/(float)RAND_MAX)*2.0;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | // Function that renders the depth peeling geometry planes and stores them in PBOs.
|
---|
| 153 | void RenderProjeccions(int buffer, int first)
|
---|
| 154 | {
|
---|
| 155 | int i, j, e;
|
---|
| 156 |
|
---|
| 157 | glUseProgram(pProjection);
|
---|
| 158 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
|
---|
| 159 |
|
---|
| 160 | changeSize(ResX, ResY);
|
---|
| 161 | glEnable (GL_DEPTH_TEST); // Enable Depth Testing
|
---|
| 162 | glDepthFunc(GL_LESS);
|
---|
| 163 |
|
---|
| 164 | glDisable(GL_CULL_FACE);
|
---|
| 165 |
|
---|
| 166 | glMatrixMode(GL_PROJECTION);
|
---|
| 167 | glLoadIdentity();
|
---|
| 168 | glOrtho(-Esfera.radius,Esfera.radius,-Esfera.radius,Esfera.radius,0,Esfera.radius * 2.0);
|
---|
| 169 |
|
---|
| 170 | glMatrixMode(GL_MODELVIEW);
|
---|
| 171 | glLoadIdentity();
|
---|
| 172 | gluLookAt(Primer.x,Primer.y,Primer.z,
|
---|
| 173 | Esfera.center.x,Esfera.center.y,Esfera.center.z,
|
---|
| 174 | 0.0f,1.0f,0.0f);
|
---|
| 175 |
|
---|
| 176 | glViewport(0,0,ResX,ResY);
|
---|
| 177 |
|
---|
| 178 | glUniform1f(SizeProjection, (float)ResX);
|
---|
| 179 | glUniform1f(FirstProjection, (float)first);
|
---|
| 180 |
|
---|
| 181 | int other = ((buffer == 1)? 0:1);
|
---|
| 182 | if(first == 0)
|
---|
| 183 | {
|
---|
| 184 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[other] ); // Bind The Buffer
|
---|
| 185 | glBindTexture(GL_TEXTURE_2D,texName[0]);
|
---|
| 186 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, ResX, ResY);
|
---|
| 187 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 ); // Bind The Buffer
|
---|
| 188 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 189 |
|
---|
| 190 | glActiveTexture(GL_TEXTURE0);
|
---|
| 191 | glBindTexture(GL_TEXTURE_2D, texName[0]);
|
---|
| 192 | glUniform1i(TexturaDepthProjection, 0);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | // Enable Pointers
|
---|
| 196 | glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
|
---|
| 197 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
|
---|
| 198 | glEnableClientState( GL_NORMAL_ARRAY ); // Enable Texture Coord Arrays
|
---|
| 199 |
|
---|
| 200 | for(i=0; i<g_pMesh.m_pObject._numGeos;i++)
|
---|
| 201 | {
|
---|
| 202 | for(j=0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
|
---|
| 203 | {
|
---|
| 204 | // Set Pointers To Our Data
|
---|
| 205 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices );
|
---|
| 206 | glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer
|
---|
| 207 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );
|
---|
| 208 | glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer
|
---|
| 209 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals );
|
---|
| 210 | glNormalPointer( GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer
|
---|
| 211 | glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );
|
---|
| 212 |
|
---|
| 213 | // Render
|
---|
| 214 | 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
|
---|
| 215 |
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
|
---|
| 220 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
|
---|
| 221 | glDisableClientState( GL_NORMAL_ARRAY ); // Disable Texture Coord Arrays
|
---|
| 222 |
|
---|
| 223 | //Copy the color buffer to PBO.
|
---|
| 224 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[buffer] ); // Bind The Buffer
|
---|
| 225 | glReadPixels(0, 0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 226 | glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
|
---|
| 227 |
|
---|
| 228 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
---|
| 229 | glUseProgram(0);
|
---|
| 230 | }
|
---|
| 231 |
|
---|
| 232 | // Function that calculates the lightmap using the neighbouring projections.
|
---|
| 233 | void RenderTransfer(int buffer, int first)
|
---|
| 234 | {
|
---|
| 235 | glUseProgram(pTransfer);
|
---|
| 236 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
|
---|
| 237 |
|
---|
| 238 | int other = ((buffer == 1)? 0:1);
|
---|
| 239 |
|
---|
| 240 | glBlendFunc(GL_ONE, GL_ONE);
|
---|
| 241 |
|
---|
| 242 | glEnable(GL_BLEND);
|
---|
| 243 |
|
---|
| 244 | glMatrixMode(GL_PROJECTION);
|
---|
| 245 | glLoadIdentity();
|
---|
| 246 | gluOrtho2D(-1,1,-1,1);
|
---|
| 247 |
|
---|
| 248 | glMatrixMode(GL_MODELVIEW);
|
---|
| 249 | glLoadIdentity();
|
---|
| 250 | glPointSize(1.0);
|
---|
| 251 |
|
---|
| 252 | glViewport(0, 0, Res2X, Res2Y);
|
---|
| 253 |
|
---|
| 254 | glUniform1f(DmaxTransfer, (GLfloat)0.3);
|
---|
| 255 | // glUniform1f(DirectionTransfer, 0.0);
|
---|
| 256 | glActiveTexture(GL_TEXTURE0);
|
---|
| 257 | glBindTexture(GL_TEXTURE_2D, texReflect[0]);
|
---|
| 258 | glUniform1i(TexturaReflectTransfer, 0);
|
---|
| 259 |
|
---|
| 260 | if(first == 1)
|
---|
| 261 | {
|
---|
| 262 | // printf("\nEntrem al first");
|
---|
| 263 | // printf("\nFirst: %d", first);
|
---|
| 264 | // printf("\nBuffer: %d", buffer);
|
---|
| 265 | //First Render
|
---|
| 266 | glUniform1f(DirectionTransfer, (float)buffer);
|
---|
| 267 | glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
|
---|
| 268 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
|
---|
| 269 | glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer
|
---|
| 270 |
|
---|
| 271 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
|
---|
| 272 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
|
---|
| 273 | glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer
|
---|
| 274 |
|
---|
| 275 | glDrawArrays(GL_POINTS, 0, ResX*ResY );
|
---|
| 276 | }
|
---|
| 277 | else
|
---|
| 278 | {
|
---|
| 279 | // printf("\nNo entrem al first");
|
---|
| 280 | // printf("\nFirst: %d", first);
|
---|
| 281 | // printf("\nBuffer: %d", buffer);
|
---|
| 282 | glUniform1f(DirectionTransfer, 0.0);
|
---|
| 283 |
|
---|
| 284 | glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
|
---|
| 285 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
|
---|
| 286 | glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer
|
---|
| 287 |
|
---|
| 288 | glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
|
---|
| 289 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
|
---|
| 290 | glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer
|
---|
| 291 |
|
---|
| 292 | glDrawArrays(GL_POINTS, 0, ResX*ResY );
|
---|
| 293 |
|
---|
| 294 | glUniform1f(DirectionTransfer, 1.0);
|
---|
| 295 |
|
---|
| 296 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
|
---|
| 297 | glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer
|
---|
| 298 |
|
---|
| 299 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
|
---|
| 300 | glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer
|
---|
| 301 |
|
---|
| 302 | glDrawArrays(GL_POINTS, 0, ResX*ResY );
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
|
---|
| 306 | glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
|
---|
| 307 |
|
---|
| 308 | glDisable(GL_BLEND);
|
---|
| 309 | glUseProgram(0);
|
---|
| 310 |
|
---|
| 311 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
---|
| 312 |
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | // Function that copies the 16-bit fp RGBA buffer of the lightmap to a 32-bit RGBA fb buffer.
|
---|
| 316 | void CopyTexture(void)
|
---|
| 317 | {
|
---|
| 318 | glUseProgram(pCopy);
|
---|
| 319 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
|
---|
| 320 | void *texturePBO;
|
---|
| 321 |
|
---|
| 322 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ObscurancesPBO ); // Bind The Buffer
|
---|
| 323 | texturePBO = glMapBuffer(GL_PIXEL_PACK_BUFFER_EXT, GL_READ_ONLY);
|
---|
| 324 | glBindTexture(GL_TEXTURE_2D,texName[1]);
|
---|
| 325 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Res2X, Res2Y, GL_RGBA, GL_FLOAT, texturePBO);
|
---|
| 326 | glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
|
---|
| 327 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 ); // Bind The Buffer
|
---|
| 328 |
|
---|
| 329 | glEnable(GL_CULL_FACE);
|
---|
| 330 |
|
---|
| 331 | glMatrixMode(GL_PROJECTION);
|
---|
| 332 | glLoadIdentity();
|
---|
| 333 | gluOrtho2D(-Res2X,Res2Y,-Res2X,Res2Y);
|
---|
| 334 |
|
---|
| 335 | glMatrixMode(GL_MODELVIEW);
|
---|
| 336 | glLoadIdentity();
|
---|
| 337 |
|
---|
| 338 | glViewport(0, 0, Res2X, Res2Y);
|
---|
| 339 |
|
---|
| 340 | glActiveTexture(GL_TEXTURE0);
|
---|
| 341 | glBindTexture(GL_TEXTURE_2D, texTransfer[0]);
|
---|
| 342 | glUniform1i(TextureCopy, 0);
|
---|
| 343 | glActiveTexture(GL_TEXTURE1);
|
---|
| 344 | glBindTexture(GL_TEXTURE_2D, texName[1]);
|
---|
| 345 | glUniform1i(Texture2Copy, 1);
|
---|
| 346 | glActiveTexture(GL_TEXTURE0);
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 | //Draw the geometry.
|
---|
| 350 | glBegin(GL_QUADS);
|
---|
| 351 | {
|
---|
| 352 | glTexCoord2f(0, 0); glVertex3f(-Res2X, -Res2Y, -0.5f);
|
---|
| 353 | glTexCoord2f(1,0); glVertex3f(Res2X, -Res2Y, -0.5f);
|
---|
| 354 | glTexCoord2f(1,1); glVertex3f(Res2X, Res2Y, -0.5f);
|
---|
| 355 | glTexCoord2f(0, 1); glVertex3f(-Res2X, Res2Y, -0.5f);
|
---|
| 356 | }
|
---|
| 357 | glEnd();
|
---|
| 358 |
|
---|
| 359 | //Copy Buffer to PBO.
|
---|
| 360 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT,ObscurancesPBO ); // Bind The Buffer
|
---|
| 361 | glReadPixels(0, 0, Res2X, Res2Y, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 362 | glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
|
---|
| 363 |
|
---|
| 364 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
|
---|
| 365 | glClearColor(0.0,0.0,0.0,0.0);
|
---|
| 366 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
| 367 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
---|
| 368 | glUseProgram(0);
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | // Function that calculates the reflectivity map from the scene data.
|
---|
| 372 | void RenderReflect(void)
|
---|
| 373 | {
|
---|
| 374 | int i, j;
|
---|
| 375 | glUseProgram(pReflect);
|
---|
| 376 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb1);
|
---|
| 377 |
|
---|
| 378 | glClearColor(0.0,0.0,0.0,0.0);
|
---|
| 379 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
| 380 |
|
---|
| 381 | glMatrixMode(GL_PROJECTION);
|
---|
| 382 | glLoadIdentity();
|
---|
| 383 | gluOrtho2D(0,1,0,1);
|
---|
| 384 |
|
---|
| 385 | glMatrixMode(GL_MODELVIEW);
|
---|
| 386 | glLoadIdentity();
|
---|
| 387 |
|
---|
| 388 | glViewport(0, 0, Res2X, Res2Y);
|
---|
| 389 |
|
---|
| 390 | // Enable Pointers
|
---|
| 391 | glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
|
---|
| 392 | glEnableClientState( GL_COLOR_ARRAY ); // Enable Texture Coord Arrays
|
---|
| 393 |
|
---|
| 394 | for(i=0; i<g_pMesh.m_pObject._numGeos;i++)
|
---|
| 395 | {
|
---|
| 396 | for(j=0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
|
---|
| 397 | {
|
---|
| 398 | // Set Pointers To Our Data
|
---|
| 399 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );
|
---|
| 400 | glVertexPointer( 2, GL_FLOAT, 0, (char *) NULL ); // Set The Vertex Pointer To The Vertex Buffer
|
---|
| 401 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors );
|
---|
| 402 | glColorPointer( 3, GL_FLOAT, 0, (char *) NULL ); // Set The TexCoord Pointer To The TexCoord Buffer
|
---|
| 403 | glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );
|
---|
| 404 |
|
---|
| 405 | // Render
|
---|
| 406 | 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
|
---|
| 407 |
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | glDisableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
|
---|
| 412 | glDisableClientState( GL_COLOR_ARRAY ); // Enable Texture Coord Arrays
|
---|
| 413 |
|
---|
| 414 | glUseProgram(0);
|
---|
| 415 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | // Function that updates the lightmap.
|
---|
| 419 | // The number of directions used to calculate the lightmap is iterations * steps
|
---|
| 420 | void UpdateTexture(int iterations, int steps)
|
---|
| 421 | {
|
---|
| 422 | printf("\nIteracions: %d => Steps: %d\n", iterations, steps);
|
---|
| 423 | for(int i = 0; i < steps; i++)
|
---|
| 424 | {
|
---|
| 425 | for(int j = 0; j < iterations; j++)
|
---|
| 426 | {
|
---|
| 427 | printf("\rProgress: %d%%",i*100/steps + j*100/(steps*iterations));
|
---|
| 428 | BuscarDireccio(); // Find a random direction
|
---|
| 429 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
|
---|
| 430 | glClearColor(0.0,0.0,1.0,1.0);
|
---|
| 431 | glClearDepth(1.0);
|
---|
| 432 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 433 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
---|
| 434 | // printf("\nRender Blau: 0");
|
---|
| 435 | // printf("\nRender Projeccions: 1, 1");
|
---|
| 436 | RenderProjeccions(1,1);
|
---|
| 437 | /*//Debug
|
---|
| 438 | glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[0] ); // Bind The Buffer
|
---|
| 439 | glBindTexture(GL_TEXTURE_2D, texName[0]);
|
---|
| 440 | glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 441 | imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
|
---|
| 442 | glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[1] ); // Bind The Buffer
|
---|
| 443 | glBindTexture(GL_TEXTURE_2D, texName[0]);
|
---|
| 444 | glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 445 | imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
|
---|
| 446 | //End Debug*/
|
---|
| 447 | // printf("\nRender Transfer: 0, 1");
|
---|
| 448 | RenderTransfer(1,1);
|
---|
| 449 | // imdebugTexImagef(GL_TEXTURE_2D,texTransfer[0],GL_RGBA,0,NULL);
|
---|
| 450 | int l = 0;
|
---|
| 451 | for(int k=1; k < MAX_LAYERS; k++)
|
---|
| 452 | {
|
---|
| 453 | // printf("\nProjeccions: %d", l);
|
---|
| 454 | // printf("\nRender Projeccions: %d, 0",l);
|
---|
| 455 | RenderProjeccions(l,0);
|
---|
| 456 | /*//Debug
|
---|
| 457 | glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[l] ); // Bind The Buffer
|
---|
| 458 | glBindTexture(GL_TEXTURE_2D, texName[0]);
|
---|
| 459 | glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 460 | imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
|
---|
| 461 | //End Debug*/
|
---|
| 462 | /*//Debug
|
---|
| 463 | glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[0] ); // Bind The Buffer
|
---|
| 464 | glBindTexture(GL_TEXTURE_2D, texName[0]);
|
---|
| 465 | glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 466 | imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
|
---|
| 467 | glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[1] ); // Bind The Buffer
|
---|
| 468 | glBindTexture(GL_TEXTURE_2D, texName[0]);
|
---|
| 469 | glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 470 | imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
|
---|
| 471 | //End Debug*/
|
---|
| 472 | l = (l == 0)? 1:0;
|
---|
| 473 | // printf("\nRender Transfer: %d, 0",l);
|
---|
| 474 | RenderTransfer(l,0);
|
---|
| 475 | // imdebugTexImagef(GL_TEXTURE_2D,texTransfer[0],GL_RGBA,0,NULL);
|
---|
| 476 | }
|
---|
| 477 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[l] ); // Bind The Buffer
|
---|
| 478 | glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
|
---|
| 479 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 ); // Bind The Buffer
|
---|
| 480 | // printf("\nRender Blau: %d",l);
|
---|
| 481 | /*//Debug
|
---|
| 482 | glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[l] ); // Bind The Buffer
|
---|
| 483 | glBindTexture(GL_TEXTURE_2D, texName[0]);
|
---|
| 484 | glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
|
---|
| 485 | imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
|
---|
| 486 | //End Debug*/
|
---|
| 487 | l = (l = 0)? 1:0;
|
---|
| 488 | // printf("\nRender Transfer: %d, 1",l);
|
---|
| 489 | RenderTransfer(l,1);
|
---|
| 490 | }
|
---|
| 491 | // imdebugTexImagef(GL_TEXTURE_2D,texTransfer[0],GL_RGBA,0,NULL);
|
---|
| 492 | CopyTexture();
|
---|
| 493 | // imdebugTexImagef(GL_TEXTURE_2D,texCopy[0],GL_RGBA,0,NULL);
|
---|
| 494 | }
|
---|
| 495 | // printf("\n");
|
---|
| 496 | printf("\r100%% Done!!!!");
|
---|
| 497 |
|
---|
| 498 | }
|
---|
| 499 |
|
---|
| 500 | // Function that generates the VBOs with the geometric data of the scene.
|
---|
| 501 | // It also initializes the constant textures used.
|
---|
| 502 | void InitGeometry(void)
|
---|
| 503 | {
|
---|
| 504 | int i, j;
|
---|
| 505 | m_pBlau = new float[ResX * ResY * 4];
|
---|
| 506 | //Initialize a blue buffer.
|
---|
| 507 | for(i = 0; i<ResX; i++)
|
---|
| 508 | {
|
---|
| 509 | for(j = 0; j<ResY; j++)
|
---|
| 510 | {
|
---|
| 511 | m_pBlau[4 * (i * ResY + j)] = 0.0;
|
---|
| 512 | m_pBlau[4 * (i * ResY + j) + 1] = 0.0;
|
---|
| 513 | m_pBlau[4 * (i * ResY + j) + 2] = 1.0;
|
---|
| 514 | m_pBlau[4 * (i * ResY + j) + 3] = 1.0;
|
---|
| 515 | }
|
---|
| 516 | }
|
---|
| 517 |
|
---|
| 518 | //Initialize a black buffer
|
---|
| 519 | for(i = 0; i<Res2X; i++)
|
---|
| 520 | {
|
---|
| 521 | for(j = 0; j<Res2Y; j++)
|
---|
| 522 | {
|
---|
| 523 | m_pNegre[4*(i*Res2Y+j)] = 0.0;
|
---|
| 524 | m_pNegre[4*(i*Res2Y+j)+1] = 0.0;
|
---|
| 525 | m_pNegre[4*(i*Res2Y+j)+2] = 0.0;
|
---|
| 526 | m_pNegre[4*(i*Res2Y+j)+3] = 0.0;
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 |
|
---|
| 531 | for(i = 0; i<g_pMesh.m_pObject._numGeos;i++)
|
---|
| 532 | {
|
---|
| 533 | for(j = 0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
|
---|
| 534 | {
|
---|
| 535 | //Aqui creeem els VBOs.
|
---|
| 536 |
|
---|
| 537 | // Generate And Bind The Index Buffer
|
---|
| 538 | glGenBuffersARB( 1, (unsigned int *)&g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs ); // Get A Valid Name
|
---|
| 539 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs ); // Bind The Buffer
|
---|
| 540 | // Load The Data
|
---|
| 541 | glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris*3*sizeof(int), g_pMesh.m_pObject._geo[i]._triSet[j]._index, GL_STATIC_DRAW_ARB );
|
---|
| 542 |
|
---|
| 543 | // Generate And Bind The Vertex Buffer
|
---|
| 544 | glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices ); // Get A Valid Name
|
---|
| 545 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices ); // Bind The Buffer
|
---|
| 546 | // Load The Data
|
---|
| 547 | glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._ver, GL_STATIC_DRAW_ARB );
|
---|
| 548 |
|
---|
| 549 |
|
---|
| 550 | // Generate And Bind The Normal Buffer
|
---|
| 551 | glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals ); // Get A Valid Name
|
---|
| 552 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals ); // Bind The Buffer
|
---|
| 553 | // Load The Data
|
---|
| 554 | glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._nor, GL_STATIC_DRAW_ARB );
|
---|
| 555 |
|
---|
| 556 | // Generate And Bind The TexCoord Buffer
|
---|
| 557 | glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords ); // Get A Valid Name
|
---|
| 558 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords ); // Bind The Buffer
|
---|
| 559 | // Load The Data
|
---|
| 560 | glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 2 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._tex, GL_STATIC_DRAW_ARB );
|
---|
| 561 |
|
---|
| 562 | // Generate And Bind The Color Buffer
|
---|
| 563 | glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors ); // Get A Valid Name
|
---|
| 564 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors ); // Bind The Buffer
|
---|
| 565 | // Load The Data
|
---|
| 566 | //*12
|
---|
| 567 | glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._refl, GL_STATIC_DRAW_ARB );
|
---|
| 568 | }
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | cout<<"\nPeta aqui\n";
|
---|
| 572 |
|
---|
| 573 | glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); // Bind The Buffer
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | // Functions that initializes the RenderTextures, the shaders and so on...
|
---|
| 577 | void init2(int numargs, char ** argv)
|
---|
| 578 | {
|
---|
| 579 |
|
---|
| 580 | g_pMesh.LoadMesh(numargs, argv);
|
---|
| 581 |
|
---|
| 582 | m_pTextureImage = new float[Res2X*Res2Y*4];// Texture of diferent colors.
|
---|
| 583 | m_pTextureReflect = new float[Res2X*Res2Y*4]; //Texture of reflectivitat.
|
---|
| 584 | m_pNegre = new float[Res2X*Res2Y*4];
|
---|
| 585 |
|
---|
| 586 | //Create Textures.
|
---|
| 587 | glGenTextures(3, &texName[0]); // Create The Textures
|
---|
| 588 |
|
---|
| 589 | InitGeometry();
|
---|
| 590 |
|
---|
| 591 | //Texture
|
---|
| 592 | // Binding
|
---|
| 593 | glBindTexture( GL_TEXTURE_2D, texName[0] );
|
---|
| 594 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, ResX, ResY, 0, GL_RGBA, GL_FLOAT, NULL);
|
---|
| 595 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 596 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 597 |
|
---|
| 598 | //Texture
|
---|
| 599 | // Binding
|
---|
| 600 | glBindTexture( GL_TEXTURE_2D, texName[1] );
|
---|
| 601 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, NULL);
|
---|
| 602 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
| 603 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
| 604 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 605 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 606 |
|
---|
| 607 |
|
---|
| 608 | //Texture
|
---|
| 609 | // Binding
|
---|
| 610 | glBindTexture( GL_TEXTURE_2D, texName[2] );
|
---|
| 611 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, m_pTextureReflect);
|
---|
| 612 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
| 613 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
| 614 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 615 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 616 |
|
---|
| 617 | // Setup GL States
|
---|
| 618 | glEnable (GL_DEPTH_TEST); // Enable Depth Testing
|
---|
| 619 |
|
---|
| 620 | // Setup GL States
|
---|
| 621 | glEnable (GL_DEPTH_TEST); // Enable Depth Testing
|
---|
| 622 |
|
---|
| 623 | //FBOs
|
---|
| 624 | glGenFramebuffersEXT(1, &fb1);
|
---|
| 625 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb1);
|
---|
| 626 |
|
---|
| 627 | glGenTextures(1,&texReflect[0]);
|
---|
| 628 |
|
---|
| 629 | glBindTexture( GL_TEXTURE_2D, texReflect[0] );
|
---|
| 630 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
|
---|
| 631 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
| 632 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
| 633 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 634 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 635 |
|
---|
| 636 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texReflect[0],0);
|
---|
| 637 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
|
---|
| 638 |
|
---|
| 639 | glGenFramebuffersEXT(1, &fb2);
|
---|
| 640 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
|
---|
| 641 |
|
---|
| 642 | glGenTextures(1,&texProjeccions[0]);
|
---|
| 643 |
|
---|
| 644 | glBindTexture( GL_TEXTURE_2D, texProjeccions[0] );
|
---|
| 645 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, ResX, ResY, 0, GL_RGBA, GL_FLOAT, 0);
|
---|
| 646 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
| 647 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
| 648 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 649 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 650 |
|
---|
| 651 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texProjeccions[0],0);
|
---|
| 652 |
|
---|
| 653 | glGenRenderbuffersEXT(1, &texProjeccions[1]); |
---|
| 654 | glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, texProjeccions[1]); |
---|
| 655 | glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, ResX, ResY ); |
---|
| 656 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, texProjeccions[1]);
|
---|
| 657 |
|
---|
| 658 | glGenFramebuffersEXT(1, &fb3);
|
---|
| 659 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
|
---|
| 660 |
|
---|
| 661 | glGenTextures(1,&texTransfer[0]);
|
---|
| 662 |
|
---|
| 663 | glBindTexture( GL_TEXTURE_2D, texTransfer[0] );
|
---|
| 664 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT16_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
|
---|
| 665 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
| 666 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
| 667 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 668 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 669 |
|
---|
| 670 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texTransfer[0],0);
|
---|
| 671 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
|
---|
| 672 |
|
---|
| 673 | glClearColor(0.0,0.0,0.0,0.0);
|
---|
| 674 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
| 675 |
|
---|
| 676 | glGenFramebuffersEXT(1, &fb4);
|
---|
| 677 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
|
---|
| 678 |
|
---|
| 679 | glGenTextures(1,&texCopy[0]);
|
---|
| 680 |
|
---|
| 681 | glBindTexture( GL_TEXTURE_2D, texCopy[0] );
|
---|
| 682 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
|
---|
| 683 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
---|
| 684 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
---|
| 685 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
---|
| 686 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
---|
| 687 |
|
---|
| 688 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texCopy[0],0);
|
---|
| 689 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
|
---|
| 690 |
|
---|
| 691 | //Create PBO
|
---|
| 692 | glGenBuffersARB( 3, &ProjectionsPBO[0] );
|
---|
| 693 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[0] ); // Bind The Buffer
|
---|
| 694 | glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
|
---|
| 695 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[1] ); // Bind The Buffer
|
---|
| 696 | glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), NULL, GL_STREAM_COPY );
|
---|
| 697 | //Possible optimitzacio: Treure aquest tercer buffer i copiar el blau al buffer que toqui.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
---|
| 698 | // glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[2] ); // Bind The Buffer
|
---|
| 699 | // glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
|
---|
| 700 |
|
---|
| 701 |
|
---|
| 702 |
|
---|
| 703 | glGenBuffersARB( 1, &ObscurancesPBO );
|
---|
| 704 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ObscurancesPBO ); // Bind The Buffer
|
---|
| 705 | glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, Res2X*Res2Y*4*sizeof(float), m_pNegre, GL_STREAM_COPY );
|
---|
| 706 | glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 ); // Bind The Buffer
|
---|
| 707 |
|
---|
| 708 |
|
---|
| 709 | //GLSL
|
---|
| 710 | //Projection Shaders
|
---|
| 711 | char *vsProjection = NULL, *fsProjection = NULL;
|
---|
| 712 |
|
---|
| 713 | vProjection = glCreateShader(GL_VERTEX_SHADER);
|
---|
| 714 | fProjection = glCreateShader(GL_FRAGMENT_SHADER);
|
---|
| 715 |
|
---|
| 716 | vsProjection = textFileRead("projection.vert");
|
---|
| 717 | fsProjection = textFileRead("projection.frag");
|
---|
| 718 |
|
---|
| 719 | if (!vsProjection) cout<<"\nNo es pot trobar el shader\n";
|
---|
| 720 | else cout<<"\nOK!\n";
|
---|
| 721 |
|
---|
| 722 | const char *vvProjection = vsProjection;
|
---|
| 723 | const char *ffProjection = fsProjection;
|
---|
| 724 |
|
---|
| 725 | glShaderSource(vProjection, 1, &vvProjection, NULL);
|
---|
| 726 | glShaderSource(fProjection, 1, &ffProjection, NULL);
|
---|
| 727 |
|
---|
| 728 | free(vsProjection); free(fsProjection);
|
---|
| 729 |
|
---|
| 730 | glCompileShader(vProjection);
|
---|
| 731 | glCompileShader(fProjection);
|
---|
| 732 |
|
---|
| 733 | pProjection = glCreateProgram();
|
---|
| 734 | glAttachShader(pProjection, vProjection);
|
---|
| 735 | glAttachShader(pProjection, fProjection);
|
---|
| 736 |
|
---|
| 737 | glLinkProgram(pProjection);
|
---|
| 738 |
|
---|
| 739 | glUseProgram(pProjection);
|
---|
| 740 | TexturaDepthProjection = glGetUniformLocation(pProjection, "ztex");
|
---|
| 741 | SizeProjection = glGetUniformLocation(pProjection, "res");
|
---|
| 742 | FirstProjection = glGetUniformLocation(pProjection, "first");
|
---|
| 743 |
|
---|
| 744 | glUseProgram(0);
|
---|
| 745 |
|
---|
| 746 | //Reflect Shaders
|
---|
| 747 | char *vsReflect = NULL, *fsReflect = NULL;
|
---|
| 748 |
|
---|
| 749 | vReflect = glCreateShader(GL_VERTEX_SHADER);
|
---|
| 750 | fReflect = glCreateShader(GL_FRAGMENT_SHADER);
|
---|
| 751 |
|
---|
| 752 | vsReflect = textFileRead("reflect.vert");
|
---|
| 753 | fsReflect = textFileRead("reflect.frag");
|
---|
| 754 |
|
---|
| 755 | const char *vvReflect = vsReflect;
|
---|
| 756 | const char *ffReflect = fsReflect;
|
---|
| 757 |
|
---|
| 758 | glShaderSource(vReflect, 1, &vvReflect, NULL);
|
---|
| 759 | glShaderSource(fReflect, 1, &ffReflect, NULL);
|
---|
| 760 |
|
---|
| 761 | free(vsReflect); free(fsReflect);
|
---|
| 762 |
|
---|
| 763 | glCompileShader(vReflect);
|
---|
| 764 | glCompileShader(fReflect);
|
---|
| 765 |
|
---|
| 766 | pReflect = glCreateProgram();
|
---|
| 767 | glAttachShader(pReflect, vReflect);
|
---|
| 768 | glAttachShader(pReflect, fReflect);
|
---|
| 769 |
|
---|
| 770 | glLinkProgram(pReflect);
|
---|
| 771 |
|
---|
| 772 | // glUseProgram(pReflect);
|
---|
| 773 | glUseProgram(0);
|
---|
| 774 |
|
---|
| 775 | //Texture Copy Shaders
|
---|
| 776 | char *vsCopy = NULL, *fsCopy = NULL;
|
---|
| 777 |
|
---|
| 778 | vCopy = glCreateShader(GL_VERTEX_SHADER);
|
---|
| 779 | fCopy = glCreateShader(GL_FRAGMENT_SHADER);
|
---|
| 780 |
|
---|
| 781 | vsCopy = textFileRead("copy.vert");
|
---|
| 782 | fsCopy = textFileRead("copy.frag");
|
---|
| 783 |
|
---|
| 784 | const char *vvCopy = vsCopy;
|
---|
| 785 | const char *ffCopy = fsCopy;
|
---|
| 786 |
|
---|
| 787 | glShaderSource(vCopy, 1, &vvCopy, NULL);
|
---|
| 788 | glShaderSource(fCopy, 1, &ffCopy, NULL);
|
---|
| 789 |
|
---|
| 790 | free(vsCopy); free(fsCopy);
|
---|
| 791 |
|
---|
| 792 | glCompileShader(vCopy);
|
---|
| 793 | glCompileShader(fCopy);
|
---|
| 794 |
|
---|
| 795 | pCopy = glCreateProgram();
|
---|
| 796 | glAttachShader(pCopy, vCopy);
|
---|
| 797 | glAttachShader(pCopy, fCopy);
|
---|
| 798 |
|
---|
| 799 | glLinkProgram(pCopy);
|
---|
| 800 |
|
---|
| 801 | glUseProgram(pCopy);
|
---|
| 802 | TextureCopy = glGetUniformLocation(pCopy, "texture");
|
---|
| 803 | Texture2Copy = glGetUniformLocation(pCopy, "texture2");
|
---|
| 804 | glUseProgram(0);
|
---|
| 805 |
|
---|
| 806 | //Energy Transfer Shaders
|
---|
| 807 | char *vsTransfer = NULL, *fsTransfer = NULL;
|
---|
| 808 |
|
---|
| 809 | vTransfer = glCreateShader(GL_VERTEX_SHADER);
|
---|
| 810 | fTransfer = glCreateShader(GL_FRAGMENT_SHADER);
|
---|
| 811 |
|
---|
| 812 | vsTransfer = textFileRead("transfer.vert");
|
---|
| 813 | fsTransfer = textFileRead("transfer.frag");
|
---|
| 814 |
|
---|
| 815 | const char *vvTransfer = vsTransfer;
|
---|
| 816 | const char *ffTransfer = fsTransfer;
|
---|
| 817 |
|
---|
| 818 | glShaderSource(vTransfer, 1, &vvTransfer, NULL);
|
---|
| 819 | glShaderSource(fTransfer, 1, &ffTransfer, NULL);
|
---|
| 820 |
|
---|
| 821 | free(vsTransfer); free(fsTransfer);
|
---|
| 822 |
|
---|
| 823 | glCompileShader(vTransfer);
|
---|
| 824 | glCompileShader(fTransfer);
|
---|
| 825 |
|
---|
| 826 | pTransfer = glCreateProgram();
|
---|
| 827 | glAttachShader(pTransfer, vTransfer);
|
---|
| 828 | glAttachShader(pTransfer, fTransfer);
|
---|
| 829 |
|
---|
| 830 | glLinkProgram(pTransfer);
|
---|
| 831 |
|
---|
| 832 | glUseProgram(pTransfer);
|
---|
| 833 | TexturaReflectTransfer = glGetUniformLocation(pTransfer, "reflectivity");
|
---|
| 834 | DirectionTransfer = glGetUniformLocation(pTransfer, "direction");
|
---|
| 835 | DmaxTransfer = glGetUniformLocation(pTransfer, "dmax");
|
---|
| 836 |
|
---|
| 837 | glUseProgram(0);
|
---|
| 838 | //Generate the reflectivity texture.
|
---|
| 839 |
|
---|
| 840 | RenderReflect();
|
---|
| 841 |
|
---|
| 842 | UpdateTexture(60,2);
|
---|
| 843 | // UpdateTexture(1,1);
|
---|
| 844 |
|
---|
| 845 | }
|
---|
| 846 |
|
---|
| 847 | // Function that interfaces with the VisualCAD.
|
---|
| 848 | int vcObscurerGenerateImage(CMesh &geom, int numargs, char **argv, int quality, int *imgUsize, int *imgVsize, float **imgRgbBuffer)
|
---|
| 849 | {
|
---|
| 850 | float divisor;
|
---|
| 851 | int *DadesTemp = new int[4];
|
---|
| 852 | float *dadesf=NULL;
|
---|
| 853 | float aux[4];
|
---|
| 854 | int *dadesi=NULL;
|
---|
| 855 | float a;
|
---|
| 856 | int qual;
|
---|
| 857 |
|
---|
| 858 | memset(&aux, 0.0, 4);
|
---|
| 859 |
|
---|
| 860 | qual = quality;
|
---|
| 861 |
|
---|
| 862 | if (qual < 1) qual = 1;
|
---|
| 863 |
|
---|
| 864 | switch (qual)
|
---|
| 865 | {
|
---|
| 866 | case 1: *imgVsize = *imgUsize = 256;
|
---|
| 867 | break;
|
---|
| 868 | case 2: *imgVsize = *imgUsize = 512;
|
---|
| 869 | break;
|
---|
| 870 | case 3: *imgVsize = *imgUsize = 1024;
|
---|
| 871 | break;
|
---|
| 872 | case 4: *imgVsize = *imgUsize = 2048;
|
---|
| 873 | break;
|
---|
| 874 | default: printf("\nResolution not supported");
|
---|
| 875 | };
|
---|
| 876 |
|
---|
| 877 | Res2X = *imgUsize;
|
---|
| 878 | Res2Y = *imgVsize;
|
---|
| 879 |
|
---|
| 880 | ResX = Res2X * 2.0;
|
---|
| 881 | ResY = Res2Y * 2.0;
|
---|
| 882 |
|
---|
| 883 | if(ResX == 4096) ResX = 2048;
|
---|
| 884 | if(ResY == 4096) ResY = 2048;
|
---|
| 885 |
|
---|
| 886 | printf("\nRes(Plans de projeccio): ResolucioX = %d , ResolucioY = %d", ResX, ResY);
|
---|
| 887 | printf("\nRes2(Lightmap): ResolucioX = %d , ResolucioY = %d", Res2X, Res2Y);
|
---|
| 888 | dadesf = new float[Res2X*Res2Y*4];
|
---|
| 889 | dadesi = new int[Res2X*Res2Y*4];
|
---|
| 890 |
|
---|
| 891 | init2(numargs, argv);
|
---|
| 892 |
|
---|
| 893 | //->g_pMesh.FreeMem();
|
---|
| 894 |
|
---|
| 895 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
|
---|
| 896 | glReadPixels(0,0,Res2X,Res2Y,GL_RGBA,GL_FLOAT,dadesf);
|
---|
| 897 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
---|
| 898 |
|
---|
| 899 | for(int i=0; i<Res2X*Res2Y; i++)
|
---|
| 900 | {
|
---|
| 901 | divisor = dadesf[4*i+3];
|
---|
| 902 | if(divisor>15)
|
---|
| 903 | {
|
---|
| 904 | dadesf[4*i] = (dadesf[4*i]/divisor);
|
---|
| 905 | dadesf[4*i+1] = (dadesf[4*i+1]/divisor);
|
---|
| 906 | dadesf[4*i+2] = (dadesf[4*i+2]/divisor);
|
---|
| 907 | dadesf[4*i+3] = 1.0;
|
---|
| 908 | }
|
---|
| 909 | else
|
---|
| 910 | {
|
---|
| 911 | a=0;
|
---|
| 912 | aux[0] = 0.0;
|
---|
| 913 | aux[1] = 0.0;
|
---|
| 914 | aux[2] = 0.0;
|
---|
| 915 | aux[3] = 0.0;
|
---|
| 916 | if(i/Res2X > 0)
|
---|
| 917 | {
|
---|
| 918 | if(i/Res2X < Res2Y-1)
|
---|
| 919 | {
|
---|
| 920 | if(i%Res2X !=0)
|
---|
| 921 | {
|
---|
| 922 | if(dadesf[4*(i-Res2X)-1]>15) //ul();
|
---|
| 923 | {
|
---|
| 924 | aux[0] += (dadesf[4*(i-Res2X)-4]/dadesf[4*(i-Res2X)-1]);
|
---|
| 925 | aux[1] += (dadesf[4*(i-Res2X)-3]/dadesf[4*(i-Res2X)-1]);
|
---|
| 926 | aux[2] += (dadesf[4*(i-Res2X)-2]/dadesf[4*(i-Res2X)-1]);
|
---|
| 927 | aux[3] += 1.0;
|
---|
| 928 | a =+ 1.0;;
|
---|
| 929 | }
|
---|
| 930 | if(dadesf[4*i-1]>15) //l();
|
---|
| 931 | {
|
---|
| 932 | aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]);
|
---|
| 933 | aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]);
|
---|
| 934 | aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]);
|
---|
| 935 | aux[3] += 1.0;
|
---|
| 936 | a =+ 1.0;;
|
---|
| 937 | }
|
---|
| 938 | if(dadesf[4*(i+Res2X)-1]>15) //dl();
|
---|
| 939 | {
|
---|
| 940 | aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]);
|
---|
| 941 | aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]);
|
---|
| 942 | aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]);
|
---|
| 943 | aux[3] += 1.0;
|
---|
| 944 | a =+ 1.0;;
|
---|
| 945 | }
|
---|
| 946 | }
|
---|
| 947 | if(dadesf[4*(i+Res2X)+3]>15) //d();
|
---|
| 948 | {
|
---|
| 949 | aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]);
|
---|
| 950 | aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]);
|
---|
| 951 | aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]);
|
---|
| 952 | aux[3] += 1.0;
|
---|
| 953 | a =+ 1.0;;
|
---|
| 954 | }
|
---|
| 955 | if(i%Res2X!=Res2X-1)
|
---|
| 956 | {
|
---|
| 957 | if(dadesf[4*(i-Res2X)+7]>15) //ur();
|
---|
| 958 | {
|
---|
| 959 | aux[0] += (dadesf[4*(i-Res2X)+4]/dadesf[4*(i-Res2X)+7]);
|
---|
| 960 | aux[1] += (dadesf[4*(i-Res2X)+5]/dadesf[4*(i-Res2X)+7]);
|
---|
| 961 | aux[2] += (dadesf[4*(i-Res2X)+6]/dadesf[4*(i-Res2X)+7]);
|
---|
| 962 | aux[3] += 1.0;
|
---|
| 963 | a =+ 1.0;;
|
---|
| 964 | }
|
---|
| 965 | if(dadesf[4*i+7]>15) //r();
|
---|
| 966 | {
|
---|
| 967 | aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]);
|
---|
| 968 | aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]);
|
---|
| 969 | aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]);
|
---|
| 970 | aux[3] += 1.0;
|
---|
| 971 | a =+ 1.0;;
|
---|
| 972 | }
|
---|
| 973 | if(dadesf[4*(i+Res2X)+7]>15) //dr();
|
---|
| 974 | {
|
---|
| 975 | aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]);
|
---|
| 976 | aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]);
|
---|
| 977 | aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]);
|
---|
| 978 | aux[3] += 1.0;
|
---|
| 979 | a =+ 1.0;;
|
---|
| 980 | }
|
---|
| 981 | }
|
---|
| 982 | if(dadesf[4*(i-Res2X)+3]>15) //u();
|
---|
| 983 | {
|
---|
| 984 | aux[0] += (dadesf[4*(i-Res2X)]/dadesf[4*(i-Res2X)+3]);
|
---|
| 985 | aux[1] += (dadesf[4*(i-Res2X)+1]/dadesf[4*(i-Res2X)+3]);
|
---|
| 986 | aux[2] += (dadesf[4*(i-Res2X)+2]/dadesf[4*(i-Res2X)+3]);
|
---|
| 987 | aux[3] += 1.0;
|
---|
| 988 | a =+ 1.0;;
|
---|
| 989 | }
|
---|
| 990 | }
|
---|
| 991 | }
|
---|
| 992 | else
|
---|
| 993 | {
|
---|
| 994 | if(i%Res2X !=0)
|
---|
| 995 | {
|
---|
| 996 | if(dadesf[4*i-1]>15) //l();
|
---|
| 997 | {
|
---|
| 998 | aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]);
|
---|
| 999 | aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]);
|
---|
| 1000 | aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]);
|
---|
| 1001 | aux[3] += 1.0;
|
---|
| 1002 | a =+ 1.0;;
|
---|
| 1003 | }
|
---|
| 1004 | if(dadesf[4*(i+Res2X)-1]>15) //dl();
|
---|
| 1005 | {
|
---|
| 1006 | aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]);
|
---|
| 1007 | aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]);
|
---|
| 1008 | aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]);
|
---|
| 1009 | aux[3] = 1.0;
|
---|
| 1010 | a =+ 1.0;;
|
---|
| 1011 | }
|
---|
| 1012 | }
|
---|
| 1013 | if(i%Res2X!=Res2X-1)
|
---|
| 1014 | {
|
---|
| 1015 | if(dadesf[4*i+7]>15) //r();
|
---|
| 1016 | {
|
---|
| 1017 | aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]);
|
---|
| 1018 | aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]);
|
---|
| 1019 | aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]);
|
---|
| 1020 | aux[3] += 1.0;
|
---|
| 1021 | a =+ 1.0;;
|
---|
| 1022 | }
|
---|
| 1023 | if(dadesf[4*(i+Res2X)+7]>15) //dr();
|
---|
| 1024 | {
|
---|
| 1025 | aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]);
|
---|
| 1026 | aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]);
|
---|
| 1027 | aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]);
|
---|
| 1028 | aux[3] += 1.0;
|
---|
| 1029 | a =+ 1.0;;
|
---|
| 1030 | }
|
---|
| 1031 | }
|
---|
| 1032 | if(dadesf[4*(i+Res2X)+3]>15) //d();
|
---|
| 1033 | {
|
---|
| 1034 | aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]);
|
---|
| 1035 | aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]);
|
---|
| 1036 | aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]);
|
---|
| 1037 | aux[3] += 1.0;
|
---|
| 1038 | a =+ 1.0;;
|
---|
| 1039 | }
|
---|
| 1040 | }
|
---|
| 1041 | if(a > 0.0)
|
---|
| 1042 | {
|
---|
| 1043 | dadesf[4*i] = aux[0]/aux[3];
|
---|
| 1044 | dadesf[4*i+1] = aux[1]/aux[3];
|
---|
| 1045 | dadesf[4*i+2] = aux[2]/aux[3];
|
---|
| 1046 | dadesf[4*i+3] = 1.0;
|
---|
| 1047 | }
|
---|
| 1048 | else
|
---|
| 1049 | {
|
---|
| 1050 | dadesf[4*i] = 0.0;
|
---|
| 1051 | dadesf[4*i+1] = 0.0;
|
---|
| 1052 | dadesf[4*i+2] = 0.0;
|
---|
| 1053 | dadesf[4*i+3] = 0.0;
|
---|
| 1054 | }
|
---|
| 1055 | }
|
---|
| 1056 | dadesi[4*i] = (int)(255.0*dadesf[4*i]);
|
---|
| 1057 | dadesi[4*i+1] = (int)(255.0*dadesf[4*i+1]);
|
---|
| 1058 | dadesi[4*i+2] = (int)(255.0*dadesf[4*i+2]);
|
---|
| 1059 | dadesi[4*i+3] = (int)(255.0*dadesf[4*i+3]);
|
---|
| 1060 |
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
| 1063 | geom = g_pMesh;
|
---|
| 1064 |
|
---|
| 1065 | imdebug("rgba b=32f w=%d h=%d %p", Res2X, Res2Y, dadesf);
|
---|
| 1066 |
|
---|
| 1067 | *imgRgbBuffer = dadesf;
|
---|
| 1068 |
|
---|
| 1069 | return 0;
|
---|
| 1070 |
|
---|
| 1071 | } |
---|