Changeset 2895 for GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
- Timestamp:
- 09/02/08 15:29:20 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
r2894 r2895 34 34 #include "FrameBufferObject.h" 35 35 #include "SsaoShader.h" 36 #include "DeferredShader.h"37 36 #include "ShadowMapping.h" 38 37 #include "Light.h" … … 95 94 static int winHeight = 768; 96 95 97 //static int winWidth = 512;98 //static int winHeight = 512;99 100 96 101 97 static float winAspectRatio = 1.0f; … … 172 168 bool useLODs = true; 173 169 174 int samplingMethod = SsaoShader::POISSON; 170 SsaoShader::SAMPLING_METHOD samplingMethod = SsaoShader::POISSON; 171 SsaoShader::SHADING_METHOD shadingMethod = SsaoShader::DEFAULT; 172 173 bool showShadowMap = false; 174 bool shadowChanged = true; 175 175 176 176 static Matrix4x4 matProjectionView = IdentityMatrix(); … … 179 179 ShadowMap *shadowMap = NULL; 180 180 Light *light = NULL; 181 181 182 182 183 // function forward declarations … … 225 226 226 227 SsaoShader *ssaoShader = NULL; 227 DeferredShader *deferredShader = NULL;228 228 229 229 static GLenum mrt[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT}; … … 431 431 InitCg(); 432 432 433 DeferredShader::Init(sCgContext);434 433 SsaoShader::Init(sCgContext); 435 434 … … 442 441 sceneQuery = new SceneQuery(bvh->GetBox(), traverser); 443 442 444 Vector3 lightDir = Normalize(Vector3(0, 1, -1)); 443 //Vector3 lightDir = Normalize(Vector3(0, 1, -1)); 444 Vector3 lightDir = Normalize(-Vector3(0.8f, -1.0f, 0.7f)); 445 445 446 light = new Light(lightDir, RgbaColor(1, 1, 1, 1)); 446 447 447 const float shadowSize = 4096; 448 shadowMap = new ShadowMap(shadowSize, bvh->GetBox(), camera); 449 448 450 449 // frame time is restarted every frame 451 450 frameTimer.Start(); … … 867 866 } 868 867 868 if (showShadowMap && !shadowMap) 869 { 870 const float shadowSize = 4096; 871 shadowMap = new ShadowMap(shadowSize, bvh->GetBox(), camera); 872 } 873 869 874 // render without shading 870 875 switch (renderType) … … 897 902 898 903 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 899 900 904 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 901 905 … … 904 908 case RenderState::DEFERRED: 905 909 906 shadowMap->ComputeShadowMap(light, traverser); 910 // change CHC state (must be done for each change of camera) 911 BvhNode::SetCurrentState(1); 912 913 if (showShadowMap && shadowChanged) 914 { 915 shadowChanged = false; 916 917 cgGLDisableProfile(RenderState::sCgFragmentProfile); 918 cgGLDisableProfile(RenderState::sCgVertexProfile); 919 920 state.SetRenderType(RenderState::DEPTH_PASS); 921 922 // the scene is rendered withouth any shading 923 shadowMap->ComputeShadowMap(light, traverser); 924 925 // change back state 926 BvhNode::SetCurrentState(0); 927 928 glEnable(GL_LIGHTING); 929 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 930 } 907 931 908 932 if (!fbo) InitFBO(); 933 909 934 910 935 // multisampling does not work with deferred shading … … 989 1014 cgGLDisableProfile(RenderState::sCgFragmentProfile); 990 1015 991 if (useSsao) 992 { 993 if (!ssaoShader) ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 994 ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor); 995 996 } 997 else 998 { 999 if (!deferredShader) deferredShader = new DeferredShader(texWidth, texHeight, myfar / 10.0f); 1000 1001 deferredShader->Render(fbo, shadowMap); 1002 } 1016 if (!ssaoShader) ssaoShader = new SsaoShader(texWidth, texHeight, camera, myfar / 10.0f); 1017 1018 ssaoShader->SetShadingMethod(shadingMethod); 1019 ssaoShader->SetSamplingMethod(samplingMethod); 1020 ssaoShader->SetUseTemporalCoherence(useTemporalCoherence); 1021 1022 ShadowMap *sm = showShadowMap ? shadowMap : NULL; 1023 ssaoShader->Render(fbo, oldViewProjMatrix, ssaoExpFactor, sm); 1003 1024 } 1004 1025 … … 1118 1139 samplingMethod = SsaoShader::GAUSS; 1119 1140 1120 ssaoShader->SetSamplingMethod(samplingMethod); 1121 1141 break; 1142 case 'Y': 1143 case 'y': 1144 showShadowMap = !showShadowMap; 1122 1145 break; 1123 1146 case 'g': 1124 case 'G':1125 useGlobIllum = !useGlobIllum;1126 ssaoShader->SetUseGlobIllum(useGlobIllum);1127 break;1128 1147 case 't': 1129 1148 case 'T': 1130 1149 useTemporalCoherence = !useTemporalCoherence; 1131 ssaoShader->SetUseTemporalCoherence(useTemporalCoherence);1132 1150 break; 1133 1151 case 'o': … … 1262 1280 break; 1263 1281 case GLUT_KEY_F8: 1264 useSsao = !useSsao; 1282 shadingMethod = (SsaoShader::SHADING_METHOD)((shadingMethod + 1) % 3); 1283 1265 1284 break; 1266 1285 case GLUT_KEY_F9: … … 1562 1581 DEL_PTR(fbo); 1563 1582 DEL_PTR(ssaoShader); 1564 DEL_PTR(deferredShader);1565 1583 1566 1584 if (sCgMrtVertexProgram) … … 1766 1784 } 1767 1785 1768 1786 // render visible object from depth pass 1769 1787 void RenderVisibleObjects() 1770 1788 {
Note: See TracChangeset
for help on using the changeset viewer.