forked from themrdemonized/xray-monolith
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathr__dsgraph_render.cpp
More file actions
885 lines (783 loc) · 23.9 KB
/
r__dsgraph_render.cpp
File metadata and controls
885 lines (783 loc) · 23.9 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
#include "stdafx.h"
#include "../../xrEngine/render.h"
#include "../../xrEngine/irenderable.h"
#include "../../xrEngine/igame_persistent.h"
#include "../../xrEngine/environment.h"
#include "../../xrEngine/CustomHUD.h"
#include "FBasicVisual.h"
using namespace R_dsgraph;
extern float r_ssaDISCARD;
extern float r_ssaDONTSORT;
extern float r_ssaHZBvsTEX;
extern float r_ssaGLOD_start, r_ssaGLOD_end;
extern ENGINE_API float psHUD_FOV;
ICF float calcLOD(float ssa/*fDistSq*/, float R)
{
return _sqrt(clampr((ssa - r_ssaGLOD_end) / (r_ssaGLOD_start - r_ssaGLOD_end), 0.f, 1.f));
}
// NORMAL
IC bool cmp_normal_items(const _NormalItem& N1, const _NormalItem& N2)
{
return (N1.ssa > N2.ssa);
}
void __fastcall mapNormal_Render(mapNormalItems& N)
{
// *** DIRECT ***
std::sort(N.begin(), N.end(), cmp_normal_items);
_NormalItem *I = &*N.begin(), *E = &*N.end();
for (; I != E; I++)
{
_NormalItem& Ni = *I;
float LOD = calcLOD(Ni.ssa, Ni.pVisual->vis.sphere.R);
#ifdef USE_DX11
RCache.LOD.set_LOD(LOD);
#endif
Ni.pVisual->Render(LOD);
}
}
// Matrix
IC bool cmp_matrix_items(const _MatrixItem& N1, const _MatrixItem& N2)
{
return (N1.ssa > N2.ssa);
}
void __fastcall mapMatrix_Render(mapMatrixItems& N)
{
// *** DIRECT ***
std::sort(N.begin(), N.end(), cmp_matrix_items);
_MatrixItem *I = &*N.begin(), *E = &*N.end();
for (; I != E; I++)
{
_MatrixItem& Ni = *I;
RCache.set_xform_world(Ni.Matrix);
RImplementation.apply_object(Ni.pObject);
RImplementation.apply_lmaterial();
float LOD = calcLOD(Ni.ssa, Ni.pVisual->vis.sphere.R);
#ifdef USE_DX11
RCache.LOD.set_LOD(LOD);
#endif
Ni.pVisual->Render(LOD);
}
N.clear();
}
// ALPHA
void __fastcall sorted_L1(mapSorted_Node* N)
{
VERIFY(N);
dxRender_Visual* V = N->val.pVisual;
VERIFY(V && V->shader._get());
RCache.set_Element(N->val.se);
RCache.set_xform_world(N->val.Matrix);
RImplementation.apply_object(N->val.pObject);
RImplementation.apply_lmaterial();
V->Render(calcLOD(N->key, V->vis.sphere.R));
}
void __fastcall sorted_L1_nops(mapSorted_Node * N)
{
VERIFY(N);
dxRender_Visual * V = N->val.pVisual;
VERIFY(V && V->shader._get());
RCache.set_Element(N->val.se);
#ifdef USE_DX11
RCache.set_PS(RImplementation.Target->s_ssfx_dumb->E[0]->passes[0]->ps);
#endif
RCache.set_xform_world(N->val.Matrix);
V->Render(0);
}
IC bool cmp_vs_nrm(mapNormalVS::TNode* N1, mapNormalVS::TNode* N2)
{
return (N1->val.ssa > N2->val.ssa);
}
IC bool cmp_vs_mat(mapMatrixVS::TNode* N1, mapMatrixVS::TNode* N2)
{
return (N1->val.ssa > N2->val.ssa);
}
IC bool cmp_ps_nrm(mapNormalPS::TNode* N1, mapNormalPS::TNode* N2)
{
#ifdef USE_DX11
return (N1->val.mapCS.ssa > N2->val.mapCS.ssa);
#else
return (N1->val.ssa > N2->val.ssa);
#endif
}
IC bool cmp_ps_mat(mapMatrixPS::TNode* N1, mapMatrixPS::TNode* N2)
{
#ifdef USE_DX11
return (N1->val.mapCS.ssa > N2->val.mapCS.ssa);
#else
return (N1->val.ssa > N2->val.ssa);
#endif
}
#if defined(USE_DX10) || defined(USE_DX11)
IC bool cmp_gs_nrm(mapNormalGS::TNode* N1, mapNormalGS::TNode* N2) { return (N1->val.ssa > N2->val.ssa); }
IC bool cmp_gs_mat(mapMatrixGS::TNode* N1, mapMatrixGS::TNode* N2) { return (N1->val.ssa > N2->val.ssa); }
#endif // USE_DX10
IC bool cmp_cs_nrm(mapNormalCS::TNode* N1, mapNormalCS::TNode* N2) { return (N1->val.ssa > N2->val.ssa); }
IC bool cmp_cs_mat(mapMatrixCS::TNode* N1, mapMatrixCS::TNode* N2) { return (N1->val.ssa > N2->val.ssa); }
IC bool cmp_states_nrm(mapNormalStates::TNode* N1, mapNormalStates::TNode* N2) { return (N1->val.ssa > N2->val.ssa); }
IC bool cmp_states_mat(mapMatrixStates::TNode* N1, mapMatrixStates::TNode* N2) { return (N1->val.ssa > N2->val.ssa); }
IC bool cmp_textures_lex2_nrm(mapNormalTextures::TNode* N1, mapNormalTextures::TNode* N2)
{
STextureList* t1 = N1->key;
STextureList* t2 = N2->key;
if ((*t1)[0] < (*t2)[0]) return true;
if ((*t1)[0] > (*t2)[0]) return false;
if ((*t1)[1] < (*t2)[1]) return true;
else return false;
}
IC bool cmp_textures_lex2_mat(mapMatrixTextures::TNode* N1, mapMatrixTextures::TNode* N2)
{
STextureList* t1 = N1->key;
STextureList* t2 = N2->key;
if ((*t1)[0] < (*t2)[0]) return true;
if ((*t1)[0] > (*t2)[0]) return false;
if ((*t1)[1] < (*t2)[1]) return true;
else return false;
}
IC bool cmp_textures_lex3_nrm(mapNormalTextures::TNode* N1, mapNormalTextures::TNode* N2)
{
STextureList* t1 = N1->key;
STextureList* t2 = N2->key;
if ((*t1)[0] < (*t2)[0]) return true;
if ((*t1)[0] > (*t2)[0]) return false;
if ((*t1)[1] < (*t2)[1]) return true;
if ((*t1)[1] > (*t2)[1]) return false;
if ((*t1)[2] < (*t2)[2]) return true;
else return false;
}
IC bool cmp_textures_lex3_mat(mapMatrixTextures::TNode* N1, mapMatrixTextures::TNode* N2)
{
STextureList* t1 = N1->key;
STextureList* t2 = N2->key;
if ((*t1)[0] < (*t2)[0]) return true;
if ((*t1)[0] > (*t2)[0]) return false;
if ((*t1)[1] < (*t2)[1]) return true;
if ((*t1)[1] > (*t2)[1]) return false;
if ((*t1)[2] < (*t2)[2]) return true;
else return false;
}
IC bool cmp_textures_lexN_nrm(mapNormalTextures::TNode* N1, mapNormalTextures::TNode* N2)
{
STextureList* t1 = N1->key;
STextureList* t2 = N2->key;
return std::lexicographical_compare(t1->begin(), t1->end(), t2->begin(), t2->end());
}
IC bool cmp_textures_lexN_mat(mapMatrixTextures::TNode* N1, mapMatrixTextures::TNode* N2)
{
STextureList* t1 = N1->key;
STextureList* t2 = N2->key;
return std::lexicographical_compare(t1->begin(), t1->end(), t2->begin(), t2->end());
}
IC bool cmp_textures_ssa_nrm(mapNormalTextures::TNode* N1, mapNormalTextures::TNode* N2)
{
return (N1->val.ssa > N2->val.ssa);
}
IC bool cmp_textures_ssa_mat(mapMatrixTextures::TNode* N1, mapMatrixTextures::TNode* N2)
{
return (N1->val.ssa > N2->val.ssa);
}
void sort_tlist_nrm
(
xr_vector<mapNormalTextures::TNode*,render_alloc<mapNormalTextures::TNode*>>& lst,
xr_vector<mapNormalTextures::TNode*,render_alloc<mapNormalTextures::TNode*>>& temp,
mapNormalTextures& textures,
BOOL bSSA
)
{
int amount = textures.begin()->key->size();
if (bSSA)
{
if (amount <= 1)
{
// Just sort by SSA
textures.getANY_P(lst);
std::sort(lst.begin(), lst.end(), cmp_textures_ssa_nrm);
}
else
{
// Split into 2 parts
mapNormalTextures::TNode* _it = textures.begin();
mapNormalTextures::TNode* _end = textures.end();
for (; _it != _end; _it++)
{
if (_it->val.ssa > r_ssaHZBvsTEX) lst.push_back(_it);
else temp.push_back(_it);
}
// 1st - part - SSA, 2nd - lexicographically
std::sort(lst.begin(), lst.end(), cmp_textures_ssa_nrm);
if (2 == amount) std::sort(temp.begin(), temp.end(), cmp_textures_lex2_nrm);
else if (3 == amount) std::sort(temp.begin(), temp.end(), cmp_textures_lex3_nrm);
else std::sort(temp.begin(), temp.end(), cmp_textures_lexN_nrm);
// merge lists
lst.insert(lst.end(), temp.begin(), temp.end());
}
}
else
{
textures.getANY_P(lst);
if (2 == amount) std::sort(lst.begin(), lst.end(), cmp_textures_lex2_nrm);
else if (3 == amount) std::sort(lst.begin(), lst.end(), cmp_textures_lex3_nrm);
else std::sort(lst.begin(), lst.end(), cmp_textures_lexN_nrm);
}
}
void sort_tlist_mat
(
xr_vector<mapMatrixTextures::TNode*,render_alloc<mapMatrixTextures::TNode*>>& lst,
xr_vector<mapMatrixTextures::TNode*,render_alloc<mapMatrixTextures::TNode*>>& temp,
mapMatrixTextures& textures,
BOOL bSSA
)
{
int amount = textures.begin()->key->size();
if (bSSA)
{
if (amount <= 1)
{
// Just sort by SSA
textures.getANY_P(lst);
std::sort(lst.begin(), lst.end(), cmp_textures_ssa_mat);
}
else
{
// Split into 2 parts
mapMatrixTextures::TNode* _it = textures.begin();
mapMatrixTextures::TNode* _end = textures.end();
for (; _it != _end; _it++)
{
if (_it->val.ssa > r_ssaHZBvsTEX) lst.push_back(_it);
else temp.push_back(_it);
}
// 1st - part - SSA, 2nd - lexicographically
std::sort(lst.begin(), lst.end(), cmp_textures_ssa_mat);
if (2 == amount) std::sort(temp.begin(), temp.end(), cmp_textures_lex2_mat);
else if (3 == amount) std::sort(temp.begin(), temp.end(), cmp_textures_lex3_mat);
else std::sort(temp.begin(), temp.end(), cmp_textures_lexN_mat);
// merge lists
lst.insert(lst.end(), temp.begin(), temp.end());
}
}
else
{
textures.getANY_P(lst);
if (2 == amount) std::sort(lst.begin(), lst.end(), cmp_textures_lex2_mat);
else if (3 == amount) std::sort(lst.begin(), lst.end(), cmp_textures_lex3_mat);
else std::sort(lst.begin(), lst.end(), cmp_textures_lexN_mat);
}
}
void R_dsgraph_structure::r_dsgraph_render_graph(u32 _priority, bool _clear)
{
//PIX_EVENT(r_dsgraph_render_graph);
Device.Statistic->RenderDUMP.Begin();
// **************************************************** NORMAL
// Perform sorting based on ScreenSpaceArea
// Sorting by SSA and changes minimizations
{
RCache.set_xform_world(Fidentity);
// Render several passes
for (u32 iPass = 0; iPass < SHADER_PASSES_MAX; ++iPass)
{
//mapNormalVS& vs = mapNormal [_priority];
mapNormalVS& vs = mapNormalPasses[_priority][iPass];
vs.getANY_P(nrmVS);
std::sort(nrmVS.begin(), nrmVS.end(), cmp_vs_nrm);
for (u32 vs_id = 0; vs_id < nrmVS.size(); vs_id++)
{
mapNormalVS::TNode* Nvs = nrmVS[vs_id];
RCache.set_VS(Nvs->key);
#if defined(USE_DX10) || defined(USE_DX11)
// GS setup
mapNormalGS& gs = Nvs->val;
gs.ssa = 0;
gs.getANY_P(nrmGS);
std::sort(nrmGS.begin(), nrmGS.end(), cmp_gs_nrm);
for (u32 gs_id = 0; gs_id < nrmGS.size(); gs_id++)
{
mapNormalGS::TNode* Ngs = nrmGS[gs_id];
RCache.set_GS(Ngs->key);
mapNormalPS& ps = Ngs->val;
ps.ssa = 0;
#else // USE_DX10
mapNormalPS& ps = Nvs->val;
ps.ssa = 0;
#endif // USE_DX10
ps.getANY_P(nrmPS);
std::sort(nrmPS.begin(), nrmPS.end(), cmp_ps_nrm);
for (u32 ps_id = 0; ps_id < nrmPS.size(); ps_id++)
{
mapNormalPS::TNode* Nps = nrmPS[ps_id];
RCache.set_PS(Nps->key);
#ifdef USE_DX11
mapNormalCS& cs = Nps->val.mapCS;
cs.ssa = 0;
RCache.set_HS(Nps->val.hs);
RCache.set_DS(Nps->val.ds);
#else
mapNormalCS& cs = Nps->val;
cs.ssa = 0;
#endif
cs.getANY_P(nrmCS);
std::sort(nrmCS.begin(), nrmCS.end(), cmp_cs_nrm);
for (u32 cs_id = 0; cs_id < nrmCS.size(); cs_id++)
{
mapNormalCS::TNode* Ncs = nrmCS[cs_id];
RCache.set_Constants(Ncs->key);
mapNormalStates& states = Ncs->val;
states.ssa = 0;
states.getANY_P(nrmStates);
std::sort(nrmStates.begin(), nrmStates.end(), cmp_states_nrm);
for (u32 state_id = 0; state_id < nrmStates.size(); state_id++)
{
mapNormalStates::TNode* Nstate = nrmStates[state_id];
RCache.set_States(Nstate->key);
mapNormalTextures& tex = Nstate->val;
tex.ssa = 0;
sort_tlist_nrm(nrmTextures, nrmTexturesTemp, tex, true);
for (u32 tex_id = 0; tex_id < nrmTextures.size(); tex_id++)
{
mapNormalTextures::TNode* Ntex = nrmTextures[tex_id];
RCache.set_Textures(Ntex->key);
RImplementation.apply_lmaterial();
mapNormalItems& items = Ntex->val;
items.ssa = 0;
mapNormal_Render(items);
if (_clear) items.clear();
}
nrmTextures.clear();
nrmTexturesTemp.clear();
if (_clear) tex.clear();
}
nrmStates.clear();
if (_clear) states.clear();
}
nrmCS.clear();
if (_clear) cs.clear();
}
nrmPS.clear();
if (_clear) ps.clear();
#if defined(USE_DX10) || defined(USE_DX11)
}
nrmGS.clear();
if (_clear) gs.clear();
#endif // USE_DX10
}
nrmVS.clear();
if (_clear) vs.clear();
}
}
// **************************************************** MATRIX
// Perform sorting based on ScreenSpaceArea
// Sorting by SSA and changes minimizations
// Render several passes
for (u32 iPass = 0; iPass < SHADER_PASSES_MAX; ++iPass)
{
//mapMatrixVS& vs = mapMatrix [_priority];
mapMatrixVS& vs = mapMatrixPasses[_priority][iPass];
vs.getANY_P(matVS);
std::sort(matVS.begin(), matVS.end(), cmp_vs_mat);
for (u32 vs_id = 0; vs_id < matVS.size(); vs_id++)
{
mapMatrixVS::TNode* Nvs = matVS[vs_id];
RCache.set_VS(Nvs->key);
#if defined(USE_DX10) || defined(USE_DX11)
mapMatrixGS& gs = Nvs->val;
gs.ssa = 0;
gs.getANY_P(matGS);
std::sort(matGS.begin(), matGS.end(), cmp_gs_mat);
for (u32 gs_id = 0; gs_id < matGS.size(); gs_id++)
{
mapMatrixGS::TNode* Ngs = matGS[gs_id];
RCache.set_GS(Ngs->key);
mapMatrixPS& ps = Ngs->val;
ps.ssa = 0;
#else // USE_DX10
mapMatrixPS& ps = Nvs->val;
ps.ssa = 0;
#endif // USE_DX10
ps.getANY_P(matPS);
std::sort(matPS.begin(), matPS.end(), cmp_ps_mat);
for (u32 ps_id = 0; ps_id < matPS.size(); ps_id++)
{
mapMatrixPS::TNode* Nps = matPS[ps_id];
RCache.set_PS(Nps->key);
#ifdef USE_DX11
mapMatrixCS& cs = Nps->val.mapCS;
cs.ssa = 0;
RCache.set_HS(Nps->val.hs);
RCache.set_DS(Nps->val.ds);
#else
mapMatrixCS& cs = Nps->val;
cs.ssa = 0;
#endif
cs.getANY_P(matCS);
std::sort(matCS.begin(), matCS.end(), cmp_cs_mat);
for (u32 cs_id = 0; cs_id < matCS.size(); cs_id++)
{
mapMatrixCS::TNode* Ncs = matCS[cs_id];
RCache.set_Constants(Ncs->key);
mapMatrixStates& states = Ncs->val;
states.ssa = 0;
states.getANY_P(matStates);
std::sort(matStates.begin(), matStates.end(), cmp_states_mat);
for (u32 state_id = 0; state_id < matStates.size(); state_id++)
{
mapMatrixStates::TNode* Nstate = matStates[state_id];
RCache.set_States(Nstate->key);
mapMatrixTextures& tex = Nstate->val;
tex.ssa = 0;
sort_tlist_mat(matTextures, matTexturesTemp, tex, true);
for (u32 tex_id = 0; tex_id < matTextures.size(); tex_id++)
{
mapMatrixTextures::TNode* Ntex = matTextures[tex_id];
RCache.set_Textures(Ntex->key);
RImplementation.apply_lmaterial();
mapMatrixItems& items = Ntex->val;
items.ssa = 0;
mapMatrix_Render(items);
}
matTextures.clear();
matTexturesTemp.clear();
if (_clear) tex.clear();
}
matStates.clear();
if (_clear) states.clear();
}
matCS.clear();
if (_clear) cs.clear();
}
matPS.clear();
if (_clear) ps.clear();
#if defined(USE_DX10) || defined(USE_DX11)
}
matGS.clear();
if (_clear) gs.clear();
#endif // USE_DX10
}
matVS.clear();
if (_clear) vs.clear();
}
Device.Statistic->RenderDUMP.End();
}
//////////////////////////////////////////////////////////////////////////
// HUD render
void R_dsgraph_structure::r_dsgraph_render_hud(bool NoPS)
{
//PIX_EVENT(r_dsgraph_render_hud);
// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Fmatrix FVold = Device.mView;
Device.mView.build_camera_dir(Device.vCameraPosition, Device.vCameraDirection, Device.vCameraTop);
Device.mProject.build_projection(
deg2rad(psHUD_FOV * 83.f),
Device.fASPECT, R_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv->far_plane);
Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);
// Rendering
rmNear();
if (!NoPS)
{
mapHUD.traverseLR(sorted_L1);
mapHUD.clear();
}
else
{
HUDMask.traverseLR(sorted_L1_nops);
HUDMask.clear();
}
rmNormal();
// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
Device.mView = FVold;
RCache.set_xform_project(Device.mProject);
}
void R_dsgraph_structure::r_dsgraph_render_hud_ui()
{
// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Device.mProject.build_projection(
deg2rad(psHUD_FOV * 83.f),
Device.fASPECT, R_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv->far_plane);
Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);
rmNear();
g_hud->RenderActiveItemUI();
rmNormal();
// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
}
//////////////////////////////////////////////////////////////////////////
// strict-sorted render
void R_dsgraph_structure::r_dsgraph_render_sorted()
{
// Sorted (back to front)
mapSorted.traverseRL(sorted_L1);
mapSorted.clear();
// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Device.mProject.build_projection(
deg2rad(psHUD_FOV * 83.f),
Device.fASPECT, R_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv->far_plane);
Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);
// Rendering
rmNear();
mapHUDSorted.traverseRL(sorted_L1);
mapHUDSorted.clear();
rmNormal();
// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
}
//////////////////////////////////////////////////////////////////////////
// strict-sorted render
void R_dsgraph_structure::r_dsgraph_render_emissive()
{
#if RENDER!=R_R1
// Sorted (back to front)
mapEmissive.traverseLR(sorted_L1);
mapEmissive.clear();
// Change projection
Fmatrix Pold = Device.mProject;
Fmatrix FTold = Device.mFullTransform;
Device.mProject.build_projection(
deg2rad(psHUD_FOV * 83.f),
Device.fASPECT, R_VIEWPORT_NEAR,
g_pGamePersistent->Environment().CurrentEnv->far_plane);
Device.mFullTransform.mul(Device.mProject, Device.mView);
RCache.set_xform_project(Device.mProject);
// Rendering
rmNear();
// Sorted (back to front)
mapHUDEmissive.traverseLR(sorted_L1);
mapHUDEmissive.clear();
rmNormal();
// Restore projection
Device.mProject = Pold;
Device.mFullTransform = FTold;
RCache.set_xform_project(Device.mProject);
#endif
}
void R_dsgraph_structure::r_dsgraph_render_water()
{
mapWater.traverseLR(sorted_L1);
mapWater.clear();
}
//////////////////////////////////////////////////////////////////////////
// strict-sorted render
void R_dsgraph_structure::r_dsgraph_render_wmarks()
{
#if RENDER!=R_R1
// Sorted (back to front)
mapWmark.traverseLR(sorted_L1);
mapWmark.clear();
#endif
}
//////////////////////////////////////////////////////////////////////////
// strict-sorted render
void R_dsgraph_structure::r_dsgraph_render_distort()
{
// Sorted (back to front)
mapDistort.traverseRL(sorted_L1);
mapDistort.clear();
}
//////////////////////////////////////////////////////////////////////////
// sub-space rendering - shortcut to render with frustum extracted from matrix
void R_dsgraph_structure::r_dsgraph_render_subspace(IRender_Sector* _sector, Fmatrix& mCombined, Fvector& _cop,
BOOL _dynamic, BOOL _precise_portals)
{
CFrustum temp;
temp.CreateFromMatrix(mCombined, FRUSTUM_P_ALL & (~FRUSTUM_P_NEAR));
r_dsgraph_render_subspace(_sector, &temp, mCombined, _cop, _dynamic, _precise_portals);
}
// sub-space rendering - main procedure
void R_dsgraph_structure::r_dsgraph_render_subspace(IRender_Sector* _sector, CFrustum* _frustum, Fmatrix& mCombined,
Fvector& _cop, BOOL _dynamic, BOOL _precise_portals)
{
VERIFY(_sector);
RImplementation.marker ++; // !!! critical here
// Save and build new frustum, disable HOM
CFrustum ViewSave = ViewBase;
ViewBase = *_frustum;
View = &ViewBase;
if (_precise_portals && RImplementation.rmPortals)
{
// Check if camera is too near to some portal - if so force DualRender
Fvector box_radius;
box_radius.set(EPS_L * 20, EPS_L * 20, EPS_L * 20);
RImplementation.Sectors_xrc.box_options(CDB::OPT_FULL_TEST);
RImplementation.Sectors_xrc.box_query(RImplementation.rmPortals, _cop, box_radius);
for (int K = 0; K < RImplementation.Sectors_xrc.r_count(); K++)
{
CPortal* pPortal = (CPortal*)RImplementation.Portals[RImplementation.rmPortals->get_tris()[RImplementation
.Sectors_xrc.
r_begin()[K].id].
dummy];
pPortal->bDualRender = TRUE;
}
}
// Traverse sector/portal structure
PortalTraverser.traverse(_sector, ViewBase, _cop, mCombined, 0);
// Determine visibility for static geometry hierrarhy
for (u32 s_it = 0; s_it < PortalTraverser.r_sectors.size(); s_it++)
{
CSector* sector = (CSector*)PortalTraverser.r_sectors[s_it];
dxRender_Visual* root = sector->root();
for (u32 v_it = 0; v_it < sector->r_frustums.size(); v_it++)
{
set_Frustum(&(sector->r_frustums[v_it]));
add_Geometry(root);
}
}
if (_dynamic)
{
set_Object(0);
// Traverse object database
g_SpatialSpace->q_frustum
(
lstRenderables,
ISpatial_DB::O_ORDERED,
STYPE_RENDERABLE,
ViewBase
);
// Determine visibility for dynamic part of scene
for (u32 o_it = 0; o_it < lstRenderables.size(); o_it++)
{
ISpatial* spatial = lstRenderables[o_it];
CSector* sector = (CSector*)spatial->spatial.sector;
if (0 == sector) continue; // disassociated from S/P structure
if (PortalTraverser.i_marker != sector->r_marker) continue; // inactive (untouched) sector
for (u32 v_it = 0; v_it < sector->r_frustums.size(); v_it++)
{
set_Frustum(&(sector->r_frustums[v_it]));
if (!View->testSphere_dirty(spatial->spatial.sphere.P, spatial->spatial.sphere.R)) continue;
// renderable
IRenderable* renderable = spatial->dcast_Renderable();
if (0 == renderable) continue; // unknown, but renderable object (r1_glow???)
renderable->renderable_Render();
}
}
#if RENDER!=R_R1
if (g_pGameLevel && (phase == RImplementation.PHASE_SMAP) && ps_actor_shadow_flags.test(RFLAG_ACTOR_SHADOW))
g_hud->Render_Actor_Shadow(); //Swartz: actor shadow
#endif
}
// Restore
ViewBase = ViewSave;
View = 0;
}
#include "fhierrarhyvisual.h"
#include "SkeletonCustom.h"
#include "../../xrEngine/fmesh.h"
#include "flod.h"
void R_dsgraph_structure::r_dsgraph_render_R1_box(IRender_Sector* _S, Fbox& BB, int sh)
{
CSector* S = (CSector*)_S;
lstVisuals.clear();
lstVisuals.push_back(S->root());
for (u32 test = 0; test < lstVisuals.size(); test++)
{
dxRender_Visual* V = lstVisuals[test];
// Visual is 100% visible - simply add it
xr_vector<dxRender_Visual*>::iterator I, E; // it may be usefull for 'hierrarhy' visuals
switch (V->Type)
{
case MT_HIERRARHY:
{
// Add all children
FHierrarhyVisual* pV = (FHierrarhyVisual*)V;
I = pV->children.begin();
E = pV->children.end();
for (; I != E; ++I)
{
dxRender_Visual* T = *I;
if (BB.intersect(T->vis.box)) lstVisuals.push_back(T);
}
}
break;
case MT_SKELETON_ANIM:
case MT_SKELETON_RIGID:
{
// Add all children (s)
CKinematics* pV = (CKinematics*)V;
pV->CalculateBones(TRUE);
I = pV->children.begin();
E = pV->children.end();
for (; I != E; ++I)
{
dxRender_Visual* T = *I;
if (BB.intersect(T->vis.box)) lstVisuals.push_back(T);
}
}
break;
case MT_LOD:
{
FLOD* pV = (FLOD*)V;
I = pV->children.begin();
E = pV->children.end();
for (; I != E; ++I)
{
dxRender_Visual* T = *I;
if (BB.intersect(T->vis.box)) lstVisuals.push_back(T);
}
}
break;
default:
{
// Renderable visual
ShaderElement* E = V->shader->E[sh]._get();
if (E && !(E->flags.bDistort))
{
for (u32 pass = 0; pass < E->passes.size(); pass++)
{
RCache.set_Element(E, pass);
V->Render(-1.f);
}
}
}
break;
}
}
}
void __fastcall pLandscape_0(mapLandscape_Node *N)
{
VERIFY(N);
dxRender_Visual *V = N->val.pVisual;
VERIFY(V && V->shader._get());
RCache.set_Element(N->val.se, 0);
float LOD = calcLOD(N->val.ssa, V->vis.sphere.R);
#ifdef USE_DX11
RCache.LOD.set_LOD(LOD);
#endif
V->Render(LOD);
}
void __fastcall pLandscape_1(mapLandscape_Node *N)
{
VERIFY(N);
dxRender_Visual *V = N->val.pVisual;
VERIFY(V && V->shader._get());
RCache.set_Element(N->val.se, 1);
RImplementation.apply_lmaterial();
float LOD = calcLOD(N->val.ssa, V->vis.sphere.R);
#ifdef USE_DX11
RCache.LOD.set_LOD(LOD);
#endif
V->Render(LOD);
}
void R_dsgraph_structure::r_dsgraph_render_landscape(u32 pass, bool _clear)
{
RCache.set_xform_world(Fidentity);
if (pass == 0)
mapLandscape.traverseLR(pLandscape_0);
else
mapLandscape.traverseLR(pLandscape_1);
if (_clear)
mapLandscape.clear();
}