[2961] | 1 | // chcdemo.cpp : Defines the entry point for the console application.
|
---|
[2642] | 2 | //
|
---|
[3019] | 3 |
|
---|
[3021] | 4 |
|
---|
| 5 | #include "common.h"
|
---|
| 6 |
|
---|
[3019] | 7 | #ifdef _CRT_SET
|
---|
| 8 | #define _CRTDBG_MAP_ALLOC
|
---|
| 9 | #include <stdlib.h>
|
---|
| 10 | #include <crtdbg.h>
|
---|
| 11 |
|
---|
| 12 | // redefine new operator
|
---|
| 13 | #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
---|
| 14 | #define new DEBUG_NEW
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[2746] | 17 | #include <math.h>
|
---|
| 18 | #include <time.h>
|
---|
[3019] | 19 | #include "glInterface.h"
|
---|
| 20 |
|
---|
| 21 |
|
---|
[2642] | 22 | #include "RenderTraverser.h"
|
---|
[2756] | 23 | #include "SceneEntity.h"
|
---|
| 24 | #include "Vector3.h"
|
---|
| 25 | #include "Matrix4x4.h"
|
---|
[2795] | 26 | #include "ResourceManager.h"
|
---|
[2756] | 27 | #include "Bvh.h"
|
---|
| 28 | #include "Camera.h"
|
---|
| 29 | #include "Geometry.h"
|
---|
[2760] | 30 | #include "BvhLoader.h"
|
---|
| 31 | #include "FrustumCullingTraverser.h"
|
---|
[2763] | 32 | #include "StopAndWaitTraverser.h"
|
---|
[2764] | 33 | #include "CHCTraverser.h"
|
---|
[2767] | 34 | #include "CHCPlusPlusTraverser.h"
|
---|
| 35 | #include "Visualization.h"
|
---|
[2769] | 36 | #include "RenderState.h"
|
---|
[2795] | 37 | #include "Timer/PerfTimer.h"
|
---|
[2796] | 38 | #include "SceneQuery.h"
|
---|
[2801] | 39 | #include "RenderQueue.h"
|
---|
[2819] | 40 | #include "Material.h"
|
---|
[2826] | 41 | #include "glfont2.h"
|
---|
[2827] | 42 | #include "PerformanceGraph.h"
|
---|
[2828] | 43 | #include "Environment.h"
|
---|
[2837] | 44 | #include "Halton.h"
|
---|
[2840] | 45 | #include "Transform3.h"
|
---|
[2853] | 46 | #include "SampleGenerator.h"
|
---|
[2857] | 47 | #include "FrameBufferObject.h"
|
---|
[2896] | 48 | #include "DeferredRenderer.h"
|
---|
[2887] | 49 | #include "ShadowMapping.h"
|
---|
| 50 | #include "Light.h"
|
---|
[2953] | 51 | #include "SceneEntityConverter.h"
|
---|
[2957] | 52 | #include "SkyPreetham.h"
|
---|
[2964] | 53 | #include "Texture.h"
|
---|
[3057] | 54 | #include "ShaderManager.h"
|
---|
[3078] | 55 | #include "MotionPath.h"
|
---|
[3113] | 56 | #include "ShaderProgram.h"
|
---|
| 57 | #include "Shape.h"
|
---|
[3219] | 58 | #include "WalkThroughRecorder.h"
|
---|
[3223] | 59 | #include "StatsWriter.h"
|
---|
[3243] | 60 | #include "VisibilitySolutionLoader.h"
|
---|
| 61 | #include "ViewCellsTree.h"
|
---|
[2642] | 62 |
|
---|
[3066] | 63 |
|
---|
[2756] | 64 | using namespace std;
|
---|
[2776] | 65 | using namespace CHCDemoEngine;
|
---|
[2642] | 66 |
|
---|
| 67 |
|
---|
[3068] | 68 | /// the environment for the program parameter
|
---|
[2828] | 69 | static Environment env;
|
---|
| 70 |
|
---|
| 71 |
|
---|
[2826] | 72 | GLuint fontTex;
|
---|
[3068] | 73 | /// the fbo used for MRT
|
---|
[3038] | 74 | FrameBufferObject *fbo = NULL;
|
---|
[2756] | 75 | /// the renderable scene geometry
|
---|
| 76 | SceneEntityContainer sceneEntities;
|
---|
[3214] | 77 | /// the dynamic objects in the scene
|
---|
[3070] | 78 | SceneEntityContainer dynamicObjects;
|
---|
[2756] | 79 | // traverses and renders the hierarchy
|
---|
[2767] | 80 | RenderTraverser *traverser = NULL;
|
---|
[2756] | 81 | /// the hierarchy
|
---|
[2767] | 82 | Bvh *bvh = NULL;
|
---|
[2793] | 83 | /// handles scene loading
|
---|
[3059] | 84 | ResourceManager *resourceManager = NULL;
|
---|
[3057] | 85 | /// handles scene loading
|
---|
| 86 | ShaderManager *shaderManager = NULL;
|
---|
[2756] | 87 | /// the scene camera
|
---|
[3062] | 88 | PerspectiveCamera *camera = NULL;
|
---|
[2795] | 89 | /// the scene camera
|
---|
[3062] | 90 | PerspectiveCamera *visCamera = NULL;
|
---|
[2767] | 91 | /// the visualization
|
---|
| 92 | Visualization *visualization = NULL;
|
---|
[3101] | 93 | /// the current render renderState
|
---|
| 94 | RenderState renderState;
|
---|
[2764] | 95 | /// the rendering algorithm
|
---|
[2795] | 96 | int renderMode = RenderTraverser::CHCPLUSPLUS;
|
---|
[3038] | 97 | /// eye near plane distance
|
---|
[3068] | 98 | const float nearDist = 0.2f;
|
---|
[3106] | 99 | //const float nearDist = 1.0f;
|
---|
[3038] | 100 | /// eye far plane distance
|
---|
[2927] | 101 | float farDist = 1e6f;
|
---|
[2856] | 102 | /// the field of view
|
---|
[3068] | 103 | const float fov = 50.0f;
|
---|
[2764] | 104 |
|
---|
[2796] | 105 | SceneQuery *sceneQuery = NULL;
|
---|
[2801] | 106 | RenderQueue *renderQueue = NULL;
|
---|
[3068] | 107 | /// traverses and renders the hierarchy
|
---|
[2897] | 108 | RenderTraverser *shadowTraverser = NULL;
|
---|
[3068] | 109 | /// the skylight + skydome model
|
---|
[2957] | 110 | SkyPreetham *preetham = NULL;
|
---|
[2897] | 111 |
|
---|
[3078] | 112 | MotionPath *motionPath = NULL;
|
---|
[3189] | 113 | /// max depth where candidates for tighter bounds are searched
|
---|
[3123] | 114 | int maxDepthForTestingChildren = 3;
|
---|
[3246] | 115 | /// use full resolution for ssao or half
|
---|
[3216] | 116 | bool ssaoUseFullResolution = false;
|
---|
[3123] | 117 |
|
---|
[3219] | 118 | /// store the frames as tga
|
---|
| 119 | bool recordFrames = false;
|
---|
| 120 | /// record the taken path
|
---|
| 121 | bool recordPath = false;
|
---|
| 122 | /// replays the recorded path
|
---|
| 123 | bool replayPath = false;
|
---|
[3223] | 124 | /// frame number for replay
|
---|
[3219] | 125 | int currentReplayFrame = -1;
|
---|
| 126 |
|
---|
[3220] | 127 | string recordedFramesSuffix("frames");
|
---|
[3223] | 128 | string statsFilename("stats");
|
---|
[3220] | 129 |
|
---|
[3238] | 130 | string filename("city");
|
---|
[3243] | 131 | string visibilitySolution("");
|
---|
[3238] | 132 |
|
---|
| 133 |
|
---|
[3219] | 134 | /// the walkThroughRecorder
|
---|
| 135 | WalkThroughRecorder *walkThroughRecorder = NULL;
|
---|
| 136 | WalkThroughPlayer *walkThroughPlayer = NULL;
|
---|
[3223] | 137 | StatsWriter *statsWriter = NULL;
|
---|
[3219] | 138 |
|
---|
[3225] | 139 | bool makeSnapShot = false;
|
---|
[3219] | 140 |
|
---|
[3244] | 141 | ViewCellsTree *viewCellsTree = NULL;
|
---|
[3246] | 142 | ViewCell *viewCell = NULL;
|
---|
[3225] | 143 |
|
---|
[3247] | 144 | bool useSkylightForIllum = true;
|
---|
| 145 |
|
---|
[3245] | 146 | static int globalVisibleId = 0;
|
---|
[3244] | 147 |
|
---|
[3245] | 148 |
|
---|
| 149 |
|
---|
[3068] | 150 | /// the technique used for rendering
|
---|
| 151 | enum RenderTechnique
|
---|
| 152 | {
|
---|
| 153 | FORWARD,
|
---|
| 154 | DEFERRED,
|
---|
| 155 | DEPTH_PASS
|
---|
| 156 | };
|
---|
| 157 |
|
---|
| 158 |
|
---|
[2994] | 159 | /// the used render type for this render pass
|
---|
| 160 | enum RenderMethod
|
---|
| 161 | {
|
---|
[3043] | 162 | RENDER_FORWARD,
|
---|
[2994] | 163 | RENDER_DEPTH_PASS,
|
---|
| 164 | RENDER_DEFERRED,
|
---|
| 165 | RENDER_DEPTH_PASS_DEFERRED,
|
---|
| 166 | RENDER_NUM_RENDER_TYPES
|
---|
| 167 | };
|
---|
[2957] | 168 |
|
---|
[2994] | 169 | /// one of four possible render methods
|
---|
[3043] | 170 | int renderMethod = RENDER_FORWARD;
|
---|
[2994] | 171 |
|
---|
[3059] | 172 | static int winWidth = 1024;
|
---|
| 173 | static int winHeight = 768;
|
---|
| 174 | static float winAspectRatio = 1.0f;
|
---|
[2994] | 175 |
|
---|
[2809] | 176 | /// these values get scaled with the frame rate
|
---|
[2828] | 177 | static float keyForwardMotion = 30.0f;
|
---|
| 178 | static float keyRotation = 1.5f;
|
---|
[2801] | 179 |
|
---|
[2826] | 180 | /// elapsed time in milliseconds
|
---|
[3059] | 181 | double elapsedTime = 1000.0;
|
---|
| 182 | double algTime = 1000.0;
|
---|
| 183 | double accumulatedTime = 1000.0;
|
---|
| 184 | float fps = 1e3f;
|
---|
[3193] | 185 | float turbitity = 5.0f;
|
---|
[2795] | 186 |
|
---|
[3212] | 187 | // ssao parameters
|
---|
| 188 | float ssaoKernelRadius = 1e-8f;
|
---|
| 189 | float ssaoSampleIntensity = 0.2f;
|
---|
[3216] | 190 | float ssaoFilterRadius = 12.0f;
|
---|
[3212] | 191 | float ssaoTempCohFactor = 255.0;
|
---|
| 192 | bool sortSamples = true;
|
---|
| 193 |
|
---|
[2945] | 194 | int shadowSize = 2048;
|
---|
[3212] | 195 |
|
---|
[3059] | 196 | /// the hud font
|
---|
[2826] | 197 | glfont::GLFont myfont;
|
---|
| 198 |
|
---|
[2809] | 199 | // rendertexture
|
---|
[3212] | 200 | int texWidth = 1024;
|
---|
| 201 | int texHeight = 768;
|
---|
[2866] | 202 |
|
---|
[2770] | 203 | int renderedObjects = 0;
|
---|
[2773] | 204 | int renderedNodes = 0;
|
---|
| 205 | int renderedTriangles = 0;
|
---|
| 206 |
|
---|
[2770] | 207 | int issuedQueries = 0;
|
---|
| 208 | int traversedNodes = 0;
|
---|
| 209 | int frustumCulledNodes = 0;
|
---|
| 210 | int queryCulledNodes = 0;
|
---|
| 211 | int stateChanges = 0;
|
---|
[2800] | 212 | int numBatches = 0;
|
---|
[2770] | 213 |
|
---|
[3101] | 214 | // mouse navigation renderState
|
---|
[2809] | 215 | int xEyeBegin = 0;
|
---|
| 216 | int yEyeBegin = 0;
|
---|
| 217 | int yMotionBegin = 0;
|
---|
| 218 | int verticalMotionBegin = 0;
|
---|
| 219 | int horizontalMotionBegin = 0;
|
---|
[2642] | 220 |
|
---|
[2792] | 221 | bool leftKeyPressed = false;
|
---|
| 222 | bool rightKeyPressed = false;
|
---|
| 223 | bool upKeyPressed = false;
|
---|
| 224 | bool downKeyPressed = false;
|
---|
[2837] | 225 | bool descendKeyPressed = false;
|
---|
| 226 | bool ascendKeyPressed = false;
|
---|
[3105] | 227 | bool leftStrafeKeyPressed = false;
|
---|
| 228 | bool rightStrafeKeyPressed = false;
|
---|
| 229 |
|
---|
[3054] | 230 | bool altKeyPressed = false;
|
---|
| 231 |
|
---|
[2994] | 232 | bool showHelp = false;
|
---|
| 233 | bool showStatistics = false;
|
---|
| 234 | bool showOptions = true;
|
---|
| 235 | bool showBoundingVolumes = false;
|
---|
| 236 | bool visMode = false;
|
---|
| 237 |
|
---|
| 238 | bool useOptimization = false;
|
---|
[3074] | 239 | bool useTightBounds = true;
|
---|
[2994] | 240 | bool useRenderQueue = true;
|
---|
| 241 | bool useMultiQueries = true;
|
---|
| 242 | bool flyMode = true;
|
---|
| 243 |
|
---|
[2875] | 244 | bool useGlobIllum = false;
|
---|
| 245 | bool useTemporalCoherence = true;
|
---|
[2994] | 246 | bool showAlgorithmTime = false;
|
---|
[2875] | 247 |
|
---|
[2994] | 248 | bool useFullScreen = false;
|
---|
| 249 | bool useLODs = true;
|
---|
| 250 | bool moveLight = false;
|
---|
| 251 |
|
---|
| 252 | bool useAdvancedShading = false;
|
---|
| 253 | bool showShadowMap = false;
|
---|
| 254 | bool renderLightView = false;
|
---|
[3054] | 255 | bool useHDR = true;
|
---|
[3175] | 256 | bool useAntiAliasing = true;
|
---|
[3215] | 257 | bool useLenseFlare = true;
|
---|
[2994] | 258 |
|
---|
[3246] | 259 | bool usePvs = false;
|
---|
| 260 |
|
---|
| 261 |
|
---|
[3054] | 262 | PerfTimer frameTimer, algTimer;
|
---|
[3212] | 263 | /// the performance graph window
|
---|
[3054] | 264 | PerformanceGraph *perfGraph = NULL;
|
---|
[2994] | 265 |
|
---|
[3189] | 266 | int sCurrentMrtSet = 0;
|
---|
[2957] | 267 |
|
---|
[3111] | 268 | static Matrix4x4 invTrafo = IdentityMatrix();
|
---|
[2825] | 269 |
|
---|
[3246] | 270 | float mouseMotion = 0.2f;
|
---|
[3111] | 271 |
|
---|
[3246] | 272 |
|
---|
[3068] | 273 | //////////////
|
---|
[3246] | 274 | //-- chc++ algorithm parameters
|
---|
[2827] | 275 |
|
---|
[3068] | 276 | /// the pixel threshold where a node is still considered invisible
|
---|
| 277 | /// (should be zero for conservative visibility)
|
---|
| 278 | int threshold;
|
---|
| 279 | int assumedVisibleFrames = 10;
|
---|
| 280 | int maxBatchSize = 50;
|
---|
| 281 | int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES;
|
---|
| 282 |
|
---|
[3244] | 283 |
|
---|
[3068] | 284 | //////////////
|
---|
| 285 |
|
---|
| 286 | enum {CAMERA_PASS = 0, LIGHT_PASS = 1};
|
---|
| 287 |
|
---|
| 288 |
|
---|
[2948] | 289 | //DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_POISSON;
|
---|
| 290 | DeferredRenderer::SAMPLING_METHOD samplingMethod = DeferredRenderer::SAMPLING_QUADRATIC;
|
---|
[2865] | 291 |
|
---|
[2894] | 292 | ShadowMap *shadowMap = NULL;
|
---|
[2952] | 293 | DirectionalLight *light = NULL;
|
---|
[3111] | 294 | DeferredRenderer *deferredShader = NULL;
|
---|
[2834] | 295 |
|
---|
[3175] | 296 |
|
---|
[3059] | 297 | SceneEntity *buddha = NULL;
|
---|
[2957] | 298 | SceneEntity *skyDome = NULL;
|
---|
[3214] | 299 | SceneEntity *sunBox = NULL;
|
---|
[2895] | 300 |
|
---|
[3214] | 301 | GLuint sunQuery = 0;
|
---|
[2952] | 302 |
|
---|
[3214] | 303 |
|
---|
[3059] | 304 | ////////////////////
|
---|
| 305 | //--- function forward declarations
|
---|
[2991] | 306 |
|
---|
[2759] | 307 | void InitExtensions();
|
---|
[3059] | 308 | void InitGLstate();
|
---|
| 309 |
|
---|
[2756] | 310 | void DisplayVisualization();
|
---|
[3059] | 311 | /// destroys all allocated resources
|
---|
[2759] | 312 | void CleanUp();
|
---|
| 313 | void SetupEyeView();
|
---|
| 314 | void SetupLighting();
|
---|
[2764] | 315 | void DisplayStats();
|
---|
[3059] | 316 | /// draw the help screen
|
---|
[2786] | 317 | void DrawHelpMessage();
|
---|
[3059] | 318 | /// render the sky dome
|
---|
[2796] | 319 | void RenderSky();
|
---|
[3059] | 320 | /// render the objects found visible in the depth pass
|
---|
[2801] | 321 | void RenderVisibleObjects();
|
---|
[2756] | 322 |
|
---|
[3215] | 323 | int TestSunVisible();
|
---|
[3214] | 324 |
|
---|
[2792] | 325 | void Begin2D();
|
---|
| 326 | void End2D();
|
---|
[3059] | 327 | /// the main loop
|
---|
| 328 | void MainLoop();
|
---|
| 329 |
|
---|
[2792] | 330 | void KeyBoard(unsigned char c, int x, int y);
|
---|
| 331 | void Special(int c, int x, int y);
|
---|
| 332 | void KeyUp(unsigned char c, int x, int y);
|
---|
| 333 | void SpecialKeyUp(int c, int x, int y);
|
---|
| 334 | void Reshape(int w, int h);
|
---|
[3101] | 335 | void Mouse(int button, int renderState, int x, int y);
|
---|
[2792] | 336 | void LeftMotion(int x, int y);
|
---|
| 337 | void RightMotion(int x, int y);
|
---|
| 338 | void MiddleMotion(int x, int y);
|
---|
[3059] | 339 | void KeyHorizontalMotion(float shift);
|
---|
| 340 | void KeyVerticalMotion(float shift);
|
---|
| 341 | /// returns the string representation of a number with the decimal points
|
---|
[2792] | 342 | void CalcDecimalPoint(string &str, int d);
|
---|
[3059] | 343 | /// Creates the traversal method (vfc, stopandwait, chc, chc++)
|
---|
[3062] | 344 | RenderTraverser *CreateTraverser(PerspectiveCamera *cam);
|
---|
[3059] | 345 | /// place the viewer on the floor plane
|
---|
[2801] | 346 | void PlaceViewer(const Vector3 &oldPos);
|
---|
[3019] | 347 | // initialise the frame buffer objects
|
---|
[2809] | 348 | void InitFBO();
|
---|
[3059] | 349 | /// changes the sunlight direction
|
---|
[2954] | 350 | void RightMotionLight(int x, int y);
|
---|
[3059] | 351 | /// render the shader map
|
---|
[2951] | 352 | void RenderShadowMap(float newfar);
|
---|
[3059] | 353 | /// function that touches each material once in order to accelarate render queue
|
---|
| 354 | void PrepareRenderQueue();
|
---|
| 355 | /// loads the specified model
|
---|
[3237] | 356 | int LoadModel(const string &model, SceneEntityContainer &entities);
|
---|
[2810] | 357 |
|
---|
[3059] | 358 | inline float KeyRotationAngle() { return keyRotation * elapsedTime * 1e-3f; }
|
---|
| 359 | inline float KeyShift() { return keyForwardMotion * elapsedTime * 1e-3f; }
|
---|
[3054] | 360 |
|
---|
[3078] | 361 | void CreateAnimation();
|
---|
| 362 |
|
---|
[3120] | 363 | SceneQuery *GetOrCreateSceneQuery();
|
---|
[3078] | 364 |
|
---|
[3246] | 365 | void LoadPvs();
|
---|
[3120] | 366 |
|
---|
[3246] | 367 | void LoadVisibilitySolution();
|
---|
[3244] | 368 |
|
---|
[3246] | 369 | void RenderViewCell();
|
---|
| 370 |
|
---|
| 371 |
|
---|
[3120] | 372 | // new view projection matrix of the camera
|
---|
[3005] | 373 | static Matrix4x4 viewProjMat = IdentityMatrix();
|
---|
[3120] | 374 | // the old view projection matrix of the camera
|
---|
[3005] | 375 | static Matrix4x4 oldViewProjMat = IdentityMatrix();
|
---|
[2820] | 376 |
|
---|
[2837] | 377 |
|
---|
[2995] | 378 |
|
---|
[2809] | 379 | static void PrintGLerror(char *msg)
|
---|
| 380 | {
|
---|
| 381 | GLenum errCode;
|
---|
| 382 | const GLubyte *errStr;
|
---|
| 383 |
|
---|
| 384 | if ((errCode = glGetError()) != GL_NO_ERROR)
|
---|
| 385 | {
|
---|
| 386 | errStr = gluErrorString(errCode);
|
---|
| 387 | fprintf(stderr,"OpenGL ERROR: %s: %s\n", errStr, msg);
|
---|
| 388 | }
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 |
|
---|
[2642] | 392 | int main(int argc, char* argv[])
|
---|
| 393 | {
|
---|
[3019] | 394 | #ifdef _CRT_SET
|
---|
| 395 | //Now just call this function at the start of your program and if you're
|
---|
| 396 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
| 397 | //window when the program shuts down. If you're not in debug mode this will
|
---|
| 398 | //be ignored. Use it as you will!
|
---|
| 399 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
| 400 |
|
---|
| 401 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
| 402 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
| 403 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
| 404 | #endif
|
---|
[3052] | 405 |
|
---|
[3019] | 406 |
|
---|
[2781] | 407 | int returnCode = 0;
|
---|
| 408 |
|
---|
[2837] | 409 | Vector3 camPos(.0f, .0f, .0f);
|
---|
[2838] | 410 | Vector3 camDir(.0f, 1.0f, .0f);
|
---|
[2952] | 411 | Vector3 lightDir(-0.8f, 1.0f, -0.7f);
|
---|
[2837] | 412 |
|
---|
[2873] | 413 | cout << "=== reading environment file ===" << endl << endl;
|
---|
[2830] | 414 |
|
---|
[3019] | 415 | const string envFileName = "default.env";
|
---|
[2837] | 416 | if (!env.Read(envFileName))
|
---|
| 417 | {
|
---|
| 418 | cerr << "loading environment " << envFileName << " failed!" << endl;
|
---|
| 419 | }
|
---|
| 420 | else
|
---|
| 421 | {
|
---|
| 422 | env.GetIntParam(string("assumedVisibleFrames"), assumedVisibleFrames);
|
---|
| 423 | env.GetIntParam(string("maxBatchSize"), maxBatchSize);
|
---|
| 424 | env.GetIntParam(string("trianglesPerVirtualLeaf"), trianglesPerVirtualLeaf);
|
---|
[3123] | 425 | env.GetIntParam(string("winWidth"), winWidth);
|
---|
| 426 | env.GetIntParam(string("winHeight"), winHeight);
|
---|
| 427 | env.GetIntParam(string("shadowSize"), shadowSize);
|
---|
| 428 | env.GetIntParam(string("maxDepthForTestingChildren"), maxDepthForTestingChildren);
|
---|
[2828] | 429 |
|
---|
[2837] | 430 | env.GetFloatParam(string("keyForwardMotion"), keyForwardMotion);
|
---|
| 431 | env.GetFloatParam(string("keyRotation"), keyRotation);
|
---|
[3246] | 432 | env.GetFloatParam(string("mouseMotion"), mouseMotion);
|
---|
[3123] | 433 | env.GetFloatParam(string("tempCohFactor"), ssaoTempCohFactor);
|
---|
[3193] | 434 | env.GetFloatParam(string("turbitity"), turbitity);
|
---|
[3123] | 435 |
|
---|
[2837] | 436 | env.GetVectorParam(string("camPosition"), camPos);
|
---|
[2838] | 437 | env.GetVectorParam(string("camDirection"), camDir);
|
---|
[2952] | 438 | env.GetVectorParam(string("lightDirection"), lightDir);
|
---|
[2865] | 439 |
|
---|
[3117] | 440 | env.GetBoolParam(string("useFullScreen"), useFullScreen);
|
---|
| 441 | env.GetBoolParam(string("useLODs"), useLODs);
|
---|
[2994] | 442 | env.GetBoolParam(string("useHDR"), useHDR);
|
---|
[3175] | 443 | env.GetBoolParam(string("useAA"), useAntiAliasing);
|
---|
[3215] | 444 | env.GetBoolParam(string("useLenseFlare"), useLenseFlare);
|
---|
[3175] | 445 | env.GetBoolParam(string("useAdvancedShading"), useAdvancedShading);
|
---|
[2994] | 446 |
|
---|
[3175] | 447 | env.GetIntParam(string("renderMethod"), renderMethod);
|
---|
[3117] | 448 |
|
---|
[3212] | 449 | env.GetFloatParam(string("ssaoKernelRadius"), ssaoKernelRadius);
|
---|
| 450 | env.GetFloatParam(string("ssaoSampleIntensity"), ssaoSampleIntensity);
|
---|
[3216] | 451 | env.GetBoolParam(string("ssaoUseFullResolution"), ssaoUseFullResolution);
|
---|
| 452 |
|
---|
[3220] | 453 | env.GetStringParam(string("recordedFramesSuffix"), recordedFramesSuffix);
|
---|
[3223] | 454 | env.GetStringParam(string("statsFilename"), statsFilename);
|
---|
[3238] | 455 | env.GetStringParam(string("filename"), filename);
|
---|
[3243] | 456 | env.GetStringParam(string("visibilitySolution"), visibilitySolution);
|
---|
[3220] | 457 |
|
---|
[3246] | 458 | env.GetBoolParam(string("usePvs"), usePvs);
|
---|
| 459 |
|
---|
[3247] | 460 | env.GetBoolParam(string("useSkylightForIllum"), useSkylightForIllum);
|
---|
| 461 |
|
---|
[2846] | 462 | //env.GetStringParam(string("modelPath"), model_path);
|
---|
[2838] | 463 | //env.GetIntParam(string("numSssaoSamples"), numSsaoSamples);
|
---|
| 464 |
|
---|
[3212] | 465 | texWidth = winWidth;
|
---|
| 466 | texHeight = winHeight;
|
---|
| 467 |
|
---|
[3251] | 468 | cout << "assumed visible frames: " << assumedVisibleFrames << endl;
|
---|
| 469 | cout << "max batch size: " << maxBatchSize << endl;
|
---|
| 470 | cout << "triangles per virtual leaf: " << trianglesPerVirtualLeaf << endl;
|
---|
[2828] | 471 |
|
---|
[3251] | 472 | cout << "key forward motion: " << keyForwardMotion << endl;
|
---|
| 473 | cout << "key rotation: " << keyRotation << endl;
|
---|
| 474 | cout << "win width: " << winWidth << endl;
|
---|
| 475 | cout << "win height: " << winHeight << endl;
|
---|
| 476 | cout << "use full screen: " << useFullScreen << endl;
|
---|
| 477 | cout << "use LODs: " << useLODs << endl;
|
---|
| 478 | cout << "camera position: " << camPos << endl;
|
---|
[2945] | 479 | cout << "shadow size: " << shadowSize << endl;
|
---|
[3175] | 480 | cout << "render method: " << renderMethod << endl;
|
---|
| 481 | cout << "use antialiasing: " << useAntiAliasing << endl;
|
---|
[3215] | 482 | cout << "use lense flare: " << useLenseFlare << endl;
|
---|
[3175] | 483 | cout << "use advanced shading: " << useAdvancedShading << endl;
|
---|
[3193] | 484 | cout << "turbitity: " << turbitity << endl;
|
---|
[3251] | 485 | cout << "temporal coherence factor: " << ssaoTempCohFactor << endl;
|
---|
[3212] | 486 | cout << "sample intensity: " << ssaoSampleIntensity << endl;
|
---|
| 487 | cout << "kernel radius: " << ssaoKernelRadius << endl;
|
---|
[3251] | 488 | cout << "use ssao full resolution: " << ssaoUseFullResolution << endl;
|
---|
[3220] | 489 | cout << "recorded frames suffix: " << recordedFramesSuffix << endl;
|
---|
[3223] | 490 | cout << "stats filename: " << statsFilename << endl;
|
---|
[3251] | 491 | cout << "static scene filename prefix: " << filename << endl;
|
---|
| 492 | cout << "use PVSs: " << usePvs << endl;
|
---|
| 493 | cout << "visibility solution: " << visibilitySolution << endl;
|
---|
| 494 | cout << "use skylight for illumination: " << useSkylightForIllum << endl;
|
---|
[2873] | 495 |
|
---|
[2846] | 496 | //cout << "model path: " << model_path << endl;
|
---|
[2881] | 497 | cout << "**** end parameters ****" << endl << endl;
|
---|
[2837] | 498 | }
|
---|
[2829] | 499 |
|
---|
[2828] | 500 | ///////////////////////////
|
---|
| 501 |
|
---|
[3062] | 502 | camera = new PerspectiveCamera(winWidth / winHeight, fov);
|
---|
[2795] | 503 | camera->SetNear(nearDist);
|
---|
[2913] | 504 | camera->SetFar(1000);
|
---|
[2888] | 505 |
|
---|
[2838] | 506 | camera->SetDirection(camDir);
|
---|
[2829] | 507 | camera->SetPosition(camPos);
|
---|
| 508 |
|
---|
[3062] | 509 | visCamera = new PerspectiveCamera(winWidth / winHeight, fov);
|
---|
[2796] | 510 | visCamera->SetNear(0.0f);
|
---|
| 511 | visCamera->Yaw(.5 * M_PI);
|
---|
[2781] | 512 |
|
---|
[2952] | 513 | // create a new light
|
---|
[2968] | 514 | light = new DirectionalLight(lightDir, RgbaColor(1, 1, 1, 1), RgbaColor(1, 1, 1, 1));
|
---|
[3061] | 515 | // the render queue for material sorting
|
---|
[3101] | 516 | renderQueue = new RenderQueue(&renderState);
|
---|
[2952] | 517 |
|
---|
[2760] | 518 | glutInitWindowSize(winWidth, winHeight);
|
---|
[2756] | 519 | glutInit(&argc, argv);
|
---|
[2853] | 520 | glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
|
---|
| 521 | //glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
|
---|
[2850] | 522 | //glutInitDisplayString("samples=2");
|
---|
| 523 |
|
---|
[2867] | 524 | SceneEntity::SetUseLODs(useLODs);
|
---|
| 525 |
|
---|
[2828] | 526 | if (!useFullScreen)
|
---|
[2856] | 527 | {
|
---|
[2828] | 528 | glutCreateWindow("FriendlyCulling");
|
---|
[2856] | 529 | }
|
---|
[2828] | 530 | else
|
---|
| 531 | {
|
---|
| 532 | glutGameModeString( "1024x768:32@75" );
|
---|
| 533 | glutEnterGameMode();
|
---|
| 534 | }
|
---|
| 535 |
|
---|
[3059] | 536 | glutDisplayFunc(MainLoop);
|
---|
[2792] | 537 | glutKeyboardFunc(KeyBoard);
|
---|
| 538 | glutSpecialFunc(Special);
|
---|
| 539 | glutReshapeFunc(Reshape);
|
---|
| 540 | glutMouseFunc(Mouse);
|
---|
[3059] | 541 | glutIdleFunc(MainLoop);
|
---|
[2792] | 542 | glutKeyboardUpFunc(KeyUp);
|
---|
| 543 | glutSpecialUpFunc(SpecialKeyUp);
|
---|
| 544 | glutIgnoreKeyRepeat(true);
|
---|
| 545 |
|
---|
[2829] | 546 | // initialise gl graphics
|
---|
[2756] | 547 | InitExtensions();
|
---|
| 548 | InitGLstate();
|
---|
[2850] | 549 |
|
---|
[2854] | 550 | glEnable(GL_MULTISAMPLE_ARB);
|
---|
| 551 | glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
|
---|
[2850] | 552 |
|
---|
[2792] | 553 | LeftMotion(0, 0);
|
---|
| 554 | MiddleMotion(0, 0);
|
---|
[2756] | 555 |
|
---|
[2829] | 556 | perfGraph = new PerformanceGraph(1000);
|
---|
[2756] | 557 |
|
---|
[3059] | 558 | resourceManager = ResourceManager::GetSingleton();
|
---|
[3057] | 559 | shaderManager = ShaderManager::GetSingleton();
|
---|
[2793] | 560 |
|
---|
[3220] | 561 |
|
---|
[3059] | 562 | ///////////
|
---|
| 563 | //-- load the static scene geometry
|
---|
[2756] | 564 |
|
---|
[3238] | 565 | LoadModel(filename + ".dem", sceneEntities);
|
---|
[3059] | 566 |
|
---|
[3074] | 567 |
|
---|
[3072] | 568 | //////////
|
---|
| 569 | //-- load some dynamic stuff
|
---|
[3059] | 570 |
|
---|
[3203] | 571 | //resourceManager->mUseNormalMapping = true;
|
---|
[3193] | 572 | //resourceManager->mUseNormalMapping = false;
|
---|
[3127] | 573 |
|
---|
[3226] | 574 | resourceManager->mUseSpecialColors = true;
|
---|
| 575 |
|
---|
[3203] | 576 | //LoadModel("fisch.dem", dynamicObjects);
|
---|
[3235] | 577 |
|
---|
[3146] | 578 | //LoadModel("venusm.dem", dynamicObjects);
|
---|
[3153] | 579 | //LoadModel("camel.dem", dynamicObjects);
|
---|
[3146] | 580 | //LoadModel("toyplane2.dem", dynamicObjects);
|
---|
[3151] | 581 | //LoadModel("elephal.dem", dynamicObjects);
|
---|
[3249] | 582 | //LoadModel("sibenik.dem", dynamicObjects);
|
---|
[3128] | 583 |
|
---|
[3250] | 584 | #if 0
|
---|
[3247] | 585 | LoadModel("hbuddha.dem", dynamicObjects);
|
---|
[3128] | 586 |
|
---|
[3072] | 587 | buddha = dynamicObjects.back();
|
---|
| 588 |
|
---|
[3194] | 589 | const Vector3 sceneCenter(470.398f, 240.364f, 181.7f);
|
---|
| 590 | //const Vector3 sceneCenter(470.398f, 240.364f, 180.3);
|
---|
[3089] | 591 |
|
---|
[3072] | 592 | Matrix4x4 transl = TranslationMatrix(sceneCenter);
|
---|
| 593 | buddha->GetTransform()->SetMatrix(transl);
|
---|
| 594 |
|
---|
[3075] | 595 | for (int i = 0; i < 10; ++ i)
|
---|
[3072] | 596 | {
|
---|
| 597 | SceneEntity *ent = new SceneEntity(*buddha);
|
---|
| 598 | resourceManager->AddSceneEntity(ent);
|
---|
| 599 |
|
---|
| 600 | Vector3 offs = Vector3::ZERO();
|
---|
| 601 |
|
---|
[3074] | 602 | offs.x = RandomValue(.0f, 50.0f);
|
---|
| 603 | offs.y = RandomValue(.0f, 50.0f);
|
---|
[3072] | 604 |
|
---|
[3120] | 605 | Vector3 newPos = sceneCenter + offs;
|
---|
| 606 |
|
---|
| 607 | transl = TranslationMatrix(newPos);
|
---|
[3072] | 608 | Transform3 *transform = resourceManager->CreateTransform(transl);
|
---|
| 609 |
|
---|
| 610 | ent->SetTransform(transform);
|
---|
| 611 | dynamicObjects.push_back(ent);
|
---|
[3125] | 612 | }
|
---|
[3247] | 613 | #endif
|
---|
[3072] | 614 |
|
---|
[3247] | 615 |
|
---|
| 616 | resourceManager->mUseNormalMapping = false;
|
---|
| 617 | resourceManager->mUseSpecialColors = false;
|
---|
| 618 |
|
---|
| 619 |
|
---|
[3059] | 620 | ///////////
|
---|
| 621 | //-- load the associated static bvh
|
---|
| 622 |
|
---|
[3238] | 623 | const string bvh_filename = string(model_path + filename + ".bvh");
|
---|
[3072] | 624 |
|
---|
[2961] | 625 | BvhLoader bvhLoader;
|
---|
[3123] | 626 | bvh = bvhLoader.Load(bvh_filename, sceneEntities, dynamicObjects, maxDepthForTestingChildren);
|
---|
[2795] | 627 |
|
---|
[2961] | 628 | if (!bvh)
|
---|
[2795] | 629 | {
|
---|
[2961] | 630 | cerr << "loading bvh " << bvh_filename << " failed" << endl;
|
---|
[2795] | 631 | CleanUp();
|
---|
| 632 | exit(0);
|
---|
| 633 | }
|
---|
| 634 |
|
---|
[3059] | 635 | /// set the depth of the bvh depending on the triangles per leaf node
|
---|
| 636 | bvh->SetVirtualLeaves(trianglesPerVirtualLeaf);
|
---|
| 637 |
|
---|
[2963] | 638 | // set far plane based on scene extent
|
---|
| 639 | farDist = 10.0f * Magnitude(bvh->GetBox().Diagonal());
|
---|
[3059] | 640 | camera->SetFar(farDist);
|
---|
[2963] | 641 |
|
---|
[2961] | 642 |
|
---|
[3059] | 643 | //////////////////
|
---|
| 644 | //-- setup the skydome model
|
---|
[2964] | 645 |
|
---|
[3070] | 646 | LoadModel("sky.dem", sceneEntities);
|
---|
[3019] | 647 | skyDome = sceneEntities.back();
|
---|
[2861] | 648 |
|
---|
[3059] | 649 | /// the turbitity of the sky (from clear to hazy, use <3 for clear sky)
|
---|
[3193] | 650 | preetham = new SkyPreetham(turbitity, skyDome);
|
---|
[2961] | 651 |
|
---|
[3118] | 652 | CreateAnimation();
|
---|
[3059] | 653 |
|
---|
[3219] | 654 |
|
---|
[3214] | 655 | //////////////////////////
|
---|
[3219] | 656 | //-- a bounding box representing the sun pos in order to test visibility
|
---|
| 657 |
|
---|
[3214] | 658 | Transform3 *trafo = resourceManager->CreateTransform(IdentityMatrix());
|
---|
[3078] | 659 |
|
---|
[3214] | 660 | // make it slightly bigger to simulate sun diameter
|
---|
| 661 | const float size = 25.0f;
|
---|
| 662 | AxisAlignedBox3 sbox(Vector3(-size), Vector3(size));
|
---|
| 663 |
|
---|
| 664 | SceneEntityConverter conv;
|
---|
| 665 |
|
---|
[3245] | 666 |
|
---|
| 667 | //////////////////
|
---|
| 668 | //-- occlusion query for sun
|
---|
| 669 |
|
---|
| 670 | // todo: clean up material
|
---|
[3215] | 671 | Material *mat = resourceManager->CreateMaterial();
|
---|
[3214] | 672 |
|
---|
| 673 | mat->GetTechnique(0)->SetDepthWriteEnabled(false);
|
---|
| 674 | mat->GetTechnique(0)->SetColorWriteEnabled(false);
|
---|
| 675 |
|
---|
| 676 | sunBox = conv.ConvertBox(sbox, mat, trafo);
|
---|
[3215] | 677 | resourceManager->AddSceneEntity(sunBox);
|
---|
| 678 |
|
---|
| 679 | /// create single occlusion query that handles sun visibility
|
---|
[3214] | 680 | glGenQueriesARB(1, &sunQuery);
|
---|
| 681 |
|
---|
| 682 |
|
---|
[3059] | 683 | //////////
|
---|
| 684 | //-- initialize the traversal algorithm
|
---|
| 685 |
|
---|
[2897] | 686 | traverser = CreateTraverser(camera);
|
---|
[3059] | 687 |
|
---|
| 688 | // the bird-eye visualization
|
---|
[3101] | 689 | visualization = new Visualization(bvh, camera, NULL, &renderState);
|
---|
[3054] | 690 |
|
---|
[3059] | 691 | // this function assign the render queue bucket ids of the materials in beforehand
|
---|
[3227] | 692 | // => probably less overhead for new parts of the scene that are not yet assigned
|
---|
[3059] | 693 | PrepareRenderQueue();
|
---|
| 694 | /// forward rendering is the default
|
---|
[3101] | 695 | renderState.SetRenderTechnique(FORWARD);
|
---|
[2847] | 696 | // frame time is restarted every frame
|
---|
| 697 | frameTimer.Start();
|
---|
[3059] | 698 |
|
---|
[3238] | 699 | //Halton::TestHalton(7, 2);
|
---|
| 700 | //HaltonSequence::TestHalton(15, 2);
|
---|
| 701 | //Halton::TestPrime();
|
---|
[3227] | 702 |
|
---|
[2857] | 703 | // the rendering loop
|
---|
[2642] | 704 | glutMainLoop();
|
---|
[3059] | 705 |
|
---|
[2642] | 706 | // clean up
|
---|
[2756] | 707 | CleanUp();
|
---|
[3019] | 708 |
|
---|
[2642] | 709 | return 0;
|
---|
| 710 | }
|
---|
| 711 |
|
---|
[2756] | 712 |
|
---|
[2809] | 713 | void InitFBO()
|
---|
[2810] | 714 | {
|
---|
[2949] | 715 | PrintGLerror("fbo start");
|
---|
[2980] | 716 |
|
---|
[2857] | 717 | // this fbo basicly stores the scene information we get from standard rendering of a frame
|
---|
[3066] | 718 | // we store diffuse colors, eye space depth and normals
|
---|
[2884] | 719 | fbo = new FrameBufferObject(texWidth, texHeight, FrameBufferObject::DEPTH_32);
|
---|
[2857] | 720 |
|
---|
[2859] | 721 | // the diffuse color buffer
|
---|
[3015] | 722 | fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST);
|
---|
[3009] | 723 | // the normals buffer
|
---|
[3197] | 724 | //fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
|
---|
| 725 | fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
|
---|
[3066] | 726 | // a rgb buffer which could hold material properties
|
---|
[3113] | 727 | //fbo->AddColorBuffer(ColorBufferObject::RGB_UBYTE, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_NEAREST);
|
---|
[3117] | 728 | // buffer holding the difference vector to the old frame
|
---|
[3167] | 729 | fbo->AddColorBuffer(ColorBufferObject::RGB_FLOAT_16, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR);
|
---|
[2879] | 730 | // another color buffer
|
---|
[3015] | 731 | fbo->AddColorBuffer(ColorBufferObject::RGBA_FLOAT_32, ColorBufferObject::WRAP_CLAMP_TO_EDGE, ColorBufferObject::FILTER_LINEAR, ColorBufferObject::FILTER_NEAREST);
|
---|
[2879] | 732 |
|
---|
[3117] | 733 | for (int i = 0; i < 4; ++ i)
|
---|
[3219] | 734 | {
|
---|
[3117] | 735 | FrameBufferObject::InitBuffer(fbo, i);
|
---|
[3219] | 736 | }
|
---|
| 737 |
|
---|
[3117] | 738 | PrintGLerror("init fbo");
|
---|
[2809] | 739 | }
|
---|
| 740 |
|
---|
| 741 |
|
---|
[2827] | 742 | bool InitFont(void)
|
---|
[2642] | 743 | {
|
---|
[2826] | 744 | glEnable(GL_TEXTURE_2D);
|
---|
| 745 |
|
---|
| 746 | glGenTextures(1, &fontTex);
|
---|
| 747 | glBindTexture(GL_TEXTURE_2D, fontTex);
|
---|
[3019] | 748 |
|
---|
[2829] | 749 | if (!myfont.Create("data/fonts/verdana.glf", fontTex))
|
---|
[2826] | 750 | return false;
|
---|
| 751 |
|
---|
| 752 | glDisable(GL_TEXTURE_2D);
|
---|
[2827] | 753 |
|
---|
[2826] | 754 | return true;
|
---|
| 755 | }
|
---|
| 756 |
|
---|
| 757 |
|
---|
| 758 | void InitGLstate()
|
---|
| 759 | {
|
---|
[3246] | 760 | glClearColor(0.4f, 0.4f, 0.4f, 1e20f);
|
---|
[2642] | 761 |
|
---|
| 762 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
---|
| 763 | glPixelStorei(GL_PACK_ALIGNMENT,1);
|
---|
| 764 |
|
---|
| 765 | glDepthFunc(GL_LESS);
|
---|
[2762] | 766 | glEnable(GL_DEPTH_TEST);
|
---|
[2642] | 767 |
|
---|
[2760] | 768 | glColor3f(1.0f, 1.0f, 1.0f);
|
---|
[2642] | 769 | glShadeModel(GL_SMOOTH);
|
---|
| 770 |
|
---|
| 771 | glMaterialf(GL_FRONT, GL_SHININESS, 64);
|
---|
| 772 | glEnable(GL_NORMALIZE);
|
---|
[2767] | 773 |
|
---|
| 774 | glDisable(GL_ALPHA_TEST);
|
---|
[2951] | 775 | glAlphaFunc(GL_GEQUAL, 0.5f);
|
---|
[2767] | 776 |
|
---|
[2642] | 777 | glFrontFace(GL_CCW);
|
---|
| 778 | glCullFace(GL_BACK);
|
---|
[2851] | 779 | glEnable(GL_CULL_FACE);
|
---|
| 780 |
|
---|
[2800] | 781 | glDisable(GL_TEXTURE_2D);
|
---|
[2762] | 782 |
|
---|
[2959] | 783 | GLfloat ambientColor[] = {0.2, 0.2, 0.2, 1.0};
|
---|
[2756] | 784 | GLfloat diffuseColor[] = {1.0, 0.0, 0.0, 1.0};
|
---|
[2759] | 785 | GLfloat specularColor[] = {0.0, 0.0, 0.0, 1.0};
|
---|
[2642] | 786 |
|
---|
[2756] | 787 | glMaterialfv(GL_FRONT, GL_AMBIENT, ambientColor);
|
---|
| 788 | glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
|
---|
| 789 | glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
|
---|
[2801] | 790 |
|
---|
| 791 | glDepthFunc(GL_LESS);
|
---|
[2826] | 792 |
|
---|
[2827] | 793 | if (!InitFont())
|
---|
[2826] | 794 | cerr << "font creation failed" << endl;
|
---|
| 795 | else
|
---|
| 796 | cout << "successfully created font" << endl;
|
---|
[2953] | 797 |
|
---|
| 798 |
|
---|
[2954] | 799 | //////////////////////////////
|
---|
| 800 |
|
---|
[2959] | 801 | //GLfloat lmodel_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
---|
| 802 | GLfloat lmodel_ambient[] = {0.7f, 0.7f, 0.8f, 1.0f};
|
---|
[2954] | 803 |
|
---|
| 804 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
---|
[2959] | 805 | //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
|
---|
| 806 | glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
|
---|
[2954] | 807 | glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL_EXT, GL_SINGLE_COLOR_EXT);
|
---|
[2642] | 808 | }
|
---|
| 809 |
|
---|
| 810 |
|
---|
[2827] | 811 | void DrawHelpMessage()
|
---|
[2826] | 812 | {
|
---|
[2642] | 813 | const char *message[] =
|
---|
| 814 | {
|
---|
| 815 | "Help information",
|
---|
| 816 | "",
|
---|
| 817 | "'F1' - shows/dismisses this message",
|
---|
[2795] | 818 | "'F2' - shows/hides bird eye view",
|
---|
[2790] | 819 | "'F3' - shows/hides bounds (boxes or tight bounds)",
|
---|
[2827] | 820 | "'F4', - shows/hides parameters",
|
---|
| 821 | "'F5' - shows/hides statistics",
|
---|
| 822 | "'F6', - toggles between fly/walkmode",
|
---|
[2826] | 823 | "'F7', - cycles throw render modes",
|
---|
| 824 | "'F8', - enables/disables ambient occlusion (only deferred)",
|
---|
| 825 | "'F9', - shows pure algorithm render time (using glFinish)",
|
---|
[2790] | 826 | "'SPACE' - cycles through occlusion culling algorithms",
|
---|
[2642] | 827 | "",
|
---|
[2827] | 828 | "'MOUSE LEFT' - turn left/right, move forward/backward",
|
---|
| 829 | "'MOUSE RIGHT' - turn left/right, move forward/backward",
|
---|
| 830 | "'MOUSE MIDDLE' - move up/down, left/right",
|
---|
| 831 | "'CURSOR UP/DOWN' - move forward/backward",
|
---|
| 832 | "'CURSOR LEFT/RIGHT' - turn left/right",
|
---|
[2642] | 833 | "",
|
---|
[2827] | 834 | "'-'/'+' - decreases/increases max batch size",
|
---|
[2837] | 835 | "'1'/'2' - downward/upward motion",
|
---|
| 836 | "'3'/'4' - decreases/increases triangles per virtual bvh leaf (sets bvh depth)",
|
---|
| 837 | "'5'/'6' - decreases/increases assumed visible frames",
|
---|
[2776] | 838 | "",
|
---|
[2786] | 839 | "'R' - use render queue",
|
---|
[2790] | 840 | "'B' - use tight bounds",
|
---|
| 841 | "'M' - use multiqueries",
|
---|
[2792] | 842 | "'O' - use CHC optimization (geometry queries for leaves)",
|
---|
[2642] | 843 | 0,
|
---|
| 844 | };
|
---|
| 845 |
|
---|
[2756] | 846 |
|
---|
[2827] | 847 | glColor4f(0.0f, 1.0f , 0.0f, 0.2f); // 20% green.
|
---|
[2756] | 848 |
|
---|
[2827] | 849 | glRecti(30, 30, winWidth - 30, winHeight - 30);
|
---|
[2642] | 850 |
|
---|
[2827] | 851 | glEnd();
|
---|
| 852 |
|
---|
[2756] | 853 | glColor3f(1.0f, 1.0f, 1.0f);
|
---|
| 854 |
|
---|
[2829] | 855 | glEnable(GL_TEXTURE_2D);
|
---|
[2827] | 856 | myfont.Begin();
|
---|
| 857 |
|
---|
| 858 | int x = 40, y = 30;
|
---|
| 859 |
|
---|
| 860 | for(int i = 0; message[i] != 0; ++ i)
|
---|
[2756] | 861 | {
|
---|
| 862 | if(message[i][0] == '\0')
|
---|
| 863 | {
|
---|
[2786] | 864 | y += 15;
|
---|
[2756] | 865 | }
|
---|
| 866 | else
|
---|
| 867 | {
|
---|
[2827] | 868 | myfont.DrawString(message[i], x, winHeight - y);
|
---|
| 869 | y += 25;
|
---|
[2642] | 870 | }
|
---|
| 871 | }
|
---|
[2829] | 872 | glDisable(GL_TEXTURE_2D);
|
---|
[2642] | 873 | }
|
---|
| 874 |
|
---|
| 875 |
|
---|
[3062] | 876 | RenderTraverser *CreateTraverser(PerspectiveCamera *cam)
|
---|
[2764] | 877 | {
|
---|
[2897] | 878 | RenderTraverser *tr;
|
---|
| 879 |
|
---|
[2764] | 880 | switch (renderMode)
|
---|
| 881 | {
|
---|
| 882 | case RenderTraverser::CULL_FRUSTUM:
|
---|
[2897] | 883 | tr = new FrustumCullingTraverser();
|
---|
[2764] | 884 | break;
|
---|
| 885 | case RenderTraverser::STOP_AND_WAIT:
|
---|
[2897] | 886 | tr = new StopAndWaitTraverser();
|
---|
[2764] | 887 | break;
|
---|
| 888 | case RenderTraverser::CHC:
|
---|
[2897] | 889 | tr = new CHCTraverser();
|
---|
[2764] | 890 | break;
|
---|
[2767] | 891 | case RenderTraverser::CHCPLUSPLUS:
|
---|
[2897] | 892 | tr = new CHCPlusPlusTraverser();
|
---|
[2767] | 893 | break;
|
---|
| 894 |
|
---|
[2764] | 895 | default:
|
---|
[2897] | 896 | tr = new FrustumCullingTraverser();
|
---|
[2764] | 897 | }
|
---|
| 898 |
|
---|
[2897] | 899 | tr->SetCamera(cam);
|
---|
| 900 | tr->SetHierarchy(bvh);
|
---|
| 901 | tr->SetRenderQueue(renderQueue);
|
---|
[3101] | 902 | tr->SetRenderState(&renderState);
|
---|
[2897] | 903 | tr->SetUseOptimization(useOptimization);
|
---|
| 904 | tr->SetUseRenderQueue(useRenderQueue);
|
---|
| 905 | tr->SetVisibilityThreshold(threshold);
|
---|
| 906 | tr->SetAssumedVisibleFrames(assumedVisibleFrames);
|
---|
| 907 | tr->SetMaxBatchSize(maxBatchSize);
|
---|
| 908 | tr->SetUseMultiQueries(useMultiQueries);
|
---|
| 909 | tr->SetUseTightBounds(useTightBounds);
|
---|
[2955] | 910 | tr->SetUseDepthPass((renderMethod == RENDER_DEPTH_PASS) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED));
|
---|
[2897] | 911 | tr->SetRenderQueue(renderQueue);
|
---|
[3066] | 912 | tr->SetShowBounds(showBoundingVolumes);
|
---|
[2897] | 913 |
|
---|
[3066] | 914 | bvh->ResetNodeClassifications();
|
---|
| 915 |
|
---|
| 916 |
|
---|
[2897] | 917 | return tr;
|
---|
[2764] | 918 | }
|
---|
| 919 |
|
---|
[3059] | 920 | /** Setup sunlight
|
---|
| 921 | */
|
---|
[2759] | 922 | void SetupLighting()
|
---|
[2642] | 923 | {
|
---|
[2759] | 924 | glEnable(GL_LIGHT0);
|
---|
[2959] | 925 | glDisable(GL_LIGHT1);
|
---|
[2825] | 926 |
|
---|
[2954] | 927 | Vector3 lightDir = -light->GetDirection();
|
---|
| 928 |
|
---|
| 929 |
|
---|
[2945] | 930 | ///////////
|
---|
| 931 | //-- first light: sunlight
|
---|
| 932 |
|
---|
[2954] | 933 | GLfloat ambient[] = {0.25f, 0.25f, 0.3f, 1.0f};
|
---|
| 934 | GLfloat diffuse[] = {1.0f, 0.95f, 0.85f, 1.0f};
|
---|
| 935 | GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
---|
[2982] | 936 |
|
---|
[2759] | 937 |
|
---|
[3175] | 938 | const bool useHDRValues =
|
---|
[3046] | 939 | ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) ||
|
---|
| 940 | (renderMethod == RENDER_DEFERRED)) && useHDR;
|
---|
[2982] | 941 |
|
---|
[3046] | 942 |
|
---|
[2954] | 943 | Vector3 sunAmbient;
|
---|
| 944 | Vector3 sunDiffuse;
|
---|
[2759] | 945 |
|
---|
[3247] | 946 | if (useSkylightForIllum)
|
---|
| 947 | {
|
---|
| 948 | preetham->ComputeSunColor(lightDir, sunAmbient, sunDiffuse, !useHDRValues);
|
---|
[2945] | 949 |
|
---|
[3247] | 950 | ambient[0] = sunAmbient.x;
|
---|
| 951 | ambient[1] = sunAmbient.y;
|
---|
| 952 | ambient[2] = sunAmbient.z;
|
---|
[2825] | 953 |
|
---|
[3247] | 954 | diffuse[0] = sunDiffuse.x;
|
---|
| 955 | diffuse[1] = sunDiffuse.y;
|
---|
| 956 | diffuse[2] = sunDiffuse.z;
|
---|
| 957 | }
|
---|
| 958 | else
|
---|
| 959 | {
|
---|
[2945] | 960 |
|
---|
[3247] | 961 | ambient[0] = .2f;
|
---|
| 962 | ambient[1] = .2f;
|
---|
| 963 | ambient[2] = .2f;
|
---|
[3077] | 964 |
|
---|
[3247] | 965 | diffuse[0] = 1.0f;
|
---|
| 966 | diffuse[1] = 1.0f;
|
---|
| 967 | diffuse[2] = 1.0f;
|
---|
| 968 | }
|
---|
[3193] | 969 |
|
---|
[2954] | 970 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
---|
| 971 | glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
---|
| 972 | glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
|
---|
[2825] | 973 |
|
---|
[2954] | 974 | GLfloat position[] = {lightDir.x, lightDir.y, lightDir.z, 0.0f};
|
---|
| 975 | glLightfv(GL_LIGHT0, GL_POSITION, position);
|
---|
[2642] | 976 | }
|
---|
| 977 |
|
---|
[2800] | 978 |
|
---|
[2795] | 979 | void SetupEyeView()
|
---|
[2642] | 980 | {
|
---|
[2861] | 981 | // store matrix of last frame
|
---|
[3005] | 982 | oldViewProjMat = viewProjMat;
|
---|
[2834] | 983 |
|
---|
[3061] | 984 | camera->SetupViewProjection();
|
---|
[2759] | 985 |
|
---|
[3061] | 986 |
|
---|
[2864] | 987 | /////////////////
|
---|
[3059] | 988 | //-- compute view projection matrix and store for later use
|
---|
[2864] | 989 |
|
---|
[2894] | 990 | Matrix4x4 matViewing, matProjection;
|
---|
[2864] | 991 |
|
---|
[2834] | 992 | camera->GetModelViewMatrix(matViewing);
|
---|
| 993 | camera->GetProjectionMatrix(matProjection);
|
---|
| 994 |
|
---|
[3005] | 995 | viewProjMat = matViewing * matProjection;
|
---|
[2642] | 996 | }
|
---|
| 997 |
|
---|
| 998 |
|
---|
[2792] | 999 | void KeyHorizontalMotion(float shift)
|
---|
| 1000 | {
|
---|
[2888] | 1001 | Vector3 hvec = -camera->GetDirection();
|
---|
[2792] | 1002 | hvec.z = 0;
|
---|
| 1003 |
|
---|
| 1004 | Vector3 pos = camera->GetPosition();
|
---|
| 1005 | pos += hvec * shift;
|
---|
| 1006 |
|
---|
| 1007 | camera->SetPosition(pos);
|
---|
| 1008 | }
|
---|
| 1009 |
|
---|
| 1010 |
|
---|
[2794] | 1011 | void KeyVerticalMotion(float shift)
|
---|
| 1012 | {
|
---|
| 1013 | Vector3 uvec = Vector3(0, 0, shift);
|
---|
| 1014 |
|
---|
| 1015 | Vector3 pos = camera->GetPosition();
|
---|
| 1016 | pos += uvec;
|
---|
| 1017 |
|
---|
| 1018 | camera->SetPosition(pos);
|
---|
| 1019 | }
|
---|
| 1020 |
|
---|
| 1021 |
|
---|
[3105] | 1022 | void KeyStrafe(float shift)
|
---|
| 1023 | {
|
---|
| 1024 | Vector3 viewDir = camera->GetDirection();
|
---|
| 1025 | Vector3 pos = camera->GetPosition();
|
---|
| 1026 |
|
---|
| 1027 | // the 90 degree rotated view vector
|
---|
| 1028 | // z zero so we don't move in the vertical
|
---|
| 1029 | Vector3 rVec(viewDir[0], viewDir[1], 0);
|
---|
| 1030 |
|
---|
| 1031 | Matrix4x4 rot = RotationZMatrix(M_PI * 0.5f);
|
---|
| 1032 | rVec = rot * rVec;
|
---|
| 1033 | pos += rVec * shift;
|
---|
| 1034 |
|
---|
| 1035 | camera->SetPosition(pos);
|
---|
| 1036 | }
|
---|
| 1037 |
|
---|
| 1038 |
|
---|
[3059] | 1039 | /** Initialize the deferred rendering pass.
|
---|
| 1040 | */
|
---|
[2948] | 1041 | void InitDeferredRendering()
|
---|
| 1042 | {
|
---|
| 1043 | if (!fbo) InitFBO();
|
---|
| 1044 | fbo->Bind();
|
---|
| 1045 |
|
---|
| 1046 | // multisampling does not work with deferred shading
|
---|
| 1047 | glDisable(GL_MULTISAMPLE_ARB);
|
---|
[3101] | 1048 | renderState.SetRenderTechnique(DEFERRED);
|
---|
[2948] | 1049 |
|
---|
| 1050 |
|
---|
[3175] | 1051 | // draw to 3 render targets
|
---|
[3118] | 1052 | if (sCurrentMrtSet == 0)
|
---|
| 1053 | {
|
---|
| 1054 | DeferredRenderer::colorBufferIdx = 0;
|
---|
| 1055 | glDrawBuffers(3, mrt);
|
---|
| 1056 | }
|
---|
| 1057 | else
|
---|
| 1058 | {
|
---|
| 1059 | DeferredRenderer::colorBufferIdx = 3;
|
---|
| 1060 | glDrawBuffers(3, mrt2);
|
---|
| 1061 | }
|
---|
[2985] | 1062 |
|
---|
[2978] | 1063 | sCurrentMrtSet = 1 - sCurrentMrtSet;
|
---|
[2948] | 1064 | }
|
---|
| 1065 |
|
---|
| 1066 |
|
---|
[3059] | 1067 | /** the main rendering loop
|
---|
| 1068 | */
|
---|
| 1069 | void MainLoop()
|
---|
[2801] | 1070 | {
|
---|
[3246] | 1071 | if (buddha)
|
---|
[3120] | 1072 | {
|
---|
[3246] | 1073 | Matrix4x4 oldTrafo = buddha->GetTransform()->GetMatrix();
|
---|
| 1074 | Vector3 buddhaPos = motionPath->GetCurrentPosition();
|
---|
| 1075 | Matrix4x4 trafo = TranslationMatrix(buddhaPos);
|
---|
[3120] | 1076 |
|
---|
[3246] | 1077 | buddha->GetTransform()->SetMatrix(trafo);
|
---|
| 1078 |
|
---|
| 1079 | #if TODO // drop objects on ground floor
|
---|
| 1080 | for (int i = 0; i < 10; ++ i)
|
---|
[3120] | 1081 | {
|
---|
[3246] | 1082 | SceneEntity *ent = dynamicObjects[i];
|
---|
| 1083 | Vector3 newPos = ent->GetWorldCenter();
|
---|
| 1084 |
|
---|
| 1085 | if (GetOrCreateSceneQuery()->CalcIntersection(newPos))
|
---|
| 1086 | {
|
---|
| 1087 | Matrix4x4 mat = TranslationMatrix(newPos - ent->GetCenter());
|
---|
| 1088 | ent->GetTransform()->SetMatrix(mat);
|
---|
| 1089 | }
|
---|
[3120] | 1090 | }
|
---|
[3221] | 1091 | #endif
|
---|
[3120] | 1092 |
|
---|
[3247] | 1093 | /*
|
---|
[3246] | 1094 | /////////////////////////
|
---|
| 1095 | //-- update animations
|
---|
[3221] | 1096 |
|
---|
[3246] | 1097 | //const float rotAngle = M_PI * 1e-3f;
|
---|
| 1098 | const float rotAngle = 1.0f * M_PI / 180.0f;
|
---|
[3225] | 1099 |
|
---|
[3246] | 1100 | Matrix4x4 rotMatrix = RotationZMatrix(rotAngle);
|
---|
[3247] | 1101 | dynamicObjects[2]->GetTransform()->MultMatrix(rotMatrix);
|
---|
[3125] | 1102 |
|
---|
[3246] | 1103 | motionPath->Move(0.01f);
|
---|
[3247] | 1104 | */
|
---|
[3246] | 1105 | }
|
---|
[3125] | 1106 |
|
---|
[3113] | 1107 |
|
---|
[3111] | 1108 | /////////////
|
---|
[3078] | 1109 |
|
---|
[3219] | 1110 | static Vector3 oldPos = camera->GetPosition();
|
---|
| 1111 | static Vector3 oldDir = camera->GetDirection();
|
---|
[2800] | 1112 |
|
---|
[2792] | 1113 | if (leftKeyPressed)
|
---|
[2795] | 1114 | camera->Pitch(KeyRotationAngle());
|
---|
[2792] | 1115 | if (rightKeyPressed)
|
---|
[2795] | 1116 | camera->Pitch(-KeyRotationAngle());
|
---|
[2792] | 1117 | if (upKeyPressed)
|
---|
[2887] | 1118 | KeyHorizontalMotion(-KeyShift());
|
---|
| 1119 | if (downKeyPressed)
|
---|
[2795] | 1120 | KeyHorizontalMotion(KeyShift());
|
---|
[2837] | 1121 | if (ascendKeyPressed)
|
---|
| 1122 | KeyVerticalMotion(KeyShift());
|
---|
| 1123 | if (descendKeyPressed)
|
---|
[2795] | 1124 | KeyVerticalMotion(-KeyShift());
|
---|
[3105] | 1125 | if (leftStrafeKeyPressed)
|
---|
| 1126 | KeyStrafe(KeyShift());
|
---|
| 1127 | if (rightStrafeKeyPressed)
|
---|
| 1128 | KeyStrafe(-KeyShift());
|
---|
[2792] | 1129 |
|
---|
[3105] | 1130 |
|
---|
[2801] | 1131 | // place view on ground
|
---|
| 1132 | if (!flyMode) PlaceViewer(oldPos);
|
---|
[2800] | 1133 |
|
---|
[2826] | 1134 | if (showAlgorithmTime)
|
---|
| 1135 | {
|
---|
| 1136 | glFinish();
|
---|
| 1137 | algTimer.Start();
|
---|
| 1138 | }
|
---|
[2809] | 1139 |
|
---|
[3219] | 1140 | // don't allow replay on record
|
---|
| 1141 | if (replayPath && !recordPath)
|
---|
| 1142 | {
|
---|
| 1143 | if (!walkThroughPlayer)
|
---|
| 1144 | walkThroughPlayer = new WalkThroughPlayer("frames.log");
|
---|
| 1145 |
|
---|
| 1146 | ++ currentReplayFrame;
|
---|
[2895] | 1147 |
|
---|
[3223] | 1148 | // reset if end of walkthrough is reached
|
---|
[3219] | 1149 | if (!walkThroughPlayer->ReadNextFrame(camera))
|
---|
| 1150 | {
|
---|
| 1151 | currentReplayFrame = -1;
|
---|
| 1152 | replayPath = false;
|
---|
| 1153 | }
|
---|
| 1154 | }
|
---|
| 1155 |
|
---|
[2931] | 1156 | if ((!shadowMap || !shadowTraverser) && (showShadowMap || renderLightView))
|
---|
| 1157 | {
|
---|
| 1158 | if (!shadowMap)
|
---|
| 1159 | shadowMap = new ShadowMap(light, shadowSize, bvh->GetBox(), camera);
|
---|
| 1160 |
|
---|
| 1161 | if (!shadowTraverser)
|
---|
| 1162 | shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera());
|
---|
| 1163 |
|
---|
| 1164 | }
|
---|
[2951] | 1165 |
|
---|
| 1166 | // bring eye modelview matrix up-to-date
|
---|
| 1167 | SetupEyeView();
|
---|
[3219] | 1168 |
|
---|
[3059] | 1169 | // set frame related parameters for GPU programs
|
---|
[3046] | 1170 | GPUProgramParameters::InitFrame(camera, light);
|
---|
[3045] | 1171 |
|
---|
[3219] | 1172 | if (recordPath)
|
---|
| 1173 | {
|
---|
| 1174 | if (!walkThroughRecorder)
|
---|
| 1175 | walkThroughRecorder = new WalkThroughRecorder("frames.log");
|
---|
| 1176 |
|
---|
| 1177 | if ((Distance(oldPos, camera->GetPosition()) > 1e-6f) ||
|
---|
| 1178 | (DotProd(oldDir, camera->GetDirection()) < 1.0f - 1e-6f))
|
---|
| 1179 | {
|
---|
| 1180 | walkThroughRecorder->WriteFrame(camera);
|
---|
| 1181 | }
|
---|
| 1182 | }
|
---|
| 1183 |
|
---|
[3059] | 1184 | // hack: store current rendering method and restore later
|
---|
[2955] | 1185 | int oldRenderMethod = renderMethod;
|
---|
[3044] | 1186 | // for rendering the light view, we use forward rendering
|
---|
[3068] | 1187 | if (renderLightView) renderMethod = FORWARD;
|
---|
[2931] | 1188 |
|
---|
[3059] | 1189 | /// enable vbo vertex array
|
---|
[2953] | 1190 | glEnableClientState(GL_VERTEX_ARRAY);
|
---|
[2931] | 1191 |
|
---|
[3251] | 1192 | if (0 && usePvs)
|
---|
[3246] | 1193 | {
|
---|
| 1194 | if (!viewCellsTree) LoadVisibilitySolution();
|
---|
[3247] | 1195 | LoadPvs();
|
---|
[3246] | 1196 | }
|
---|
| 1197 |
|
---|
[2931] | 1198 | // render with the specified method (forward rendering, forward + depth, deferred)
|
---|
[2955] | 1199 | switch (renderMethod)
|
---|
[2825] | 1200 | {
|
---|
[3043] | 1201 | case RENDER_FORWARD:
|
---|
[2825] | 1202 |
|
---|
[2851] | 1203 | glEnable(GL_MULTISAMPLE_ARB);
|
---|
[3101] | 1204 | renderState.SetRenderTechnique(FORWARD);
|
---|
[3223] | 1205 |
|
---|
[2829] | 1206 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
[2953] | 1207 | glEnableClientState(GL_NORMAL_ARRAY);
|
---|
[2825] | 1208 | break;
|
---|
| 1209 |
|
---|
[2955] | 1210 | case RENDER_DEPTH_PASS_DEFERRED:
|
---|
[2948] | 1211 |
|
---|
[2950] | 1212 | glDisable(GL_MULTISAMPLE_ARB);
|
---|
[3101] | 1213 | renderState.SetUseAlphaToCoverage(false);
|
---|
| 1214 | renderState.SetRenderTechnique(DEPTH_PASS);
|
---|
[2949] | 1215 |
|
---|
[3175] | 1216 | if (!fbo) InitFBO();
|
---|
| 1217 | fbo->Bind();
|
---|
[3223] | 1218 | // render to single depth texture
|
---|
[2948] | 1219 | glDrawBuffers(1, mrt);
|
---|
[3223] | 1220 | // clear buffer once
|
---|
[2951] | 1221 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
[2948] | 1222 |
|
---|
[3068] | 1223 | // the scene is rendered withouth any shading
|
---|
[3101] | 1224 | // (should be handled by render renderState)
|
---|
[2948] | 1225 | glShadeModel(GL_FLAT);
|
---|
| 1226 | break;
|
---|
| 1227 |
|
---|
[2955] | 1228 | case RENDER_DEPTH_PASS:
|
---|
[2851] | 1229 |
|
---|
| 1230 | glEnable(GL_MULTISAMPLE_ARB);
|
---|
[3101] | 1231 | renderState.SetRenderTechnique(DEPTH_PASS);
|
---|
[2857] | 1232 |
|
---|
[3067] | 1233 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
| 1234 |
|
---|
[3068] | 1235 | // the scene is rendered withouth any shading
|
---|
[3101] | 1236 | // (should be handled by render renderState)
|
---|
[2943] | 1237 | glShadeModel(GL_FLAT);
|
---|
[2825] | 1238 | break;
|
---|
| 1239 |
|
---|
[3048] | 1240 | case RENDER_DEFERRED:
|
---|
[2851] | 1241 |
|
---|
[2948] | 1242 | if (showShadowMap && !renderLightView)
|
---|
[2951] | 1243 | RenderShadowMap(camera->GetFar());
|
---|
| 1244 |
|
---|
[2948] | 1245 | //glPushAttrib(GL_VIEWPORT_BIT);
|
---|
[2825] | 1246 | glViewport(0, 0, texWidth, texHeight);
|
---|
| 1247 |
|
---|
[2948] | 1248 | InitDeferredRendering();
|
---|
[2951] | 1249 |
|
---|
[2953] | 1250 | glEnableClientState(GL_NORMAL_ARRAY);
|
---|
[2954] | 1251 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
[2825] | 1252 | break;
|
---|
| 1253 | }
|
---|
| 1254 |
|
---|
[2801] | 1255 | glDepthFunc(GL_LESS);
|
---|
| 1256 | glDisable(GL_TEXTURE_2D);
|
---|
| 1257 | glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
---|
[2825] | 1258 |
|
---|
[2801] | 1259 |
|
---|
[3059] | 1260 | // set proper lod levels for current frame using current eye point
|
---|
[2847] | 1261 | LODLevel::InitFrame(camera->GetPosition());
|
---|
[3059] | 1262 | // set up sunlight
|
---|
[2954] | 1263 | SetupLighting();
|
---|
[2795] | 1264 |
|
---|
[2801] | 1265 |
|
---|
[2931] | 1266 | if (renderLightView)
|
---|
| 1267 | {
|
---|
[3101] | 1268 | // change CHC++ set of renderState variables:
|
---|
[3059] | 1269 | // must be done for each change of camera because otherwise
|
---|
| 1270 | // the temporal coherency is broken
|
---|
[3054] | 1271 | BvhNode::SetCurrentState(LIGHT_PASS);
|
---|
[3005] | 1272 | shadowMap->RenderShadowView(shadowTraverser, viewProjMat);
|
---|
[3054] | 1273 | BvhNode::SetCurrentState(CAMERA_PASS);
|
---|
[2931] | 1274 | }
|
---|
| 1275 | else
|
---|
[3079] | 1276 | {
|
---|
[3251] | 1277 | if (usePvs)
|
---|
| 1278 | {
|
---|
| 1279 | if (!viewCellsTree) LoadVisibilitySolution();
|
---|
| 1280 | LoadPvs();
|
---|
| 1281 | }
|
---|
| 1282 | else
|
---|
[2931] | 1283 | // actually render the scene geometry using the specified algorithm
|
---|
[3245] | 1284 | traverser->RenderScene();
|
---|
[2948] | 1285 | }
|
---|
[2892] | 1286 |
|
---|
[2931] | 1287 |
|
---|
[2825] | 1288 | /////////
|
---|
[2809] | 1289 | //-- do the rest of the rendering
|
---|
[2893] | 1290 |
|
---|
[3244] | 1291 | // return from depth pass and render visible objects
|
---|
[2955] | 1292 | if ((renderMethod == RENDER_DEPTH_PASS) ||
|
---|
| 1293 | (renderMethod == RENDER_DEPTH_PASS_DEFERRED))
|
---|
[2801] | 1294 | {
|
---|
| 1295 | RenderVisibleObjects();
|
---|
| 1296 | }
|
---|
| 1297 |
|
---|
[3215] | 1298 | const bool useDeferred =
|
---|
| 1299 | ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED));
|
---|
[3214] | 1300 |
|
---|
[3215] | 1301 | // if no lense flare => just set sun to invisible
|
---|
[3221] | 1302 | const int sunVisiblePixels = useLenseFlare && useDeferred ? TestSunVisible() : 0;
|
---|
[3214] | 1303 |
|
---|
[3246] | 1304 |
|
---|
[3215] | 1305 |
|
---|
[2796] | 1306 | ///////////////
|
---|
| 1307 | //-- render sky
|
---|
[2795] | 1308 |
|
---|
[2894] | 1309 | // q: should we render sky after deferred shading?
|
---|
| 1310 | // this would conveniently solves some issues (e.g, skys without shadows)
|
---|
[2893] | 1311 |
|
---|
[3051] | 1312 | RenderSky();
|
---|
[2801] | 1313 |
|
---|
[2961] | 1314 |
|
---|
[3221] | 1315 | //////////////////////////////
|
---|
| 1316 |
|
---|
[3215] | 1317 | if (useDeferred)
|
---|
[2825] | 1318 | {
|
---|
[2881] | 1319 | FrameBufferObject::Release();
|
---|
[2810] | 1320 |
|
---|
[3247] | 1321 | if (!deferredShader)
|
---|
| 1322 | {
|
---|
| 1323 | deferredShader =
|
---|
| 1324 | new DeferredRenderer(texWidth, texHeight, camera, ssaoUseFullResolution);
|
---|
| 1325 |
|
---|
| 1326 | deferredShader->SetKernelRadius(ssaoKernelRadius);
|
---|
| 1327 | deferredShader->SetSampleIntensity(ssaoSampleIntensity);
|
---|
| 1328 | deferredShader->SetSsaoFilterRadius(ssaoFilterRadius);
|
---|
| 1329 | }
|
---|
| 1330 |
|
---|
[2903] | 1331 | DeferredRenderer::SHADING_METHOD shadingMethod;
|
---|
| 1332 |
|
---|
| 1333 | if (useAdvancedShading)
|
---|
| 1334 | {
|
---|
| 1335 | if (useGlobIllum)
|
---|
| 1336 | shadingMethod = DeferredRenderer::GI;
|
---|
| 1337 | else
|
---|
| 1338 | shadingMethod = DeferredRenderer::SSAO;
|
---|
| 1339 | }
|
---|
| 1340 | else
|
---|
[3216] | 1341 | {
|
---|
[2903] | 1342 | shadingMethod = DeferredRenderer::DEFAULT;
|
---|
[3216] | 1343 | }
|
---|
[2903] | 1344 |
|
---|
[3225] | 1345 | static int snapShotIdx = 0;
|
---|
| 1346 |
|
---|
[3215] | 1347 | deferredShader->SetSunVisiblePixels(sunVisiblePixels);
|
---|
[3111] | 1348 | deferredShader->SetShadingMethod(shadingMethod);
|
---|
| 1349 | deferredShader->SetSamplingMethod(samplingMethod);
|
---|
[3247] | 1350 |
|
---|
[3111] | 1351 | deferredShader->SetUseTemporalCoherence(useTemporalCoherence);
|
---|
[3242] | 1352 | //deferredShader->SetSortSamples(sortSamples);
|
---|
| 1353 | deferredShader->SetTemporalCoherenceFactorForSsao(ssaoTempCohFactor);
|
---|
| 1354 | deferredShader->SetUseToneMapping(useHDR);
|
---|
| 1355 | deferredShader->SetUseAntiAliasing(useAntiAliasing);
|
---|
[2903] | 1356 |
|
---|
[3242] | 1357 |
|
---|
[3225] | 1358 | if (recordFrames && replayPath)
|
---|
| 1359 | deferredShader->SetSaveFrame(recordedFramesSuffix, currentReplayFrame);
|
---|
| 1360 | else if (makeSnapShot)
|
---|
| 1361 | deferredShader->SetSaveFrame("snap", snapShotIdx ++);
|
---|
| 1362 | else
|
---|
| 1363 | deferredShader->SetSaveFrame("", -1);
|
---|
| 1364 |
|
---|
[3226] | 1365 | //if (makeSnapShot) makeSnapShot = false;
|
---|
[3225] | 1366 |
|
---|
[2895] | 1367 | ShadowMap *sm = showShadowMap ? shadowMap : NULL;
|
---|
[3242] | 1368 | deferredShader->Render(fbo, light, sm);
|
---|
[2825] | 1369 | }
|
---|
[2827] | 1370 |
|
---|
[2893] | 1371 |
|
---|
[3101] | 1372 | renderState.SetRenderTechnique(FORWARD);
|
---|
| 1373 | renderState.Reset();
|
---|
[2827] | 1374 |
|
---|
[2893] | 1375 |
|
---|
| 1376 | glDisableClientState(GL_VERTEX_ARRAY);
|
---|
| 1377 | glDisableClientState(GL_NORMAL_ARRAY);
|
---|
[2931] | 1378 |
|
---|
[2955] | 1379 | renderMethod = oldRenderMethod;
|
---|
[2893] | 1380 |
|
---|
| 1381 |
|
---|
| 1382 | ///////////
|
---|
| 1383 |
|
---|
| 1384 |
|
---|
[2826] | 1385 | if (showAlgorithmTime)
|
---|
| 1386 | {
|
---|
| 1387 | glFinish();
|
---|
[2827] | 1388 |
|
---|
[2826] | 1389 | algTime = algTimer.Elapsedms();
|
---|
[2827] | 1390 | perfGraph->AddData(algTime);
|
---|
[2828] | 1391 |
|
---|
[2827] | 1392 | perfGraph->Draw();
|
---|
[2826] | 1393 | }
|
---|
[2827] | 1394 | else
|
---|
| 1395 | {
|
---|
| 1396 | if (visMode) DisplayVisualization();
|
---|
| 1397 | }
|
---|
[2825] | 1398 |
|
---|
[2884] | 1399 | glFlush();
|
---|
[2847] | 1400 |
|
---|
| 1401 | const bool restart = true;
|
---|
| 1402 | elapsedTime = frameTimer.Elapsedms(restart);
|
---|
| 1403 |
|
---|
[3223] | 1404 | // statistics
|
---|
[2764] | 1405 | DisplayStats();
|
---|
[2767] | 1406 |
|
---|
[2642] | 1407 | glutSwapBuffers();
|
---|
[3219] | 1408 |
|
---|
| 1409 | oldPos = camera->GetPosition();
|
---|
| 1410 | oldDir = camera->GetDirection();
|
---|
[2642] | 1411 | }
|
---|
| 1412 |
|
---|
| 1413 |
|
---|
[3219] | 1414 | #pragma warning(disable : 4100)
|
---|
[2792] | 1415 | void KeyBoard(unsigned char c, int x, int y)
|
---|
[2642] | 1416 | {
|
---|
| 1417 | switch(c)
|
---|
| 1418 | {
|
---|
| 1419 | case 27:
|
---|
[3212] | 1420 | // write out current position on exit
|
---|
[3134] | 1421 | Debug << "camPosition=" << camera->GetPosition().x << " " << camera->GetPosition().y << " " << camera->GetPosition().z << endl;
|
---|
| 1422 | Debug << "camDirection=" << camera->GetDirection().x << " " << camera->GetDirection().y << " " << camera->GetDirection().z << endl;
|
---|
| 1423 |
|
---|
[2792] | 1424 | CleanUp();
|
---|
[2642] | 1425 | exit(0);
|
---|
[2948] | 1426 | case 32: // space
|
---|
[2800] | 1427 | renderMode = (renderMode + 1) % RenderTraverser::NUM_TRAVERSAL_TYPES;
|
---|
[2897] | 1428 |
|
---|
| 1429 | DEL_PTR(traverser);
|
---|
| 1430 | traverser = CreateTraverser(camera);
|
---|
| 1431 |
|
---|
[2931] | 1432 | if (shadowTraverser)
|
---|
[2897] | 1433 | {
|
---|
[2948] | 1434 | // shadow traverser has to be recomputed
|
---|
[2897] | 1435 | DEL_PTR(shadowTraverser);
|
---|
[2948] | 1436 | shadowTraverser = CreateTraverser(shadowMap->GetShadowCamera());
|
---|
[2897] | 1437 | }
|
---|
| 1438 |
|
---|
[2642] | 1439 | break;
|
---|
| 1440 | case '+':
|
---|
[2867] | 1441 | if (maxBatchSize < 10)
|
---|
| 1442 | maxBatchSize = 10;
|
---|
| 1443 | else
|
---|
| 1444 | maxBatchSize += 10;
|
---|
| 1445 |
|
---|
[2776] | 1446 | traverser->SetMaxBatchSize(maxBatchSize);
|
---|
[2642] | 1447 | break;
|
---|
| 1448 | case '-':
|
---|
[2776] | 1449 | maxBatchSize -= 10;
|
---|
| 1450 | if (maxBatchSize < 0) maxBatchSize = 1;
|
---|
| 1451 | traverser->SetMaxBatchSize(maxBatchSize);
|
---|
[2642] | 1452 | break;
|
---|
[2837] | 1453 | case 'M':
|
---|
| 1454 | case 'm':
|
---|
| 1455 | useMultiQueries = !useMultiQueries;
|
---|
| 1456 | traverser->SetUseMultiQueries(useMultiQueries);
|
---|
| 1457 | break;
|
---|
| 1458 | case '1':
|
---|
| 1459 | descendKeyPressed = true;
|
---|
| 1460 | break;
|
---|
| 1461 | case '2':
|
---|
| 1462 | ascendKeyPressed = true;
|
---|
| 1463 | break;
|
---|
| 1464 | case '3':
|
---|
[3212] | 1465 | if (trianglesPerVirtualLeaf >= 100) trianglesPerVirtualLeaf -= 100;
|
---|
[2837] | 1466 | bvh->SetVirtualLeaves(trianglesPerVirtualLeaf);
|
---|
| 1467 | break;
|
---|
| 1468 | case '4':
|
---|
| 1469 | trianglesPerVirtualLeaf += 100;
|
---|
| 1470 | bvh->SetVirtualLeaves(trianglesPerVirtualLeaf);
|
---|
| 1471 | break;
|
---|
| 1472 | case '5':
|
---|
[2776] | 1473 | assumedVisibleFrames -= 1;
|
---|
| 1474 | if (assumedVisibleFrames < 1) assumedVisibleFrames = 1;
|
---|
| 1475 | traverser->SetAssumedVisibleFrames(assumedVisibleFrames);
|
---|
| 1476 | break;
|
---|
[2837] | 1477 | case '6':
|
---|
[2776] | 1478 | assumedVisibleFrames += 1;
|
---|
| 1479 | traverser->SetAssumedVisibleFrames(assumedVisibleFrames);
|
---|
| 1480 | break;
|
---|
[2837] | 1481 | case '7':
|
---|
[3227] | 1482 | ssaoTempCohFactor *= 1.0f / 1.2f;
|
---|
[3216] | 1483 | cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl;
|
---|
[2776] | 1484 | break;
|
---|
[2767] | 1485 | case '8':
|
---|
[3227] | 1486 | ssaoTempCohFactor *= 1.2f;
|
---|
[3216] | 1487 | cout << "new temporal coherence factor: " << ssaoTempCohFactor << endl;
|
---|
[2837] | 1488 | break;
|
---|
[3212] | 1489 | case '9':
|
---|
| 1490 | ssaoKernelRadius *= 0.8f;
|
---|
[3216] | 1491 | cout << "new ssao kernel radius: " << ssaoKernelRadius << endl;
|
---|
[3247] | 1492 | if (deferredShader) deferredShader->SetKernelRadius(ssaoKernelRadius);
|
---|
[3212] | 1493 | break;
|
---|
| 1494 | case '0':
|
---|
[3227] | 1495 | ssaoKernelRadius *= 1.0f / 0.8f;
|
---|
[3247] | 1496 | if (deferredShader) deferredShader->SetKernelRadius(ssaoKernelRadius);
|
---|
[3216] | 1497 | cout << "new ssao kernel radius: " << ssaoKernelRadius << endl;
|
---|
[3212] | 1498 | break;
|
---|
| 1499 | case 'n':
|
---|
| 1500 | ssaoSampleIntensity *= 0.9f;
|
---|
[3247] | 1501 | if (deferredShader) deferredShader->SetSampleIntensity(ssaoSampleIntensity);
|
---|
[3216] | 1502 | cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl;
|
---|
[3212] | 1503 | break;
|
---|
| 1504 | case 'N':
|
---|
[3227] | 1505 | ssaoSampleIntensity *= 1.0f / 0.9f;
|
---|
[3247] | 1506 | if (deferredShader) deferredShader->SetSampleIntensity(ssaoSampleIntensity);
|
---|
[3216] | 1507 | cout << "new ssao sample intensity: " << ssaoSampleIntensity << endl;
|
---|
[3212] | 1508 | break;
|
---|
[3216] | 1509 | case 'o':
|
---|
| 1510 | ssaoFilterRadius *= 0.9f;
|
---|
[3247] | 1511 | if (deferredShader) deferredShader->SetSsaoFilterRadius(ssaoFilterRadius);
|
---|
[3216] | 1512 | cout << "new ssao filter radius: " << ssaoFilterRadius << endl;
|
---|
| 1513 | break;
|
---|
| 1514 | case 'O':
|
---|
[3227] | 1515 | ssaoFilterRadius *= 1.0f / 0.9f;
|
---|
[3247] | 1516 | if (deferredShader) deferredShader->SetSsaoFilterRadius(ssaoFilterRadius);
|
---|
[3216] | 1517 | cout << "new ssao filter radius: " << ssaoFilterRadius << endl;
|
---|
| 1518 | break;
|
---|
[3219] | 1519 | /* case 'o':
|
---|
| 1520 | case 'O':
|
---|
| 1521 | useOptimization = !useOptimization;
|
---|
| 1522 | // chc optimization of using the objects instead of
|
---|
| 1523 | // the bounding boxes for querying previously visible nodes
|
---|
| 1524 | traverser->SetUseOptimization(useOptimization);
|
---|
| 1525 | break;*/
|
---|
[3175] | 1526 | case 'l':
|
---|
| 1527 | case 'L':
|
---|
[2865] | 1528 | useLODs = !useLODs;
|
---|
| 1529 | SceneEntity::SetUseLODs(useLODs);
|
---|
[3216] | 1530 | cout << "using LODs: " << useLODs << endl;
|
---|
[2865] | 1531 | break;
|
---|
[2887] | 1532 | case 'P':
|
---|
| 1533 | case 'p':
|
---|
[2930] | 1534 | samplingMethod = DeferredRenderer::SAMPLING_METHOD((samplingMethod + 1) % 3);
|
---|
| 1535 | cout << "ssao sampling method: " << samplingMethod << endl;
|
---|
[2887] | 1536 | break;
|
---|
[2895] | 1537 | case 'Y':
|
---|
| 1538 | case 'y':
|
---|
| 1539 | showShadowMap = !showShadowMap;
|
---|
| 1540 | break;
|
---|
[2875] | 1541 | case 'g':
|
---|
[2903] | 1542 | case 'G':
|
---|
| 1543 | useGlobIllum = !useGlobIllum;
|
---|
| 1544 | break;
|
---|
[2875] | 1545 | case 't':
|
---|
| 1546 | case 'T':
|
---|
| 1547 | useTemporalCoherence = !useTemporalCoherence;
|
---|
| 1548 | break;
|
---|
[2767] | 1549 | case 'a':
|
---|
| 1550 | case 'A':
|
---|
[2931] | 1551 | leftKeyPressed = true;
|
---|
[2767] | 1552 | break;
|
---|
| 1553 | case 'd':
|
---|
| 1554 | case 'D':
|
---|
[2931] | 1555 | rightKeyPressed = true;
|
---|
[2767] | 1556 | break;
|
---|
| 1557 | case 'w':
|
---|
| 1558 | case 'W':
|
---|
[2931] | 1559 | upKeyPressed = true;
|
---|
[2767] | 1560 | break;
|
---|
[2829] | 1561 | case 's':
|
---|
| 1562 | case 'S':
|
---|
[2931] | 1563 | downKeyPressed = true;
|
---|
[2767] | 1564 | break;
|
---|
[3105] | 1565 | case 'j':
|
---|
| 1566 | case 'J':
|
---|
| 1567 | leftStrafeKeyPressed = true;
|
---|
| 1568 | break;
|
---|
| 1569 | case 'k':
|
---|
| 1570 | case 'K':
|
---|
| 1571 | rightStrafeKeyPressed = true;
|
---|
| 1572 | break;
|
---|
[2767] | 1573 | case 'r':
|
---|
| 1574 | case 'R':
|
---|
[2931] | 1575 | useRenderQueue = !useRenderQueue;
|
---|
| 1576 | traverser->SetUseRenderQueue(useRenderQueue);
|
---|
[2790] | 1577 | break;
|
---|
[2786] | 1578 | case 'b':
|
---|
| 1579 | case 'B':
|
---|
[2931] | 1580 | useTightBounds = !useTightBounds;
|
---|
| 1581 | traverser->SetUseTightBounds(useTightBounds);
|
---|
[2790] | 1582 | break;
|
---|
[3175] | 1583 | case 'v':
|
---|
| 1584 | case 'V':
|
---|
[2931] | 1585 | renderLightView = !renderLightView;
|
---|
| 1586 | break;
|
---|
[2994] | 1587 | case 'h':
|
---|
| 1588 | case 'H':
|
---|
| 1589 | useHDR = !useHDR;
|
---|
| 1590 | break;
|
---|
[3175] | 1591 | case 'i':
|
---|
| 1592 | case 'I':
|
---|
| 1593 | useAntiAliasing = !useAntiAliasing;
|
---|
| 1594 | break;
|
---|
[3215] | 1595 | case 'c':
|
---|
| 1596 | case 'C':
|
---|
| 1597 | useLenseFlare = !useLenseFlare;
|
---|
[3189] | 1598 | break;
|
---|
[3219] | 1599 | case 'u':
|
---|
| 1600 | case 'U':
|
---|
[3220] | 1601 | // move light source instead of camera tilt
|
---|
[3219] | 1602 | moveLight = !moveLight;
|
---|
| 1603 | break;
|
---|
[3225] | 1604 | case '#':
|
---|
| 1605 | // make a snapshot of the current frame
|
---|
| 1606 | makeSnapShot = true;
|
---|
| 1607 | break;
|
---|
[3246] | 1608 | case '.':
|
---|
| 1609 | // enable / disable view cells
|
---|
| 1610 | usePvs = !usePvs;
|
---|
| 1611 | if (!usePvs) SceneEntity::SetGlobalVisibleId(-1);
|
---|
| 1612 | break;
|
---|
[2642] | 1613 | default:
|
---|
| 1614 | return;
|
---|
| 1615 | }
|
---|
| 1616 |
|
---|
| 1617 | glutPostRedisplay();
|
---|
| 1618 | }
|
---|
| 1619 |
|
---|
| 1620 |
|
---|
[2792] | 1621 | void SpecialKeyUp(int c, int x, int y)
|
---|
[2642] | 1622 | {
|
---|
[2792] | 1623 | switch (c)
|
---|
| 1624 | {
|
---|
| 1625 | case GLUT_KEY_LEFT:
|
---|
| 1626 | leftKeyPressed = false;
|
---|
| 1627 | break;
|
---|
| 1628 | case GLUT_KEY_RIGHT:
|
---|
| 1629 | rightKeyPressed = false;
|
---|
| 1630 | break;
|
---|
| 1631 | case GLUT_KEY_UP:
|
---|
| 1632 | upKeyPressed = false;
|
---|
| 1633 | break;
|
---|
| 1634 | case GLUT_KEY_DOWN:
|
---|
| 1635 | downKeyPressed = false;
|
---|
| 1636 | break;
|
---|
[2953] | 1637 | case GLUT_ACTIVE_ALT:
|
---|
| 1638 | altKeyPressed = false;
|
---|
| 1639 | break;
|
---|
[2792] | 1640 | default:
|
---|
| 1641 | return;
|
---|
| 1642 | }
|
---|
| 1643 | }
|
---|
| 1644 |
|
---|
| 1645 |
|
---|
| 1646 | void KeyUp(unsigned char c, int x, int y)
|
---|
| 1647 | {
|
---|
| 1648 | switch (c)
|
---|
| 1649 | {
|
---|
[2879] | 1650 |
|
---|
[2792] | 1651 | case 'A':
|
---|
| 1652 | case 'a':
|
---|
| 1653 | leftKeyPressed = false;
|
---|
| 1654 | break;
|
---|
| 1655 | case 'D':
|
---|
| 1656 | case 'd':
|
---|
| 1657 | rightKeyPressed = false;
|
---|
| 1658 | break;
|
---|
| 1659 | case 'W':
|
---|
| 1660 | case 'w':
|
---|
| 1661 | upKeyPressed = false;
|
---|
| 1662 | break;
|
---|
[2829] | 1663 | case 'S':
|
---|
| 1664 | case 's':
|
---|
[2792] | 1665 | downKeyPressed = false;
|
---|
| 1666 | break;
|
---|
[2837] | 1667 | case '1':
|
---|
| 1668 | descendKeyPressed = false;
|
---|
[2794] | 1669 | break;
|
---|
[2837] | 1670 | case '2':
|
---|
| 1671 | ascendKeyPressed = false;
|
---|
[2794] | 1672 | break;
|
---|
[3105] | 1673 | case 'j':
|
---|
| 1674 | case 'J':
|
---|
| 1675 | leftStrafeKeyPressed = false;
|
---|
| 1676 | break;
|
---|
| 1677 | case 'k':
|
---|
| 1678 | case 'K':
|
---|
| 1679 | rightStrafeKeyPressed = false;
|
---|
| 1680 | break;
|
---|
[2792] | 1681 | default:
|
---|
| 1682 | return;
|
---|
| 1683 | }
|
---|
| 1684 | //glutPostRedisplay();
|
---|
| 1685 | }
|
---|
| 1686 |
|
---|
| 1687 |
|
---|
| 1688 | void Special(int c, int x, int y)
|
---|
| 1689 | {
|
---|
[2642] | 1690 | switch(c)
|
---|
| 1691 | {
|
---|
| 1692 | case GLUT_KEY_F1:
|
---|
| 1693 | showHelp = !showHelp;
|
---|
| 1694 | break;
|
---|
[2790] | 1695 | case GLUT_KEY_F2:
|
---|
[2795] | 1696 | visMode = !visMode;
|
---|
[2790] | 1697 | break;
|
---|
| 1698 | case GLUT_KEY_F3:
|
---|
| 1699 | showBoundingVolumes = !showBoundingVolumes;
|
---|
| 1700 | traverser->SetShowBounds(showBoundingVolumes);
|
---|
| 1701 | break;
|
---|
| 1702 | case GLUT_KEY_F4:
|
---|
[2827] | 1703 | showOptions = !showOptions;
|
---|
[2790] | 1704 | break;
|
---|
| 1705 | case GLUT_KEY_F5:
|
---|
[2827] | 1706 | showStatistics = !showStatistics;
|
---|
[2790] | 1707 | break;
|
---|
[2800] | 1708 | case GLUT_KEY_F6:
|
---|
| 1709 | flyMode = !flyMode;
|
---|
| 1710 | break;
|
---|
[2801] | 1711 | case GLUT_KEY_F7:
|
---|
[2825] | 1712 |
|
---|
[2955] | 1713 | renderMethod = (renderMethod + 1) % 4;
|
---|
| 1714 |
|
---|
| 1715 | traverser->SetUseDepthPass(
|
---|
| 1716 | (renderMethod == RENDER_DEPTH_PASS) ||
|
---|
| 1717 | (renderMethod == RENDER_DEPTH_PASS_DEFERRED)
|
---|
| 1718 | );
|
---|
[2825] | 1719 |
|
---|
[2801] | 1720 | break;
|
---|
[2803] | 1721 | case GLUT_KEY_F8:
|
---|
[2903] | 1722 | useAdvancedShading = !useAdvancedShading;
|
---|
[2821] | 1723 | break;
|
---|
[2826] | 1724 | case GLUT_KEY_F9:
|
---|
| 1725 | showAlgorithmTime = !showAlgorithmTime;
|
---|
| 1726 | break;
|
---|
[2954] | 1727 | case GLUT_KEY_F10:
|
---|
[3219] | 1728 | replayPath = !replayPath;
|
---|
| 1729 |
|
---|
| 1730 | if (replayPath)
|
---|
| 1731 | {
|
---|
| 1732 | cout << "replaying path" << endl;
|
---|
| 1733 | currentReplayFrame = -1;
|
---|
| 1734 | }
|
---|
| 1735 | else
|
---|
| 1736 | {
|
---|
| 1737 | cout << "finished replaying path" << endl;
|
---|
| 1738 | }
|
---|
| 1739 |
|
---|
[2954] | 1740 | break;
|
---|
[3219] | 1741 | case GLUT_KEY_F11:
|
---|
| 1742 | recordPath = !recordPath;
|
---|
| 1743 |
|
---|
| 1744 | if (recordPath)
|
---|
| 1745 | {
|
---|
| 1746 | cout << "recording path" << endl;
|
---|
| 1747 | }
|
---|
| 1748 | else
|
---|
| 1749 | {
|
---|
| 1750 | cout << "finished recording path" << endl;
|
---|
| 1751 | // start over with new frame recording next time
|
---|
| 1752 | DEL_PTR(walkThroughRecorder);
|
---|
| 1753 | }
|
---|
| 1754 |
|
---|
| 1755 | break;
|
---|
| 1756 | case GLUT_KEY_F12:
|
---|
| 1757 | recordFrames = !recordFrames;
|
---|
| 1758 |
|
---|
| 1759 | if (recordFrames)
|
---|
| 1760 | cout << "recording frames on replaying" << endl;
|
---|
| 1761 | else
|
---|
| 1762 | cout << "finished recording frames on replaying" << endl;
|
---|
| 1763 | break;
|
---|
[2642] | 1764 | case GLUT_KEY_LEFT:
|
---|
[2767] | 1765 | {
|
---|
[2792] | 1766 | leftKeyPressed = true;
|
---|
[2795] | 1767 | camera->Pitch(KeyRotationAngle());
|
---|
[2767] | 1768 | }
|
---|
[2642] | 1769 | break;
|
---|
| 1770 | case GLUT_KEY_RIGHT:
|
---|
[2767] | 1771 | {
|
---|
[2792] | 1772 | rightKeyPressed = true;
|
---|
[2795] | 1773 | camera->Pitch(-KeyRotationAngle());
|
---|
[2767] | 1774 | }
|
---|
[2642] | 1775 | break;
|
---|
| 1776 | case GLUT_KEY_UP:
|
---|
[2767] | 1777 | {
|
---|
[2792] | 1778 | upKeyPressed = true;
|
---|
[2795] | 1779 | KeyHorizontalMotion(KeyShift());
|
---|
[2767] | 1780 | }
|
---|
[2642] | 1781 | break;
|
---|
| 1782 | case GLUT_KEY_DOWN:
|
---|
[2767] | 1783 | {
|
---|
[2792] | 1784 | downKeyPressed = true;
|
---|
[2795] | 1785 | KeyHorizontalMotion(-KeyShift());
|
---|
[2767] | 1786 | }
|
---|
[2642] | 1787 | break;
|
---|
| 1788 | default:
|
---|
| 1789 | return;
|
---|
| 1790 |
|
---|
| 1791 | }
|
---|
| 1792 |
|
---|
| 1793 | glutPostRedisplay();
|
---|
| 1794 | }
|
---|
[2767] | 1795 |
|
---|
[2642] | 1796 | #pragma warning( default : 4100 )
|
---|
| 1797 |
|
---|
| 1798 |
|
---|
[2792] | 1799 | void Reshape(int w, int h)
|
---|
[2642] | 1800 | {
|
---|
[2759] | 1801 | winAspectRatio = 1.0f;
|
---|
[2642] | 1802 |
|
---|
| 1803 | glViewport(0, 0, w, h);
|
---|
| 1804 |
|
---|
| 1805 | winWidth = w;
|
---|
| 1806 | winHeight = h;
|
---|
| 1807 |
|
---|
[2833] | 1808 | if (w) winAspectRatio = (float) w / (float) h;
|
---|
[2642] | 1809 |
|
---|
[2758] | 1810 | glMatrixMode(GL_PROJECTION);
|
---|
| 1811 | glLoadIdentity();
|
---|
[2642] | 1812 |
|
---|
[2927] | 1813 | gluPerspective(fov, winAspectRatio, nearDist, farDist);
|
---|
[2788] | 1814 |
|
---|
[2758] | 1815 | glMatrixMode(GL_MODELVIEW);
|
---|
| 1816 |
|
---|
[2642] | 1817 | glutPostRedisplay();
|
---|
| 1818 | }
|
---|
| 1819 |
|
---|
| 1820 |
|
---|
[3101] | 1821 | void Mouse(int button, int renderState, int x, int y)
|
---|
[2642] | 1822 | {
|
---|
[3101] | 1823 | if ((button == GLUT_LEFT_BUTTON) && (renderState == GLUT_DOWN))
|
---|
[2642] | 1824 | {
|
---|
| 1825 | xEyeBegin = x;
|
---|
| 1826 | yMotionBegin = y;
|
---|
| 1827 |
|
---|
[2792] | 1828 | glutMotionFunc(LeftMotion);
|
---|
[2642] | 1829 | }
|
---|
[3101] | 1830 | else if ((button == GLUT_RIGHT_BUTTON) && (renderState == GLUT_DOWN))
|
---|
[2642] | 1831 | {
|
---|
[2829] | 1832 | xEyeBegin = x;
|
---|
[2758] | 1833 | yEyeBegin = y;
|
---|
| 1834 | yMotionBegin = y;
|
---|
| 1835 |
|
---|
[2954] | 1836 | if (!moveLight)
|
---|
| 1837 | glutMotionFunc(RightMotion);
|
---|
| 1838 | else
|
---|
| 1839 | glutMotionFunc(RightMotionLight);
|
---|
[2758] | 1840 | }
|
---|
[3101] | 1841 | else if ((button == GLUT_MIDDLE_BUTTON) && (renderState == GLUT_DOWN))
|
---|
[2758] | 1842 | {
|
---|
[2642] | 1843 | horizontalMotionBegin = x;
|
---|
| 1844 | verticalMotionBegin = y;
|
---|
[2792] | 1845 | glutMotionFunc(MiddleMotion);
|
---|
[2642] | 1846 | }
|
---|
| 1847 |
|
---|
| 1848 | glutPostRedisplay();
|
---|
| 1849 | }
|
---|
| 1850 |
|
---|
[2758] | 1851 |
|
---|
| 1852 | /** rotation for left/right mouse drag
|
---|
[2642] | 1853 | motion for up/down mouse drag
|
---|
| 1854 | */
|
---|
[2792] | 1855 | void LeftMotion(int x, int y)
|
---|
[2642] | 1856 | {
|
---|
[2758] | 1857 | Vector3 viewDir = camera->GetDirection();
|
---|
| 1858 | Vector3 pos = camera->GetPosition();
|
---|
| 1859 |
|
---|
| 1860 | // don't move in the vertical direction
|
---|
[2764] | 1861 | Vector3 horView(viewDir[0], viewDir[1], 0);
|
---|
[2642] | 1862 |
|
---|
[2795] | 1863 | float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0;
|
---|
[2756] | 1864 |
|
---|
[2795] | 1865 | camera->Pitch(eyeXAngle);
|
---|
[2787] | 1866 |
|
---|
[3246] | 1867 | pos += horView * (yMotionBegin - y) * mouseMotion;
|
---|
[2795] | 1868 |
|
---|
[2758] | 1869 | camera->SetPosition(pos);
|
---|
[2642] | 1870 |
|
---|
| 1871 | xEyeBegin = x;
|
---|
| 1872 | yMotionBegin = y;
|
---|
[2758] | 1873 |
|
---|
[2642] | 1874 | glutPostRedisplay();
|
---|
| 1875 | }
|
---|
| 1876 |
|
---|
[2758] | 1877 |
|
---|
[2954] | 1878 | void RightMotionLight(int x, int y)
|
---|
| 1879 | {
|
---|
| 1880 | float theta = 0.2f * M_PI * (xEyeBegin - x) / 180.0f;
|
---|
| 1881 | float phi = 0.2f * M_PI * (yMotionBegin - y) / 180.0f;
|
---|
| 1882 |
|
---|
| 1883 | Vector3 lightDir = light->GetDirection();
|
---|
| 1884 |
|
---|
| 1885 | Matrix4x4 roty = RotationYMatrix(theta);
|
---|
| 1886 | Matrix4x4 rotx = RotationXMatrix(phi);
|
---|
| 1887 |
|
---|
| 1888 | lightDir = roty * lightDir;
|
---|
| 1889 | lightDir = rotx * lightDir;
|
---|
| 1890 |
|
---|
[2967] | 1891 | // normalize to avoid accumulating errors
|
---|
| 1892 | lightDir.Normalize();
|
---|
| 1893 |
|
---|
[2954] | 1894 | light->SetDirection(lightDir);
|
---|
| 1895 |
|
---|
| 1896 | xEyeBegin = x;
|
---|
| 1897 | yMotionBegin = y;
|
---|
| 1898 |
|
---|
| 1899 | glutPostRedisplay();
|
---|
| 1900 | }
|
---|
| 1901 |
|
---|
| 1902 |
|
---|
[2767] | 1903 | /** rotation for left / right mouse drag
|
---|
| 1904 | motion for up / down mouse drag
|
---|
[2758] | 1905 | */
|
---|
[2792] | 1906 | void RightMotion(int x, int y)
|
---|
[2758] | 1907 | {
|
---|
[2829] | 1908 | float eyeXAngle = 0.2f * M_PI * (xEyeBegin - x) / 180.0;
|
---|
[2795] | 1909 | float eyeYAngle = -0.2f * M_PI * (yEyeBegin - y) / 180.0;
|
---|
[2758] | 1910 |
|
---|
[2795] | 1911 | camera->Yaw(eyeYAngle);
|
---|
[2829] | 1912 | camera->Pitch(eyeXAngle);
|
---|
[2780] | 1913 |
|
---|
[2829] | 1914 | xEyeBegin = x;
|
---|
[2758] | 1915 | yEyeBegin = y;
|
---|
[2829] | 1916 |
|
---|
[2758] | 1917 | glutPostRedisplay();
|
---|
| 1918 | }
|
---|
| 1919 |
|
---|
| 1920 |
|
---|
[3105] | 1921 | /** strafe
|
---|
| 1922 | */
|
---|
[2792] | 1923 | void MiddleMotion(int x, int y)
|
---|
[2642] | 1924 | {
|
---|
[2758] | 1925 | Vector3 viewDir = camera->GetDirection();
|
---|
| 1926 | Vector3 pos = camera->GetPosition();
|
---|
| 1927 |
|
---|
[2642] | 1928 | // the 90 degree rotated view vector
|
---|
| 1929 | // y zero so we don't move in the vertical
|
---|
[2764] | 1930 | Vector3 rVec(viewDir[0], viewDir[1], 0);
|
---|
[2642] | 1931 |
|
---|
[2764] | 1932 | Matrix4x4 rot = RotationZMatrix(M_PI * 0.5f);
|
---|
[2758] | 1933 | rVec = rot * rVec;
|
---|
[2642] | 1934 |
|
---|
[3246] | 1935 | pos -= rVec * (x - horizontalMotionBegin) * mouseMotion;
|
---|
| 1936 | pos[2] += (verticalMotionBegin - y) * mouseMotion;
|
---|
[2642] | 1937 |
|
---|
[2758] | 1938 | camera->SetPosition(pos);
|
---|
| 1939 |
|
---|
[2642] | 1940 | horizontalMotionBegin = x;
|
---|
| 1941 | verticalMotionBegin = y;
|
---|
[2758] | 1942 |
|
---|
[2642] | 1943 | glutPostRedisplay();
|
---|
| 1944 | }
|
---|
| 1945 |
|
---|
| 1946 |
|
---|
[2756] | 1947 | void InitExtensions(void)
|
---|
[2642] | 1948 | {
|
---|
| 1949 | GLenum err = glewInit();
|
---|
[2756] | 1950 |
|
---|
[2642] | 1951 | if (GLEW_OK != err)
|
---|
| 1952 | {
|
---|
| 1953 | // problem: glewInit failed, something is seriously wrong
|
---|
| 1954 | fprintf(stderr,"Error: %s\n", glewGetErrorString(err));
|
---|
| 1955 | exit(1);
|
---|
| 1956 | }
|
---|
[2756] | 1957 | if (!GLEW_ARB_occlusion_query)
|
---|
[2642] | 1958 | {
|
---|
[2756] | 1959 | printf("I require the GL_ARB_occlusion_query to work.\n");
|
---|
[2642] | 1960 | exit(1);
|
---|
| 1961 | }
|
---|
| 1962 | }
|
---|
| 1963 |
|
---|
| 1964 |
|
---|
[2826] | 1965 | void Begin2D()
|
---|
[2642] | 1966 | {
|
---|
| 1967 | glDisable(GL_LIGHTING);
|
---|
| 1968 | glDisable(GL_DEPTH_TEST);
|
---|
| 1969 |
|
---|
[2826] | 1970 | glMatrixMode(GL_PROJECTION);
|
---|
[2642] | 1971 | glPushMatrix();
|
---|
| 1972 | glLoadIdentity();
|
---|
[2834] | 1973 |
|
---|
[2826] | 1974 | gluOrtho2D(0, winWidth, 0, winHeight);
|
---|
[2642] | 1975 |
|
---|
[2826] | 1976 | glMatrixMode(GL_MODELVIEW);
|
---|
[2642] | 1977 | glPushMatrix();
|
---|
| 1978 | glLoadIdentity();
|
---|
| 1979 | }
|
---|
| 1980 |
|
---|
| 1981 |
|
---|
[2826] | 1982 | void End2D()
|
---|
[2642] | 1983 | {
|
---|
[2834] | 1984 | glMatrixMode(GL_PROJECTION);
|
---|
[2642] | 1985 | glPopMatrix();
|
---|
[2834] | 1986 |
|
---|
[2642] | 1987 | glMatrixMode(GL_MODELVIEW);
|
---|
| 1988 | glPopMatrix();
|
---|
| 1989 |
|
---|
| 1990 | glEnable(GL_LIGHTING);
|
---|
| 1991 | glEnable(GL_DEPTH_TEST);
|
---|
| 1992 | }
|
---|
| 1993 |
|
---|
| 1994 |
|
---|
[2787] | 1995 | // displays the visualisation of culling algorithm
|
---|
| 1996 | void DisplayVisualization()
|
---|
[2796] | 1997 | {
|
---|
[3246] | 1998 | // render current view cell
|
---|
| 1999 | if (usePvs) RenderViewCell();
|
---|
| 2000 |
|
---|
| 2001 | visualization->SetViewCell(usePvs ? viewCell : NULL);
|
---|
[2787] | 2002 | visualization->SetFrameId(traverser->GetCurrentFrameId());
|
---|
[3246] | 2003 |
|
---|
[3245] | 2004 |
|
---|
[2792] | 2005 | Begin2D();
|
---|
[2642] | 2006 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
---|
| 2007 | glEnable(GL_BLEND);
|
---|
[2827] | 2008 | glColor4f(0.0f ,0.0f, 0.0f, 0.5f);
|
---|
[2642] | 2009 |
|
---|
[2827] | 2010 | glRecti(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth, winHeight);
|
---|
[2642] | 2011 | glDisable(GL_BLEND);
|
---|
[2792] | 2012 | End2D();
|
---|
[2788] | 2013 |
|
---|
| 2014 |
|
---|
| 2015 | AxisAlignedBox3 box = bvh->GetBox();
|
---|
| 2016 |
|
---|
[2948] | 2017 | const float offs = box.Size().x * 0.3f;
|
---|
[2834] | 2018 |
|
---|
[2838] | 2019 | Vector3 vizpos = Vector3(box.Min().x, box.Min().y - box.Size().y * 0.35f, box.Min().z + box.Size().z * 50);
|
---|
[2806] | 2020 |
|
---|
[2795] | 2021 | visCamera->SetPosition(vizpos);
|
---|
[2838] | 2022 | visCamera->ResetPitchAndYaw();
|
---|
[2892] | 2023 |
|
---|
[2834] | 2024 | glPushAttrib(GL_VIEWPORT_BIT);
|
---|
[2806] | 2025 | glViewport(winWidth - winWidth / 3, winHeight - winHeight / 3, winWidth / 3, winHeight / 3);
|
---|
[2796] | 2026 |
|
---|
| 2027 | glMatrixMode(GL_PROJECTION);
|
---|
[2834] | 2028 | glPushMatrix();
|
---|
| 2029 |
|
---|
[2787] | 2030 | glLoadIdentity();
|
---|
[2807] | 2031 | glOrtho(-offs, offs, -offs, offs, 0.0f, box.Size().z * 100.0f);
|
---|
[2787] | 2032 |
|
---|
[2796] | 2033 | glMatrixMode(GL_MODELVIEW);
|
---|
[2834] | 2034 | glPushMatrix();
|
---|
[2787] | 2035 |
|
---|
[2796] | 2036 | visCamera->SetupCameraView();
|
---|
[2806] | 2037 |
|
---|
| 2038 | Matrix4x4 rotZ = RotationZMatrix(-camera->GetPitch());
|
---|
| 2039 | glMultMatrixf((float *)rotZ.x);
|
---|
| 2040 |
|
---|
[2887] | 2041 | // inverse translation in order to fix current position
|
---|
[2838] | 2042 | Vector3 pos = camera->GetPosition();
|
---|
[2806] | 2043 | glTranslatef(-pos.x, -pos.y, -pos.z);
|
---|
| 2044 |
|
---|
| 2045 |
|
---|
[2788] | 2046 | GLfloat position[] = {0.8f, 1.0f, 1.5f, 0.0f};
|
---|
| 2047 | glLightfv(GL_LIGHT0, GL_POSITION, position);
|
---|
[2787] | 2048 |
|
---|
[2788] | 2049 | GLfloat position1[] = {bvh->GetBox().Center().x, bvh->GetBox().Max().y, bvh->GetBox().Center().z, 1.0f};
|
---|
| 2050 | glLightfv(GL_LIGHT1, GL_POSITION, position1);
|
---|
[2787] | 2051 |
|
---|
[2642] | 2052 | glClear(GL_DEPTH_BUFFER_BIT);
|
---|
| 2053 |
|
---|
[2888] | 2054 |
|
---|
[2767] | 2055 | ////////////
|
---|
[2787] | 2056 | //-- visualization of the occlusion culling
|
---|
| 2057 |
|
---|
[3063] | 2058 | visualization->Render(showShadowMap);
|
---|
[2887] | 2059 |
|
---|
[2767] | 2060 |
|
---|
[2834] | 2061 | // reset previous settings
|
---|
| 2062 | glPopAttrib();
|
---|
| 2063 |
|
---|
| 2064 | glMatrixMode(GL_PROJECTION);
|
---|
| 2065 | glPopMatrix();
|
---|
| 2066 | glMatrixMode(GL_MODELVIEW);
|
---|
| 2067 | glPopMatrix();
|
---|
[2642] | 2068 | }
|
---|
| 2069 |
|
---|
[2767] | 2070 |
|
---|
[2642] | 2071 | // cleanup routine after the main loop
|
---|
[2756] | 2072 | void CleanUp()
|
---|
[2642] | 2073 | {
|
---|
[2756] | 2074 | DEL_PTR(traverser);
|
---|
[2796] | 2075 | DEL_PTR(sceneQuery);
|
---|
[2756] | 2076 | DEL_PTR(bvh);
|
---|
[2767] | 2077 | DEL_PTR(visualization);
|
---|
[2787] | 2078 | DEL_PTR(camera);
|
---|
[2801] | 2079 | DEL_PTR(renderQueue);
|
---|
[2827] | 2080 | DEL_PTR(perfGraph);
|
---|
[2879] | 2081 | DEL_PTR(fbo);
|
---|
[3111] | 2082 | DEL_PTR(deferredShader);
|
---|
[3019] | 2083 | DEL_PTR(light);
|
---|
| 2084 | DEL_PTR(visCamera);
|
---|
| 2085 | DEL_PTR(preetham);
|
---|
[3020] | 2086 | DEL_PTR(shadowMap);
|
---|
| 2087 | DEL_PTR(shadowTraverser);
|
---|
[3078] | 2088 | DEL_PTR(motionPath);
|
---|
[3219] | 2089 | DEL_PTR(walkThroughRecorder);
|
---|
| 2090 | DEL_PTR(walkThroughPlayer);
|
---|
[3223] | 2091 | DEL_PTR(statsWriter);
|
---|
[3244] | 2092 | DEL_PTR(viewCellsTree);
|
---|
[3052] | 2093 |
|
---|
[3037] | 2094 | ResourceManager::DelSingleton();
|
---|
[3057] | 2095 | ShaderManager::DelSingleton();
|
---|
| 2096 |
|
---|
[3059] | 2097 | resourceManager = NULL;
|
---|
[3057] | 2098 | shaderManager = NULL;
|
---|
[2642] | 2099 | }
|
---|
| 2100 |
|
---|
| 2101 |
|
---|
| 2102 | // this function inserts a dezimal point after each 1000
|
---|
[2829] | 2103 | void CalcDecimalPoint(string &str, int d, int len)
|
---|
[2642] | 2104 | {
|
---|
[2827] | 2105 | static vector<int> numbers;
|
---|
| 2106 | numbers.clear();
|
---|
| 2107 |
|
---|
[2829] | 2108 | static string shortStr;
|
---|
| 2109 | shortStr.clear();
|
---|
[2642] | 2110 |
|
---|
[2829] | 2111 | static char hstr[100];
|
---|
| 2112 |
|
---|
[2642] | 2113 | while (d != 0)
|
---|
| 2114 | {
|
---|
| 2115 | numbers.push_back(d % 1000);
|
---|
| 2116 | d /= 1000;
|
---|
| 2117 | }
|
---|
| 2118 |
|
---|
| 2119 | // first element without leading zeros
|
---|
| 2120 | if (numbers.size() > 0)
|
---|
| 2121 | {
|
---|
[2800] | 2122 | sprintf(hstr, "%d", numbers.back());
|
---|
[2829] | 2123 | shortStr.append(hstr);
|
---|
[2642] | 2124 | }
|
---|
| 2125 |
|
---|
[2764] | 2126 | for (int i = (int)numbers.size() - 2; i >= 0; i--)
|
---|
[2642] | 2127 | {
|
---|
[2800] | 2128 | sprintf(hstr, ",%03d", numbers[i]);
|
---|
[2829] | 2129 | shortStr.append(hstr);
|
---|
[2642] | 2130 | }
|
---|
[2829] | 2131 |
|
---|
| 2132 | int dif = len - (int)shortStr.size();
|
---|
| 2133 |
|
---|
| 2134 | for (int i = 0; i < dif; ++ i)
|
---|
| 2135 | {
|
---|
| 2136 | str += " ";
|
---|
| 2137 | }
|
---|
| 2138 |
|
---|
| 2139 | str.append(shortStr);
|
---|
[2764] | 2140 | }
|
---|
| 2141 |
|
---|
| 2142 |
|
---|
| 2143 | void DisplayStats()
|
---|
| 2144 | {
|
---|
[2826] | 2145 | static char msg[9][300];
|
---|
[2764] | 2146 |
|
---|
[2826] | 2147 | static double frameTime = elapsedTime;
|
---|
| 2148 | static double renderTime = algTime;
|
---|
| 2149 |
|
---|
[2818] | 2150 | const float expFactor = 0.1f;
|
---|
[2767] | 2151 |
|
---|
[2802] | 2152 | // if some strange render time spike happened in this frame => don't count
|
---|
[2826] | 2153 | if (elapsedTime < 500) frameTime = elapsedTime * expFactor + (1.0f - expFactor) * elapsedTime;
|
---|
| 2154 |
|
---|
| 2155 | static float rTime = 1000.0f;
|
---|
[2764] | 2156 |
|
---|
[3223] | 2157 | // the render time used up purely for the traversal algorithm using glfinish
|
---|
[2826] | 2158 | if (showAlgorithmTime)
|
---|
| 2159 | {
|
---|
| 2160 | if (algTime < 500) renderTime = algTime * expFactor + (1.0f - expFactor) * renderTime;
|
---|
| 2161 | }
|
---|
[2802] | 2162 |
|
---|
[2826] | 2163 | accumulatedTime += elapsedTime;
|
---|
| 2164 |
|
---|
[2776] | 2165 | if (accumulatedTime > 500) // update every fraction of a second
|
---|
[2770] | 2166 | {
|
---|
| 2167 | accumulatedTime = 0;
|
---|
| 2168 |
|
---|
[2826] | 2169 | if (frameTime) fps = 1e3f / (float)frameTime;
|
---|
| 2170 |
|
---|
| 2171 | rTime = renderTime;
|
---|
[2773] | 2172 |
|
---|
[2948] | 2173 | if (renderLightView && shadowTraverser)
|
---|
| 2174 | {
|
---|
| 2175 | renderedTriangles = shadowTraverser->GetStats().mNumRenderedTriangles;
|
---|
| 2176 | renderedObjects = shadowTraverser->GetStats().mNumRenderedGeometry;
|
---|
| 2177 | renderedNodes = shadowTraverser->GetStats().mNumRenderedNodes;
|
---|
| 2178 | }
|
---|
| 2179 | else if (showShadowMap && shadowTraverser)
|
---|
| 2180 | {
|
---|
| 2181 | renderedNodes = traverser->GetStats().mNumRenderedNodes + shadowTraverser->GetStats().mNumRenderedNodes;
|
---|
| 2182 | renderedObjects = traverser->GetStats().mNumRenderedGeometry + shadowTraverser->GetStats().mNumRenderedGeometry;
|
---|
| 2183 | renderedTriangles = traverser->GetStats().mNumRenderedTriangles + shadowTraverser->GetStats().mNumRenderedTriangles;
|
---|
| 2184 | }
|
---|
| 2185 | else
|
---|
| 2186 | {
|
---|
| 2187 | renderedTriangles = traverser->GetStats().mNumRenderedTriangles;
|
---|
| 2188 | renderedObjects = traverser->GetStats().mNumRenderedGeometry;
|
---|
| 2189 | renderedNodes = traverser->GetStats().mNumRenderedNodes;
|
---|
| 2190 | }
|
---|
| 2191 |
|
---|
[2770] | 2192 | traversedNodes = traverser->GetStats().mNumTraversedNodes;
|
---|
| 2193 | frustumCulledNodes = traverser->GetStats().mNumFrustumCulledNodes;
|
---|
| 2194 | queryCulledNodes = traverser->GetStats().mNumQueryCulledNodes;
|
---|
| 2195 | issuedQueries = traverser->GetStats().mNumIssuedQueries;
|
---|
| 2196 | stateChanges = traverser->GetStats().mNumStateChanges;
|
---|
[2800] | 2197 | numBatches = traverser->GetStats().mNumBatches;
|
---|
[2770] | 2198 | }
|
---|
| 2199 |
|
---|
[2764] | 2200 |
|
---|
[3223] | 2201 | ////////////////
|
---|
| 2202 | //-- record stats on walkthrough
|
---|
| 2203 |
|
---|
| 2204 | static float accTime = .0f;
|
---|
| 2205 | static float averageTime = .0f;
|
---|
| 2206 |
|
---|
| 2207 | if (currentReplayFrame > -1)
|
---|
| 2208 | {
|
---|
| 2209 | accTime += frameTime;
|
---|
| 2210 | averageTime = accTime / (currentReplayFrame + 1);
|
---|
| 2211 |
|
---|
| 2212 | if (!statsWriter)
|
---|
| 2213 | statsWriter = new StatsWriter(statsFilename);
|
---|
| 2214 |
|
---|
| 2215 | FrameStats frameStats;
|
---|
| 2216 | frameStats.mFrame = currentReplayFrame;
|
---|
| 2217 | frameStats.mFPS = 1e3f / (float)frameTime;
|
---|
| 2218 | frameStats.mTime = frameTime;
|
---|
| 2219 | frameStats.mNodes = renderedNodes;
|
---|
| 2220 | frameStats.mObjects = renderedObjects;
|
---|
| 2221 | frameStats.mTriangles = renderedTriangles;
|
---|
| 2222 |
|
---|
| 2223 | statsWriter->WriteFrameStats(frameStats);
|
---|
| 2224 | }
|
---|
| 2225 | else if (statsWriter)
|
---|
| 2226 | {
|
---|
| 2227 | Debug << "average frame time " << averageTime << " for traversal algorithm " << renderMode << endl;
|
---|
| 2228 |
|
---|
| 2229 | // reset average frame time
|
---|
[3224] | 2230 | averageTime = accTime = .0f;
|
---|
[3223] | 2231 |
|
---|
| 2232 | DEL_PTR(statsWriter);
|
---|
| 2233 | }
|
---|
| 2234 |
|
---|
| 2235 |
|
---|
[2826] | 2236 | Begin2D();
|
---|
[2808] | 2237 |
|
---|
[2826] | 2238 | glEnable(GL_BLEND);
|
---|
| 2239 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
---|
[2764] | 2240 |
|
---|
[2826] | 2241 | if (showHelp)
|
---|
| 2242 | {
|
---|
| 2243 | DrawHelpMessage();
|
---|
| 2244 | }
|
---|
| 2245 | else
|
---|
| 2246 | {
|
---|
[2829] | 2247 | if (showOptions)
|
---|
| 2248 | {
|
---|
| 2249 | glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
|
---|
| 2250 | glRecti(5, winHeight - 95, winWidth * 2 / 3 - 5, winHeight - 5);
|
---|
| 2251 | }
|
---|
| 2252 |
|
---|
| 2253 | if (showStatistics)
|
---|
| 2254 | {
|
---|
| 2255 | glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
|
---|
| 2256 | glRecti(5, winHeight - 165, winWidth * 2 / 3 - 5, winHeight - 100);
|
---|
| 2257 | }
|
---|
| 2258 |
|
---|
| 2259 | glEnable(GL_TEXTURE_2D);
|
---|
[2827] | 2260 | myfont.Begin();
|
---|
[2769] | 2261 |
|
---|
[2826] | 2262 | if (showOptions)
|
---|
| 2263 | {
|
---|
[2829] | 2264 | glColor3f(0.0f, 1.0f, 0.0f);
|
---|
[2826] | 2265 | int i = 0;
|
---|
| 2266 |
|
---|
[3065] | 2267 | static char *renderMethodStr[] =
|
---|
| 2268 | {"forward", "depth pass + forward", "deferred shading", "depth pass + deferred"};
|
---|
[2826] | 2269 | sprintf(msg[i ++], "multiqueries: %d, tight bounds: %d, render queue: %d",
|
---|
[3065] | 2270 | useMultiQueries, useTightBounds, useRenderQueue);
|
---|
[3246] | 2271 | sprintf(msg[i ++], "render technique: %s, use pvss: %d", renderMethodStr[renderMethod], usePvs);
|
---|
[2826] | 2272 | sprintf(msg[i ++], "triangles per virtual leaf: %5d", trianglesPerVirtualLeaf);
|
---|
| 2273 | sprintf(msg[i ++], "assumed visible frames: %4d, max batch size: %4d",
|
---|
| 2274 | assumedVisibleFrames, maxBatchSize);
|
---|
[2808] | 2275 |
|
---|
[2826] | 2276 | for (int j = 0; j < 4; ++ j)
|
---|
[2829] | 2277 | myfont.DrawString(msg[j], 10.0f, winHeight - 5 - j * 20);
|
---|
[2826] | 2278 | }
|
---|
[2808] | 2279 |
|
---|
[2786] | 2280 | if (showStatistics)
|
---|
[2764] | 2281 | {
|
---|
[2829] | 2282 | glColor3f(1.0f, 1.0f, 0.0f);
|
---|
| 2283 |
|
---|
[2948] | 2284 | string objStr, totalObjStr;
|
---|
| 2285 | string triStr, totalTriStr;
|
---|
[2826] | 2286 |
|
---|
[2829] | 2287 | int len = 10;
|
---|
[2948] | 2288 | CalcDecimalPoint(objStr, renderedObjects, len);
|
---|
[3059] | 2289 | CalcDecimalPoint(totalObjStr, (int)resourceManager->GetNumEntities(), len);
|
---|
[2826] | 2290 |
|
---|
[2948] | 2291 | CalcDecimalPoint(triStr, renderedTriangles, len);
|
---|
| 2292 | CalcDecimalPoint(totalTriStr, bvh->GetBvhStats().mTriangles, len);
|
---|
| 2293 |
|
---|
[2826] | 2294 | int i = 4;
|
---|
| 2295 |
|
---|
[2953] | 2296 | if (0)
|
---|
| 2297 | {
|
---|
| 2298 | sprintf(msg[i ++], "rendered: %s of %s objects, %s of %s triangles",
|
---|
| 2299 | objStr.c_str(), totalObjStr.c_str(), triStr.c_str(), totalTriStr.c_str());
|
---|
| 2300 | }
|
---|
| 2301 | else
|
---|
| 2302 | {
|
---|
| 2303 | sprintf(msg[i ++], "rendered: %6d of %6d nodes, %s of %s triangles",
|
---|
| 2304 | renderedNodes, bvh->GetNumVirtualNodes(), triStr.c_str(), totalTriStr.c_str());
|
---|
| 2305 | }
|
---|
[2826] | 2306 |
|
---|
| 2307 | sprintf(msg[i ++], "traversed: %5d, frustum culled: %5d, query culled: %5d",
|
---|
| 2308 | traversedNodes, frustumCulledNodes, queryCulledNodes);
|
---|
[3251] | 2309 | sprintf(msg[i ++], "issued queries: %5d, state changes: %5d, render batches: %5d",
|
---|
[2826] | 2310 | issuedQueries, stateChanges, numBatches);
|
---|
| 2311 |
|
---|
| 2312 | for (int j = 4; j < 7; ++ j)
|
---|
[2829] | 2313 | myfont.DrawString(msg[j], 10.0f, winHeight - (j + 1) * 20);
|
---|
[2764] | 2314 | }
|
---|
[2790] | 2315 |
|
---|
[2826] | 2316 | glColor3f(1.0f, 1.0f, 1.0f);
|
---|
| 2317 | static char *alg_str[] = {"Frustum Cull", "Stop and Wait", "CHC", "CHC ++"};
|
---|
[2827] | 2318 |
|
---|
| 2319 | if (!showAlgorithmTime)
|
---|
[3065] | 2320 | sprintf(msg[7], "%s: %6.1f fps", alg_str[renderMode], fps);
|
---|
[2827] | 2321 | else
|
---|
| 2322 | sprintf(msg[7], "%s: %6.1f ms", alg_str[renderMode], rTime);
|
---|
[3010] | 2323 |
|
---|
[2829] | 2324 | myfont.DrawString(msg[7], 1.3f, 690.0f, 760.0f);//, top_color, bottom_color);
|
---|
[2827] | 2325 |
|
---|
| 2326 | //sprintf(msg[8], "algorithm time: %6.1f ms", rTime);
|
---|
| 2327 | //myfont.DrawString(msg[8], 720.0f, 730.0f);
|
---|
[2764] | 2328 | }
|
---|
| 2329 |
|
---|
[2826] | 2330 | glDisable(GL_BLEND);
|
---|
| 2331 | glDisable(GL_TEXTURE_2D);
|
---|
| 2332 |
|
---|
[2792] | 2333 | End2D();
|
---|
[2764] | 2334 | }
|
---|
[2796] | 2335 |
|
---|
| 2336 |
|
---|
| 2337 | void RenderSky()
|
---|
| 2338 | {
|
---|
[2959] | 2339 | if ((renderMethod == RENDER_DEFERRED) || (renderMethod == RENDER_DEPTH_PASS_DEFERRED))
|
---|
[3101] | 2340 | renderState.SetRenderTechnique(DEFERRED);
|
---|
[2958] | 2341 |
|
---|
[3036] | 2342 | const bool useToneMapping =
|
---|
| 2343 | ((renderMethod == RENDER_DEPTH_PASS_DEFERRED) ||
|
---|
| 2344 | (renderMethod == RENDER_DEFERRED)) && useHDR;
|
---|
[3059] | 2345 |
|
---|
[3101] | 2346 | preetham->RenderSkyDome(-light->GetDirection(), camera, &renderState, !useToneMapping);
|
---|
[3212] | 2347 |
|
---|
| 2348 | /// once again reset the renderState just to make sure
|
---|
[3101] | 2349 | renderState.Reset();
|
---|
[2801] | 2350 | }
|
---|
[2796] | 2351 |
|
---|
[2948] | 2352 |
|
---|
[2895] | 2353 | // render visible object from depth pass
|
---|
[2801] | 2354 | void RenderVisibleObjects()
|
---|
| 2355 | {
|
---|
[2955] | 2356 | if (renderMethod == RENDER_DEPTH_PASS_DEFERRED)
|
---|
[2948] | 2357 | {
|
---|
[2950] | 2358 | if (showShadowMap && !renderLightView)
|
---|
[2951] | 2359 | {
|
---|
[3068] | 2360 | // usethe maximal visible distance to focus shadow map
|
---|
[3235] | 2361 | const float newFar = min(camera->GetFar(), traverser->GetMaxVisibleDistance());
|
---|
| 2362 | RenderShadowMap(newFar);
|
---|
[2951] | 2363 | }
|
---|
[3068] | 2364 | // initialize deferred rendering
|
---|
[2948] | 2365 | InitDeferredRendering();
|
---|
| 2366 | }
|
---|
[2949] | 2367 | else
|
---|
[2950] | 2368 | {
|
---|
[3101] | 2369 | renderState.SetRenderTechnique(FORWARD);
|
---|
[2950] | 2370 | }
|
---|
[2948] | 2371 |
|
---|
[3127] | 2372 |
|
---|
[3068] | 2373 | /////////////////
|
---|
[3101] | 2374 | //-- reset gl renderState before the final visible objects pass
|
---|
[3068] | 2375 |
|
---|
[3101] | 2376 | renderState.Reset();
|
---|
[3068] | 2377 |
|
---|
[2953] | 2378 | glEnableClientState(GL_NORMAL_ARRAY);
|
---|
[3068] | 2379 | /// switch back to smooth shading
|
---|
[3067] | 2380 | glShadeModel(GL_SMOOTH);
|
---|
[3068] | 2381 | /// reset alpha to coverage flag
|
---|
[3101] | 2382 | renderState.SetUseAlphaToCoverage(true);
|
---|
[3067] | 2383 | // clear color
|
---|
| 2384 | glClear(GL_COLOR_BUFFER_BIT);
|
---|
[3039] | 2385 |
|
---|
[3068] | 2386 | // draw only objects having exactly the same depth as the current sample
|
---|
| 2387 | glDepthFunc(GL_EQUAL);
|
---|
[2951] | 2388 |
|
---|
[2949] | 2389 | //cout << "visible: " << (int)traverser->GetVisibleObjects().size() << endl;
|
---|
| 2390 |
|
---|
[3068] | 2391 | SceneEntityContainer::const_iterator sit,
|
---|
[2801] | 2392 | sit_end = traverser->GetVisibleObjects().end();
|
---|
| 2393 |
|
---|
| 2394 | for (sit = traverser->GetVisibleObjects().begin(); sit != sit_end; ++ sit)
|
---|
[2948] | 2395 | {
|
---|
[2801] | 2396 | renderQueue->Enqueue(*sit);
|
---|
[2948] | 2397 | }
|
---|
[3068] | 2398 | /// now render out everything in one giant pass
|
---|
[2801] | 2399 | renderQueue->Apply();
|
---|
| 2400 |
|
---|
[3068] | 2401 | // switch back to standard depth func
|
---|
[2801] | 2402 | glDepthFunc(GL_LESS);
|
---|
[3101] | 2403 | renderState.Reset();
|
---|
[2949] | 2404 |
|
---|
| 2405 | PrintGLerror("visibleobjects");
|
---|
[2801] | 2406 | }
|
---|
| 2407 |
|
---|
| 2408 |
|
---|
[3120] | 2409 | SceneQuery *GetOrCreateSceneQuery()
|
---|
[2801] | 2410 | {
|
---|
[3037] | 2411 | if (!sceneQuery)
|
---|
[3101] | 2412 | sceneQuery = new SceneQuery(bvh->GetBox(), traverser, &renderState);
|
---|
[3037] | 2413 |
|
---|
[3120] | 2414 | return sceneQuery;
|
---|
| 2415 | }
|
---|
| 2416 |
|
---|
| 2417 |
|
---|
| 2418 | void PlaceViewer(const Vector3 &oldPos)
|
---|
| 2419 | {
|
---|
[2801] | 2420 | Vector3 playerPos = camera->GetPosition();
|
---|
[3120] | 2421 | bool validIntersect = GetOrCreateSceneQuery()->CalcIntersection(playerPos);
|
---|
[2801] | 2422 |
|
---|
[2853] | 2423 | if (validIntersect)
|
---|
[2848] | 2424 | // && ((playerPos.z - oldPos.z) < bvh->GetBox().Size(2) * 1e-1f))
|
---|
[2801] | 2425 | {
|
---|
| 2426 | camera->SetPosition(playerPos);
|
---|
| 2427 | }
|
---|
[2809] | 2428 | }
|
---|
[2948] | 2429 |
|
---|
| 2430 |
|
---|
[2951] | 2431 | void RenderShadowMap(float newfar)
|
---|
[2948] | 2432 | {
|
---|
[2953] | 2433 | glDisableClientState(GL_NORMAL_ARRAY);
|
---|
[3101] | 2434 | renderState.SetRenderTechnique(DEPTH_PASS);
|
---|
[3038] | 2435 |
|
---|
| 2436 | // hack: disable cull face because of alpha textured balconies
|
---|
| 2437 | glDisable(GL_CULL_FACE);
|
---|
[3101] | 2438 | renderState.LockCullFaceEnabled(true);
|
---|
[3068] | 2439 |
|
---|
| 2440 | /// don't use alpha to coverage for the depth map (problems with fbo rendering)
|
---|
[3101] | 2441 | renderState.SetUseAlphaToCoverage(false);
|
---|
[2948] | 2442 |
|
---|
[3101] | 2443 | // change CHC++ set of renderState variables
|
---|
[2980] | 2444 | // this must be done for each change of camera because
|
---|
[2948] | 2445 | // otherwise the temporal coherency is broken
|
---|
[3054] | 2446 | BvhNode::SetCurrentState(LIGHT_PASS);
|
---|
[2948] | 2447 | // hack: temporarily change camera far plane
|
---|
[2951] | 2448 | camera->SetFar(newfar);
|
---|
[2948] | 2449 | // the scene is rendered withouth any shading
|
---|
[3005] | 2450 | shadowMap->ComputeShadowMap(shadowTraverser, viewProjMat);
|
---|
[2948] | 2451 |
|
---|
| 2452 | camera->SetFar(farDist);
|
---|
| 2453 |
|
---|
[3101] | 2454 | renderState.SetUseAlphaToCoverage(true);
|
---|
| 2455 | renderState.LockCullFaceEnabled(false);
|
---|
[3102] | 2456 | glEnable(GL_CULL_FACE);
|
---|
[2948] | 2457 |
|
---|
[2953] | 2458 | glEnableClientState(GL_NORMAL_ARRAY);
|
---|
[3101] | 2459 | // change back renderState
|
---|
[3054] | 2460 | BvhNode::SetCurrentState(CAMERA_PASS);
|
---|
[2952] | 2461 | }
|
---|
[3059] | 2462 |
|
---|
[3068] | 2463 |
|
---|
[3110] | 2464 | /** Touch each material once in order to preload the render queue
|
---|
[3059] | 2465 | bucket id of each material
|
---|
| 2466 | */
|
---|
| 2467 | void PrepareRenderQueue()
|
---|
| 2468 | {
|
---|
| 2469 | for (int i = 0; i < 3; ++ i)
|
---|
| 2470 | {
|
---|
[3101] | 2471 | renderState.SetRenderTechnique(i);
|
---|
[3059] | 2472 |
|
---|
| 2473 | // fill all shapes into the render queue once so we can establish the buckets
|
---|
| 2474 | ShapeContainer::const_iterator sit, sit_end = (*resourceManager->GetShapes()).end();
|
---|
| 2475 |
|
---|
| 2476 | for (sit = (*resourceManager->GetShapes()).begin(); sit != sit_end; ++ sit)
|
---|
| 2477 | {
|
---|
[3071] | 2478 | static Transform3 dummy(IdentityMatrix());
|
---|
[3110] | 2479 | renderQueue->Enqueue(*sit, NULL);
|
---|
[3059] | 2480 | }
|
---|
| 2481 |
|
---|
| 2482 | // just clear queue again
|
---|
| 2483 | renderQueue->Clear();
|
---|
| 2484 | }
|
---|
| 2485 | }
|
---|
| 2486 |
|
---|
| 2487 |
|
---|
[3237] | 2488 | int LoadModel(const string &model, SceneEntityContainer &entities)
|
---|
[3059] | 2489 | {
|
---|
| 2490 | const string filename = string(model_path + model);
|
---|
| 2491 |
|
---|
[3237] | 2492 | int numEntities = 0;
|
---|
| 2493 |
|
---|
[3127] | 2494 | cout << "\nloading model " << filename << endl;
|
---|
[3237] | 2495 |
|
---|
| 2496 | if (numEntities = resourceManager->Load(filename, entities))
|
---|
[3225] | 2497 | {
|
---|
[3127] | 2498 | cout << "model " << filename << " successfully loaded" << endl;
|
---|
[3225] | 2499 | }
|
---|
[3059] | 2500 | else
|
---|
| 2501 | {
|
---|
| 2502 | cerr << "loading model " << filename << " failed" << endl;
|
---|
[3225] | 2503 |
|
---|
[3059] | 2504 | CleanUp();
|
---|
| 2505 | exit(0);
|
---|
| 2506 | }
|
---|
[3237] | 2507 |
|
---|
| 2508 | return numEntities;
|
---|
[3078] | 2509 | }
|
---|
| 2510 |
|
---|
| 2511 |
|
---|
| 2512 | void CreateAnimation()
|
---|
| 2513 | {
|
---|
| 2514 | const float radius = 5.0f;
|
---|
[3080] | 2515 | const Vector3 center(480.398f, 268.364f, 181.3);
|
---|
[3078] | 2516 |
|
---|
| 2517 | VertexArray vertices;
|
---|
| 2518 |
|
---|
[3080] | 2519 | /*for (int i = 0; i < 360; ++ i)
|
---|
[3078] | 2520 | {
|
---|
| 2521 | float angle = (float)i * M_PI / 180.0f;
|
---|
| 2522 |
|
---|
| 2523 | Vector3 offs = Vector3(cos(angle) * radius, sin(angle) * radius, 0);
|
---|
| 2524 | vertices.push_back(center + offs);
|
---|
[3080] | 2525 | }*/
|
---|
| 2526 |
|
---|
| 2527 | for (int i = 0; i < 5; ++ i)
|
---|
| 2528 | {
|
---|
| 2529 | Vector3 offs = Vector3(i, 0, 0);
|
---|
| 2530 | vertices.push_back(center + offs);
|
---|
[3078] | 2531 | }
|
---|
| 2532 |
|
---|
[3080] | 2533 |
|
---|
| 2534 | for (int i = 0; i < 5; ++ i)
|
---|
| 2535 | {
|
---|
| 2536 | Vector3 offs = Vector3(4 -i, 0, 0);
|
---|
| 2537 | vertices.push_back(center + offs);
|
---|
| 2538 | }
|
---|
| 2539 |
|
---|
[3078] | 2540 | motionPath = new MotionPath(vertices);
|
---|
[3214] | 2541 | }
|
---|
| 2542 |
|
---|
[3215] | 2543 | /** This function returns the number of visible pixels of a
|
---|
| 2544 | bounding box representing the sun.
|
---|
| 2545 | */
|
---|
| 2546 | int TestSunVisible()
|
---|
[3214] | 2547 | {
|
---|
| 2548 | // assume sun is at a far away point along the light vector
|
---|
| 2549 | Vector3 sunPos = light->GetDirection() * -1e3f;
|
---|
| 2550 | sunPos += camera->GetPosition();
|
---|
| 2551 |
|
---|
| 2552 | sunBox->GetTransform()->SetMatrix(TranslationMatrix(sunPos));
|
---|
| 2553 |
|
---|
| 2554 | glBeginQueryARB(GL_SAMPLES_PASSED_ARB, sunQuery);
|
---|
| 2555 |
|
---|
| 2556 | sunBox->Render(&renderState);
|
---|
| 2557 |
|
---|
| 2558 | glEndQueryARB(GL_SAMPLES_PASSED_ARB);
|
---|
| 2559 |
|
---|
| 2560 | GLuint sampleCount;
|
---|
| 2561 |
|
---|
| 2562 | glGetQueryObjectuivARB(sunQuery, GL_QUERY_RESULT_ARB, &sampleCount);
|
---|
| 2563 |
|
---|
[3215] | 2564 | return sampleCount;
|
---|
[3214] | 2565 | }
|
---|
[3244] | 2566 |
|
---|
| 2567 |
|
---|
[3245] | 2568 | static Technique GetVizTechnique()
|
---|
| 2569 | {
|
---|
| 2570 | Technique tech;
|
---|
| 2571 | tech.Init();
|
---|
| 2572 |
|
---|
| 2573 | tech.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
|
---|
| 2574 | tech.SetDiffuse(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
|
---|
| 2575 | tech.SetAmbient(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f));
|
---|
| 2576 |
|
---|
| 2577 | return tech;
|
---|
| 2578 | }
|
---|
| 2579 |
|
---|
| 2580 |
|
---|
[3246] | 2581 | void LoadPvs()
|
---|
[3244] | 2582 | {
|
---|
[3245] | 2583 | viewCell = viewCellsTree->GetViewCell(camera->GetPosition());
|
---|
[3244] | 2584 |
|
---|
[3245] | 2585 | int numTriangles = 0;
|
---|
| 2586 |
|
---|
[3251] | 2587 | SceneEntity::SetGlobalVisibleId(globalVisibleId);
|
---|
| 2588 |
|
---|
[3245] | 2589 | for (int i = 0; i < viewCell->mPvs.Size(); ++ i)
|
---|
[3244] | 2590 | {
|
---|
[3245] | 2591 | SceneEntity *ent = viewCell->mPvs.GetEntry(i);
|
---|
[3251] | 2592 |
|
---|
[3245] | 2593 | ent->SetVisibleId(globalVisibleId);
|
---|
[3251] | 2594 | ent->Render(&renderState);
|
---|
[3245] | 2595 |
|
---|
| 2596 | numTriangles += ent->CountNumTriangles();
|
---|
[3244] | 2597 | }
|
---|
[3245] | 2598 |
|
---|
[3251] | 2599 | ++ globalVisibleId;
|
---|
[3246] | 2600 | }
|
---|
[3245] | 2601 |
|
---|
[3246] | 2602 |
|
---|
| 2603 | void LoadVisibilitySolution()
|
---|
| 2604 | {
|
---|
| 2605 | ///////////
|
---|
| 2606 | //-- load the visibility solution
|
---|
| 2607 |
|
---|
| 2608 | const string vis_filename =
|
---|
| 2609 | string(model_path + visibilitySolution + ".vis");
|
---|
| 2610 |
|
---|
| 2611 | VisibilitySolutionLoader visLoader;
|
---|
| 2612 |
|
---|
| 2613 | viewCellsTree = visLoader.Load(vis_filename, bvh);
|
---|
[3247] | 2614 |
|
---|
| 2615 | if (!viewCellsTree)
|
---|
| 2616 | {
|
---|
| 2617 | cerr << "loading pvs failed" << endl;
|
---|
| 2618 | CleanUp();
|
---|
| 2619 | exit(0);
|
---|
| 2620 | }
|
---|
[3246] | 2621 | }
|
---|
| 2622 |
|
---|
| 2623 |
|
---|
| 2624 | void RenderViewCell()
|
---|
| 2625 | {
|
---|
[3245] | 2626 | // render current view cell
|
---|
| 2627 | static Technique vcTechnique = GetVizTechnique();
|
---|
| 2628 |
|
---|
| 2629 | vcTechnique.Render(&renderState);
|
---|
| 2630 | Visualization::RenderBoxForViz(viewCell->GetBox());
|
---|
[3246] | 2631 | } |
---|