- Timestamp:
- 07/07/08 10:52:03 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 4 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/CHCTraverser.cpp
r2795 r2818 119 119 } 120 120 121 122 121 // always traverse a node if it was visible 123 122 if (wasVisible) -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r2795 r2818 22 22 mAmbientColor = RgbaColor(0.2f, 0.2f, 0.2f, 1.0f); 23 23 mDiffuseColor = RgbaColor(1.0f, 1.0f, 1.0f, 1.0f); 24 //mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f); 25 mSpecularColor = RgbaColor(0.5f, 0.5f, 0.5f, 1.0f); 24 mSpecularColor = RgbaColor(.0f, .0f, .0f, 1.0f); 26 25 mEmmisiveColor = RgbaColor(.0f, .0f, .0f, 1.0f); 27 26 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r2816 r2818 1 1 #include "RenderState.h" 2 #include "glInterface.h"3 2 #include "Geometry.h" 4 3 #include "Material.h" … … 7 6 namespace CHCDemoEngine 8 7 { 8 9 CGprofile RenderState::sCgFragmentProfile; 10 CGprofile RenderState::sCgVertexProfile; 9 11 10 12 … … 34 36 glDisable(GL_LIGHTING); 35 37 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 38 39 cgGLDisableProfile(sCgFragmentProfile); 40 cgGLDisableProfile(sCgVertexProfile); 36 41 } 37 42 … … 49 54 glEnable(GL_LIGHTING); 50 55 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 56 57 cgGLEnableProfile(sCgFragmentProfile); 58 cgGLEnableProfile(sCgVertexProfile); 51 59 } 52 60 … … 68 76 { 69 77 mAlphaTestEnabled = true; 70 //glEnable(GL_ALPHA_TEST);78 glEnable(GL_ALPHA_TEST); 71 79 } 72 80 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r2801 r2818 4 4 5 5 #include "common.h" 6 #include "glInterface.h" 7 #include <Cg/cg.h> 8 #include <Cg/cgGL.h> 6 9 7 10 … … 51 54 bool IsDepthPass() { return mIsDepthPass; } 52 55 56 static CGprofile sCgFragmentProfile; 57 static CGprofile sCgVertexProfile; 58 59 53 60 protected: 54 61 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.cpp
r2802 r2818 4 4 #include "Material.h" 5 5 #include "RenderState.h" 6 #include <Cg/cg.h> 7 #include <Cg/cgGL.h> 6 8 7 9 … … 9 11 { 10 12 13 CGparameter SceneEntity::sModelMatrixParam; 11 14 12 15 SceneEntity::SceneEntity(Geometry *geometry, … … 29 32 if (mTransform) 30 33 { 31 glPushMatrix(); 32 glMultMatrixf((float *)mTransform->x); 34 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)mTransform->x); 35 //glPushMatrix(); 36 //glMultMatrixf((float *)mTransform->x); 33 37 mGeometry->Render(state); 34 38 35 glPopMatrix();39 //glPopMatrix(); 36 40 } 37 41 else 38 42 { 43 static Matrix4x4 identity = IdentityMatrix(); 44 45 cgGLSetMatrixParameterfc(sModelMatrixParam, (const float *)identity.x); 39 46 mGeometry->Render(state); 40 47 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r2802 r2818 2 2 #define __SCENEENTITY_H 3 3 4 #include "glInterface.h" 4 5 #include "common.h" 5 6 #include "AxisAlignedBox3.h" 6 7 #include "Triangle3.h" 7 8 #include <Cg/cg.h> 9 #include <Cg/cgGL.h> 8 10 9 11 namespace CHCDemoEngine 10 12 { 13 14 11 15 12 16 class Material; … … 23 27 24 28 public: 29 static CGparameter sModelMatrixParam; 25 30 /** Creates a scene entity. 26 31 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2817 r2818 1 1 // occquery.cpp : Defines the entry point for the console application. 2 2 // 3 #include "glInterface.h" 3 4 #include <math.h> 4 5 #include <time.h> 5 6 #include "common.h" 6 #include "glInterface.h"7 7 #include "RenderTraverser.h" 8 8 #include "SceneEntity.h" … … 209 209 static CGprogram sCgMrtFragmentProgram = NULL; 210 210 211 static CGprofile sCgFragmentProfile;212 static CGprofile sCgVertexProfile;213 214 211 static CGparameter sColorsTexParam; 215 212 static CGparameter sPositionsTexParam; … … 217 214 static CGparameter sNoiseTexParam; 218 215 219 /*static CGparameter sTexSizeParam; 220 static CGparameter sSamplesParam; 221 static CGparameter sEyeVecParam; 222 static CGparameter sRadiusParam; 223 */ 224 static CGparameter sProjectionMatrixParam; 225 static CGparameter sModelViewMatrixParam; 216 static CGparameter sModelViewProjMatrixParam; 217 //static CGparameter sModelMatrixParam; 226 218 static CGparameter sMaxDepthParam; 227 219 … … 276 268 277 269 glutCreateWindow("FriendlyCulling"); 270 271 //glutGameModeString( "1024x768:32@75" ); //the settings for fullscreen mode 272 //glutEnterGameMode(); //set glut to fullscreen using the settings in the line above 278 273 279 274 glutDisplayFunc(Display); … … 333 328 //bvh = bvhLoader.Load("data/city/model/city.bvh", sceneEntities); 334 329 335 myfar = 1 .0f * Magnitude(bvh->GetBox().Diagonal());330 myfar = 10.0f * Magnitude(bvh->GetBox().Diagonal()); 336 331 337 332 if (!bvh) … … 353 348 visualization = new Visualization(bvh, camera, NULL, &state); 354 349 355 sceneQuery = new SceneQuery(bvh->GetBox(), traverser);350 //sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 356 351 357 352 … … 376 371 377 372 // get the best profile for this hardware 378 sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);373 RenderState::sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT); 379 374 //assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN); 380 cgGLSetOptimalOptions( sCgFragmentProfile);381 382 sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);383 cgGLSetOptimalOptions( sCgVertexProfile);375 cgGLSetOptimalOptions(RenderState::sCgFragmentProfile); 376 377 RenderState::sCgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX); 378 cgGLSetOptimalOptions(RenderState::sCgVertexProfile); 384 379 385 380 sCgMrtVertexProgram = … … 387 382 CG_SOURCE, 388 383 "src/shaders/mrt.cg", 389 sCgVertexProfile,384 RenderState::sCgVertexProfile, 390 385 "vtx", 391 386 NULL); … … 394 389 { 395 390 cgGLLoadProgram(sCgMrtVertexProgram); 396 397 sModelViewMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj"); 391 392 SceneEntity::sModelMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelMatrix"); 393 sModelViewProjMatrixParam = cgGetNamedParameter(sCgMrtVertexProgram, "ModelViewProj"); 398 394 } 399 395 … … 402 398 CG_SOURCE, 403 399 "src/shaders/mrt.cg", 404 sCgFragmentProfile,400 RenderState::sCgFragmentProfile, 405 401 "frag", 406 402 NULL); … … 411 407 412 408 sMaxDepthParam = cgGetNamedParameter(sCgMrtFragmentProgram, "maxDepth"); 413 cgGLSetParameter1f(sMaxDepthParam, 1.0f / myfar); 409 410 cgGLSetParameter1f(sMaxDepthParam, 10.0f / myfar); 414 411 } 415 412 else … … 426 423 "src/shaders/deferred.cg", 427 424 //"src/test.cg", 428 sCgFragmentProfile,425 RenderState::sCgFragmentProfile, 429 426 NULL, 430 427 NULL); … … 438 435 sColorsTexParam = cgGetNamedParameter(sCgSSAOProgram, "colors"); 439 436 sNormalsTexParam = cgGetNamedParameter(sCgSSAOProgram, "normals"); 440 sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture"); 441 442 sProjectionMatrixParam = cgGetNamedParameter(sCgSSAOProgram, "ProjTrafo"); 443 444 /*sTexSizeParam = cgGetNamedParameter(sCgSSAOProgram, "invTexSize"); 445 sRadiusParam = cgGetNamedParameter(sCgSSAOProgram, "radius"); 446 sEyeVecParam = cgGetNamedParameter(sCgSSAOProgram, "eyevec"); 447 sSamplesParam = cgGetNamedParameter(sCgSSAOProgram, "samples"); 448 449 cgGLSetParameter1f(sTexSizeParam, 1.0f / (float)texWidth); 450 cgGLSetParameter1f(sRadiusParam, radius); 451 cgGLSetParameterArray3f(sSamplesParam, 0, 32, (const float *)samples);*/ 437 sNoiseTexParam = cgGetNamedParameter(sCgSSAOProgram, "noiseTexture"); 452 438 } 453 439 else … … 455 441 456 442 PrintGLerror("init"); 443 444 cout << "cg initialised" << endl; 457 445 } 458 446 … … 584 572 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 585 573 586 587 ////////////////588 //-- second fbo589 590 /*glGenFramebuffersEXT(1, &fbo2);591 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo2);592 593 // create color buffer594 glGenRenderbuffersEXT(1, &occlusionbuffer);595 //glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA32F_ARB, texWidth, texHeight);596 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, samples, GL_FLOAT_RGBA_NV, texWidth2, texHeight2);597 glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, occlusionbuffer);598 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, occlusionbuffer);599 600 glGenTextures(1, &occlusionTex);601 glBindTexture(GL_TEXTURE_2D, occlusionTex);602 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, texWidth2, texHeight2, 0, GL_RGBA, GL_FLOAT, NULL);603 glGenerateMipmapEXT(GL_TEXTURE_2D);604 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTex, 0);605 606 PrintFBOStatus(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));607 608 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);*/609 574 PrintGLerror("fbo"); 610 575 } … … 882 847 glViewport(0, 0, texWidth, texHeight); 883 848 884 cgGLEnableProfile( sCgFragmentProfile);849 cgGLEnableProfile(RenderState::sCgFragmentProfile); 885 850 cgGLBindProgram(sCgMrtFragmentProgram); 886 851 887 cgGLEnableProfile( sCgVertexProfile);852 cgGLEnableProfile(RenderState::sCgVertexProfile); 888 853 cgGLBindProgram(sCgMrtVertexProgram); 889 854 … … 896 861 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 897 862 863 // set modelview matrix for shaders 864 cgGLSetStateMatrixParameter(sModelViewProjMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); 865 898 866 // render without shading 899 867 if (depthPass) … … 907 875 glEnable(GL_LIGHTING); 908 876 } 909 877 878 static Matrix4x4 identity = IdentityMatrix(); 879 880 cgGLSetMatrixParameterfc(SceneEntity::sModelMatrixParam, (const float *)identity.x); 910 881 // bring eye modelview matrix up-to-date 911 882 SetupEyeView(); 912 883 913 Vector3 dir = camera->GetDirection();914 //cgGLSetParameter3f(sEyeVecParam, dir.x, dir.y, dir.z);915 916 // set modelview matrix for shaders917 cgGLSetStateMatrixParameter(sModelViewMatrixParam, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);918 cgGLEnableProfile(sCgVertexProfile);919 920 884 // actually render the scene geometry using one of the specified algorithms 921 885 traverser->RenderScene(); … … 947 911 948 912 949 cgGLDisableProfile( sCgVertexProfile);950 cgGLDisableProfile( sCgFragmentProfile);913 cgGLDisableProfile(RenderState::sCgVertexProfile); 914 cgGLDisableProfile(RenderState::sCgFragmentProfile); 951 915 952 916 glPopAttrib(); 953 917 954 cgGLSetStateMatrixParameter(sProjectionMatrixParam, CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);955 956 918 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 957 919 … … 1497 1459 static char msg[7][300]; 1498 1460 1499 static double renderTime = algTime;1500 const float expFactor = 0. 5f;1461 static double renderTime = elapsedTime;//algTime; 1462 const float expFactor = 0.1f; 1501 1463 1502 1464 // if some strange render time spike happened in this frame => don't count … … 1629 1591 { 1630 1592 glDisable(GL_TEXTURE_2D); 1631 //glEnable(GL_TEXTURE_2D);1593 1632 1594 glDisable(GL_LIGHTING); 1633 //glBindTexture(GL_TEXTURE_2D, noiseTex);1595 1634 1596 glMatrixMode(GL_PROJECTION); 1635 1597 glPushMatrix(); … … 1641 1603 1642 1604 const float offs = 0.5f; 1643 //glPushAttrib(GL_VIEWPORT_BIT); 1644 //glViewport(-offs, texHeight); 1605 1645 1606 glOrtho(-offs, offs, -offs, offs, 0, 1); 1646 1607 1647 1608 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1648 1609 1649 cgGLEnableProfile( sCgFragmentProfile);1610 cgGLEnableProfile(RenderState::sCgFragmentProfile); 1650 1611 cgGLBindProgram(sCgSSAOProgram); 1651 1612 … … 1668 1629 1669 1630 glBegin(GL_QUADS); 1670 #if 1 1631 1671 1632 // slightly larger than screen size in order to hide ambient occlusion errors 1672 float offs2 = 0.55f;1673 //float offs2 = 0.5f;1633 //float offs2 = 0.55f; 1634 float offs2 = 0.5f; 1674 1635 1675 1636 glColor3f(bl.x, bl.y, bl.z); glTexCoord2f(0, 0); glVertex3f(-offs2, -offs2, -0.5f); … … 1677 1638 glColor3f(tr.x, tr.y, tr.z); glTexCoord2f(1, 1); glVertex3f( offs2, offs2, -0.5f); 1678 1639 glColor3f(tl.x, tl.y, tl.z); glTexCoord2f(0, 1); glVertex3f(-offs2, offs2, -0.5f); 1679 #else 1680 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 1681 glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 1682 glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f); 1683 glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f); 1684 #endif 1640 1685 1641 glEnd(); 1686 1642 … … 1690 1646 cgGLDisableTextureParameter(sNoiseTexParam); 1691 1647 1692 cgGLDisableProfile( sCgFragmentProfile);1648 cgGLDisableProfile(RenderState::sCgFragmentProfile); 1693 1649 1694 1650 glEnable(GL_LIGHTING); -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/deferred.cg
r2817 r2818 60 60 uniform sampler2D positions, 61 61 uniform sampler2D normals, 62 const uniform float4x4 ProjTrafo,63 62 uniform sampler2D noiseTexture 64 63 ) 65 64 { 66 65 // the current world position 67 float4 centerPositionW = tex2D(positions, IN.texCoord.xy); 68 float3 centerPosition = centerPositionW.xyz; 66 float4 centerPosition = tex2D(positions, IN.texCoord.xy); 67 // the w coordinate from the persp. projection 68 float w = centerPosition.w; 69 69 70 70 // the normal on the current position … … 87 87 //sample noisetex; r stores costheta, g stores sintheta 88 88 float3 noise = tex2D(noiseTexture, IN.texCoord.xy).xyz * 2.0f - 1.0f; 89 90 //float2 offsetTransformed = offset;//reflect(offset, noise.xy); 89 90 // rotation 91 //float2 offsetTransformed = offset; 91 92 float2 offsetTransformed; 92 93 offsetTransformed.x = noise.r * offset.x - noise.g * offset.y; … … 94 95 95 96 // weight with projected coordinate to reach similar kernel size for near and far 96 float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * centerPositionW.w;97 float2 texcoord = IN.texCoord.xy + offsetTransformed * areaSize * w; 97 98 98 99 float3 sample_position = tex2D(positions, texcoord).xyz; 99 100 100 float3 vector_to_sample = sample_position - centerPosition ;101 float3 vector_to_sample = sample_position - centerPosition.xyz; 101 102 float length_to_sample = length(vector_to_sample); 102 103 float3 direction_to_sample = vector_to_sample / (length_to_sample + 1e-9f); … … 125 126 uniform sampler2D positions, 126 127 uniform sampler2D normals, 127 const uniform float4x4 ProjTrafo,128 128 uniform sampler2D noiseTexture) 129 129 { … … 137 137 138 138 // expand normal 139 normal = normal * 2.0f - 1.0f;139 normal = normalize(normal * 2.0f - 1.0f); 140 140 141 141 float4 position = tex2D(positions, IN.texCoord.xy); … … 146 146 float3 light = normalize(lightDir.xyz); 147 147 float3 light2 = normalize(lightDir2.xyz); 148 148 149 149 float diffuseLight = max(dot(normal, light), 0.0f); 150 150 float diffuseLight2 = max(dot(normal, light2), 0.0f); … … 152 152 float diffuse = diffuseLight + diffuseLight2; 153 153 154 float ao = ssao(IN, positions, normals, ProjTrafo,noiseTexture);154 float ao = ssao(IN, positions, normals, noiseTexture); 155 155 //OUT.color = ao; 156 156 OUT.color = ao * (ambient + diffuse) * color; 157 //OUT.color = (ambient + diffuse) * color; 158 159 //float4 currentPos = tex2D(normals, IN.texCoord.xy) * 0.5f + 0.5f; 160 //float4 currentPos = tex2D(normals, IN.texCoord.xy); 161 //OUT.color = currentPos; 157 //OUT.color = (ambient + diffuse) * color; 162 158 163 159 return OUT; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/mrt.cg
r2813 r2818 41 41 42 42 43 vtxout vtx(vtxin IN, uniform float4x4 ModelViewProj) 43 vtxout vtx(vtxin IN, 44 const uniform float4x4 ModelViewProj, 45 uniform float4x4 ModelMatrix) 44 46 { 45 47 vtxout OUT; 46 48 47 49 // transform the vertex position into eye space 48 OUT.position = mul(ModelViewProj, IN.position);49 50 50 OUT.color = IN.color; 51 51 52 52 OUT.texCoord = IN.texCoord; 53 OUT.worldPos = mul(ModelMatrix, IN.position); 54 55 // transform the vertex position into eye space 56 OUT.position = mul(ModelViewProj, OUT.worldPos); 57 53 58 OUT.worldPos = IN.position; 54 // eye pos with linear depth 55 //OUT.worldPos = OUT.position; 59 56 60 OUT.normal = IN.normal; 57 61 … … 66 70 pix.col = tex2D(tex, IN.texCoord.xy); 67 71 pix.pos = IN.worldPos * maxDepth; 72 pix.norm = IN.normal; 68 73 pix.pos.w = IN.projPos.w; 69 pix.norm = IN.normal;70 74 71 75 return pix;
Note: See TracChangeset
for help on using the changeset viewer.