forked from mapbase-source/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewrender.cpp
More file actions
7122 lines (5783 loc) · 223 KB
/
Copy pathviewrender.cpp
File metadata and controls
7122 lines (5783 loc) · 223 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Responsible for drawing the scene
//
//===========================================================================//
#include "cbase.h"
#include "view.h"
#include "iviewrender.h"
#include "view_shared.h"
#include "ivieweffects.h"
#include "iinput.h"
#include "model_types.h"
#include "clientsideeffects.h"
#include "particlemgr.h"
#include "viewrender.h"
#include "iclientmode.h"
#include "voice_status.h"
#include "glow_overlay.h"
#include "materialsystem/imesh.h"
#include "materialsystem/itexture.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"
#include "materialsystem/imaterialsystem.h"
#include "detailobjectsystem.h"
#include "tier0/vprof.h"
#include "tier1/mempool.h"
#include "vstdlib/jobthread.h"
#include "datacache/imdlcache.h"
#include "engine/IEngineTrace.h"
#include "engine/ivmodelinfo.h"
#include "tier0/icommandline.h"
#include "view_scene.h"
#include "particles_ez.h"
#include "engine/IStaticPropMgr.h"
#include "engine/ivdebugoverlay.h"
#include "c_pixel_visibility.h"
#include "clienteffectprecachesystem.h"
#include "c_rope.h"
#include "c_effects.h"
#include "smoke_fog_overlay.h"
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "vgui_int.h"
#include "ienginevgui.h"
#include "ScreenSpaceEffects.h"
#include "toolframework_client.h"
#include "c_func_reflective_glass.h"
#include "KeyValues.h"
#include "renderparm.h"
#include "studio_stats.h"
#include "con_nprint.h"
#include "clientmode_shared.h"
#include "sourcevr/isourcevirtualreality.h"
#include "client_virtualreality.h"
#ifdef TF_CLIENT_DLL
#include "tf/c_tf_player.h"
#endif
#ifdef PORTAL
//#include "C_Portal_Player.h"
#include "portal_render_targets.h"
#include "PortalRender.h"
#endif
#if defined( HL2_CLIENT_DLL ) || defined( CSTRIKE_DLL ) || defined( TF_CLIENT_DLL )
#define USE_MONITORS
#endif
#include "rendertexture.h"
#include "viewpostprocess.h"
#include "viewdebug.h"
#if defined USES_ECON_ITEMS
#include "econ_wearable.h"
#endif
#ifdef USE_MONITORS
#include "c_point_camera.h"
#endif // USE_MONITORS
#ifdef MAPBASE
#include "mapbase/c_func_fake_worldportal.h"
#include "colorcorrectionmgr.h"
#endif
// Projective textures
#include "C_Env_Projected_Texture.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
static void testfreezeframe_f( void )
{
view->FreezeFrame( 3.0 );
}
static ConCommand test_freezeframe( "test_freezeframe", testfreezeframe_f, "Test the freeze frame code.", FCVAR_CHEAT );
//-----------------------------------------------------------------------------
static ConVar r_visocclusion( "r_visocclusion", "0", FCVAR_CHEAT );
extern ConVar r_flashlightdepthtexture;
extern ConVar vcollide_wireframe;
extern ConVar r_depthoverlay;
extern ConVar mat_viewportscale;
extern ConVar mat_viewportupscale;
extern bool g_bDumpRenderTargets;
//-----------------------------------------------------------------------------
// Convars related to controlling rendering
//-----------------------------------------------------------------------------
static ConVar cl_maxrenderable_dist("cl_maxrenderable_dist", "3000", FCVAR_CHEAT, "Max distance from the camera at which things will be rendered" );
ConVar r_entityclips( "r_entityclips", "1" ); //FIXME: Nvidia drivers before 81.94 on cards that support user clip planes will have problems with this, require driver update? Detect and disable?
// Matches the version in the engine
static ConVar r_drawopaqueworld( "r_drawopaqueworld", "1", FCVAR_CHEAT );
static ConVar r_drawtranslucentworld( "r_drawtranslucentworld", "1", FCVAR_CHEAT );
static ConVar r_3dsky( "r_3dsky","1", 0, "Enable the rendering of 3d sky boxes" );
static ConVar r_skybox( "r_skybox","1", FCVAR_CHEAT, "Enable the rendering of sky boxes" );
#ifdef TF_CLIENT_DLL
ConVar r_drawviewmodel( "r_drawviewmodel","1", FCVAR_DONTRECORD );
#else
ConVar r_drawviewmodel( "r_drawviewmodel","1", FCVAR_CHEAT );
#endif
static ConVar r_drawtranslucentrenderables( "r_drawtranslucentrenderables", "1", FCVAR_CHEAT );
static ConVar r_drawopaquerenderables( "r_drawopaquerenderables", "1", FCVAR_CHEAT );
static ConVar r_threaded_renderables( "r_threaded_renderables", "0" );
#ifdef MAPBASE
static ConVar r_skybox_use_complex_views( "r_skybox_use_complex_views", "0", FCVAR_CHEAT, "Enable complex views in skyboxes, like reflective glass" );
#endif
// FIXME: This is not static because we needed to turn it off for TF2 playtests
ConVar r_DrawDetailProps( "r_DrawDetailProps", "1", FCVAR_NONE, "0=Off, 1=Normal, 2=Wireframe" );
ConVar r_worldlistcache( "r_worldlistcache", "1" );
//-----------------------------------------------------------------------------
// Convars related to fog color
//-----------------------------------------------------------------------------
static ConVar fog_override( "fog_override", "0", FCVAR_CHEAT );
// set any of these to use the maps fog
static ConVar fog_start( "fog_start", "-1", FCVAR_CHEAT );
static ConVar fog_end( "fog_end", "-1", FCVAR_CHEAT );
static ConVar fog_color( "fog_color", "-1 -1 -1", FCVAR_CHEAT );
static ConVar fog_enable( "fog_enable", "-1", FCVAR_CHEAT );
static ConVar fog_startskybox( "fog_startskybox", "-1", FCVAR_CHEAT );
static ConVar fog_endskybox( "fog_endskybox", "-1", FCVAR_CHEAT );
static ConVar fog_maxdensityskybox( "fog_maxdensityskybox", "-1", FCVAR_CHEAT );
static ConVar fog_colorskybox( "fog_colorskybox", "-1 -1 -1", FCVAR_CHEAT );
static ConVar fog_enableskybox( "fog_enableskybox", "-1", FCVAR_CHEAT );
static ConVar fog_maxdensity( "fog_maxdensity", "-1", FCVAR_CHEAT );
static ConVar fog_radial( "fog_radial", "-1", FCVAR_CHEAT );
static ConVar fog_radialskybox( "fog_radialskybox", "-1", FCVAR_CHEAT );
//-----------------------------------------------------------------------------
// Water-related convars
//-----------------------------------------------------------------------------
static ConVar r_debugcheapwater( "r_debugcheapwater", "0", FCVAR_CHEAT );
#ifndef _X360
static ConVar r_waterforceexpensive( "r_waterforceexpensive", "0", FCVAR_ARCHIVE );
#endif
static ConVar r_waterforcereflectentities( "r_waterforcereflectentities", "0", FCVAR_ALLOWED_IN_COMPETITIVE );
static ConVar r_WaterDrawRefraction( "r_WaterDrawRefraction", "1", 0, "Enable water refraction" );
static ConVar r_WaterDrawReflection( "r_WaterDrawReflection", "1", 0, "Enable water reflection" );
static ConVar r_ForceWaterLeaf( "r_ForceWaterLeaf", "1", 0, "Enable for optimization to water - considers view in leaf under water for purposes of culling" );
static ConVar mat_drawwater( "mat_drawwater", "1", FCVAR_CHEAT );
static ConVar mat_clipz( "mat_clipz", "1" );
//-----------------------------------------------------------------------------
// Other convars
//-----------------------------------------------------------------------------
static ConVar r_screenfademinsize( "r_screenfademinsize", "0" );
static ConVar r_screenfademaxsize( "r_screenfademaxsize", "0" );
static ConVar cl_drawmonitors( "cl_drawmonitors", "1" );
static ConVar r_eyewaterepsilon( "r_eyewaterepsilon", "10.0f", FCVAR_CHEAT );
#ifdef TF_CLIENT_DLL
static ConVar pyro_dof( "pyro_dof", "1", FCVAR_ARCHIVE );
#endif
extern ConVar cl_leveloverview;
extern ConVar localplayer_visionflags;
#ifdef MAPBASE
static ConVar r_nearz_skybox( "r_nearz_skybox", "2.0", FCVAR_CHEAT );
#endif
//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
static Vector g_vecCurrentRenderOrigin(0,0,0);
static QAngle g_vecCurrentRenderAngles(0,0,0);
static Vector g_vecCurrentVForward(0,0,0), g_vecCurrentVRight(0,0,0), g_vecCurrentVUp(0,0,0);
static VMatrix g_matCurrentCamInverse;
bool s_bCanAccessCurrentView = false;
IntroData_t *g_pIntroData = NULL;
static bool g_bRenderingView = false; // For debugging...
static int g_CurrentViewID = VIEW_NONE;
bool g_bRenderingScreenshot = false;
#define FREEZECAM_SNAPSHOT_FADE_SPEED 340
float g_flFreezeFlash = 0.0f;
//-----------------------------------------------------------------------------
CON_COMMAND( r_cheapwaterstart, "" )
{
if( args.ArgC() == 2 )
{
float dist = atof( args[ 1 ] );
view->SetCheapWaterStartDistance( dist );
}
else
{
float start, end;
view->GetWaterLODParams( start, end );
Warning( "r_cheapwaterstart: %f\n", start );
}
}
CON_COMMAND( r_cheapwaterend, "" )
{
if( args.ArgC() == 2 )
{
float dist = atof( args[ 1 ] );
view->SetCheapWaterEndDistance( dist );
}
else
{
float start, end;
view->GetWaterLODParams( start, end );
Warning( "r_cheapwaterend: %f\n", end );
}
}
//-----------------------------------------------------------------------------
// Describes a pruned set of leaves to be rendered this view. Reference counted
// because potentially shared by a number of views
//-----------------------------------------------------------------------------
struct ClientWorldListInfo_t : public CRefCounted1<WorldListInfo_t>
{
ClientWorldListInfo_t()
{
memset( (WorldListInfo_t *)this, 0, sizeof(WorldListInfo_t) );
m_pActualLeafIndex = NULL;
m_bPooledAlloc = false;
}
// Allocate a list intended for pruning
static ClientWorldListInfo_t *AllocPooled( const ClientWorldListInfo_t &exemplar );
// Because we remap leaves to eliminate unused leaves, we need a remap
// when drawing translucent surfaces, which requires the *original* leaf index
// using m_pActualLeafMap[ remapped leaf index ] == actual leaf index
LeafIndex_t *m_pActualLeafIndex;
private:
virtual bool OnFinalRelease();
bool m_bPooledAlloc;
static CObjectPool<ClientWorldListInfo_t> gm_Pool;
};
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
class CWorldListCache
{
public:
CWorldListCache()
{
}
void Flush()
{
for ( int i = m_Entries.FirstInorder(); i != m_Entries.InvalidIndex(); i = m_Entries.NextInorder( i ) )
{
delete m_Entries[i];
}
m_Entries.RemoveAll();
}
bool Find( const CViewSetup &viewSetup, IWorldRenderList **ppList, ClientWorldListInfo_t **ppListInfo )
{
Entry_t lookup( viewSetup );
int i = m_Entries.Find( &lookup );
if ( i != m_Entries.InvalidIndex() )
{
Entry_t *pEntry = m_Entries[i];
*ppList = InlineAddRef( pEntry->pList );
*ppListInfo = InlineAddRef( pEntry->pListInfo );
return true;
}
return false;
}
void Add( const CViewSetup &viewSetup, IWorldRenderList *pList, ClientWorldListInfo_t *pListInfo )
{
m_Entries.Insert( new Entry_t( viewSetup, pList, pListInfo ) );
}
private:
struct Entry_t
{
Entry_t( const CViewSetup &viewSetup, IWorldRenderList *pList = NULL, ClientWorldListInfo_t *pListInfo = NULL ) :
pList( ( pList ) ? InlineAddRef( pList ) : NULL ),
pListInfo( ( pListInfo ) ? InlineAddRef( pListInfo ) : NULL )
{
// @NOTE (toml 8/18/2006): because doing memcmp, need to fill all of the fields and the padding!
memset( &m_bOrtho, 0, offsetof(Entry_t, pList ) - offsetof(Entry_t, m_bOrtho ) );
m_bOrtho = viewSetup.m_bOrtho;
m_OrthoLeft = viewSetup.m_OrthoLeft;
m_OrthoTop = viewSetup.m_OrthoTop;
m_OrthoRight = viewSetup.m_OrthoRight;
m_OrthoBottom = viewSetup.m_OrthoBottom;
fov = viewSetup.fov;
origin = viewSetup.origin;
angles = viewSetup.angles;
zNear = viewSetup.zNear;
zFar = viewSetup.zFar;
m_flAspectRatio = viewSetup.m_flAspectRatio;
m_bOffCenter = viewSetup.m_bOffCenter;
m_flOffCenterTop = viewSetup.m_flOffCenterTop;
m_flOffCenterBottom = viewSetup.m_flOffCenterBottom;
m_flOffCenterLeft = viewSetup.m_flOffCenterLeft;
m_flOffCenterRight = viewSetup.m_flOffCenterRight;
}
~Entry_t()
{
if ( pList )
pList->Release();
if ( pListInfo )
pListInfo->Release();
}
// The fields from CViewSetup that would actually affect the list
float m_OrthoLeft;
float m_OrthoTop;
float m_OrthoRight;
float m_OrthoBottom;
float fov;
Vector origin;
QAngle angles;
float zNear;
float zFar;
float m_flAspectRatio;
float m_flOffCenterTop;
float m_flOffCenterBottom;
float m_flOffCenterLeft;
float m_flOffCenterRight;
bool m_bOrtho;
bool m_bOffCenter;
IWorldRenderList *pList;
ClientWorldListInfo_t *pListInfo;
};
class CEntryComparator
{
public:
CEntryComparator( int ) {}
bool operator!() const { return false; }
bool operator()( const Entry_t *lhs, const Entry_t *rhs ) const
{
return ( memcmp( lhs, rhs, sizeof(Entry_t) - ( sizeof(Entry_t) - offsetof(Entry_t, pList ) ) ) < 0 );
}
};
CUtlRBTree<Entry_t *, unsigned short, CEntryComparator> m_Entries;
};
CWorldListCache g_WorldListCache;
//-----------------------------------------------------------------------------
// Standard 3d skybox view
//-----------------------------------------------------------------------------
class CSkyboxView : public CRendering3dView
{
DECLARE_CLASS( CSkyboxView, CRendering3dView );
public:
CSkyboxView(CViewRender *pMainView) :
CRendering3dView( pMainView ),
m_pSky3dParams( NULL )
{
}
bool Setup( const CViewSetup &view, int *pClearFlags, SkyboxVisibility_t *pSkyboxVisible );
void Draw();
protected:
#ifdef PORTAL
virtual bool ShouldDrawPortals() { return false; }
#endif
virtual SkyboxVisibility_t ComputeSkyboxVisibility();
bool GetSkyboxFogEnable();
void Enable3dSkyboxFog( void );
void DrawInternal( view_id_t iSkyBoxViewID, bool bInvokePreAndPostRender, ITexture *pRenderTarget, ITexture *pDepthTarget );
sky3dparams_t * PreRender3dSkyboxWorld( SkyboxVisibility_t nSkyboxVisible );
sky3dparams_t *m_pSky3dParams;
};
//-----------------------------------------------------------------------------
// 3d skybox view when drawing portals
//-----------------------------------------------------------------------------
#ifdef PORTAL
class CPortalSkyboxView : public CSkyboxView
{
DECLARE_CLASS( CPortalSkyboxView, CSkyboxView );
public:
CPortalSkyboxView(CViewRender *pMainView) :
CSkyboxView( pMainView ),
m_pRenderTarget( NULL )
{}
bool Setup( const CViewSetup &view, int *pClearFlags, SkyboxVisibility_t *pSkyboxVisible, ITexture *pRenderTarget = NULL );
//Skybox drawing through portals with workarounds to fix area bits, position/scaling, view id's..........
void Draw();
private:
virtual SkyboxVisibility_t ComputeSkyboxVisibility();
ITexture *m_pRenderTarget;
};
#endif
//-----------------------------------------------------------------------------
// Shadow depth texture
//-----------------------------------------------------------------------------
class CShadowDepthView : public CRendering3dView
{
DECLARE_CLASS( CShadowDepthView, CRendering3dView );
public:
CShadowDepthView(CViewRender *pMainView) : CRendering3dView( pMainView ) {}
void Setup( const CViewSetup &shadowViewIn, ITexture *pRenderTarget, ITexture *pDepthTexture );
void Draw();
private:
ITexture *m_pRenderTarget;
ITexture *m_pDepthTexture;
};
//-----------------------------------------------------------------------------
// Freeze frame. Redraws the frame at which it was enabled.
//-----------------------------------------------------------------------------
class CFreezeFrameView : public CRendering3dView
{
DECLARE_CLASS( CFreezeFrameView, CRendering3dView );
public:
CFreezeFrameView(CViewRender *pMainView) : CRendering3dView( pMainView ) {}
void Setup( const CViewSetup &view );
void Draw();
private:
CMaterialReference m_pFreezeFrame;
CMaterialReference m_TranslucentSingleColor;
};
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
class CBaseWorldView : public CRendering3dView
{
DECLARE_CLASS( CBaseWorldView, CRendering3dView );
protected:
CBaseWorldView(CViewRender *pMainView) : CRendering3dView( pMainView ) {}
virtual bool AdjustView( float waterHeight );
void DrawSetup( float waterHeight, int flags, float waterZAdjust, int iForceViewLeaf = -1 );
void DrawExecute( float waterHeight, view_id_t viewID, float waterZAdjust );
virtual void PushView( float waterHeight );
virtual void PopView();
void SSAO_DepthPass();
void DrawDepthOfField();
#ifdef MAPBASE
virtual ITexture *GetRefractionTexture() { return GetWaterRefractionTexture(); }
virtual ITexture *GetReflectionTexture() { return GetWaterReflectionTexture(); }
#endif
};
//-----------------------------------------------------------------------------
// Draws the scene when there's no water or only cheap water
//-----------------------------------------------------------------------------
class CSimpleWorldView : public CBaseWorldView
{
DECLARE_CLASS( CSimpleWorldView, CBaseWorldView );
public:
CSimpleWorldView(CViewRender *pMainView) : CBaseWorldView( pMainView ) {}
void Setup( const CViewSetup &view, int nClearFlags, bool bDrawSkybox, const VisibleFogVolumeInfo_t &fogInfo, const WaterRenderInfo_t& info, ViewCustomVisibility_t *pCustomVisibility = NULL );
void Draw();
private:
VisibleFogVolumeInfo_t m_fogInfo;
};
//-----------------------------------------------------------------------------
// Base class for scenes with water
//-----------------------------------------------------------------------------
class CBaseWaterView : public CBaseWorldView
{
DECLARE_CLASS( CBaseWaterView, CBaseWorldView );
public:
CBaseWaterView(CViewRender *pMainView) :
CBaseWorldView( pMainView ),
m_SoftwareIntersectionView( pMainView )
{}
// void Setup( const CViewSetup &, const WaterRenderInfo_t& info );
protected:
void CalcWaterEyeAdjustments( const VisibleFogVolumeInfo_t &fogInfo, float &newWaterHeight, float &waterZAdjust, bool bSoftwareUserClipPlane );
class CSoftwareIntersectionView : public CBaseWorldView
{
DECLARE_CLASS( CSoftwareIntersectionView, CBaseWorldView );
public:
CSoftwareIntersectionView(CViewRender *pMainView) : CBaseWorldView( pMainView ) {}
void Setup( bool bAboveWater );
void Draw();
private:
CBaseWaterView *GetOuter() { return GET_OUTER( CBaseWaterView, m_SoftwareIntersectionView ); }
};
friend class CSoftwareIntersectionView;
CSoftwareIntersectionView m_SoftwareIntersectionView;
WaterRenderInfo_t m_waterInfo;
float m_waterHeight;
float m_waterZAdjust;
bool m_bSoftwareUserClipPlane;
VisibleFogVolumeInfo_t m_fogInfo;
};
//-----------------------------------------------------------------------------
// Scenes above water
//-----------------------------------------------------------------------------
class CAboveWaterView : public CBaseWaterView
{
DECLARE_CLASS( CAboveWaterView, CBaseWaterView );
public:
CAboveWaterView(CViewRender *pMainView) :
CBaseWaterView( pMainView ),
m_ReflectionView( pMainView ),
m_RefractionView( pMainView ),
m_IntersectionView( pMainView )
{}
void Setup( const CViewSetup &view, bool bDrawSkybox, const VisibleFogVolumeInfo_t &fogInfo, const WaterRenderInfo_t& waterInfo );
void Draw();
class CReflectionView : public CBaseWorldView
{
DECLARE_CLASS( CReflectionView, CBaseWorldView );
public:
CReflectionView(CViewRender *pMainView) : CBaseWorldView( pMainView ) {}
void Setup( bool bReflectEntities );
void Draw();
private:
CAboveWaterView *GetOuter() { return GET_OUTER( CAboveWaterView, m_ReflectionView ); }
};
class CRefractionView : public CBaseWorldView
{
DECLARE_CLASS( CRefractionView, CBaseWorldView );
public:
CRefractionView(CViewRender *pMainView) : CBaseWorldView( pMainView ) {}
void Setup();
void Draw();
private:
CAboveWaterView *GetOuter() { return GET_OUTER( CAboveWaterView, m_RefractionView ); }
};
class CIntersectionView : public CBaseWorldView
{
DECLARE_CLASS( CIntersectionView, CBaseWorldView );
public:
CIntersectionView(CViewRender *pMainView) : CBaseWorldView( pMainView ) {}
void Setup();
void Draw();
private:
CAboveWaterView *GetOuter() { return GET_OUTER( CAboveWaterView, m_IntersectionView ); }
};
friend class CRefractionView;
friend class CReflectionView;
friend class CIntersectionView;
bool m_bViewIntersectsWater;
CReflectionView m_ReflectionView;
CRefractionView m_RefractionView;
CIntersectionView m_IntersectionView;
};
//-----------------------------------------------------------------------------
// Scenes below water
//-----------------------------------------------------------------------------
class CUnderWaterView : public CBaseWaterView
{
DECLARE_CLASS( CUnderWaterView, CBaseWaterView );
public:
CUnderWaterView(CViewRender *pMainView) :
CBaseWaterView( pMainView ),
m_RefractionView( pMainView )
{}
void Setup( const CViewSetup &view, bool bDrawSkybox, const VisibleFogVolumeInfo_t &fogInfo, const WaterRenderInfo_t& info );
void Draw();
class CRefractionView : public CBaseWorldView
{
DECLARE_CLASS( CRefractionView, CBaseWorldView );
public:
CRefractionView(CViewRender *pMainView) : CBaseWorldView( pMainView ) {}
void Setup();
void Draw();
private:
CUnderWaterView *GetOuter() { return GET_OUTER( CUnderWaterView, m_RefractionView ); }
};
friend class CRefractionView;
bool m_bDrawSkybox; // @MULTICORE (toml 8/17/2006): remove after setup hoisted
CRefractionView m_RefractionView;
};
//-----------------------------------------------------------------------------
// Scenes containing reflective glass
//-----------------------------------------------------------------------------
class CReflectiveGlassView : public CSimpleWorldView
{
DECLARE_CLASS( CReflectiveGlassView, CSimpleWorldView );
public:
CReflectiveGlassView( CViewRender *pMainView ) : BaseClass( pMainView )
{
}
virtual bool AdjustView( float flWaterHeight );
virtual void PushView( float waterHeight );
virtual void PopView( );
void Setup( const CViewSetup &view, int nClearFlags, bool bDrawSkybox, const VisibleFogVolumeInfo_t &fogInfo, const WaterRenderInfo_t &waterInfo, const cplane_t &reflectionPlane );
void Draw();
cplane_t m_ReflectionPlane;
#ifdef MAPBASE
ITexture *GetReflectionTexture() { return m_pRenderTarget; }
ITexture *m_pRenderTarget;
#endif
};
class CRefractiveGlassView : public CSimpleWorldView
{
DECLARE_CLASS( CRefractiveGlassView, CSimpleWorldView );
public:
CRefractiveGlassView( CViewRender *pMainView ) : BaseClass( pMainView )
{
}
virtual bool AdjustView( float flWaterHeight );
virtual void PushView( float waterHeight );
virtual void PopView( );
void Setup( const CViewSetup &view, int nClearFlags, bool bDrawSkybox, const VisibleFogVolumeInfo_t &fogInfo, const WaterRenderInfo_t &waterInfo, const cplane_t &reflectionPlane );
void Draw();
cplane_t m_ReflectionPlane;
#ifdef MAPBASE
ITexture *GetRefractionTexture() { return m_pRenderTarget; }
ITexture *m_pRenderTarget;
#endif
};
//-----------------------------------------------------------------------------
// Computes draw flags for the engine to build its world surface lists
//-----------------------------------------------------------------------------
static inline unsigned long BuildEngineDrawWorldListFlags( unsigned nDrawFlags )
{
unsigned long nEngineFlags = 0;
if ( nDrawFlags & DF_DRAWSKYBOX )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_SKYBOX;
}
if ( nDrawFlags & DF_RENDER_ABOVEWATER )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_STRICTLYABOVEWATER;
nEngineFlags |= DRAWWORLDLISTS_DRAW_INTERSECTSWATER;
}
if ( nDrawFlags & DF_RENDER_UNDERWATER )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_STRICTLYUNDERWATER;
nEngineFlags |= DRAWWORLDLISTS_DRAW_INTERSECTSWATER;
}
if ( nDrawFlags & DF_RENDER_WATER )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_WATERSURFACE;
}
if( nDrawFlags & DF_CLIP_SKYBOX )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_CLIPSKYBOX;
}
if( nDrawFlags & DF_SHADOW_DEPTH_MAP )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_SHADOWDEPTH;
}
if( nDrawFlags & DF_RENDER_REFRACTION )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_REFRACTION;
}
if( nDrawFlags & DF_RENDER_REFLECTION )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_REFLECTION;
}
if( nDrawFlags & DF_SSAO_DEPTH_PASS )
{
nEngineFlags |= DRAWWORLDLISTS_DRAW_SSAO | DRAWWORLDLISTS_DRAW_STRICTLYUNDERWATER | DRAWWORLDLISTS_DRAW_INTERSECTSWATER | DRAWWORLDLISTS_DRAW_STRICTLYABOVEWATER ;
nEngineFlags &= ~( DRAWWORLDLISTS_DRAW_WATERSURFACE | DRAWWORLDLISTS_DRAW_REFRACTION | DRAWWORLDLISTS_DRAW_REFLECTION );
}
return nEngineFlags;
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
static void SetClearColorToFogColor()
{
unsigned char ucFogColor[3];
CMatRenderContextPtr pRenderContext( materials );
pRenderContext->GetFogColor( ucFogColor );
if( g_pMaterialSystemHardwareConfig->GetHDRType() == HDR_TYPE_INTEGER )
{
// @MULTICORE (toml 8/16/2006): Find a way to not do this twice in eye above water case
float scale = LinearToGammaFullRange( pRenderContext->GetToneMappingScaleLinear().x );
ucFogColor[0] *= scale;
ucFogColor[1] *= scale;
ucFogColor[2] *= scale;
}
pRenderContext->ClearColor4ub( ucFogColor[0], ucFogColor[1], ucFogColor[2], 255 );
}
//-----------------------------------------------------------------------------
// Precache of necessary materials
//-----------------------------------------------------------------------------
#ifdef HL2_CLIENT_DLL
CLIENTEFFECT_REGISTER_BEGIN( PrecacheViewRender )
CLIENTEFFECT_MATERIAL( "scripted/intro_screenspaceeffect" )
CLIENTEFFECT_REGISTER_END()
#endif
CLIENTEFFECT_REGISTER_BEGIN( PrecachePostProcessingEffects )
CLIENTEFFECT_MATERIAL( "dev/blurfiltery_and_add_nohdr" )
CLIENTEFFECT_MATERIAL( "dev/blurfilterx" )
CLIENTEFFECT_MATERIAL( "dev/blurfilterx_nohdr" )
CLIENTEFFECT_MATERIAL( "dev/blurfiltery" )
CLIENTEFFECT_MATERIAL( "dev/blurfiltery_nohdr" )
CLIENTEFFECT_MATERIAL( "dev/bloomadd" )
CLIENTEFFECT_MATERIAL( "dev/downsample" )
#ifdef CSTRIKE_DLL
CLIENTEFFECT_MATERIAL( "dev/downsample_non_hdr_cstrike" )
#else
CLIENTEFFECT_MATERIAL( "dev/downsample_non_hdr" )
#endif
CLIENTEFFECT_MATERIAL( "dev/no_pixel_write" )
CLIENTEFFECT_MATERIAL( "dev/lumcompare" )
CLIENTEFFECT_MATERIAL( "dev/floattoscreen_combine" )
CLIENTEFFECT_MATERIAL( "dev/copyfullframefb_vanilla" )
CLIENTEFFECT_MATERIAL( "dev/copyfullframefb" )
CLIENTEFFECT_MATERIAL( "dev/engine_post" )
CLIENTEFFECT_MATERIAL( "dev/depth_of_field" )
CLIENTEFFECT_MATERIAL( "dev/blurgaussian_3x3" )
CLIENTEFFECT_MATERIAL( "dev/motion_blur" )
CLIENTEFFECT_MATERIAL( "dev/upscale" )
#ifdef TF_CLIENT_DLL
CLIENTEFFECT_MATERIAL( "dev/pyro_blur_filter_y" )
CLIENTEFFECT_MATERIAL( "dev/pyro_blur_filter_x" )
CLIENTEFFECT_MATERIAL( "dev/pyro_dof" )
CLIENTEFFECT_MATERIAL( "dev/pyro_vignette_border" )
CLIENTEFFECT_MATERIAL( "dev/pyro_vignette" )
CLIENTEFFECT_MATERIAL( "dev/pyro_post" )
#endif
CLIENTEFFECT_REGISTER_END_CONDITIONAL( engine->GetDXSupportLevel() >= 90 )
//-----------------------------------------------------------------------------
// Accessors to return the current view being rendered
//-----------------------------------------------------------------------------
const Vector &CurrentViewOrigin()
{
Assert( s_bCanAccessCurrentView );
return g_vecCurrentRenderOrigin;
}
const QAngle &CurrentViewAngles()
{
Assert( s_bCanAccessCurrentView );
return g_vecCurrentRenderAngles;
}
const Vector &CurrentViewForward()
{
Assert( s_bCanAccessCurrentView );
return g_vecCurrentVForward;
}
const Vector &CurrentViewRight()
{
Assert( s_bCanAccessCurrentView );
return g_vecCurrentVRight;
}
const Vector &CurrentViewUp()
{
Assert( s_bCanAccessCurrentView );
return g_vecCurrentVUp;
}
const VMatrix &CurrentWorldToViewMatrix()
{
Assert( s_bCanAccessCurrentView );
return g_matCurrentCamInverse;
}
//-----------------------------------------------------------------------------
// Methods to set the current view/guard access to view parameters
//-----------------------------------------------------------------------------
void AllowCurrentViewAccess( bool allow )
{
s_bCanAccessCurrentView = allow;
}
bool IsCurrentViewAccessAllowed()
{
return s_bCanAccessCurrentView;
}
void SetupCurrentView( const Vector &vecOrigin, const QAngle &angles, view_id_t viewID )
{
tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s", __FUNCTION__ );
// Store off view origin and angles
g_vecCurrentRenderOrigin = vecOrigin;
g_vecCurrentRenderAngles = angles;
// Compute the world->main camera transform
ComputeCameraVariables( vecOrigin, angles,
&g_vecCurrentVForward, &g_vecCurrentVRight, &g_vecCurrentVUp, &g_matCurrentCamInverse );
g_CurrentViewID = viewID;
s_bCanAccessCurrentView = true;
// Cache off fade distances
float flScreenFadeMinSize, flScreenFadeMaxSize;
view->GetScreenFadeDistances( &flScreenFadeMinSize, &flScreenFadeMaxSize );
modelinfo->SetViewScreenFadeRange( flScreenFadeMinSize, flScreenFadeMaxSize );
CMatRenderContextPtr pRenderContext( materials );
#ifdef PORTAL
if ( g_pPortalRender->GetViewRecursionLevel() == 0 )
{
pRenderContext->SetIntRenderingParameter( INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA, ((viewID == VIEW_MAIN) || (viewID == VIEW_3DSKY)) ? 1 : 0 );
}
#else
pRenderContext->SetIntRenderingParameter( INT_RENDERPARM_WRITE_DEPTH_TO_DESTALPHA, ((viewID == VIEW_MAIN) || (viewID == VIEW_3DSKY)) ? 1 : 0 );
#endif
}
view_id_t CurrentViewID()
{
Assert( g_CurrentViewID != VIEW_ILLEGAL );
return ( view_id_t )g_CurrentViewID;
}
//-----------------------------------------------------------------------------
// Purpose: Portal views are considered 'Main' views. This function tests a view id
// against all view ids used by portal renderables, as well as the main view.
//-----------------------------------------------------------------------------
bool IsMainView ( view_id_t id )
{
#if defined(PORTAL)
return ( (id == VIEW_MAIN) || g_pPortalRender->IsPortalViewID( id ) );
#else
return (id == VIEW_MAIN);
#endif
}
void FinishCurrentView()
{
s_bCanAccessCurrentView = false;
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
void CSimpleRenderExecutor::AddView( CRendering3dView *pView )
{
CBase3dView *pPrevRenderer = m_pMainView->SetActiveRenderer( pView );
pView->Draw();
m_pMainView->SetActiveRenderer( pPrevRenderer );
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CViewRender::CViewRender()
: m_SimpleExecutor( this )
{
m_flCheapWaterStartDistance = 0.0f;
m_flCheapWaterEndDistance = 0.1f;
m_BaseDrawFlags = 0;
m_pActiveRenderer = NULL;
m_pCurrentlyDrawingEntity = NULL;
m_szCurrentScriptMaterialName[0] = '\0';
}
//-----------------------------------------------------------------------------
// Purpose: Called once per level change
//-----------------------------------------------------------------------------
void CViewRender::LevelShutdown( void )
{
g_pScreenSpaceEffects->ShutdownScreenSpaceEffects();
g_CurrentViewID = VIEW_NONE;
m_ScriptOverlayMaterial.Shutdown();
m_szCurrentScriptMaterialName[0] = '\0';
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
inline bool CViewRender::ShouldDrawEntities( void )
{
return ( !m_pDrawEntities || (m_pDrawEntities->GetInt() != 0) );
}
//-----------------------------------------------------------------------------