Ignore:
Timestamp:
07/04/08 15:40:05 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp

    r2811 r2817  
    175175        } 
    176176 
    177         for (int i = 0; i < vertexCount; i += 3) 
    178         { 
    179                 Triangle3 tri(vertices[i], vertices[i + 1], vertices[i + 2]); 
    180                 Vector3 n = tri.GetNormal(); 
    181                 normals[i + 0] = n; 
    182                 normals[i + 1] = n; 
    183                 normals[i + 2] = n; 
    184         } 
    185  
    186177        return new Geometry(vertices, normals, texcoords, vertexCount, true); 
    187178} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp

    r2800 r2817  
    107107Texture::~Texture() 
    108108{ 
     109        glDeleteTextures(1, &mTexId); 
    109110        free(mImage); 
    110111} 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r2816 r2817  
    146146 
    147147static Vector3 samples[32]; 
    148  
     148GLubyte *randomNormals; 
    149149 
    150150// function forward declarations 
     
    527527        glGenRenderbuffersEXT(1, &positionsBuffer); 
    528528        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, positionsBuffer); 
    529         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 
    530         //glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA32F_ARB, texWidth, texHeight); 
     529        //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight); 
     530        glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_RGBA32F_ARB, texWidth, texHeight); 
    531531         
    532532        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, positionsBuffer); 
     
    535535        glBindTexture(GL_TEXTURE_2D, positionsTex); 
    536536        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
    537         glGenerateMipmapEXT(GL_TEXTURE_2D); 
     537        //glGenerateMipmapEXT(GL_TEXTURE_2D); 
    538538        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, positionsTex, 0); 
    539539 
    540         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    541         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
    542  
    543         //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
    544         //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
     540        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     541        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
     542 
     543        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
     544        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 
    545545 
    546546        PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); 
     
    559559        glBindTexture(GL_TEXTURE_2D, normalsTex); 
    560560        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  texWidth, texHeight, 0, GL_RGBA, GL_FLOAT, NULL); 
    561         glGenerateMipmapEXT(GL_TEXTURE_2D); 
     561        //glGenerateMipmapEXT(GL_TEXTURE_2D); 
    562562        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 0); 
    563563 
    564         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    565         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
     564        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     565        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    566566 
    567567        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 
     
    14521452        if (sCgContext) 
    14531453                cgDestroyContext(sCgContext); 
     1454 
     1455        glDeleteFramebuffersEXT(1, &fbo); 
     1456        glDeleteRenderbuffersEXT(1, &depthBuffer); 
     1457        glDeleteRenderbuffersEXT(1, &colorsBuffer); 
     1458        glDeleteRenderbuffersEXT(1, &normalsBuffer); 
     1459        glDeleteRenderbuffersEXT(1, &positionsBuffer); 
     1460 
     1461        glDeleteTextures(1, &colorsTex); 
     1462        glDeleteTextures(1, &normalsTex); 
     1463        glDeleteTextures(1, &positionsTex); 
     1464        glDeleteTextures(1, &noiseTex); 
    14541465} 
    14551466 
     
    16291640        glLoadIdentity(); 
    16301641 
    1631         glOrtho(-0.5f, 0.5f, -0.5f, 0.5f, 0, 1); 
     1642        const float offs = 0.5f; 
     1643        //glPushAttrib(GL_VIEWPORT_BIT); 
     1644        //glViewport(-offs, texHeight); 
     1645        glOrtho(-offs, offs, -offs, offs, 0, 1); 
    16321646         
    16331647        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     
    16551669        glBegin(GL_QUADS); 
    16561670#if 1 
    1657         glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 
    1658         glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 
    1659         glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( 1,  1, -0.5f); 
    1660         glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-1,  1, -0.5f); 
     1671        // slightly larger than screen size in order to hide ambient occlusion errors 
     1672        float offs2 = 0.55f; 
     1673        //float offs2 = 0.5f; 
     1674 
     1675        glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); 
     1676        glColor3f(br.x, br.y, br.z); glTexCoord2f(1, 0); glVertex3f( offs2, -offs2, -0.5f); 
     1677        glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2,  offs2, -0.5f); 
     1678        glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-offs2,  offs2, -0.5f); 
    16611679#else 
    16621680        glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 
     
    17271745        tl = tl * 0.5f + 0.5f; 
    17281746        tr = tr * 0.5f + 0.5f; 
    1729  
    1730 /* 
    1731         cout << "tl: " << tl << endl; 
    1732         cout << "tr: " << tr << endl; 
    1733         cout << "bl: " << bl << endl; 
    1734         cout << "br: " << bl << endl << endl; 
    1735         */ 
    1736 } 
    1737  
    1738  
    1739 void CreateNoiseTex3D() 
    1740 { 
    1741         Vector3 *data = new Vector3[texWidth * texHeight]; 
    1742  
    1743         for (int i = 0; i < texWidth * texHeight; ++ i) 
    1744         { 
    1745                 // create random samples over sphere 
    1746                 const float rx = RandomValue(0, 1); 
    1747                 const float ry = RandomValue(0, 1); 
    1748  
    1749                 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    1750                 const float phi = 2.0f * M_PI * ry; 
    1751  
    1752                 data[i] = Vector3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); 
    1753                 // bring in 0 .. 1 so we can use unsigned byte 
    1754                 data[i] = data[i] * 0.5f + 0.5f; 
    1755         } 
    1756  
    1757         glGenTextures(1, &noiseTex); 
    1758         glBindTexture(GL_TEXTURE_2D, noiseTex); 
    1759         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,  texWidth, texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 
    1760         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    1761         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    1762  
    1763         glBindTexture(GL_TEXTURE_2D, 0); 
    1764  
    1765         PrintGLerror("noisetexture"); 
    1766 } 
    1767  
    1768 #if 0 
     1747} 
     1748 
     1749 
    17691750void CreateNoiseTex2D() 
    17701751{ 
    1771         Vector3 *data = new Vector3[texWidth * texHeight]; 
    1772  
    1773         for (int i = 0; i < texWidth * texHeight; ++ i) 
     1752        randomNormals = new GLubyte[texWidth * texHeight * 4]; 
     1753 
     1754        for (int i = 0; i < texWidth * texHeight * 4; i += 4) 
    17741755        { 
    17751756                // create random samples over sphere 
     
    17771758                const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    17781759 
    1779                 data[i] = Vector3(sin(theta), cos(theta), 0); 
    1780  
    1781                 //if (i % 10000) cout << "vec: " << data[i] << endl; 
    1782          
    1783                 // bring in 0 .. 1 so we could use unsigned byte 
    1784                 data[i] = 1;//data[i] * 0.5f + 0.5f; 
    1785         } 
    1786  
    1787         glGenTextures(1, &noiseTex); 
    1788         glBindTexture(GL_TEXTURE_2D, noiseTex); 
    1789         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, texWidth, texHeight, 0, GL_RGB, GL_FLOAT, (float *)data); 
    1790          
    1791         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    1792         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 
    1793  
    1794         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    1795         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    1796  
    1797         glBindTexture(GL_TEXTURE_2D, 0); 
    1798  
    1799         PrintGLerror("noisetexture"); 
    1800 } 
    1801  
    1802 #else 
    1803 void CreateNoiseTex2D() 
    1804 { 
    1805         GLubyte *data = new GLubyte[texWidth * texHeight * 4]; 
    1806  
    1807         for (int i = 0; i < texWidth * texHeight * 4; i += 4) 
    1808         { 
    1809                 // create random samples over sphere 
    1810                 const float rx = RandomValue(0, 1); 
    1811                 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 
    1812  
    1813                 data[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
    1814                 data[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
    1815                 data[i + 2] = 0; 
    1816                 data[i + 3] = 255; 
    1817  
    1818                 //if (i % 100000) cout << "vec: " << " " << (int)data[i] << " " << (int)data[i + 1] << endl; 
     1760                randomNormals[i + 0] = (GLubyte)((cos(theta) * 0.5f + 0.5f) * 255.0f); 
     1761                randomNormals[i + 1] = (GLubyte)((sin(theta) * 0.5f + 0.5f) * 255.0f); 
     1762                randomNormals[i + 2] = 0; 
     1763                randomNormals[i + 3] = 255; 
    18191764        } 
    18201765 
     
    18221767        glGenTextures(1, &noiseTex); 
    18231768        glBindTexture(GL_TEXTURE_2D, noiseTex); 
    1824         //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 
    18251769        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 
    18261770 
    1827         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, data); 
    1828         //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 
    1829         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    1830         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
     1771        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, randomNormals); 
     1772        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
     1773        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    18311774        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
    18321775        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
    18331776 
    18341777        glBindTexture(GL_TEXTURE_2D, 0); 
    1835  
    18361778        glDisable(GL_TEXTURE_2D); 
    18371779 
     
    18391781        PrintGLerror("noisetexture"); 
    18401782} 
    1841 #endif 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg

    r2816 r2817  
    7979 
    8080  //const float areaSize = 5e-1f; 
    81   const float areaSize = 2e-1f; 
    82   const float sampleIntensity = 0.1f; 
     81  const float areaSize = 3e-1f; 
     82  const float sampleIntensity = 0.2f; 
    8383   
    8484  for (int i = 0; i < SAMPLES; i ++) { 
     
    130130  pixel OUT; 
    131131 
    132   float4 lightDir = float4(0.8f, 1.0f, 1.5f, 0.0f); 
     132  float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 
    133133  float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 
    134134   
     
    145145  // float3 L = normalize(lightPosition - position); 
    146146  float3 light = normalize(lightDir.xyz); 
    147   float3 light2 = normalize(lightDir.xyz); 
     147  float3 light2 = normalize(lightDir2.xyz); 
    148148 
    149149  float diffuseLight = max(dot(normal, light), 0.0f); 
     
    155155  //OUT.color = ao;  
    156156  OUT.color = ao * (ambient + diffuse) * color; 
     157//OUT.color = (ambient + diffuse) * color; 
    157158 
    158159  //float4 currentPos = tex2D(normals, IN.texCoord.xy) * 0.5f + 0.5f; 
    159   //float4 currentPos = tex2D(positions, IN.texCoord.xy); 
    160   //OUT.color = currentPos.w; 
    161    
    162      
     160  //float4 currentPos = tex2D(normals, IN.texCoord.xy); 
     161  //OUT.color = currentPos; 
     162       
    163163  return OUT; 
    164164} 
Note: See TracChangeset for help on using the changeset viewer.