forked from thargor6/mb3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeaderTrafos.pas
1651 lines (1589 loc) · 69.2 KB
/
HeaderTrafos.pas
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
unit HeaderTrafos;
// All kind of transformations between Header and Light values
// + calc Thread parameters
interface
uses TypeDefinitions, Math3D, Windows;
type
THybridPars = record
start1, end1, repeat1: Integer;
start2, end2, repeat2: Integer;
end;
procedure MakeLightValsFromHeaderLight(Header: TPMandHeader10; Lvals: TPLightVals; ImScale: Double; StereoMode: Integer);
procedure MakeLightValsFromHeaderLightNavi(Header: TPMandHeader10; Lvals: TPLightValsNavi; ImScale: Double);
function GetMCTparasFromHeader(var Header: TMandHeader10; bIniCalcMaps: LongBool): TMCTparameter;
//procedure MakeLightVals(H1, H2: TMandHeader10; var L1, L2: TLightVals);
procedure AssignLightVal(Ldest, Lsource: TPLightVals);
procedure AssignHeader(H1, H2: TPMandHeader10);
function isSingleF(HA: PTHeaderCustomAddon; var FirstIndex: Integer): LongBool;
procedure IniCFsFromHAddon(PHaddon: PTHeaderCustomAddon; PHCustomF: array of Pointer);
procedure Ini1CFfromHAddon(PHaddon: PTHeaderCustomAddon; PHCustomF: PTCustomFormula; i: Integer);
procedure CalcVGradsFromHeader8rots(Header: TPMandHeader10);
procedure GetHAddOnFromInternFormula(PMHeader: TPMandHeader10; f, t: Integer);
procedure NormVGrads(Header: TPMandHeader10);
function LengthOfSize(Header: TPMandHeader10): Double;
procedure CalcHSVecsFromLights(Lvals: TPLightVals; MCTpars: PMCTparameter);
function GetDEstopFactor(Header: TPMandHeader10): Double;
function CalcCamPos(Header: TPMandHeader10): TVec3D;
procedure StereoChange(Header: TPMandHeader10; Mode: Integer; var midPos: TVec3D; pMatrix: TPMatrix3);
function CalcXoff(Header: TPMandHeader10): Single;
procedure CalcPosLightsRelPos(Header: TPMandHeader10; Lvals: TPLightVals);
procedure CalcSCstartAndSCmul(Header: TPMandHeader10; var sCStart, sCmul: Single; bIsInside: LongBool);
function GetRealMidPos(Header: TPMandHeader10): TVec3D;
function CalcViewVecH(x, y: Single; header: TPMandHeader10): TVec3D;
procedure CheckDEoption(const startNr, endNr: Integer; pHCA: PTHeaderCustomAddon;
const PHCustomF: array of Pointer; var DEoption: Integer);
//procedure GetHybridPars(var HybridPars: THybridPars; pHCA: PTHeaderCustomAddon);
//procedure CalcPosLightsRelPosAni(Header: TPMandHeader10; Lvals: TPLightVals);
var calcHybridCustoms: array[0..5] of TCustomFormula;
bGetMCTPverbose: LongBool = True;
const
InternFormulaNames: array[0..9] of AnsiString = ('Integer Power', 'Real Power',
'Quaternion', 'Tricorn', 'Amazing Box', 'Bulbox', 'Folding Int Pow','test',
'testIFS', 'Aexion C');
InternFormulaMax: Integer = 9;
implementation
uses Math, DivUtils, formulas, CustomFormulas, Mand, SysUtils, LightAdjust,
Navigator, Animation, Interpolation, PaintThread, Types, DOF, Tiling,
FileHandling, Calc, Maps{, OTrapDEcalc};
function GetDEstopFactor(Header: TPMandHeader10): Double;
var x1, x2, ze: Double;
begin
with Header^ do
begin
CalcStepWidth(Header);
ze := MaxCD(1e-16, (dZend - dZstart) / dStepWidth);
if bPlanarOptic = 2 then
x1 := s001 * Height / (Sin(s001) * Pi)
else
x1 := s001 * Height / (Sin(s001) * MaxCD(d1d65535, dFOVy * Pid180)); //relative camdistance, fixed sin
x2 := dStepWidth * (x1 + ze) / x1; // stepwidth at Zend
Result := (x2 - dStepWidth) / (dStepWidth * MaxCD(d1d6, ze));
end;
end;
//0..1
function CalcViewVecH(x, y: Single; header: TPMandHeader10): TVec3D;
var CAFX, CAFY, FOVXmul, FOVy, d: Double;
VGrads: TMatrix3;
begin
with header^ do
begin
CalcStepWidth(Header);
VGrads := NormaliseMatrixTo(dStepWidth, @hVGrads);
if bPlanarOptic = 2 then
begin
FOVy := Pi;
FOVXmul := PiM2;
end
else
begin
FOVy := dFOVy * Pid180;
FOVXmul := FOVy * Width / Height;
end;
CAFX := (CalcXoff(Header) - x) * FOVXmul;
CAFY := (y - s05) * FOVy;
if bPlanarOptic = 1 then
begin
Result[0] := -CAFX;
Result[1] := CAFY;
d := MinCS(1.5, MaxCS(s001, FOVy * s05));
Result[2] := Cos(d) * d / Sin(d);
NormaliseVectorVar(Result);
end
else if bPlanarOptic = 2 then
BuildViewVectorDSphereFOV(CAFY, CAFX, @Result)
else BuildViewVectorDFOV(CAFY, CAFX, @Result);
RotateVectorReverse(@Result, @VGrads);
end;
end;
function CalcCamPos(Header: TPMandHeader10): TVec3D;
var VPoff, startoff, s, c: Double;
v: TVec3D;
begin
with Header^ do
begin
CalcStepWidth(Header);
if bStereoMode = 2 then VPoff := 0 else
begin
SinCosD(MinCD(Abs(dFOVy), 180) * Pid180 * s05, s, c);
VPoff := dStepWidth * Height * s05 * c / MaxCD(0.01, s); //offset viewplane to campos ..here mindist add?
end;
startoff := dZstart - dZmid - VPoff; //Zoffset campos to Zmid
Result := GetRealMidPos(Header);
v := CalcViewVecH(s05, s05, Header); //normed to dStepWidth!
mAddVecWeight(@Result, @v, startoff / dStepWidth);
end;
end;
function CalcXoff(Header: TPMandHeader10): Single;
var Xoff: Double;
begin
with Header^ do
begin
Xoff := -0.065 / MaxCD(d1em100, StereoScreenWidth);
Result := s05;
case Header.bStereoMode of
1: Result := s05 + Xoff;
3: Result := s05 * (1 - Xoff);
4: Result := s05 * (1 + Xoff);
end;
end;
end;
function GetRealMidPos(Header: TPMandHeader10): TVec3D;
var eyedist, Xadd: Double;
v: TVec3D;
begin
with Header^ do
begin
CalcStepWidth(Header);
v := NormaliseVectorTo(dStepWidth, TPVec3D(@hVGrads)^);
eyedist := -0.065 * Width * StereoScreenDistance / (StereoMinDistance * StereoScreenWidth);
Xadd := 0;
case Header.bStereoMode of
1: Xadd := eyedist * (StereoScreenDistance - StereoMinDistance) / StereoScreenDistance; //very left from midpos
3: Xadd := -0.5 * eyedist * (StereoScreenDistance - StereoMinDistance) / StereoScreenDistance; //right
4: Xadd := s05 * eyedist * (StereoScreenDistance - StereoMinDistance) / StereoScreenDistance; //left
end; //dest, src, add
mCopyAddVecWeight(@Result, TPVec3D(@dXmid), @v, Xadd);
end;
end;
procedure StereoChange(Header: TPMandHeader10; Mode: Integer; var midPos: TVec3D; pMatrix: TPMatrix3);
var eyedist, Xadd: Double;
v: TVec3D;
begin
with Header^ do
begin
CalcStepWidth(Header);
v := NormaliseVectorTo(dStepWidth, TPVec3D(pMatrix)^);
eyedist := 0.065 * Width * StereoScreenDistance / MaxCD(d1em100, (StereoMinDistance * StereoScreenWidth));
Xadd := 0;
case Mode of
1: Xadd := -eyedist * (StereoScreenDistance - StereoMinDistance) / StereoScreenDistance; //very left from midpos
3: Xadd := s05 * eyedist * (StereoScreenDistance - StereoMinDistance) / StereoScreenDistance; //right
4: Xadd := -0.5 * eyedist * (StereoScreenDistance - StereoMinDistance) / StereoScreenDistance; //left
end; //dest, src, add
mCopyAddVecWeight(@midPos, TPVec3D(@dXmid), @v, Xadd);
end;
end;
procedure Ini1CFfromHAddon(PHaddon: PTHeaderCustomAddon; PHCustomF: PTCustomFormula; i: Integer);
var dOptionVtmp: array[0..15] of Double;
j: Integer;
begin
with PHaddon.Formulas[i] do
begin
if (iFnr <= InternFormulaMax) and (iFnr >= 0) then
begin
SetCFoptionsFromOldF(iFnr, PHCustomF);
PutStringInCustomF(CustomFname, InternFormulaNames[iFnr]);
end
else if (iFnr > 0) and (CustomFname[0] > 0) and LoadCustomFormulaFromHeader(CustomFname, PHCustomF^, dOptionVtmp) then
begin
iFnr := 20;
if iOptionCount < PHCustomF.iCFOptionCount then
begin //fill all above loadedcount with defaults when loading formula
if AnsiCompareText(CustomFtoStr(CustomFname), 'CylinderIFS') = 0 then
begin
if iOptionCount < 9 then
begin
dOptionValue[8] := dOptionValue[7];
dOptionValue[7] := 0;
if iOptionCount < 8 then dOptionValue[6] := 0;
iOptionCount := 9;
end;
end
else if AnsiCompareText(CustomFtoStr(CustomFname), 'SphereHeightMap') = 0 then
begin
for j := PHCustomF.iCFOptionCount - 1 downto 9 do
begin
dOptionValue[j] := dOptionValue[j - 1];
end;
dOptionValue[8] := 1;
dOptionValue[2] := dOptionValue[2] / NotZero(dOptionValue[5]);
dOptionValue[3] := dOptionValue[3] / NotZero(dOptionValue[6]);
iOptionCount := PHCustomF.iCFOptionCount;
end;
for j := iOptionCount to PHCustomF.iCFOptionCount - 1 do //ini rest of values with defaults (Vtmp)
dOptionValue[j] := dOptionVtmp[j];
iOptionCount := PHCustomF.iCFOptionCount;
end;
end
else
begin
iItCount := 0;
iOptionCount := 0;
iFnr := -1;
CustomFname[0] := 0;
Exit;
end;
CopyTypeAndOptionFromCFtoHAddon(PHCustomF, PHaddon, i);
end;
end;
procedure GetHAddOnFromInternFormula(PMHeader: TPMandHeader10; f, t: Integer);
var i: Integer;
pCF: PTCustomFormula;
const
oa: array[0..9, 0..1] of Double = ((8,-1),(8,-1),(-1,0),(-2,1),(2,0.5),(2,0.5),(2,-1),(-1,0),(0,0),(8,1));
begin
if f <= InternFormulaMax then
with PTHeaderCustomAddon(PMHeader.PCFAddon).Formulas[t] do
begin
iFnr := f;
pCF := PTCustomFormula(PMHeader.PHCustomF[t]);
SetCFoptionsFromOldF(f, pCF);
for i := 0 to 1 do dOptionValue[i] := oa[f][i];
for i := 2 to 15 do dOptionValue[i] := 0;
for i := 0 to 15 do byOptionType[i] := pCF.byOptionTypes[i];
iOptionCount := pCF.iCFOptionCount;
if f = 4 then dOptionValue[2] := 1 //Box
else if f = 5 then //BulBox
begin
dOptionValue[2] := 1;
dOptionValue[3] := 1;
dOptionValue[4] := 2;
dOptionValue[5] := 2;
end
else if f = 6 then dOptionValue[2] := 2
else if f = 7 then
begin
for i := 0 to testhybridOptionCount - 1 do dOptionValue[i] := testhybridOptionVals[i];
end
else if f = 8 then
begin
for i := 0 to testIFSOptionCount - 1 do dOptionValue[i] := testIFSOptionVals[i];
end
else if f = 9 then //Aexion C [Power, Z mul, Enable RotC (0,1), Cond Phi (0,1), Power C, Cz mul, PowC on dist Z-C, Mod (0,1)]
begin
dOptionValue[2] := 1;
dOptionValue[3] := 1;
dOptionValue[4] := 8;
dOptionValue[5] := 1;
end;
PutStringInCustomF(CustomFname, InternFormulaNames[f]);
CFdescription := CFdescriptionIntern[f];
end;
end;
procedure IniCFsFromHAddon(PHaddon: PTHeaderCustomAddon; PHCustomF: array of Pointer);
var i, i2: Integer;
begin
if (PHaddon.bOptions1 and 3) = 1 then i2 := 1 else i2 := 5;
for i := 0 to i2 do Ini1CFfromHAddon(PHaddon, PHCustomF[i], i);
end;
procedure AssignHeader(H1, H2: TPMandHeader10);
var p6: TP6;
begin
SaveHeaderPointers(H1, p6);
H1^ := H2^;
InsertHeaderPointers(H1, p6);
PTHeaderCustomAddon(H1.PCFAddon)^ := PTHeaderCustomAddon(H2.PCFAddon)^;
end;
procedure NormVGrads(Header: TPMandHeader10);
begin
CalcStepWidth(Header);
with Header^ do hVGrads := NormaliseMatrixTo(dStepWidth, @hVGrads);
end;
function LengthOfSize(Header: TPMandHeader10): Double;
begin
with Header^ do Result := Sqrt(Sqr(Width) + Sqr(Height));
end;
procedure AssignLightVal(Ldest, Lsource: TPLightVals);
begin
Ldest^ := Lsource^;
Ldest.PLValigned := TPLValigned((Integer(@Ldest.LColSbuf[0]) + 15) and $FFFFFFF0);
Ldest.PLValigned^ := Lsource.PLValigned^;
end;
procedure CalcVGradsFromHeader8rots(Header: TPMandHeader10);
var Esin1, Esin2, Esin3, Ecos1, Ecos2, Ecos3: Double;
step, x1, x2, y1, y2, z1, z2: Double;
i: Integer;
begin
with Header^ do //calculate Vectors from Rotation settings
begin
SinCosD(dXWrot, Esin1, Ecos1); // Y-Z rotation (X axis)
SinCosD(dYWrot, Esin2, Ecos2); // X-Z rotation (Y axis)
SinCosD(dZWrot, Esin3, Ecos3); // X-Y rotation (Z axis)
step := 2.1345 / (dZoom * Width);
if bCalc3D > 0 then
step := step * (s001 + Abs(Cos(Max(-1.25, Min(1.25, dFOVy)) * s05)));
for i := 0 to 2 do
begin
x1 := 0;
y1 := 0;
z1 := 0;
case i of
0: x1 := step; // calculate gradients in X direction
1: y1 := step; // calculate gradients in Y direction
2: z1 := step; // calculate gradients in Z direction
end;
x2 := x1; // rotate X axis
y2 := Ecos1 * y1 + Esin1 * z1;
z2 := Ecos1 * z1 - Esin1 * y1;
x1 := Ecos2 * x2 + Esin2 * z2; // rotate Y axis
y1 := y2;
z1 := Ecos2 * z2 - Esin2 * x2;
PDouble(Integer(@hVGrads[0,0]) + i * 24)^ := Ecos3 * x1 + Esin3 * y1; // rotate Z axis
PDouble(Integer(@hVGrads[0,1]) + i * 24)^ := Ecos3 * y1 - Esin3 * x1;
PDouble(Integer(@hVGrads[0,2]) + i * 24)^ := z1;
end;
end;
end;
function isSingleF(HA: PTHeaderCustomAddon; var FirstIndex: Integer): LongBool;
var i, j: Integer;
begin
i := 0;
FirstIndex := -1;
for j := 0 to 5 do if HA.Formulas[j].iItCount > 0 then
begin
Inc(i);
if FirstIndex = -1 then FirstIndex := j;
end;
Result := (i < 2);
if Result and (HA.bOptions1 = 2) then FirstIndex := -1; //not a valid formula option, need 2nd formula
end;
{procedure GetHybridPars(var HybridPars: THybridPars; pHCA: PTHeaderCustomAddon);
var x: Integer;
begin
with HybridPars do
begin
start1 := 0;
if (pHCA.bOptions1 and 3) = 1 then
begin //ipol hybrid
end1 := 0;
repeat1 := 0;
start2 := 1;
end2 := 1;
repeat2 := 1;
Exit;
end;
// else
begin
x := 5;
while (x > 0) and (pHCA.Formulas[x].iItCount = 0) do Dec(x);
end1 := Min(x, pHCA.bHybOpt1 and 7);
start2 := Max(end1 + 1, Min(x, pHCA.bHybOpt2 and 7));
end2 := Max(start2, Min(x, (pHCA.bHybOpt2 shr 4) and 7));
repeat2 := Max(start2, Min(end2, (pHCA.bHybOpt2 shr 8) and 7)); //start2, end2, repeat2 3x 4bit
if (pHCA.bOptions1 and 3) = 0 then end1 := x;
x := end1;
while (x > 0) and (pHCA.Formulas[x].iItCount <= 0) do Dec(x);
repeat1 := Min(x, pHCA.bHybOpt1 shr 4);
if (pHCA.bOptions1 and 3) = 2 then
begin
x := 5;
while (x > start2) and (pHCA.Formulas[x].iItCount <= 0) do Dec(x);
repeat2 := Min(x, repeat2);
end;
end;
pHCA.bHybOpt1 := end1 or (repeat1 shl 4);
pHCA.bHybOpt2 := start2 or (end2 shl 4) or (repeat2 shl 8);
end;
end; }
procedure CheckDEoption(const startNr, endNr: Integer; pHCA: PTHeaderCustomAddon;
const PHCustomF: array of Pointer; var DEoption: Integer);
var i, de, difsShapes: Integer;
begin
DEoption := -1;
for i := startNr to endNr do if pHCA.Formulas[i].iItCount > 0 then
begin
de := PTCustomFormula(PHCustomF[i]).iDEoption;
if (de < 0) or (de > 20) or (DEoption = de) then Continue;
if de = 20 then Inc(difsShapes);
if ((DEoption in [0..19]) and (de > 19)) or ((DEoption > 19) and (de in [0..19])) then
begin
DEoption := -1;
Break;
end
else
case DEoption of
-1: DEoption := de;
2: if not (de in [2,5,6,11]) then DEoption := 0;
4: if not (de in [5,6]) then DEoption := 0;
5: if de = 4 then DEoption := 4 else if de in [2,11] then DEoption := 2 else if de <> 6 then DEoption := 0;
6: if de in [2,4,5,11] then DEoption := de else DEoption := 0;
11: if de in [2,5] then DEoption := 2 else if de <> 6 then DEoption := 0;
end;
end;
if DEoption > 19 then
if difsShapes = 0 then DEoption := -1 else DEoption := 20;
end;
procedure CheckFormulaOptions(const startNr, endNr: Integer; pHCA: PTHeaderCustomAddon;
const PHCustomF: array of Pointer; var DEoption: Integer;
var MandFunctionDE: TMandFunctionDE; var MandFunction: TMandFunction;
var nHybrid: array of Integer; const bDisableADE: LongBool);
var i, de, difsShapes, LastValidF, LastF: Integer;
begin
DEoption := -1;
difsShapes := 0;
LastValidF := startNr;
LastF := startNr;
for i := startNr to endNr do if nHybrid[i] <> 0 then
begin
LastF := i;
de := PTCustomFormula(PHCustomF[i]).iDEoption;
if (de < 0) or (de > 20) then nHybrid[i] := -Abs(nHybrid[i])
else LastValidF := i;
if (de < 0) or (DEoption = de) then Continue;
if de = 20 then Inc(difsShapes);
if ((DEoption in [0..19]) and (de > 19)) or ((DEoption > 19) and (de in [0..19])) then
begin
DEoption := -1;
Mand3DForm.OutMessage('Error, mixing of dIFS with other formulas will not work!');
Break;
end
else
case DEoption of
-1,21,22: DEoption := de;
2: if not (de in [2,5,6,11]) then DEoption := 0;
4: if not (de in [5,6]) then DEoption := 0;
5: if de = 4 then DEoption := 4 else if de in [2,11] then DEoption := 2 else if de <> 6 then DEoption := 0;
6: if de in [2,4,5,11] then DEoption := de else DEoption := 0;
11: if de in [2,5] then DEoption := 2 else if de <> 6 then DEoption := 0;
end;
if bDisableADE then
case DEoption of
2,11: DEoption := 0;
5,6: DEoption := 4;
end;
end;
if startNr < (pHCA.bHybOpt2 and 7) then
begin
if LastValidF < (pHCA.bHybOpt1 shr 4) then pHCA.bHybOpt1 := (pHCA.bHybOpt1 and 7) or (LastValidF shl 4);
if (pHCA.bOptions1 = 2) and (pHCA.bOptions3 = 5) and ((DEoption < 0) or (DEoption > 20)) then
for i := startNr to endNr do if nHybrid[i] <> 0 then
begin
nHybrid[i] := Abs(nHybrid[i]);
DEoption := Max(0, PTCustomFormula(PHCustomF[i]).iDEoption);
Inc(difsShapes);
Break;
end;
end //mix
else
begin
if LastValidF < (pHCA.bHybOpt2 shr 8) then pHCA.bHybOpt2 := (pHCA.bHybOpt2 and $77) or (LastValidF shl 8);
pHCA.bHybOpt2 := (pHCA.bHybOpt2 and $707) or (LastF shl 4);
end;
if DEoption > 19 then
begin
if difsShapes = 0 then
begin
DEoption := -1;
Mand3DForm.OutMessage('Error, no dIFS shape formula selected.');
end
else DEoption := 20;
end;
MandFunction := fIsMemberAlternating;
MandFunctionDE := fIsMemberAlternatingDE;
case DEoption of
4..6: begin
MandFunctionDE := doHybrid4DDEPas;
MandFunction := fIsMemberAlternating4D;
end;
20: MandFunctionDE := doHybridIFS3D;// MandFunction := doHybridIFS3D; end;
end;
end;
{DEoption: [0,1]: 3D
[2,11] = 3D ADE [11] ABox
[4]: 4D
[5,6]: 4D ADE [6] ABox
[20..22]: dIFS [20] dIFS shapes}
function GetMCTparasFromHeader(var Header: TMandHeader10; bIniCalcMaps: LongBool): TMCTparameter;
var x1, x2, y1, z1, z2: Double;
n, x, i, j, ia, i52, itmp: Integer;
bIsInterpolHybrid, bDisableADE, bIsDEcomb, bTmp, bSecondPart: LongBool;
TileRect: TRect;
Crop: Integer;
PCFA: PTHeaderCustomAddon;
begin //calcHybridFormulas -> usage of own calcformulas! ->formulaclass
with Header do
begin
PCFA := PTHeaderCustomAddon(PCFAddon);
CheckHybridOptions(PCFA);
//GetHybridPars(HybridPars, PCFAddon);
Result.StartFrom1 := 0;
Result.wEndTo := PCFA.bHybOpt1 and 7;
Result.RepeatFrom1 := PCFA.bHybOpt1 shr 4;
Result.StartFrom2 := PCFA.bHybOpt2 and 7;
Result.iEnd2 := (PCFA.bHybOpt2 shr 4) and 7;
Result.RepeatFrom2 := (PCFA.bHybOpt2 shr 8) and 7;
Result.CalcDE := CalcDEfull;
Result.iSmNormals := (iOptions shr 6) and 15;
Result.msDEstop := MaxCS(s0001, sDEstop);
Result.DEstop := Result.msDEstop;
Result.sZstepDiv := MaxCS(0.0001, mZstepDiv);
Result.iDEAddSteps := bStepsafterDEStop;
Result.iMandHeight := Height;
Result.iMandWidth := Width;
if Header.TilingOptions <> 0 then
GetTilingInfosFromHeader(@Header, Result.CalcRect, Crop)
else Result.CalcRect := Rect(0, 0, Width - 1, Height - 1);
Result.SLoffset := GetTileSize(@Header).X * SizeOf(TsiLight5);
StereoChange(@Header, bStereoMode, TPVec3D(@Result.Xmit)^, @hVgrads);
Result.bInsideRendering := (PCFA.bOptions2 and 6) <> 0;
Result.bInAndOutside := (PCFA.bOptions2 and 4) <> 0;
Result.bCalcInside := Result.bInsideRendering;
if bPlanarOptic = 2 then Result.FOVy := Pi else Result.FOVy := dFOVy * Pid180;
Result.iMaxIt := Iterations;
Result.iMinIt := Min(Iterations, MinimumIterations);
Result.iMaxitF2 := iMaxItsF2;
Result.calc3D := bCalc3D <> 0;
Result.ColorOption := Min(5, byColor2Option); //(Light.TBoptions and $20000) shr 17; // for navigator + new color choices 0..6
Result.ColorOnIt := bColorOnIt;
Result.calcHardShadow := bCalculateHardShadow or (bCalc1HSsoft shl 8);
Result.dRstop := Sqr(RStop);
Result.Rstop3D := Sqr(Result.dRstop) * 64;
Result.iCutOptions := bCutOption;
FastMove(dCutX, Result.dCOX, 24);
Result.bDoJulia := bIsJulia <> 0;
FastMove(dJx, Result.dJUx, 24);
Result.dJUw := dJw;
Result.dDEscale := 1;
Result.pAl16vars := PAligned16;
Result.bVaryDEstop := (bVaryDEstopOnFOV <> 0);
Result.Vgrads := hVGrads;
Result.DEAOmaxL := sDEAOmaxL;
Result.DEmixCol := DEmixColorOption;
Result.FmixPow := sFmixPow;
Result.SoftShadowRadius := ShortFloatToSingle(@MCSoftShadowRadius);
Result.iSliceCalc := bSliceCalc; // default=mid, must set properly by procedure after getMCT
Result.MCTCameraOptic := Min(2, bPlanarOptic and 3);
// Result.bDoubleCheck := (iOptions and 2) > 0;
Result.sHSmaxLengthMultiplier := HSmaxLengthMultiplier;
Result.AOdither := AODEdithering;
Result.bCalcAmbShadow := (bCalcAmbShadowAutomatic and 1) <> 0;
x1 := Min(1.5, Max(s001, Result.FOVy * s05));
Result.mctPlOpticZ := Cos(x1) * x1 / Sin(x1);
Result.DFogOnIt := bDFogIt;
if (bVolLightNr and 7) > 0 then Result.DFogOnIt := 65535;
n := Min(5, Max(0, (bVolLightNr and 7) - 1));
if (Light.Lights[n].Loption and 4) <> 0 then //poslight
Result.VLmul := 1000 * ShortFloatToSingle(@Light.Lights[n].Lamp) / Width else
Result.VLmul := 300 * ShortFloatToSingle(@Light.Lights[n].Lamp) / Width;
Result.VLstepmul := Sqrt(1 / (1 + 0.1 * ((bVolLightNr shr 4) - 2)));
Result.FOVXoff := CalcXoff(@Header) * Width;
if bPlanarOptic = 2 then Result.FOVXmul := PiM2 / Width else Result.FOVXmul := Result.FOVy / Height;
MakeCustomFsFromHeader(Header);
bIsInterpolHybrid := (PCFA.bOptions1 and 3) = 1;
if bIsInterpolHybrid then i52 := 1 else i52 := 5;
bIsDEcomb := (PCFA.bOptions1 and 3) = 2;
if bIsDEcomb then Result.FormulaType := Min(6 , Max(1, PCFA.bOptions3 + 1))
else Result.FormulaType := 0;
bDisableADE := (PCFA.bOptions2 and 1) <> 0;
if not bIsDEcomb then Result.iMaxitF2 := Result.iMaxIt;
if bIsInterpolHybrid then
begin
Result.wEndTo := 1;
CheckDEoption(0, 1, PCFA, PHCustomF, Result.DEoption);
Result.DEoption2 := Result.DEoption;
if Result.DEoption in [4..6] then
begin
Result.mMandFunction := doInterpolHybridPas4D;
Result.mMandFunctionDE := doInterpolHybridPas4DDE;
end
else
begin
Result.mMandFunction := fIsMemberIpol;
Result.mMandFunctionDE := fIsMemberIpolDE;
end;
Result.mMandFunction2 := Result.mMandFunction;
Result.mMandFunctionDE2 := Result.mMandFunctionDE;
Result.IsCustomDE := Result.DEoption in [2,5,6,11];
Result.IsCustomDE2 := Result.IsCustomDE;
if Result.isCustomDE then Result.CalcDE := CalcDEanalytic
else Result.CalcDE := CalcDEnoADE;
n := -2;
if Result.DEoption in [20..22] then
Mand3DForm.OutMessage('Error, dIFS do not work in interpolation hybrid.')
else for x := 0 to 1 do
if PTHeaderCustomAddon(PCFAddon).Formulas[x].iFnr >= 0 then Inc(n);
x1 := PSingle(@PCFA.Formulas[0].iItCount)^;
x2 := PSingle(@PCFA.Formulas[1].iItCount)^;
y1 := x1 + x2;
if y1 < 1e-10 then
begin
y1 := 1;
x1 := 1;
x2 := 0;
end
else y1 := 1 / y1;
PSingle(@Result.nHybrid[0])^ := x1 * y1;
PSingle(@Result.nHybrid[1])^ := x2 * y1;
end
else
begin
isSingleF(PCFA, n);
for x := 0 to 5 do Result.nHybrid[x] := PCFA.Formulas[x].iItCount;
CheckFormulaOptions(0, Result.wEndTo, PCFA, PHCustomF, Result.DEoption,
Result.mMandFunctionDE, Result.mMandFunction, Result.nHybrid, bDisableADE);
if (PCFA.bHybOpt1 shr 4) < Result.RepeatFrom1 then
Result.RepeatFrom1 := Min(Result.RepeatFrom1, PCFA.bHybOpt1 shr 4);
Result.IsCustomDE := Result.DEoption in [2,5,6,11,20];
// if (Result.DEoption <> 20) and bDisableADE then Result.IsCustomDE := False;
if not bIsDEcomb then Result.DEoption2 := 0 else
begin
CheckFormulaOptions(Result.StartFrom2, 5{Result.iEnd2}, PCFA,
PHCustomF, Result.DEoption2, Result.mMandFunctionDE2,
Result.mMandFunction2, Result.nHybrid, bDisableADE);
Result.IsCustomDE2 := Result.DEoption2 in [2,5,6,11,20];
// if (Result.DEoption2 <> 20) and bDisableADE then Result.IsCustomDE2 := False;
if Result.FormulaType > 5 then
begin
if Result.DEoption2 <> 20 then
begin
Mand3DForm.OutMessage('Error, second hybrid type must be dIFS.');
Result.bMCTisValid := False;
end
else Result.mMandFunctionDE2 := doHybridIFS3DnoVecIni;
end;
end;
if bIsDEcomb then Result.CalcDE := CalcDEfull else
if Result.isCustomDE then Result.CalcDE := CalcDEanalytic
else Result.CalcDE := CalcDEnoADE;
end;
with Result do
begin
bMCTisValid := (n >= 0) and (DEoption >= 0) and ((DEoption2 >= 0) or not bIsDEcomb);
if ((DEoption = 20) or (DEoption2 = 20)) and not SupportSSE2 then
begin
bMCTisValid := False;
Mand3DForm.OutMessage('Error, CPU must support SSE2 for dIFS.');
Exit;
end;
if bMCTisValid then
begin
dColPlus := 0; //for am.box color vary on scale
dDEscale := 1;
dDEscale2 := 1;
n := 0; //calc DEscale
x1 := 0;
y1 := 0;
i := 0; //for both hybrid parts..
ia := 0;
itmp := 0;
for x := 0 to i52 do
begin
if bIsInterpolHybrid or (nHybrid[x] <> 0) then
begin
fHPVar[x] := PTCustomFormula(PHCustomF[x]).pConstPointer16;
if bIsInterpolHybrid or (nHybrid[x] > 0) then
begin
if PTCustomFormula(PHCustomF[x]).dSIpow > 1 then
z1 := PTCustomFormula(PHCustomF[x]).dSIpow
else //if PTHeaderCustomAddon(PCFAddon).Formulas[x].byOptionType[0] in [0, 14] then
z1 := PCFA.Formulas[x].dOptionValue[0]; //must be smarter , check name (pow, scale)
Result.fHln[x] := 1 / Ln(MaxCD(2, Abs(z1)));
end
else Result.fHln[x] := 1 / Ln(2);
bSecondPart := x > wEndTo;
if bSecondPart then bTmp := IsCustomDE2 else bTmp := IsCustomDE;
if bSecondPart and (itmp = 0) then
begin
Inc(itmp);
if (n > 0) and (DEoption <> 20) then
begin
dDEscale := x1 / n;
if i > 0 then dColPlus := Power(Abs(y1 / i), 0.25) * 40 - 49;
ia := i;
end;
n := 0;
x1 := 0;
y1 := 0;
i := 0;
end;
AssignCustomFormula(@calcHybridCustoms[x], PTCustomFormula(PHCustomF[x]));
fHybrid[x] := ThybridIteration2(calcHybridCustoms[x].pCodePointer);
if bIsInterpolHybrid then z1 := PSingle(@nHybrid[x])^
else z1 := Abs(nHybrid[x]);
j := PTCustomFormula(PHCustomF[x]).iDEoption;
if bTmp and (bIsInterpolHybrid or (nHybrid[x] > 0)) and (j in [5,11]) then
begin
if bIsInterpolHybrid then Inc(n) else n := n + Abs(nHybrid[x]);
if bIsInterpolHybrid then Inc(i) else i := i + Abs(nHybrid[x]);
x2 := NotZero(PDouble(Integer(calcHybridCustoms[x].pConstPointer16) - 16)^);
if x2 < 0 then x1 := x1 + 0.65 * z1
else x1 := x1 + (x2 * 1.2 + 1) / x2 * z1;
y1 := y1 + Abs(x2) * z1;
end
else if bIsInterpolHybrid or (PTCustomFormula(PHCustomF[x]).iDEoption >= 0) then
begin
if bIsInterpolHybrid then Inc(n) else n := n + Abs(nHybrid[x]);
if bTmp then x1 := x1 + PTCustomFormula(PHCustomF[x]).dADEscale * z1
else x1 := x1 + PTCustomFormula(PHCustomF[x]).dDEscale * z1;
if (PCFA.Formulas[x].iFnr = 4) and not bTmp then
begin
ThybridIteration(calcHybridCustoms[x].pCodePointer) := fHybridCube;
fHybrid[x] := ThybridIteration2(calcHybridCustoms[x].pCodePointer);
end;
end;
if (not bIsInterpolHybrid) and (nHybrid[x] < 0) then
nHybrid[x] := Abs(nHybrid[x]) or -2147483648; //-> $80000000; set high bit only, not negative!
end
else
begin
if calcHybridCustoms[x].bCPmemReserved then
VirtualFree(calcHybridCustoms[x].pCodePointer, 4096, MEM_DECOMMIT);
ThybridIteration(calcHybridCustoms[x].pCodePointer) := EmptyFormula;
calcHybridCustoms[x].bCPmemReserved := False;
end;
end;
for x := i52 + 1 to 5 do
begin
if calcHybridCustoms[x].bCPmemReserved then
VirtualFree(calcHybridCustoms[x].pCodePointer, 4096, MEM_DECOMMIT);
ThybridIteration(calcHybridCustoms[x].pCodePointer) := EmptyFormula;
calcHybridCustoms[x].bCPmemReserved := False;
end;
if (bIsDEcomb or (itmp = 0)) and (n > 0) and (DEoption2 <> 20) then
begin
if bIsInterpolHybrid then n := 1;
dDEscale2 := x1 / n;
if (i > ia) then dColPlus := Power(Abs(y1 / i), 0.25) * 40 - 49;
if itmp = 0 then result.dDEscale := result.dDEscale2;
end;
mctColorMul := sColorMul * 512; //LLI multiplier
CalcPPZvals(Header, Zcorr, ZcMul, Zend);
sZZstmitDif := Zend;
StepWidth := dStepWidth;
Zend := MaxCD(1e-10, (dZend - dZstart) / StepWidth);
mctColVarDEstopMul := 0.6; // calc parameter for keeping the colortabindex constant on zooming in (more or less)
{ if bIsInterpolHybrid then
begin
x2 := 0;
for x := 0 to 1 do if PSingle(@nHybrid[x])^ > 0 then
begin
y1 := PSingle(@nHybrid[x])^;
x2 := x2 + y1; //?? plenty
if PTCustomFormula(PHCustomF[x]).iDEoption in [1..3, 5..40] then
if PCFA.Formulas[x].byOptionType[0] in [0, 14] then
begin
x1 := PDouble(Integer(calcHybridCustoms[x].pConstPointer16) - 16)^;
if x1 > 1 then mctColVarDEstopMul := mctColVarDEstopMul + y1 * s05 / (ln(x1) + 0.03)
else if x1 < -1 then mctColVarDEstopMul := mctColVarDEstopMul + y1 * s05 / (ln(-x1) + 0.03)
else x2 := x2 - y1;
end
else if PTCustomFormula(PHCustomF[x]).iDEoption in [0, 4] then
mctColVarDEstopMul := mctColVarDEstopMul + y1 * 0.6
else x2 := x2 - y1;
end;
if x2 > 0 then mctColVarDEstopMul := mctColVarDEstopMul / x2
else mctColVarDEstopMul := 0.6;
end
else }
begin
ia := 0;
itmp := 0;
y1 := 0;
z1 := 0;
z2 := 0;
bSecondPart := False;
for x := 0 to i52 do if bIsInterpolHybrid or (nHybrid[x] > 0) then
begin
if (x > wEndTo) and not bSecondPart then
begin
bSecondPart := True;
if z1 > 0 then mctColVarDEstopMul := y1 / z1 else mctColVarDEstopMul := 0.6;
z2 := z1;
z1 := 0;
y1 := 0;
if (DEoption2 = 20) or not bIsDEcomb then Break;
end;
if bIsInterpolHybrid then x2 := PSingle(@nHybrid[x])^ else x2 := nHybrid[x];
if PTCustomFormula(PHCustomF[x]).iDEoption in [0, 4] then
begin
y1 := y1 + x2 * 0.6;
z1 := z1 + x2;
end
else if PTCustomFormula(PHCustomF[x]).iDEoption in [1..3, 5..40] then
begin //check type
if PCFA.Formulas[x].byOptionType[0] in [0, 14] then //and scale or power
begin
x1 := PDouble(Integer(calcHybridCustoms[x].pConstPointer16) - 16)^;
if x1 > 1 then
begin
if x1 < 1.2 then x1 := 1.1 + Sqr(x1 - 1) * 2.5;
y1 := y1 + x2 * s05 / (ln(x1) + 0.03);
z1 := z1 + x2;
end
else if x1 < -1 then
begin
if x1 > -1.2 then x1 := -1.1 - Sqr(x1 + 1) * 2.5;//ln(3) 1/1.1
y1 := y1 + x2 * s05 / (ln(-x1) + 0.03); //ln(2)=0.693147 1/1.4427
z1 := z1 + x2; //ln(1.3)=0.26236 1/3.8115
end; //ln(1.1)=0.09531
{ end
else //test
begin
y1 := y1 + x2 * 0.6;
z1 := z1 + x2; }
end; //ln(1.3)=0.26236 1/ 3.8115
end;
end
else if (not bIsInterpolHybrid) and (nHybrid[x] < 0) then if x > wEndTo then Inc(ia) else Inc(itmp);
if ((z1 >= z2) and (z1 > 1e-3)) or ((ia > itmp) and (Abs(z1 - z2) < 1e-3) and (z1 > 1e-3)) then
mctColVarDEstopMul := y1 / z1
else if z2 < 1e-3 then mctColVarDEstopMul := 0.6;
end;
bMCTFirstStepRandom := (iOptions and 1) <> 0;
mctMH04ZSD := Max(iMandWidth, iMandHeight) * s05 * Sqrt(sZstepDiv + s0001) * MaxCS(s001, sRaystepLimiter); //* DEstop in calculation
if bVaryDEstop then mctDEstopFactor := GetDEstopFactor(@Header)
else mctDEstopFactor := 0;
dLNRStop := Ln(Ln(RStop));
NormalsOnDE := (bNormalsOnDE > 0) or IsCustomDE;
if bIsInterpolHybrid then result.fHln[0] := fHln[0] * PSingle(@nHybrid[0])^ + fHln[1] * PSingle(@nHybrid[1])^;
if bPlanarOptic = 2 then //pano
begin
x1 := 0;
y1 := 0;
end else begin
x1 := iMandWidth * s05;
y1 := iMandHeight * s05;
end;
x2 := StepWidth;
if calc3D or (iSliceCalc = 1) then z1 := (dZstart - dZmid) / StepWidth
else if iSliceCalc = 3 then
begin
x2 := x2 * (1 + Sin(FOVy) * Zend / iMandHeight);
z1 := (dZend - dZmid) / x2;
end else begin
iSliceCalc := 2;
z1 := 0;
x2 := x2 * (1 + Sin(FOVy) * (dZmid - dZstart) / (StepWidth * iMandHeight));
end;
VGrads := NormaliseMatrixTo(x2, @hVGrads);
Ystart[0] := Xmit + z1 * Vgrads[2, 0] - y1 * Vgrads[1, 0] - x1 * Vgrads[0, 0];
Ystart[1] := Ymit + z1 * Vgrads[2, 1] - y1 * Vgrads[1, 1] - x1 * Vgrads[0, 1];
Ystart[2] := Zmit + z1 * Vgrads[2, 2] - y1 * Vgrads[1, 2] - x1 * Vgrads[0, 2];
mctDEoffset := Min(msDEstop * 0.1, 0.004); //for 4point DE calculation
for x := 0 to 5 do pInitialization[x] := nil;
if DEoption = 20 then dDEscale := 1;
if DEoption2 = 20 then dDEscale2 := 1;
if (DEoption = 20) or (DEoption2 = 20) then //dIFS
begin
iDEAddSteps := Max(iDEAddSteps, Round(MinCS(1, sZstepDiv) * 2) + 2);
if (not bIsDEcomb) or (FormulaType < 5) then iMinIt := 1;
bIsIFS := True;
NormalsOnDE := True;
end
else bIsIFS := False;
if (DEoption = 20) and ((not bIsDEcomb) or (DEoption2 = 20)) then
begin
mctMH04ZSD := Max(iMandWidth, iMandHeight); //raystep limiter
mctColVarDEstopMul := 0;
end;
if FormulaType > 5 then i := iMaxIt + iMaxitF2
else i := Max(iMaxIt, iMaxitF2);
mctsM := 32767 / Max(1, i + 1);
dColPlus := dColPlus + i * 0.1;
//new:
// dColPlus := i * 0.1 - ln(msDEstop * StepWidth); //- -12
sStepWm103 := StepWidth * 1.03;
BuildSMatrix4(dXWrot, dYWrot, dZWrot, Smatrix4d);
if iCutOptions > 0 then iCutOptions := iCutOptions or
((Ord(Vgrads[2,0] > 0) and 1) shl 4) or
((Ord(Vgrads[2,1] > 0) and 1) shl 5) or
((Ord(Vgrads[2,2] > 0) and 1) shl 6);
FSIstart := mFSIstart; //for montecarlo etc //tiling?
FSIoffset := mFSIoffset;
{ // if OTrapMode then
begin
NormalsOnDE := True;
if bIsDEcomb then CalcDE := CalcOTrapDEfull
else CalcDE := CalcOTrapDE;
IsCustomDE := True;
IsCustomDE2 := True;
dDEscale := 1;
dDEscale2 := 1;
mMandFunction := do3DalternateOTrap;
if bIsDEcomb then CalcDE := CalcOTrapDEfull
else CalcDE := CalcOTrapDEnoADE;
IsCustomDE := False;
IsCustomDE2 := False;
end; }
IsCustomDE1 := IsCustomDE;
if IsCustomDE then dDEscale := dDEscale / dStepWidth
else dDEscale := dDEscale * mctDEoffset;
if bIsDEcomb then
begin
NormalsOnDE := True;
sDEcombSmooth := MaxCS(1e-30, sDEcombS) / dStepWidth;
if IsCustomDE2 then dDEscale2 := dDEscale2 / dStepWidth
else dDEscale2 := dDEscale2 * mctDEoffset;
if DEoption2 <> 20 then bIsIFS := False; //just taken from previous version
end;
mctDEoffset006 := mctDEoffset * s006;
mctDEoffset := mctDEoffset * StepWidth; //new
if NormalsOnDE then TCalculateNormalsFunc(pCalcNormals) := RMCalculateNormals
else TCalculateNormalsFunc(pCalcNormals) := RMCalculateNormalsOnSmoothIt;
if (iOptions and 4) = 0 then msDEsub := 0 else
begin
sZstepDiv := sZstepDiv * sZstepDiv + (1.2 * sZstepDiv) * (1 - sZstepDiv);
msDEsub := MinCS(0.9, Sqrt(sZstepDiv));
end;
if bMCTisValid then
begin
if bIniCalcMaps then
try
IniCalcMaps(@Header);
except
if bGetMCTPverbose then Mand3DForm.OutMessage('Error in calcmap init.');
end;
if bGetMCTPverbose then Mand3DForm.OutMessage('Parameters ok.');
end;
end;
if not bMCTisValid then Mand3DForm.OutMessage('Error, formula option is not valid.');
end;
end;
end;
procedure CalcHSVecsFromLights(Lvals: TPLightVals; MCTpars: PMCTparameter);
var i: Integer;
M: TMatrix3;
begin
M := NormaliseMatrixTo(1, @MCTpars.VGrads);
for i := 0 to 5 do
if (Lvals.iLightPos[i] and 1) = 0 then
begin
MCTpars.HSvecs[i] := NormaliseSVectorTo(-MCTpars.StepWidth, Lvals.PLValigned.LN[i]);
RotateVectorReverse(@MCTpars.HSvecs[i], @M);
end
else MCTpars.HSvecs[i] := AddSVec2Vec3(@Lvals.PLValigned.LN[i], @MCTpars.Xmit); //for mc
end;
function HSumSVec(sv: TSVec): Single;
begin
Result := (sv[0] + sv[1] + sv[3]) * s1d3;
end;
function DistanceFromViewVecToLightPos(var ViewVec, LightPos, SPos: TSVec): Double;