00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022 #ifndef __VR3SHADOWCONTROLLER_H__
00023 #define __VR3SHADOWCONTROLLER_H__
00024
00025
00026 #include <unordered_set>
00027
00029
00036 struct VR3ShadowShaderParams {
00038 GLint numactivesources;
00040 GLfloat projmat[16*VR3SDOW_NUM_SOURCES];
00042 GLfloat viewmat[16*VR3SDOW_NUM_SOURCES];
00044 GLfloat znear[VR3SDOW_NUM_SOURCES];
00046 GLfloat zfar[VR3SDOW_NUM_SOURCES];
00048 GLfloat intensity[VR3SDOW_NUM_SOURCES];
00050 GLfloat minvariance[VR3SDOW_NUM_SOURCES];
00052 GLfloat bleedred[VR3SDOW_NUM_SOURCES];
00054 GLfloat depthscale[VR3SDOW_NUM_SOURCES];
00055 };
00056
00058
00230 class VR3ShadowController {
00232 friend class VR3Scene;
00234 friend class VR3Obj;
00235
00237
00243 int m_mode;
00244
00246 static VR3ShadowController* ms_activecontroller;
00247
00249
00253 struct ShadowSource {
00254
00256
00257
00259 bool init;
00261 bool active;
00262
00264
00266
00267
00269 GLuint shadFBO;
00271 GLuint depthRBO;
00273 GLuint shadTex;
00275 GLuint blurFBO;
00277 GLuint blurTex;
00278
00280
00282
00283
00285 GLfloat viewmat[16];
00287 GLfloat projmatfetch[16];
00289 GLfloat projmat[16];
00291 GLfloat znear;
00293 GLfloat zfar;
00295
00304 GLfloat vfvertices[8][3];
00305
00307
00309
00310
00312 GLsizei width;
00314 GLsizei height;
00316 GLfloat mapsize[2];
00317
00319
00321
00322
00324 GLint filtersize;
00326 GLfloat intensity;
00328 GLfloat minvariance;
00330 GLfloat bleedred;
00332 GLfloat depthscale;
00333
00335
00337
00339 GLfloat clearcolor[4];
00340 };
00341
00343 ShadowSource m_sources[VR3SDOW_NUM_SOURCES];
00344
00346
00350 std::unordered_set<VR3Obj*> m_receivers;
00351
00353
00360 std::unordered_set<VR3Obj*> m_casters;
00361
00362
00364 GLuint m_shadowmap_program;
00366 const GLint* m_shadowmap_unilocs;
00367
00369 GLuint m_blur_programs[2];
00371 const GLint* m_blur_unilocs[2];
00372
00374 GLuint m_VAO;
00376 GLuint m_VBO;
00377
00379 VR3ShadowShaderParams m_shadparams;
00380
00382
00387 const GLfloat* m_cursrcviewmat;
00388
00390
00395 const GLfloat* m_cursrcprojmat;
00396
00398
00402 int m_meshcounter;
00403
00405
00406 bool m_face_culling;
00408 bool m_vf_culling;
00410 bool m_source_culling;
00411
00413 VR3ShadowController(const VR3ShadowController&);
00415 VR3ShadowController& operator = (const VR3ShadowController&);
00416
00417
00418
00420
00421
00423
00428 void PrepareVAO();
00429
00431
00432
00433
00435
00436
00438
00452 bool SourceVisibilityTest(const ShadowSource* src);
00453
00455
00456
00457
00459
00460
00462
00479 void DrawShadowMaps();
00480
00482
00483 public:
00484
00485
00486
00488
00489
00491
00496 static VR3ShadowController* GetActiveController()
00497 { return ms_activecontroller; }
00498
00500
00503 void Activate();
00504
00506
00509 void Deactivate();
00510
00512
00513
00514
00516
00517
00519
00527 VR3ShadowController(int mode = VR3SDOWCTRL_AUTOMATIC);
00528
00530
00534 ~VR3ShadowController();
00535
00537
00538
00539
00541
00542
00543 private:
00544
00546
00554 void AutoCastShadows(VR3Obj* obj, bool cast);
00555
00557
00565 void AutoReceiveShadows(VR3Obj* obj, bool receive);
00566
00567 public:
00568
00570
00578 void CastShadows(VR3Obj* obj, bool cast);
00579
00581
00589 void ReceiveShadows(VR3Obj* obj, bool receive);
00590
00592
00597 bool InCasters(VR3Obj* obj)
00598 { return (m_casters.find(obj)!=m_casters.end()); }
00599
00601
00606 bool InReceivers(VR3Obj* obj)
00607 { return (m_receivers.find(obj)!=m_receivers.end()); }
00608
00610
00611
00612
00614
00615
00617
00636 void InitSource( int id,
00637 GLfloat srcposX, GLfloat srcposY, GLfloat srcposZ,
00638 GLfloat srcupX, GLfloat srcupY, GLfloat srcupZ,
00639 GLfloat srctargetX, GLfloat srctargetY, GLfloat srctargetZ,
00640 GLfloat fovy,
00641 GLfloat aspect,
00642 GLfloat znear,
00643 GLfloat zfar,
00644 GLsizei width,
00645 GLsizei height,
00646 GLint filtersize = VR3SDOW_DEF_FILTERSIZE,
00647 GLfloat intensity = VR3SDOW_DEF_INTENSITY,
00648 GLfloat minvariance = VR3SDOW_DEF_MINVARIANCE,
00649 GLfloat bleedred = VR3SDOW_DEF_BLEEDREDUCTION,
00650 GLfloat depthscale = VR3SDOW_DEF_DEPTHSCALE );
00651
00653
00661 void DeinitSource(int id);
00662
00664
00679 void SetFrustumParam( int id,
00680 GLfloat srcposX, GLfloat srcposY, GLfloat srcposZ,
00681 GLfloat srcupX, GLfloat srcupY, GLfloat srcupZ,
00682 GLfloat srctargetX, GLfloat srctargetY, GLfloat srctargetZ,
00683 GLfloat fovy,
00684 GLfloat aspect,
00685 GLfloat znear,
00686 GLfloat zfar );
00687
00689
00698 void SetMapParam( int id,
00699 GLsizei width,
00700 GLsizei height );
00701
00703
00713 void SetAlgorithmParam( int id,
00714 GLint filtersize = VR3SDOW_DEF_FILTERSIZE,
00715 GLfloat intensity = VR3SDOW_DEF_INTENSITY,
00716 GLfloat minvariance = VR3SDOW_DEF_MINVARIANCE,
00717 GLfloat bleedred = VR3SDOW_DEF_BLEEDREDUCTION,
00718 GLfloat depthscale = VR3SDOW_DEF_DEPTHSCALE );
00719
00720
00721
00723
00724
00726
00738 void Enable(int feature, int optional_param = 0);
00739
00741
00753 void Disable(int feature, int optional_param = 0);
00754
00756
00769 bool IsEnabled(int feature, int optional_param = 0);
00770
00772
00778 bool CheckVFCulling()
00779 { return m_vf_culling; }
00780
00782
00783
00784
00786
00787
00789
00793 const VR3ShadowShaderParams* FetchParameters()
00794 { return &m_shadparams; }
00795
00797
00801 const GLfloat* FetchViewMat()
00802 { return m_cursrcviewmat; }
00803
00805
00809 const GLfloat* FetchProjMat()
00810 { return m_cursrcprojmat; }
00811
00813
00817 void IncMeshCounter()
00818 { m_meshcounter++; }
00819
00821
00822
00823
00825
00826
00828
00834 const GLint* GetUniforms()
00835 { return m_shadowmap_unilocs; }
00836
00838 };
00839
00840 #endif