-
Notifications
You must be signed in to change notification settings - Fork 1
/
effect.txt
1427 lines (1125 loc) · 42.3 KB
/
effect.txt
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
float4 ScreenSize=float4(1920,(1/1920),(1920/1080),(1080/1920));
static float FlipSize = ScreenSize.w*ScreenSize.x;
static float2 screenRes = {ScreenSize.x,FlipSize};
float4 Timer;
float FadeFactor = 1;
#define SEEDX Timer.w
#define PIX 3.1415926535897932384626433832795
#include "enbseries_mastereffect.ini"
//needful variables users should not change
//#define TILT_SHIFT
#define AUTO_FOCUS
float FocalPlaneDepth=0.50;
float FarBlurDepth=50.00;
float TiltShiftAngle=30.0;
//#define NOT_BLURRING_SKY_MODE
#define fFlareHorizontal 1
//#include "effect_config.txt"
//--------------------------------------------------------------------------------------
// Textures
//--------------------------------------------------------------------------------------
texture2D texColor;
texture2D texDepth;
texture2D texNoise;
//--------------------------------------------------------------------------------------
// Sampler Inputs
//--------------------------------------------------------------------------------------
sampler2D InputSampler = sampler_state
{
Texture = (texColor);
MinFilter = POINT;
MagFilter = POINT;
MipFilter = POINT;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
sampler2D SamplerDepth = sampler_state
{
Texture = <texDepth>;
MinFilter = POINT;
MagFilter = POINT;
MipFilter = NONE;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
sampler2D SamplerNoise = sampler_state
{
Texture = <texNoise>;
MinFilter = POINT;
MagFilter = POINT;
MipFilter = NONE;//NONE;
AddressU = Wrap;
AddressV = Wrap;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};
struct VS_OUTPUT_POST
{
float4 vpos : POSITION;
float2 txcoord : TEXCOORD0;
};
struct VS_INPUT_POST
{
float3 pos : POSITION;
float2 txcoord : TEXCOORD0;
};
float pixelWidth;
float pixelHeight;
//--------------------------------------------------------------------------------------
// Vertex Shader Input
//--------------------------------------------------------------------------------------
VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
{
VS_OUTPUT_POST OUT;
float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
OUT.vpos=pos;
OUT.txcoord.xy=IN.txcoord.xy;
return OUT;
}
//--------------------------------------------------------------------------------------
// Helpers
//--------------------------------------------------------------------------------------
#include "effect_functions.txt"
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
#if (GPDOF==1)
float4 PS_ProcessPass1(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float4 res;
float2 coord=IN.txcoord.xy;
float4 origcolor=tex2D(InputSampler, coord.xy);
float scenedepth=tex2D(SamplerDepth, IN.txcoord.xy).x;
float2 FocusCoords=FocusPoint;
float2 FocuspixelSize=ScreenSize.y;
FocuspixelSize.y*=ScreenSize.z;
const float2 Focusoffset[4]=
{
float2(0.0, 1.0),
float2(0.0, -1.0),
float2(1.0, 0.0),
float2(-1.0, 0.0)
};
float Focusres=linearlizeDepth(tex2D(SamplerDepth, FocusCoords.xy).x);
for (int i=0; i<4; i++)
{
FocusCoords.xy=FocusCoords.xy;
FocusCoords.xy+=Focusoffset[i] * FocuspixelSize.xy * FocusSampleRange;
#ifdef NOT_BLURRING_SKY_MODE
Focusres+=linearlizeDepth(tex2D(SamplerDepth, FocusCoords).x);
#else
Focusres+=min(linearlizeDepth(tex2D(SamplerDepth, FocusCoords).x), DepthClip);
#endif
}
Focusres*=0.2;
float scenefocus = Focusres.x;
//float scenefocus=tex2D(SamplerFocus, 0.5).x;
res.xyz=origcolor.xyz;
float depth=linearlizeDepth(scenedepth);
#ifdef AUTO_FOCUS
float focalPlaneDepth=scenefocus;
float farBlurDepth=scenefocus*pow(4.0, FarBlurCurve);
#else
float focalPlaneDepth=FocalPlaneDepth;
float farBlurDepth=FarBlurDepth;
#endif
#ifdef TILT_SHIFT
float shiftAngle=(frac(TiltShiftAngle / 90.0) == 0) ? 0.0 : TiltShiftAngle;
float depthShift=1.0 + (0.5 - coord.x)*tan(-shiftAngle * 0.017453292);
focalPlaneDepth*=depthShift;
farBlurDepth*=depthShift;
#endif
if(depth < focalPlaneDepth)
res.w=(depth - focalPlaneDepth)/focalPlaneDepth;
else
{
res.w=(depth - focalPlaneDepth)/(farBlurDepth - focalPlaneDepth);
res.w=saturate(res.w);
}
res.w=res.w * 0.5 + 0.5;
#ifdef NOT_BLURRING_SKY_MODE
#define DEPTH_OF_FIELD_QULITY 0
res.w=(depth > 1000.0) ? 0.5 : res.w;
#endif
#if (SPLITSCREEN==1)
return (IN.txcoord.x < 0.5) ? tex2D(InputSampler, IN.txcoord) : res;
#endif
return res;
}
float4 PS_ProcessPass2(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float4 res;
float2 coord=IN.txcoord.xy;
float4 origcolor=tex2D(InputSampler, coord.xy);
float centerDepth=origcolor.w;
float2 pixelSize=ScreenSize.y;
pixelSize.y*=ScreenSize.z;
float blurAmount=abs(centerDepth * 2.0 - 1.0);
float discRadius=blurAmount * float(DEPTH_OF_FIELD_QULITY);
discRadius*=RadiusSacleMultipiler;
#ifdef AUTO_FOCUS
discRadius*=(centerDepth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
#endif
res.xyz=origcolor.xyz;
res.w=dot(res.xyz, 0.3333);
res.w=max((res.w - BokehBrightnessThreshold) * BokehBrightnessMultipiler, 0.0);
res.xyz*=1.0 + res.w*blurAmount;
res.w=1.0;
int sampleCycle=0;
int sampleCycleCounter=0;
int sampleCounterInCycle=0;
#ifdef POLYGONAL_BOKEH
float basedAngle=360.0 / POLYGON_NUM;
float2 currentVertex;
float2 nextVertex;
int dofTaps=DEPTH_OF_FIELD_QULITY * (DEPTH_OF_FIELD_QULITY + 1) * POLYGON_NUM / 2.0;
#else
int dofTaps=DEPTH_OF_FIELD_QULITY * (DEPTH_OF_FIELD_QULITY + 1) * 4;
#endif
for(int i=0; i < dofTaps; i++)
{
if(sampleCounterInCycle % sampleCycle == 0)
{
sampleCounterInCycle=0;
sampleCycleCounter++;
#ifdef POLYGONAL_BOKEH
sampleCycle+=POLYGON_NUM;
currentVertex.xy=float2(1.0 , 0.0);
sincos(basedAngle* 0.017453292, nextVertex.y, nextVertex.x);
#else
sampleCycle+=8;
#endif
}
sampleCounterInCycle++;
#ifdef POLYGONAL_BOKEH
float sampleAngle=basedAngle / float(sampleCycleCounter) * sampleCounterInCycle;
float remainAngle=frac(sampleAngle / basedAngle) * basedAngle;
if(remainAngle == 0)
{
currentVertex=nextVertex;
sincos((sampleAngle + basedAngle) * 0.017453292, nextVertex.y, nextVertex.x);
}
float2 sampleOffset=lerp(currentVertex.xy, nextVertex.xy, remainAngle / basedAngle);
#else
float sampleAngle=0.78539816 / float(sampleCycleCounter) * sampleCounterInCycle;
float2 sampleOffset;
sincos(sampleAngle, sampleOffset.y, sampleOffset.x);
#endif
sampleOffset*=sampleCycleCounter / float(DEPTH_OF_FIELD_QULITY);
float2 coordLow=coord.xy + (pixelSize.xy * sampleOffset.xy * discRadius);
float4 tap=tex2D(InputSampler, coordLow.xy);
float weight=(tap.w >= centerDepth) ? 1.0 : abs(tap.w * 2.0 - 1.0);
float luma=dot(tap.xyz, 0.3333);
float brightMultipiler=max((luma - BokehBrightnessThreshold) * BokehBrightnessMultipiler, 0.0);
tap.xyz*=1.0 + brightMultipiler*abs(tap.w*2.0 - 1.0);
tap.xyz*=1.0 + BokehBias * pow(float(sampleCycleCounter)/float(DEPTH_OF_FIELD_QULITY), BokehBiasCurve);
res.xyz+=tap.xyz * weight;
res.w+=weight;
}
res.xyz /= res.w;
res.w=centerDepth;
#if (SPLITSCREEN==1)
return (IN.txcoord.x < 0.5) ? tex2D(InputSampler, IN.txcoord) : res;
#endif
return res;
}
float4 PS_ProcessPass3(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float2 coord=IN.txcoord.xy;
float2 pixelSize=ScreenSize.y;
pixelSize.y*=ScreenSize.z;
float4 origcolor=tex2D(InputSampler, coord.xy);
float depth=origcolor.w;
float blurAmount=abs(depth * 2.0 - 1.0);
float discRadius=blurAmount * float(DEPTH_OF_FIELD_QULITY) * RadiusSacleMultipiler;
#ifdef AUTO_FOCUS
discRadius*=(depth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
#endif
float4 res=origcolor;
float3 distortion=float3(-1.0, 0.0, 1.0);
distortion*=ChromaticAberrationAmount*discRadius;
origcolor=tex2D(InputSampler, coord.xy + pixelSize.xy*distortion.x);
origcolor.w=smoothstep(0.0, depth, origcolor.w);
res.x=lerp(res.x, origcolor.x, origcolor.w);
origcolor=tex2D(InputSampler, coord.xy + pixelSize.xy*distortion.z);
origcolor.w=smoothstep(0.0, depth, origcolor.w);
res.z=lerp(res.z, origcolor.z, origcolor.w);
#if (SPLITSCREEN==1)
return (IN.txcoord.x < 0.5) ? tex2D(InputSampler, IN.txcoord) : res;
#endif
return res;
}
float4 PS_ProcessPass4(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float2 coord=IN.txcoord.xy;
float2 pixelSize=ScreenSize.y;
pixelSize.y*=ScreenSize.z;
float4 origcolor=tex2D(InputSampler, coord.xy);
float depth=origcolor.w;
float blurAmount=abs(depth*2.0 - 1.0);
#if (DEPTH_OF_FIELD_QULITY > 0)
#ifdef AUTO_FOCUS
blurAmount*=(depth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
#endif
blurAmount=smoothstep(0.15, 1.0, blurAmount);
#endif
float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541,
0.0162162162};
float4 res=origcolor * weight[0];
for(int i=1; i < 5; i++)
{
res+=tex2D(InputSampler, coord.xy + float2(i*pixelSize.x*blurAmount, 0)) * weight[i];
res+=tex2D(InputSampler, coord.xy - float2(i*pixelSize.x*blurAmount, 0)) * weight[i];
}
res.w=depth;
#if (SPLITSCREEN==1)
return (IN.txcoord.x < 0.5) ? tex2D(InputSampler, IN.txcoord) : res;
#endif
return res;
}
float4 PS_ProcessPass5(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float2 coord=IN.txcoord.xy;
float2 pixelSize=ScreenSize.y;
pixelSize.y*=ScreenSize.z;
float4 origcolor=tex2D(InputSampler, coord.xy);
float depth=origcolor.w;
float blurAmount=abs(depth*2.0 - 1.0);
#if (DEPTH_OF_FIELD_QULITY > 0)
#ifdef AUTO_FOCUS
blurAmount*=(depth < 0.5) ? (1.0 / max(NearBlurCurve, 1.0)) : 1.0;
#endif
blurAmount=smoothstep(0.15, 1.0, blurAmount);
#endif
float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541,
0.0162162162};
float4 res=origcolor * weight[0];
for(int i=1; i < 5; i++)
{
res+=tex2D(InputSampler, coord.xy + float2(0, i*pixelSize.y*blurAmount)) * weight[i];
res+=tex2D(InputSampler, coord.xy - float2(0, i*pixelSize.y*blurAmount)) * weight[i];
}
float origgray=dot(res.xyz, 0.3333);
origgray/=origgray + 1.0;
coord.xy=IN.txcoord.xy*16.0 + origgray;
float4 cnoi=tex2D(SamplerNoise, coord);
float noiseAmount=NoiseAmount*pow(blurAmount, NoiseCurve);
res=lerp(res, (cnoi.x+0.5)*res, noiseAmount*saturate(1.0-origgray*1.8));
res.w=depth;
#if (SPLITSCREEN==1)
return (IN.txcoord.x < 0.5) ? tex2D(InputSampler, IN.txcoord) : res;
#endif
return res;
}
#endif
float4 Tonemap(VS_OUTPUT_POST i, float2 vPos : VPOS) : COLOR
{
float2 fvTexelSizeBloom = float2(1.0 / 1920, 1.0 / 1080);
#if (SHARPEN==1)
float4 color = 9 * tex2D(InputSampler, i.txcoord);
color -= tex2D(InputSampler, i.txcoord.xy + float2(-fvTexelSizeBloom.x, fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(0.0, fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(fvTexelSizeBloom.x, fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(fvTexelSizeBloom.x, 0.0) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(fvTexelSizeBloom.x, -fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(0.0, -fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(-fvTexelSizeBloom.x, -fvTexelSizeBloom.y) * fSharpScale);
color -= tex2D(InputSampler, i.txcoord.xy + float2(-fvTexelSizeBloom.x, 0.0) * fSharpScale);
#endif
#if (SHARPEN==0)
float4 color = tex2D(InputSampler, i.txcoord);
#endif
#if(BLOOM_CRISP==1)
float steps = EBloomSteps;
float4 bloomcolor= 0;
fvTexelSizeBloom *= EBloomRadius;
float2 direction;
for(float x = 1; x<=steps; x++)
{
direction=float2(-0.707, 0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.383, 0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, 1.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.383, 0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, 0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.924, 0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.707, 0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, 1.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, 0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.924, 0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-1.0, 0.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-1.0, 0.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, 0.0)*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(1.0, 0.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(1.0, 0.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.924, -0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.707, -0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, -1.0) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, -0.707) * 0.524*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.924, -0.383) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.707, -0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(-0.383, -0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.0, -1.0) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.383, -0.924) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
direction=float2(0.707, -0.707) * 1.282*x*fvTexelSizeBloom;
bloomcolor += tex2Dlod(InputSampler, float4(i.txcoord.xy + direction.xy,0,1)) * (steps-x)*(1/steps);
}
bloomcolor /= 25*steps;
bloomcolor *= bloomcolor*EBloomCurve;
float sVal = EBloomSat;
float sLuma = dot(bloomcolor.xyz,float3(0.27, 0.67, 0.06));
float3 sNcolor = normalize(bloomcolor);
sNcolor.xyz = pow(sNcolor.xyz, sVal);
float sNluma = dot(sNcolor.xyz,float3(0.27, 0.67, 0.06));
bloomcolor.xyz = sNcolor.xyz*sLuma/sNluma;
color += bloomcolor*EBloomAmount;
#endif
#if (SKYRIMTONEMAP==1)
float4 Adaptation=float4( 0.0, 0.0, 0.0, 1 );
float grayadaptation = Luminance(color);
#if (POSTPROCESS==1)
grayadaptation = max(grayadaptation, 0.0);
grayadaptation = min(grayadaptation, 50.0);
color.xyz = color.xyz / (grayadaptation * EAdaptationMaxV1 + EAdaptationMinV1);
float cgray = dot( color.xyz, float3(0.27, 0.67, 0.06));
cgray = pow(cgray, EContrastV1);
float3 poweredcolor = pow( color.xyz, EColorSaturationV1);
float newgray = dot(poweredcolor.xyz, float3(0.27, 0.67, 0.06));
color.xyz = poweredcolor.xyz * cgray / (newgray + 0.0001);
float3 luma = color.xyz;
float lumamax = 300.0;
color.xyz = ( color.xyz * (1.0 + color.xyz / lumamax)) / ( color.xyz + EToneMappingCurveV1);
#endif
#if (POSTPROCESS==2)
grayadaptation = max(grayadaptation, 0.0);
grayadaptation = min(grayadaptation, 50.0);
color.xyz = color.xyz / (grayadaptation * EAdaptationMaxV2 + EAdaptationMinV2);
float3 xncol = normalize( color.xyz);
float3 scl = color.xyz / xncol.xyz;
scl = pow(scl, EIntensityContrastV2);
xncol.xyz = pow(xncol.xyz, EColorSaturationV2);
color.xyz = scl*xncol.xyz;
float lumamax = EToneMappingOversaturationV2;
color.xyz = ( color.xyz * (1.0 + color.xyz / lumamax)) / ( color.xyz + EToneMappingCurveV2);
color.xyz*=4;
#endif
#if (POSTPROCESS==3)
color.xyz *= 35;
float lumamax = EToneMappingOversaturationV3;
color.xyz = ( color.xyz * (1.0 + color.xyz / lumamax)) / ( color.xyz + EToneMappingCurveV3);
#endif
#if (POSTPROCESS == 4)
grayadaptation = max(grayadaptation, 0.0);
grayadaptation = min(grayadaptation, 50.0);
color.xyz = color.xyz / (grayadaptation * EAdaptationMaxV4 + EAdaptationMinV4);
float Y = dot( color.xyz, float3(0.299, 0.587, 0.114)); //0.299 * R + 0.587 * G + 0.114 * B;
float U = dot( color.xyz, float3(-0.14713, -0.28886, 0.436)); //-0.14713 * R - 0.28886 * G + 0.436 * B;
float V = dot( color.xyz, float3(0.615, -0.51499, -0.10001)); //0.615 * R - 0.51499 * G - 0.10001 * B;
Y = pow(Y, EBrightnessCurveV4);
Y = Y * EBrightnessMultiplierV4;
color.xyz = V * float3(1.13983, -0.58060, 0.0) + U * float3(0.0, -0.39465, 2.03211) + Y;
color.xyz = max( color.xyz, 0.0);
color.xyz = color.xyz / ( color.xyz + EBrightnessToneMappingCurveV4);
#endif
#if (POSTPROCESS == 5)
float hnd = 1;
float2 hndtweak = float2( 3.1 , 1.5 );
grayadaptation = max(grayadaptation, 0.0);
grayadaptation = min(grayadaptation, 50.0);
color.xyz *= lerp( hndtweak.x, hndtweak.y, hnd );
float3 xncol = normalize( color.xyz);
float3 scl = color.xyz/xncol.xyz;
scl = pow(scl, EIntensityContrastV5);
xncol.xyz = pow(xncol.xyz, EColorSaturationV5);
color.xyz = scl*xncol.xyz;
color.xyz *= HCompensateSatV5; // compensate for darkening caused my EcolorSat above
color.xyz = color.xyz / ( color.xyz + EToneMappingCurveV5);
color.xyz *= 4;
#endif
#if (POSTPROCESS==6)
//Postprocessing V6 by Kermles
//hd6/ppv2///////////////////////////////////////////
float EIntensityContrastV6 = EIntensityContrastV6Day;
float EColorSaturationV6 = EColorSaturationV6Day;
float HCompensateSatV6 = HCompensateSatV6Day;
float EToneMappingCurveV6 = EToneMappingCurveV6Day;
float EBrightnessV6 = EBrightnessV6Day;
float EToneMappingOversaturationV6 = EToneMappingOversaturationV6Day;
float EAdaptationMaxV6 = EAdaptationMaxV6Day;
float EAdaptationMinV6 = EAdaptationMinV6Day;
float lumamax = EToneMappingOversaturationV6;
//kermles////////////////////////////////////////////
float EAdaptationCompensateV6 = EAdaptationCompensateV6Day;
float EBrightnessMaxV6 = EBrightnessMaxV6Day;
float EBrightnessMinV6 = EBrightnessMinV6Day;
float3 moodColor = EMoodColorDay;
float moodAmount = EMoodAmountDay;
float moodCurve = EMoodCurveDay;
float3 shadowColor = EShadowColorDay;
float shadowThreshold = EShadowThresholdDay;
float shadowCurve = EShadowCurveDay;
float3 brightSpotColor = EBrightSpotColorDay;
float brightSpotThreshold = EBrightSpotThresholdDay;
float brightSpotCurve = EBrightSpotCurveDay / 10;
float hsvDesatCurve = EHSVDesatCurveDay;
float PPAmount = 0.5; //controls interpolation between vanilla colors and PP6 colors
float4 ncolor; //temporary variable for color adjustments
float avgbr; //temporary variable for color adjustments
//begin pp code/////////////////////////////////////////////////
//store vanilla colors//////////////////////////////////////////
float4 oldcolor = color;
//convert to hsv////////////////////////////////////////////////
float3 hsvncolor = RGBtoHSV( color.xyz );
hsvncolor.y = max( hsvncolor.y, 0.0 );
hsvncolor.z = max( hsvncolor.z, 0.0 );
//desaturate based on original saturation then resaturate///////
hsvncolor.y = pow( hsvncolor.y, hsvDesatCurve );
hsvncolor.y = saturate(hsvncolor.y * EColorSaturationV6);
//convert back to rgb///////////////////////////////////////////
hsvncolor.y = max( hsvncolor.y, 0.0 );
color.xyz = HSVtoRGB( hsvncolor );
//brightness clamping///////////////////////////////////////////
color.xyz=clamp( color.xyz, EBrightnessMinV6, EBrightnessMaxV6);
//ppv2 modified by kermles//////////////////////////////////////
grayadaptation = clamp(grayadaptation, 0, 50);
color.xyz *= EBrightnessV6;
float3 xncol = normalize( color.xyz);
float3 scl = color.xyz/xncol.xyz;
scl = pow(scl, EIntensityContrastV6);
xncol.xyz = pow(xncol.xyz, EColorSaturationV6);
color.xyz = scl*xncol.xyz;
color.xyz *= HCompensateSatV6;
color.xyz = ( color.xyz * (1.0 + color.xyz/lumamax))/( color.xyz + EToneMappingCurveV6);
//mood coloring/////////////////////////////////////////////////
ncolor = color;
avgbr = (ncolor.x + ncolor.y + ncolor.z)/3;
moodColor.xyz = lerp( moodColor/10, moodColor, saturate( avgbr * 2 ) );
moodColor.xyz = lerp( moodColor, 1, saturate( avgbr - 0.5 ) * 2 );
moodColor.xyz = lerp( ncolor, moodColor, saturate(avgbr / moodCurve));
ncolor.xyz = lerp( ncolor, moodColor, saturate( avgbr * moodAmount ) );
color.xyz = max(0, ncolor);
//shadows///////////////////////////////////////////////////////
ncolor = color;
avgbr = (ncolor.x + ncolor.y + ncolor.z)/3;
shadowColor = lerp(0.1*(2.55-shadowColor), 2.55-shadowColor, saturate(avgbr*2));
shadowColor = lerp(shadowColor, 1, saturate(avgbr-0.5)*2);
ncolor.xyz = max(ncolor, pow(ncolor, ((1.0+ncolor) * (shadowColor))*shadowThreshold)/shadowCurve);
color.xyz = saturate(ncolor);
//brightspots///////////////////////////////////////////////////
brightSpotColor = lerp(brightSpotColor/10, brightSpotColor, saturate(avgbr*2));
brightSpotColor = lerp(brightSpotColor, 1, saturate(avgbr-0.5)*2);
ncolor = 1- color;
ncolor.xyz = max(ncolor, pow(ncolor, ((1.0 + ncolor) * (brightSpotColor))*brightSpotThreshold)/brightSpotCurve);
color.xyz = saturate(1-ncolor);
//convert to hsv////////////////////////////////////////////////
hsvncolor = RGBtoHSV( color.xyz );
hsvncolor.y = max( hsvncolor.y, 0.0 );
hsvncolor.z = max( hsvncolor.z, 0.0 );
//adaptation/contrast///////////////////////////////////////////
hsvncolor.z = pow(hsvncolor.z, (grayadaptation*EAdaptationMaxV6+EAdaptationMinV6));
//convert back to rgb///////////////////////////////////////////
hsvncolor.y = max( hsvncolor.y, 0.0 );
hsvncolor.z = max( hsvncolor.z, 0.0 );
color.xyz = HSVtoRGB( hsvncolor );
color.xyz /= grayadaptation*EAdaptationMaxV6+EAdaptationMinV6;
color.xyz /= EAdaptationCompensateV6;
//rerun ppv2////////////////////////////////////////////////////
color.xyz *= EBrightnessV6;
xncol = normalize( color.xyz);
scl = color.xyz/xncol.xyz;
scl = pow(scl, EIntensityContrastV6);
xncol.xyz = pow(xncol.xyz, EColorSaturationV6);
color.xyz = scl*xncol.xyz;
color.xyz *= HCompensateSatV6;
color.xyz = ( color.xyz * (1.0 + color.xyz/lumamax))/( color.xyz + EToneMappingCurveV6);
//lerp between vanilla and pp6 colors///////////////////////////
color = lerp(oldcolor, color, PPAmount);
#endif
#endif
#define const_1 (DARK_LEVEL/255.0)
#define const_2 (255.0/(255.0-BRIGHT_LEVEL))
#if (TVLEVELS==1)
color.xyz = (color.xyz - const_1) * const_2;
#endif
#if (COLORWASHOUT==1)
float colorGray=dot(color.xyz, 0.333);
float colorGray2=(colorGray*(6.2*colorGray+0.5))/(colorGray*(6.2*colorGray+1.7)+0.06);
float colorGray3=pow(colorGray, 0.36);
float colorWashout=saturate(colorGray2 - ColorWashoutThreshold)/(1.00 - ColorWashoutThreshold);
colorWashout=saturate(pow(colorWashout, ColorWashoutPow) * ColorWashoutAmount);
float3 middleColor=(color.xyz+0.0001)/(colorGray+0.000001);
middleColor.xyz=lerp(pow(middleColor.xyz, ColorSaturation), middleColor.xyz, ColorSaturation);
middleColor.xyz=lerp(middleColor.xyz, 1.00, saturate(colorWashout*ColorWashoutAmount));
float tonemapMix=(0.5 - ColorDullnessAmount)*0.60; //temp
colorGray=lerp(colorGray2, colorGray3, tonemapMix);
color.xyz=middleColor.xyz*colorGray;
color.xyz *= ExpAdjustment;
#endif
#if (VIBRANCEPASS==1)
float3 lumCoeff = float3(0.2126, 0.7152, 0.0722);
float vibranceluma = dot(lumCoeff, color.xyz);
float max_color = max(color.x, max(color.y,color.z)); //Find the strongest color
float min_color = min(color.x, max(color.y,color.z)); //Find the weakest color
float color_saturation = max_color - min_color;
color.xyz = lerp(vibranceluma, color.xyz, (1.0 + (Vibrance * (1.0 - (sign(Vibrance) * color_saturation)))));
#endif
#if (HDR==1)
color = TonemapPass(color);
#endif
#if (FILMICPASS==1)
color = FilmPass(color);
#endif
#if (CROSSPROCESS==1)
color = CrossProcess_PS(color);
#endif
#if (COLORMOOD==1)
color = MoodPass(color);
#endif
#if (SEPIA==1)
color = SepiaPass(color);
#endif
#if(COLORBOOST==1)
float Zmiddlegray=(color.r+color.g+color.b)*0.333;
float3 Zdiffcolor=color.rgb-Zmiddlegray;
color.rgb+=Zdiffcolor*0.6;
color.rgb-=Zdiffcolor*0.1;
#endif
#if (FINALADJUSTER==1)
color = FinalAdjusterPass(color);
#endif
#if (SPLITSCREEN==1)
return (i.txcoord.x < 0.5) ? tex2D(InputSampler, i.txcoord) : color;
#endif
color.w=1;
return color;
}
float4 Flares(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float4 res;
#if (CHROMATICABBERATION==0)
float3 origcolor=tex2D(InputSampler, IN.txcoord.xy);
#endif
#if (CHROMATICABBERATION==1)
float4 coord=0.0;
coord.xy=IN.txcoord.xy;
coord.w=0.0;
float3 eta = float3(1.0+ChromaticAmount*0.9,1.0+ChromaticAmount*0.6,1.0+ChromaticAmount*0.3);
float2 center;
center.x = coord.x-0.5;
center.y = coord.y-0.5;
float LensZoom = 1.0/LensSize;
float r2 = (IN.txcoord.x-0.5) * (IN.txcoord.x-0.5) + (IN.txcoord.y-0.5) * (IN.txcoord.y-0.5);
float f = 0;
if( LensDistortionCubic == 0.0){
f = 1 + r2 * LensDistortion;
}else{
f = 1 + r2 * (LensDistortion + LensDistortionCubic * sqrt(r2));
};
float x = f*LensZoom*(coord.x-0.5)+0.5;
float y = f*LensZoom*(coord.y-0.5)+0.5;
float2 rCoords = (f*eta.r)*LensZoom*(center.xy*0.5)+0.5;
float2 gCoords = (f*eta.g)*LensZoom*(center.xy*0.5)+0.5;
float2 bCoords = (f*eta.b)*LensZoom*(center.xy*0.5)+0.5;
float4 inputDistord = float4(tex2D(InputSampler,rCoords).r , tex2D(InputSampler,gCoords).g ,tex2D(InputSampler,bCoords).b, tex2D(InputSampler,float2(x,y)).a);
float4 schmotzcolor = float4(inputDistord.r,inputDistord.g,inputDistord.b,1);
float3 origcolor = schmotzcolor.xyz;
#endif
#if (LENZ==1)
float3 lenz=0;
float2 lenzuv=0.0;
const float3 offset[15]=
{
float3(0.3, 0.01, 4),
float3(0.7, 0.25, 25),
float3(0.3, 0.25, 15),
// Full
float3(1, 1.0, 5),
// Arriere
float3(-0.15, 20, 1),
float3(-0.3, 20, 1),
// Avant
float3(0.5, 0.1, 1),
float3(0.01, 10, 1),
float3(20, 0.25, 1),
float3(1000, 5, 100),
//Plein ecran passe inverse
float3(0.5, -0.5, 2),
//Rond bleu du debut
float3(2, 2, -5),
//2eme partie de la passe FS
float3(-5, 0.2, 0.2),
//Derniere passe
float3(0.15, 0.5, 20),
float3(0.4, 1, 10)
};
const float3 factors[15]=
{
float3(0.5, 0.5, 0),
float3(0, 0.5, 0),
float3(0, 0, 0.5),
// Full
float3(0.2, 0.25, 0),
// Arriere
float3(0.15, 0, 0.0),
float3(0, 0.0, 0.15),
// Avant
float3(0.2, 0.2, 0.05),
float3(0.25, 0.25, 0.25),
float3(1, 1, 1),
float3(0, 0.25, 1),
//Plein ecran
float3(0, 0,0.25),
//Rond bleu au debut
float3(0, 0, 1),
//Derniere passe avec passe full combine
float3(2, 2, 2),
float3(1, 1, 0.25),
float3(0, 0, 0)
};
for (int i=0; i<15; i++)
{
float2 distfact=(IN.txcoord.xy-0.5);
lenzuv.xy=offset[i].x*distfact;
lenzuv.xy*=pow(2.0*length(float2(distfact.x*ScreenSize.z,distfact.y)), offset[i].y);
lenzuv.xy*=offset[i].z*0.5;
lenzuv.xy=0.5-lenzuv.xy;
float3 templenz=sampleblurred(lenzuv.xy);
templenz=templenz*factors[i];
distfact=(lenzuv.xy-0.5);
distfact*=2.0;
templenz*=saturate(1.0-dot(distfact,distfact));
float maxlenz=max(templenz.x, max(templenz.y, templenz.z));
float tempnor=(maxlenz/(1.0+maxlenz));
tempnor=pow(tempnor, ELenzPower);
templenz.xyz*=tempnor;
lenz+=templenz;
}
lenz.xyz*=1.25*ELenzIntensity;
res.xyz=origcolor + lenz;
#endif
#if (LENZ==0)
res.xyz=origcolor.xyz;
#endif
res.w=1.0;
return res;
}
#if (MATSO_FLARE==1)
float4 PS_ProcessPass_Anamorphic(VS_OUTPUT_POST IN, float2 vPos : VPOS, uniform int axis) : COLOR
{
float4 res;
float2 coord = IN.txcoord.xy;
#if (fFlareHorizontal==1)
#define fFlareAxis 0
#endif
#if (fFlareVertical==1)
#define fFlareAxis 90
#endif
float3 anamFlare = AnamorphicSample(axis, coord.xy, fFlareBlur) * fFlareTint;
#ifdef fFlareHorizontal
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 4)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 3)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 2)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 1)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -1)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -2)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -3)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -4)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
#endif
#ifdef fFlareVertical
anamFlare += AnamorphicSample(axis, coord.xy+float2(4, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
anamFlare += AnamorphicSample(axis, coord.xy+float2(3, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(2, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(1, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(1, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(2, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(3, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(4, 0)*FlareRadius, fFlareBlur) * fFlareTint* 0.30;
#endif
res.rgb = anamFlare * fFlareIntensity;
res.a = 1.0;
return res;
}
#endif
#if (GODRAYS==1)
float4 PS_ProcessSunShafts(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float2 texCoord = IN.txcoord;
// Calculate vector from pixel to light source in screen space.
half2 deltaTexCoord = (texCoord - ScreenLightPos.xy);
// Divide by number of samples and scale by control factor.
deltaTexCoord *= 1.0f / NUM_SAMPLES * Density;
// Store initial sample.
half3 color = max(float4(0,0,0,0),tex2D(InputSampler, texCoord)-SStresh);