/
rend_fakeradio.cpp
1611 lines (1416 loc) · 53.9 KB
/
rend_fakeradio.cpp
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
/** @file rend_fakeradio.cpp Faked Radiosity Lighting.
*
* @authors Copyright © 2004-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include <cstring>
#include "de_base.h"
#include "de_console.h"
#include "de_render.h"
#include "de_graphics.h"
#include "de_misc.h"
#include "de_play.h"
#include "gl/sys_opengl.h"
#include <de/vector1.h>
#include "MaterialSnapshot"
#include "MaterialVariantSpec"
#include "render/rendpoly.h"
using namespace de;
#define MIN_OPEN (.1f)
#define EDGE_OPEN_THRESHOLD (8) // world units (Z axis)
#define MINDIFF (8) // min plane height difference (world units)
#define INDIFF (8) // max plane height for indifference offset
#define BOTTOM (0)
#define TOP (1)
typedef struct edge_s {
boolean done;
LineDef *line;
Sector *sector;
float length;
binangle_t diff;
} edge_t;
static void scanEdges(shadowcorner_t topCorners[2], shadowcorner_t bottomCorners[2],
shadowcorner_t sideCorners[2], edgespan_t spans[2], LineDef const &line, int backSide);
int rendFakeRadio = true; ///< cvar
float rendFakeRadioDarkness = 1.2f; ///< cvar
static byte devFakeRadioUpdate = true; ///< cvar
void Rend_RadioRegister()
{
C_VAR_INT ("rend-fakeradio", &rendFakeRadio, 0, 0, 2);
C_VAR_FLOAT("rend-fakeradio-darkness", &rendFakeRadioDarkness, 0, 0, 2);
C_VAR_BYTE ("rend-dev-fakeradio-update", &devFakeRadioUpdate, CVF_NO_ARCHIVE, 0, 1);
}
float Rend_RadioCalcShadowDarkness(float lightLevel)
{
return (0.6f - lightLevel * 0.4f) * 0.65f * rendFakeRadioDarkness;
}
void Rend_RadioUpdateLine(LineDef &line, int backSide)
{
// Disabled completely?
if(!rendFakeRadio || levelFullBright) return;
// Updates are disabled?
if(!devFakeRadioUpdate) return;
// Sides without sectors don't need updating. $degenleaf
if(!line.hasSector(backSide)) return;
// Have already determined the shadow properties on this side?
SideDef &sideDef = line.sideDef(backSide);
if(sideDef.fakeRadioUpdateCount == frameCount) return;
// Not yet - Calculate now.
for(uint i = 0; i < 2; ++i)
{
sideDef.spans[i].length = line.length();
sideDef.spans[i].shift = 0;
}
scanEdges(sideDef.topCorners, sideDef.bottomCorners, sideDef.sideCorners, sideDef.spans, line, backSide);
sideDef.fakeRadioUpdateCount = frameCount; // Mark as done.
}
/**
* Set the vertex colors in the rendpoly.
*/
static void setRendpolyColor(ColorRawf *rcolors, uint num, float const shadowRGB[3], float darkness)
{
darkness = MINMAX_OF(0, darkness, 1);
for(uint i = 0; i < num; ++i)
{
rcolors[i].rgba[CR] = shadowRGB[CR];
rcolors[i].rgba[CG] = shadowRGB[CG];
rcolors[i].rgba[CB] = shadowRGB[CB];
rcolors[i].rgba[CA] = darkness;
}
}
/// @return @c true, if there is open space in the sector.
static inline boolean isSectorOpen(Sector const *sector)
{
return (sector && sector->ceiling().height() > sector->floor().height());
}
/**
* Set the rendpoly's X offset and texture size.
*
* @param length If negative; implies that the texture is flipped horizontally.
*/
static inline float calcTexCoordX(float lineLength, float segOffset)
{
if(lineLength > 0) return segOffset;
return lineLength + segOffset;
}
/**
* Set the rendpoly's Y offset and texture size.
*
* @param size If negative; implies that the texture is flipped vertically.
*/
static inline float calcTexCoordY(float z, float bottom, float top, float texHeight)
{
if(texHeight > 0) return top - z;
return bottom - z;
}
/// @todo This algorithm should be rewritten to work at HEdge level.
static void scanNeighbor(boolean scanTop, LineDef const *line, uint side,
edge_t *edge, boolean toLeft)
{
int const SEP = 10;
LineDef *iter;
LineOwner *own;
binangle_t diff = 0;
coord_t lengthDelta = 0, gap = 0;
coord_t iFFloor, iFCeil;
coord_t iBFloor, iBCeil;
int scanSecSide = side;
Sector const *startSector = line->sectorPtr(side);
Sector const *scanSector;
boolean clockwise = toLeft;
boolean stopScan = false;
boolean closed;
coord_t fCeil, fFloor;
fFloor = startSector->floor().visHeight();
fCeil = startSector->ceiling().visHeight();
// Retrieve the start owner node.
own = R_GetVtxLineOwner(&line->vertex(side^!toLeft), line);
do
{
// Select the next line.
diff = (clockwise? own->angle() : own->prev().angle());
iter = &own->_link[clockwise]->line();
scanSecSide = (iter->hasFrontSector() && iter->frontSectorPtr() == startSector);
// Step over selfreferencing lines.
while((!iter->hasFrontSector() && !iter->hasBackSector()) || // $degenleaf
iter->isSelfReferencing())
{
own = own->_link[clockwise];
diff += (clockwise? own->angle() : own->prev().angle());
iter = &own->_link[clockwise]->line();
scanSecSide = (iter->frontSectorPtr() == startSector);
}
// Determine the relative backsector.
if(iter->hasSideDef(scanSecSide))
scanSector = iter->sectorPtr(scanSecSide);
else
scanSector = NULL;
// Pick plane heights for relative offset comparison.
if(!stopScan)
{
iFFloor = iter->frontSector().floor().visHeight();
iFCeil = iter->frontSector().ceiling().visHeight();
if(iter->hasBackSideDef())
{
iBFloor = iter->backSector().floor().visHeight();
iBCeil = iter->backSector().ceiling().visHeight();
}
else
iBFloor = iBCeil = 0;
}
lengthDelta = 0;
if(!stopScan)
{
// This line will attribute to this hedge's shadow edge.
// Store identity for later use.
edge->diff = diff;
edge->line = iter;
edge->sector = const_cast<Sector *>(scanSector);
closed = false;
if(side == 0 && iter->hasBackSideDef())
{
if(scanTop)
{
if(iBFloor >= fCeil)
closed = true; // Compared to "this" sector anyway
}
else
{
if(iBCeil <= fFloor)
closed = true; // Compared to "this" sector anyway
}
}
// Does this line's length contribute to the alignment of the
// texture on the hedge shadow edge being rendered?
if(scanTop)
{
if(iter->hasBackSideDef() &&
((side == 0 && iter->backSectorPtr() == line->frontSectorPtr() &&
iFCeil >= fCeil) ||
(side == 1 && iter->backSectorPtr() == line->backSectorPtr() &&
iFCeil >= fCeil) ||
(side == 0 && closed == false && iter->backSectorPtr() != line->frontSectorPtr() &&
iBCeil >= fCeil &&
isSectorOpen(iter->backSectorPtr()))))
{
gap += iter->length(); // Should we just mark it done instead?
}
else
{
edge->length += iter->length() + gap;
gap = 0;
}
}
else
{
if(iter->hasBackSideDef() &&
((side == 0 && iter->backSectorPtr() == line->frontSectorPtr() &&
iFFloor <= fFloor) ||
(side == 1 && iter->backSectorPtr() == line->backSectorPtr() &&
iFFloor <= fFloor) ||
(side == 0 && closed == false && iter->backSectorPtr() != line->frontSectorPtr() &&
iBFloor <= fFloor &&
isSectorOpen(iter->backSectorPtr()))))
{
gap += iter->length(); // Should we just mark it done instead?
}
else
{
lengthDelta = iter->length() + gap;
gap = 0;
}
}
}
// Time to stop?
if(iter == line)
{
stopScan = true;
}
else
{
// Is this line coalignable?
if(!(diff >= BANG_180 - SEP && diff <= BANG_180 + SEP))
stopScan = true; // no.
else if(scanSector)
{
// Perhaps its a closed edge?
if(!isSectorOpen(scanSector))
{
stopScan = true;
}
else
{
// A height difference from the start sector?
if(scanTop)
{
if(scanSector->ceiling().visHeight() != fCeil &&
scanSector->floor().visHeight() <
startSector->ceiling().visHeight())
stopScan = true;
}
else
{
if(scanSector->floor().visHeight() != fFloor &&
scanSector->ceiling().visHeight() >
startSector->floor().visHeight())
stopScan = true;
}
}
}
}
// Swap to the iter line's owner node (i.e: around the corner)?
if(!stopScan)
{
// Around the corner.
if(own->_link[clockwise] == iter->v2Owner())
own = iter->v1Owner();
else if(own->_link[clockwise] == iter->v1Owner())
own = iter->v2Owner();
// Skip into the back neighbor sector of the iter line if
// heights are within accepted range.
if(scanSector && line->hasSideDef(side^1) &&
scanSector != line->sectorPtr(side^1) &&
((scanTop && scanSector->ceiling().visHeight() ==
startSector->ceiling().visHeight()) ||
(!scanTop && scanSector->floor().visHeight() ==
startSector->floor().visHeight())))
{
// If the map is formed correctly, we should find a back
// neighbor attached to this line. However, if this is not
// the case and a line which SHOULD be two sided isn't, we
// need to check whether there is a valid neighbor.
LineDef *backNeighbor =
R_FindLineNeighbor(startSector, iter, own, !toLeft, NULL);
if(backNeighbor && backNeighbor != iter)
{
// Into the back neighbor sector.
own = own->_link[clockwise];
startSector = scanSector;
}
}
// The last line was co-alignable so apply any length delta.
edge->length += lengthDelta;
}
} while(!stopScan);
// Now we've found the furthest coalignable neighbor, select the back
// neighbor if present for "edge open-ness" comparison.
if(edge->sector) // the back sector of the coalignable neighbor.
{
// Since we have the details of the backsector already, simply
// get the next neighbor (it IS the backneighbor).
edge->line =
R_FindLineNeighbor(edge->sector, edge->line,
edge->line->vertexOwner((edge->line->hasBackSideDef() && edge->line->backSectorPtr() == edge->sector)^!toLeft),
!toLeft, &edge->diff);
}
}
static void scanNeighbors(shadowcorner_t top[2], shadowcorner_t bottom[2],
LineDef const &line, uint side, edgespan_t spans[2], boolean toLeft)
{
if(line.isSelfReferencing()) return;
coord_t fFloor = line.sector(side).floor().visHeight();
coord_t fCeil = line.sector(side).ceiling().visHeight();
edge_t edges[2]; // {bottom, top}
std::memset(edges, 0, sizeof(edges));
scanNeighbor(false, &line, side, &edges[0], toLeft);
scanNeighbor(true, &line, side, &edges[1], toLeft);
for(uint i = 0; i < 2; ++i)
{
shadowcorner_t *corner = (i == 0 ? &bottom[!toLeft] : &top[!toLeft]);
edge_t *edge = &edges[i];
edgespan_t *span = &spans[i];
// Increment the apparent line length/offset.
span->length += edge->length;
if(toLeft)
span->shift += edge->length;
// Compare the relative angle difference of this edge to determine
// an "open-ness" factor.
if(edge->line && edge->line != &line)
{
if(edge->diff > BANG_180)
{
// The corner between the walls faces outwards.
corner->corner = -1;
}
else if(edge->diff == BANG_180)
{
// Perfectly coaligned? Great.
corner->corner = 0;
}
else if(edge->diff < BANG_45 / 5)
{
// The difference is too small, there won't be a shadow.
corner->corner = 0;
}
// 90 degrees is the largest effective difference.
else if(edge->diff > BANG_90)
{
corner->corner = (float) BANG_90 / edge->diff;
}
else
{
corner->corner = (float) edge->diff / BANG_90;
}
}
else
{
// Consider it coaligned.
corner->corner = 0;
}
// Determine relative height offsets (affects shadow map selection).
if(edge->sector)
{
corner->proximity = edge->sector;
if(i == 0) // Floor.
{
corner->pOffset = corner->proximity->floor().visHeight() - fFloor;
corner->pHeight = corner->proximity->floor().visHeight();
}
else // Ceiling.
{
corner->pOffset = corner->proximity->ceiling().visHeight() - fCeil;
corner->pHeight = corner->proximity->ceiling().visHeight();
}
}
else
{
corner->proximity = NULL;
corner->pOffset = 0;
corner->pHeight = 0;
}
}
}
/**
* To determine the dimensions of a shadow, we'll need to scan edges. Edges
* are composed of aligned lines. It's important to note that the scanning
* is done separately for the top/bottom edges (both in the left and right
* direction) and the left/right edges.
*
* The length of the top/bottom edges are returned in the array 'spans'.
*
* This may look like a complicated operation (performed for all wall polys)
* but in most cases this won't take long. Aligned neighbours are relatively
* rare.
*/
static void scanEdges(shadowcorner_t topCorners[2], shadowcorner_t bottomCorners[2],
shadowcorner_t sideCorners[2], edgespan_t spans[2], LineDef const &line,
int backSide)
{
uint const sid = (backSide? BACK : FRONT);
std::memset(sideCorners, 0, sizeof(shadowcorner_t) * 2);
// Find the sidecorners first: left and right neighbour.
for(uint i = 0; i < 2; ++i)
{
binangle_t diff = 0;
LineOwner *vo = line.vertexOwner(i ^ sid);
LineDef *other = R_FindSolidLineNeighbor(line.sectorPtr(sid), &line, vo, i, &diff);
if(other && other != &line)
{
if(diff > BANG_180)
{
// The corner between the walls faces outwards.
sideCorners[i].corner = -1;
}
else if(diff == BANG_180)
{
sideCorners[i].corner = 0;
}
else if(diff < BANG_45 / 5)
{
// The difference is too small, there won't be a shadow.
sideCorners[i].corner = 0;
}
else if(diff > BANG_90)
{
// 90 degrees is the largest effective difference.
sideCorners[i].corner = (float) BANG_90 / diff;
}
else
{
sideCorners[i].corner = (float) diff / BANG_90;
}
}
else
{
sideCorners[i].corner = 0;
}
scanNeighbors(topCorners, bottomCorners, line, sid, spans, !i);
}
}
typedef struct {
lightingtexid_t texture;
boolean horizontal;
float shadowMul;
float texWidth;
float texHeight;
float texOffset[2];
float wallLength;
} rendershadowseg_params_t;
static void setTopShadowParams(rendershadowseg_params_t *p, float size, coord_t top,
coord_t const *xOffset, coord_t const *segLength, coord_t fFloor, coord_t fCeil,
shadowcorner_t const *botCn, shadowcorner_t const *topCn, shadowcorner_t const *sideCn,
edgespan_t const *spans)
{
p->shadowMul = 1;
p->horizontal = false;
p->texHeight = size;
p->texOffset[VY] = calcTexCoordY(top, fFloor, fCeil, p->texHeight);
p->wallLength = *segLength;
p->texture = LST_RADIO_OO;
// Corners without a neighbour backsector
if(sideCn[0].corner == -1 || sideCn[1].corner == -1)
{
// At least one corner faces outwards
p->texture = LST_RADIO_OO;
p->texWidth = spans[TOP].length;
p->texOffset[VX] =
calcTexCoordX(spans[TOP].length, spans[TOP].shift + *xOffset);
if((sideCn[0].corner == -1 && sideCn[1].corner == -1) ||
(topCn[0].corner == -1 && topCn[1].corner == -1))
{
// Both corners face outwards
p->texture = LST_RADIO_OO;//CC;
}
else if(sideCn[1].corner == -1)
{
// right corner faces outwards
if(-topCn[0].pOffset < 0 && botCn[0].pHeight < fCeil)
{
// Must flip horizontally!
p->texWidth = -spans[TOP].length;
p->texOffset[VX] =
calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset);
p->texture = LST_RADIO_OE;
}
}
else // left corner faces outwards
{
if(-topCn[1].pOffset < 0 && botCn[1].pHeight < fCeil)
{
p->texture = LST_RADIO_OE;
}
}
}
else
{
// Corners WITH a neighbour backsector
p->texWidth = spans[TOP].length;
p->texOffset[VX] = calcTexCoordX(spans[TOP].length, spans[TOP].shift + *xOffset);
if(topCn[0].corner == -1 && topCn[1].corner == -1)
{
// Both corners face outwards
p->texture = LST_RADIO_OO;//CC;
}
else if(topCn[1].corner == -1 && topCn[0].corner > MIN_OPEN)
{
// Right corner faces outwards
p->texture = LST_RADIO_OO;
}
else if(topCn[0].corner == -1 && topCn[1].corner > MIN_OPEN)
{
// Left corner faces outwards
p->texture = LST_RADIO_OO;
}
// Open edges
else if(topCn[0].corner <= MIN_OPEN && topCn[1].corner <= MIN_OPEN)
{
// Both edges are open
p->texture = LST_RADIO_OO;
if(topCn[0].proximity && topCn[1].proximity)
{
if(-topCn[0].pOffset >= 0 && -topCn[1].pOffset < 0)
{
p->texture = LST_RADIO_CO;
// The shadow can't go over the higher edge.
if(size > -topCn[0].pOffset)
{
if(-topCn[0].pOffset < INDIFF)
{
p->texture = LST_RADIO_OE;
}
else
{
p->texHeight = -topCn[0].pOffset;
p->texOffset[VY] = calcTexCoordY(top, fFloor, fCeil, p->texHeight);
}
}
}
else if(-topCn[0].pOffset < 0 && -topCn[1].pOffset >= 0)
{
// Must flip horizontally!
p->texture = LST_RADIO_CO;
p->texWidth = -spans[TOP].length;
p->texOffset[VX] = calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset);
// The shadow can't go over the higher edge.
if(size > -topCn[1].pOffset)
{
if(-topCn[1].pOffset < INDIFF)
{
p->texture = LST_RADIO_OE;
}
else
{
p->texHeight = -topCn[1].pOffset;
p->texOffset[VY] = calcTexCoordY(top, fFloor, fCeil, p->texHeight);
}
}
}
}
else
{
if(-topCn[0].pOffset < -MINDIFF)
{
// Must flip horizontally!
p->texture = LST_RADIO_OE;
p->texWidth = -spans[BOTTOM].length;
p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset);
}
else if(-topCn[1].pOffset < -MINDIFF)
{
p->texture = LST_RADIO_OE;
}
}
}
else if(topCn[0].corner <= MIN_OPEN)
{
if(-topCn[0].pOffset < 0)
p->texture = LST_RADIO_CO;
else
p->texture = LST_RADIO_OO;
// Must flip horizontally!
p->texWidth = -spans[TOP].length;
p->texOffset[VX] = calcTexCoordX(-spans[TOP].length, spans[TOP].shift + *xOffset);
}
else if(topCn[1].corner <= MIN_OPEN)
{
if(-topCn[1].pOffset < 0)
p->texture = LST_RADIO_CO;
else
p->texture = LST_RADIO_OO;
}
else // C/C ???
{
p->texture = LST_RADIO_OO;
}
}
}
static void setBottomShadowParams(rendershadowseg_params_t *p, float size, coord_t top,
coord_t const *xOffset, coord_t const *segLength, coord_t fFloor, coord_t fCeil,
shadowcorner_t const *botCn, shadowcorner_t const *topCn, shadowcorner_t const *sideCn,
edgespan_t const *spans)
{
p->shadowMul = 1;
p->horizontal = false;
p->texHeight = -size;
p->texOffset[VY] = calcTexCoordY(top, fFloor, fCeil, p->texHeight);
p->wallLength = *segLength;
p->texture = LST_RADIO_OO;
// Corners without a neighbour backsector
if(sideCn[0].corner == -1 || sideCn[1].corner == -1)
{
// At least one corner faces outwards
p->texture = LST_RADIO_OO;
p->texWidth = spans[BOTTOM].length;
p->texOffset[VX] = calcTexCoordX(spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset);
if((sideCn[0].corner == -1 && sideCn[1].corner == -1) ||
(botCn[0].corner == -1 && botCn[1].corner == -1) )
{
// Both corners face outwards
p->texture = LST_RADIO_OO;//CC;
}
else if(sideCn[1].corner == -1) // right corner faces outwards
{
if(botCn[0].pOffset < 0 && topCn[0].pHeight > fFloor)
{
// Must flip horizontally!
p->texWidth = -spans[BOTTOM].length;
p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset);
p->texture = LST_RADIO_OE;
}
}
else
{
// left corner faces outwards
if(botCn[1].pOffset < 0 && topCn[1].pHeight > fFloor)
{
p->texture = LST_RADIO_OE;
}
}
}
else
{ // Corners WITH a neighbour backsector
p->texWidth = spans[BOTTOM].length;
p->texOffset[VX] = calcTexCoordX(spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset);
if(botCn[0].corner == -1 && botCn[1].corner == -1)
{
// Both corners face outwards
p->texture = LST_RADIO_OO;//CC;
}
else if(botCn[1].corner == -1 && botCn[0].corner > MIN_OPEN)
{
// Right corner faces outwards
p->texture = LST_RADIO_OO;
}
else if(botCn[0].corner == -1 && botCn[1].corner > MIN_OPEN)
{
// Left corner faces outwards
p->texture = LST_RADIO_OO;
}
// Open edges
else if(botCn[0].corner <= MIN_OPEN && botCn[1].corner <= MIN_OPEN)
{
// Both edges are open
p->texture = LST_RADIO_OO;
if(botCn[0].proximity && botCn[1].proximity)
{
if(botCn[0].pOffset >= 0 && botCn[1].pOffset < 0)
{
p->texture = LST_RADIO_CO;
// The shadow can't go over the higher edge.
if(size > botCn[0].pOffset)
{
if(botCn[0].pOffset < INDIFF)
{
p->texture = LST_RADIO_OE;
}
else
{
p->texHeight = -botCn[0].pOffset;
p->texOffset[VY] = calcTexCoordY(top, fFloor, fCeil, p->texHeight);
}
}
}
else if(botCn[0].pOffset < 0 && botCn[1].pOffset >= 0)
{
// Must flip horizontally!
p->texture = LST_RADIO_CO;
p->texWidth = -spans[BOTTOM].length;
p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset);
if(size > botCn[1].pOffset)
{
if(botCn[1].pOffset < INDIFF)
{
p->texture = LST_RADIO_OE;
}
else
{
p->texHeight = -botCn[1].pOffset;
p->texOffset[VY] = calcTexCoordY(top, fFloor, fCeil, p->texHeight);
}
}
}
}
else
{
if(botCn[0].pOffset < -MINDIFF)
{
// Must flip horizontally!
p->texture = LST_RADIO_OE;
p->texWidth = -spans[BOTTOM].length;
p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset);
}
else if(botCn[1].pOffset < -MINDIFF)
{
p->texture = LST_RADIO_OE;
}
}
}
else if(botCn[0].corner <= MIN_OPEN) // Right Corner is Closed
{
if(botCn[0].pOffset < 0)
p->texture = LST_RADIO_CO;
else
p->texture = LST_RADIO_OO;
// Must flip horizontally!
p->texWidth = -spans[BOTTOM].length;
p->texOffset[VX] = calcTexCoordX(-spans[BOTTOM].length, spans[BOTTOM].shift + *xOffset);
}
else if(botCn[1].corner <= MIN_OPEN) // Left Corner is closed
{
if(botCn[1].pOffset < 0)
p->texture = LST_RADIO_CO;
else
p->texture = LST_RADIO_OO;
}
else // C/C ???
{
p->texture = LST_RADIO_OO;
}
}
}
static void setSideShadowParams(rendershadowseg_params_t *p, float size, coord_t bottom,
coord_t top, boolean rightSide, boolean bottomGlow, boolean topGlow,
coord_t const *xOffset, coord_t const *segLength, coord_t fFloor,
coord_t fCeil, bool hasBackSector, coord_t bFloor, coord_t bCeil, coord_t const *lineLength,
shadowcorner_t const *sideCn)
{
p->shadowMul = sideCn[rightSide? 1 : 0].corner * .8f;
p->shadowMul *= p->shadowMul * p->shadowMul;
p->horizontal = true;
p->texOffset[VY] = bottom - fFloor;
p->texHeight = fCeil - fFloor;
p->wallLength = *segLength;
if(rightSide)
{
// Right shadow.
p->texOffset[VX] = -(*lineLength) + *xOffset;
// Make sure the shadow isn't too big
if(size > *lineLength)
{
if(sideCn[0].corner <= MIN_OPEN)
p->texWidth = -(*lineLength);
else
p->texWidth = -((*lineLength) / 2);
}
else
{
p->texWidth = -size;
}
}
else
{
// Left shadow.
p->texOffset[VX] = *xOffset;
// Make sure the shadow isn't too big
if(size > *lineLength)
{
if(sideCn[1].corner <= MIN_OPEN)
p->texWidth = *lineLength;
else
p->texWidth = (*lineLength) / 2;
}
else
{
p->texWidth = size;
}
}
if(hasBackSector)
{
// There is a backside.
if(bFloor > fFloor && bCeil < fCeil)
{
if(!bottomGlow && !topGlow)
{
p->texture = LST_RADIO_CC;
}
else if(bottomGlow)
{
p->texOffset[VY] = bottom - fCeil;
p->texHeight = -(fCeil - fFloor);
p->texture = LST_RADIO_CO;
}
else
{
p->texture = LST_RADIO_CO;
}
}
else if(bFloor > fFloor)
{
if(!bottomGlow && !topGlow)
{
p->texture = LST_RADIO_CC;
}
else if(bottomGlow)
{
p->texOffset[VY] = bottom - fCeil;
p->texHeight = -(fCeil - fFloor);
p->texture = LST_RADIO_CO;
}
else
{
p->texture = LST_RADIO_CO;
}
}
else if(bCeil < fCeil)
{
if(!bottomGlow && !topGlow)
{
p->texture = LST_RADIO_CC;
}
else if(bottomGlow)
{
p->texOffset[VY] = bottom - fCeil;
p->texHeight = -(fCeil - fFloor);
p->texture = LST_RADIO_CO;
}
else
{
p->texture = LST_RADIO_CO;
}
}
}
else
{
if(bottomGlow)
{
p->texHeight = -(fCeil - fFloor);
p->texOffset[VY] = calcTexCoordY(top, fFloor, fCeil, p->texHeight);
p->texture = LST_RADIO_CO;
}
else if(topGlow)
{
p->texture = LST_RADIO_CO;
}
else
{
p->texture = LST_RADIO_CC;
}
}
}
static void quadTexCoords(rtexcoord_t *tc, rvertex_t const *rverts, float wallLength,
float texWidth, float texHeight, float texOrigin[2][3], float const texOffset[2],
boolean horizontal)
{
if(horizontal)
{
// Special horizontal coordinates for wall shadows.
tc[0].st[0] = tc[2].st[0] = rverts[0].pos[VX] - texOrigin[0][VX] + texOffset[VY] / texHeight;
tc[0].st[1] = tc[1].st[1] = rverts[0].pos[VY] - texOrigin[0][VY] + texOffset[VX] / texWidth;
tc[1].st[0] = tc[0].st[0] + (rverts[1].pos[VZ] - texOrigin[1][VZ]) / texHeight;
tc[3].st[0] = tc[0].st[0] + (rverts[3].pos[VZ] - texOrigin[1][VZ]) / texHeight;
tc[3].st[1] = tc[0].st[1] + wallLength / texWidth;
tc[2].st[1] = tc[0].st[1] + wallLength / texWidth;
return;
}
tc[0].st[0] = tc[1].st[0] = rverts[0].pos[VX] - texOrigin[0][VX] + texOffset[VX] / texWidth;
tc[3].st[1] = tc[1].st[1] = rverts[0].pos[VY] - texOrigin[0][VY] + texOffset[VY] / texHeight;
tc[3].st[0] = tc[2].st[0] = tc[0].st[0] + wallLength / texWidth;
tc[2].st[1] = tc[3].st[1] + (rverts[1].pos[VZ] - rverts[0].pos[VZ]) / texHeight;
tc[0].st[1] = tc[3].st[1] + (rverts[3].pos[VZ] - rverts[2].pos[VZ]) / texHeight;
}
static void drawWallSectionShadow(rvertex_t const *origVertices,
rendershadowseg_params_t const &wsParms, RendRadioWallSectionParms const &parms)
{
DENG_ASSERT(origVertices);
float texOrigin[2][3];
ColorRawf *rcolors;
rtexcoord_t *rtexcoords;
uint realNumVertices = 4;
if(parms.wall.left.divCount || parms.wall.right.divCount)
realNumVertices = 3 + parms.wall.left.divCount + 3 + parms.wall.right.divCount;
else
realNumVertices = 4;
// Top left.
texOrigin[0][VX] = origVertices[1].pos[VX];
texOrigin[0][VY] = origVertices[1].pos[VY];
texOrigin[0][VZ] = origVertices[1].pos[VZ];
// Bottom right.
texOrigin[1][VX] = origVertices[2].pos[VX];
texOrigin[1][VY] = origVertices[2].pos[VY];
texOrigin[1][VZ] = origVertices[2].pos[VZ];
// Allocate enough for the divisions too.
rtexcoords = R_AllocRendTexCoords(realNumVertices);