- Timestamp:
- 07/04/08 15:40:05 (16 years ago)
- 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 175 175 } 176 176 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 186 177 return new Geometry(vertices, normals, texcoords, vertexCount, true); 187 178 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Texture.cpp
r2800 r2817 107 107 Texture::~Texture() 108 108 { 109 glDeleteTextures(1, &mTexId); 109 110 free(mImage); 110 111 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2816 r2817 146 146 147 147 static Vector3 samples[32]; 148 148 GLubyte *randomNormals; 149 149 150 150 // function forward declarations … … 527 527 glGenRenderbuffersEXT(1, &positionsBuffer); 528 528 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); 531 531 532 532 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_RENDERBUFFER_EXT, positionsBuffer); … … 535 535 glBindTexture(GL_TEXTURE_2D, positionsTex); 536 536 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); 538 538 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, positionsTex, 0); 539 539 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); 545 545 546 546 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); … … 559 559 glBindTexture(GL_TEXTURE_2D, normalsTex); 560 560 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); 562 562 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, normalsTex, 0); 563 563 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); 566 566 567 567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); … … 1452 1452 if (sCgContext) 1453 1453 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); 1454 1465 } 1455 1466 … … 1629 1640 glLoadIdentity(); 1630 1641 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); 1632 1646 1633 1647 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 1655 1669 glBegin(GL_QUADS); 1656 1670 #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); 1661 1679 #else 1662 1680 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); … … 1727 1745 tl = tl * 0.5f + 0.5f; 1728 1746 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 1769 1750 void CreateNoiseTex2D() 1770 1751 { 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) 1774 1755 { 1775 1756 // create random samples over sphere … … 1777 1758 const float theta = 2.0f * acos(sqrt(1.0f - rx)); 1778 1759 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; 1819 1764 } 1820 1765 … … 1822 1767 glGenTextures(1, &noiseTex); 1823 1768 glBindTexture(GL_TEXTURE_2D, noiseTex); 1824 //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);1825 1769 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 1826 1770 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); 1831 1774 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 1832 1775 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 1833 1776 1834 1777 glBindTexture(GL_TEXTURE_2D, 0); 1835 1836 1778 glDisable(GL_TEXTURE_2D); 1837 1779 … … 1839 1781 PrintGLerror("noisetexture"); 1840 1782 } 1841 #endif -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2816 r2817 79 79 80 80 //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; 83 83 84 84 for (int i = 0; i < SAMPLES; i ++) { … … 130 130 pixel OUT; 131 131 132 float4 lightDir = float4(0.8f, 1.0f, 1.5f, 0.0f);132 float4 lightDir = float4(0.8f, -1.0f, 0.7f, 0.0f); 133 133 float4 lightDir2 = float4(-0.5f, 0.5f, 0.4f, 0.0f); 134 134 … … 145 145 // float3 L = normalize(lightPosition - position); 146 146 float3 light = normalize(lightDir.xyz); 147 float3 light2 = normalize(lightDir .xyz);147 float3 light2 = normalize(lightDir2.xyz); 148 148 149 149 float diffuseLight = max(dot(normal, light), 0.0f); … … 155 155 //OUT.color = ao; 156 156 OUT.color = ao * (ambient + diffuse) * color; 157 //OUT.color = (ambient + diffuse) * color; 157 158 158 159 //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 163 163 return OUT; 164 164 }
Note: See TracChangeset
for help on using the changeset viewer.