-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopengl32.fx
3611 lines (2938 loc) · 113 KB
/
opengl32.fx
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
#include "MasterEffect.h"
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// END OF TWEAKING VARIABLES //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//global vars
#define ScreenSize float4(BUFFER_WIDTH, BUFFER_RCP_WIDTH, float(BUFFER_WIDTH) / float(BUFFER_HEIGHT), float(BUFFER_HEIGHT) / float(BUFFER_WIDTH)) //x=Width, y=1/Width, z=ScreenScaleY, w=1/ScreenScaleY
#define PixelSize float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)
#define PI 3.1415972
#define PIOVER180 0.017453292
#define AUTHOR MartyMcFly
#define FOV 75
#define LumCoeff float3(0.212656, 0.715158, 0.072186)
#define zFarPlane 1
#define zNearPlane 0.001 //I know, weird values but ReShade's depthbuffer is ... odd
#define aspect (BUFFER_RCP_HEIGHT/BUFFER_RCP_WIDTH)
#define InvFocalLen float2(tan(0.5f*radians(FOV)) / (float)BUFFER_RCP_HEIGHT * (float)BUFFER_RCP_WIDTH, tan(0.5f*radians(FOV)))
uniform float4 Timer < source = "timer"; >;
#pragma message "MasterEffect ReBorn 1.1.287 by Marty McFly"
#if( USE_HDR_LEVEL == 0)
#define RENDERMODE RGBA8
#endif
#if( USE_HDR_LEVEL == 1)
#define RENDERMODE RGBA16F
#endif
#if( USE_HDR_LEVEL == 2)
#define RENDERMODE RGBA32F
#endif
//textures
texture texBloom1 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RENDERMODE;};
texture texBloom2 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RENDERMODE;};
texture texBloom3 { Width = BUFFER_WIDTH/2; Height = BUFFER_HEIGHT/2; Format = RENDERMODE;};
texture texBloom4 { Width = BUFFER_WIDTH/4; Height = BUFFER_HEIGHT/4; Format = RENDERMODE;};
texture texBloom5 { Width = BUFFER_WIDTH/8; Height = BUFFER_HEIGHT/8; Format = RENDERMODE;};
texture texLens1 { Width = BUFFER_WIDTH/2; Height = BUFFER_HEIGHT/2; Format = RENDERMODE;};
texture texLens2 { Width = BUFFER_WIDTH/2; Height = BUFFER_HEIGHT/2; Format = RENDERMODE;};
texture2D texLDR : COLOR;
texture texHDR1 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 5; Format = RENDERMODE;};
texture texHDR2 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 5; Format = RENDERMODE;};
texture texOcclusion1 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA16F;}; //MUST be at least 16, 8 gives heavy artifacts when blurring.
texture texOcclusion2 { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA16F;}; //"Optimizations" can be done elsewhere, not here.
texture texCoC { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; MipLevels = 5; Format = RGBA16F;};
texture2D texDepth : DEPTH;
texture texNoise < string source = "MasterEffect/internal/mcnoise.png"; > {Width = BUFFER_WIDTH;Height = BUFFER_HEIGHT;Format = RGBA8;};
texture texSprite < string source = "MasterEffect/mcsprite.png"; > {Width = BUFFER_WIDTH;Height = BUFFER_HEIGHT;Format = RGBA8;};
texture texDirt < string source = "MasterEffect/mcdirt.png"; > {Width = BUFFER_WIDTH;Height = BUFFER_HEIGHT;Format = RGBA8;};
texture texLUT < string source = "MasterEffect/mclut.png"; > {Width = 256; Height = 1; Format = RGBA8;};
texture texLUT3D < string source = "MasterEffect/mclut3d.png"; > {Width = 256; Height = 16; Format = RGBA8;};
texture texMask < string source = "MasterEffect/mcmask.png"; > {Width = BUFFER_WIDTH;Height = BUFFER_HEIGHT;Format = R8;};
texture texHeat < string source = "MasterEffect/internal/mcheat.png"; > {Width = 512;Height = 512;Format = RGBA8;};
//samplers
sampler SamplerBloom1 { Texture = texBloom1; };
sampler SamplerBloom2 { Texture = texBloom2; };
sampler SamplerBloom3 { Texture = texBloom3; };
sampler SamplerBloom4 { Texture = texBloom4; };
sampler SamplerBloom5 { Texture = texBloom5; };
sampler SamplerLens1 { Texture = texLens1; };
sampler SamplerLens2 { Texture = texLens2; };
sampler2D SamplerLDR
{
Texture = texLDR;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerHDR1
{
Texture = texHDR1;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerHDR2
{
Texture = texHDR2;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerOcclusion1
{
Texture = texOcclusion1;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerOcclusion2
{
Texture = texOcclusion2;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerCoC
{
Texture = texCoC;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerDepth
{
Texture = texDepth;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerNoise
{
Texture = texNoise;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = Wrap;
AddressV = Wrap;
};
sampler2D SamplerSprite
{
Texture = texSprite;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerDirt
{
Texture = texDirt;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerLUT
{
Texture = texLUT;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerLUT3D
{
Texture = texLUT3D;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerMask
{
Texture = texMask;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D SamplerHeat
{
Texture = texHeat;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Repeat;
AddressV = Repeat;
};
struct VS_OUTPUT_POST
{
float4 vpos : SV_Position;
float2 txcoord : TEXCOORD0;
};
struct VS_INPUT_POST
{
uint id : SV_VertexID;
};
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Vertex Shaders //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VS_OUTPUT_POST VS_MasterEffect(VS_INPUT_POST IN)
{
VS_OUTPUT_POST OUT;
OUT.txcoord.x = (IN.id == 2) ? 2.0 : 0.0;
OUT.txcoord.y = (IN.id == 1) ? 2.0 : 0.0;
OUT.vpos = float4(OUT.txcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
return OUT;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SMAA //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "MasterEffect/internal/mcsmaa.hlsl"
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Functions //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
float GetLinearDepth(float depth)
{
return 1 / ((depth * ((zFarPlane - zNearPlane) / (-zFarPlane * zNearPlane)) + zFarPlane / (zFarPlane * zNearPlane)));
}
float3 GetNormalFromDepth(float fDepth, float2 vTexcoord) {
const float2 offset1 = float2(0.0,0.001);
const float2 offset2 = float2(0.001,0.0);
float depth1 = GetLinearDepth(tex2Dlod(SamplerDepth, float4(vTexcoord + offset1,0,0)).x);
float depth2 = GetLinearDepth(tex2Dlod(SamplerDepth, float4(vTexcoord + offset2,0,0)).x);
float3 p1 = float3(offset1, depth1 - fDepth);
float3 p2 = float3(offset2, depth2 - fDepth);
float3 normal = cross(p1, p2);
normal.z = -normal.z;
return normalize(normal);
}
float GetRandom(float2 co){
return frac(sin(dot(co, float2(12.9898, 78.233))) * 43758.5453);
}
float3 GetRandomVector(float2 vTexCoord) {
return 2 * normalize(float3(GetRandom(vTexCoord - 0.5f),
GetRandom(vTexCoord + 0.5f),
GetRandom(vTexCoord))) - 1;
}
float4 GetAtlasTex(sampler tex, float2 coord, float spaltenzahl, float reihenzahl, float spalte, float reihe)
{
return tex2Dlod(tex, float4(coord.xy/float2(spaltenzahl, reihenzahl)+float2((spalte-1)/spaltenzahl,(reihe-1)/reihenzahl),0,0));
}
float4 GaussBlur22(float2 coord, sampler tex, float mult, float lodlevel, bool isBlurVert) //texcoord, texture, blurmult in pixels, tex2dlod level, axis (0=horiz, 1=vert)
{
float4 sum = 0;
float2 axis = (isBlurVert) ? float2(0, 1) : float2(1, 0);
float weight[11] = {0.082607, 0.080977, 0.076276, 0.069041, 0.060049, 0.050187, 0.040306, 0.031105, 0.023066, 0.016436, 0.011254};
for(int i=-10; i < 11; i++)
{
float currweight = weight[abs(i)];
sum += tex2Dlod(tex, float4(coord.xy + axis.xy * (float)i * PixelSize * mult,0,lodlevel)) * currweight;
}
return sum;
}
float4 GaussBlurGeneric(float2 coord, sampler tex, float mult, float lodlevel, bool isBlurVert, float Radius, float Quality) //texcoord, texture, blurmult in pixels, tex2dlod level, axis (0=horiz, 1=vert), offset count, quality
{
float2 axis = (isBlurVert) ? float2(0, 1) : float2(1, 0);
float4 Sigma = 0;
Sigma.x = 1.0f / ( sqrt( 2.0f * PI ) * Radius );
Sigma.y = exp( -0.5f / ( Radius * Radius ));
Sigma.z = Sigma.y * Sigma.y;
Sigma.w = Sigma.x;
Sigma.xy *= Sigma.yz;
float4 sum = tex2Dlod(tex, float4(coord.xy,0,lodlevel))*Sigma.x;
for(int i = 1; i < 150 && Sigma.w < Quality; i++)
{
sum += tex2Dlod(tex, float4(coord.xy + axis.xy * (float)i * PixelSize * mult,0,lodlevel)) * Sigma.x;
sum += tex2Dlod(tex, float4(coord.xy - axis.xy * (float)i * PixelSize * mult,0,lodlevel)) * Sigma.x;
Sigma.w += 2.0 * Sigma.x;
Sigma.xy *= Sigma.yz;
}
sum /= Sigma.w;
return sum;
}
float smootherstep(float edge0, float edge1, float x)
{
x = clamp((x - edge0)/(edge1 - edge0), 0.0, 1.0);
return x*x*x*(x*(x*6 - 15) + 10);
}
float3 Hue(in float3 RGB)
{
// Based on work by Sam Hocevar and Emil Persson
float Epsilon = 1e-10;
float4 P = (RGB.g < RGB.b) ? float4(RGB.bg, -1.0, 2.0/3.0) : float4(RGB.gb, 0.0, -1.0/3.0);
float4 Q = (RGB.r < P.x) ? float4(P.xyw, RGB.r) : float4(RGB.r, P.yzx);
float C = Q.x - min(Q.w, Q.y);
float H = abs((Q.w - Q.y) / (6 * C + Epsilon) + Q.z);
return float3(H, C, Q.x);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Passes //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
float4 BorderPass( float4 colorInput, float2 tex )
{
float3 fBorderColor_float = fBorderColor;
float2 screen_size = float2(BUFFER_WIDTH, BUFFER_HEIGHT);
float screen_ratio = (BUFFER_WIDTH/BUFFER_HEIGHT);
float2 fBorderWidth_variable = fBorderWidth;
// -- calculate the right fBorderWidth for a given fBorderRatio --
//if (!any(fBorderWidth)) //if fBorderWidth is not used
if (fBorderWidth.x == -fBorderWidth.y) //if fBorderWidth is not used
if (screen_ratio < fBorderRatio)
fBorderWidth_variable = float2(0.0, (screen_size.y - (screen_size.x / fBorderRatio)) * 0.5);
else
fBorderWidth_variable = float2((screen_size.x - (screen_size.y * fBorderRatio)) * 0.5, 0.0);
float2 border = (PixelSize.xy * fBorderWidth_variable); //Translate integer pixel width to floating point
float2 within_border = saturate((-tex * tex + tex) - (-border * border + border)); //becomes positive when inside the border and 0 when outside
colorInput.rgb = all(within_border) ? colorInput.rgb : fBorderColor_float ; //if the pixel is within the border use the original color, if not use the fBorderColor
return colorInput; //return the pixel
}
float3 CartoonPass( float3 colorInput, float2 tex, float2 pixelsize, sampler colorsampler )
{
float diff1 = dot(LumCoeff,tex2D(colorsampler, tex + pixelsize).rgb);
diff1 = dot(float4(LumCoeff,-1.0),float4(tex2D(colorsampler, tex - pixelsize).rgb , diff1));
float diff2 = dot(LumCoeff,tex2D(colorsampler, tex +float2(pixelsize.x,-pixelsize.y)).rgb);
diff2 = dot(float4(LumCoeff,-1.0),float4(tex2D(colorsampler, tex +float2(-pixelsize.x,pixelsize.y)).rgb , diff2));
float edge = dot(float2(diff1,diff2),float2(diff1,diff2));
colorInput.rgb = pow(edge,CartoonEdgeSlope) * -CartoonPower + colorInput.rgb;
return saturate(colorInput);
}
float3 LevelsPass( float3 colorInput )
{
#define black_point_float ( Levels_black_point / 255.0 )
#define white_point_float ( 255.0 / (Levels_white_point - Levels_black_point))
colorInput.rgb = colorInput.rgb * white_point_float - (black_point_float * white_point_float);
return colorInput;
}
float3 TechniPass_prod80(float3 colorInput)
{
float3 colStrength = float3(ColStrengthR,ColStrengthG,ColStrengthB);
float3 tsource = saturate(colorInput.rgb);
float3 ttemp = 1 - tsource;
float3 ttarget = ttemp.grg;
float3 ttarget2 = ttemp.bbr;
float3 ttemp2 = tsource.rgb * ttarget.rgb;
ttemp2.rgb *= ttarget2.rgb;
ttemp.rgb = ttemp2.rgb * colStrength;
ttemp2.rgb *= TechniBrightness;
ttarget.rgb = ttemp.grg;
ttarget2.rgb = ttemp.bbr;
ttemp.rgb = tsource.rgb - ttarget.rgb;
ttemp.rgb += ttemp2.rgb;
ttemp2.rgb = ttemp.rgb - ttarget2.rgb;
colorInput.rgb = lerp(tsource.rgb, ttemp2.rgb, TechniStrength);
colorInput.rgb = lerp(dot(colorInput.rgb, 0.333), colorInput.rgb, TechniSat);
return colorInput.rgb;
}
float3 TechnicolorPass( float3 colorInput )
{
#define cyanfilter float3(0.0, 1.30, 1.0)
#define magentafilter float3(1.0, 0.0, 1.05)
#define yellowfilter float3(1.6, 1.6, 0.05)
#define redorangefilter float2(1.05, 0.620) //RG_
#define greenfilter float2(0.30, 1.0) //RG_
#define magentafilter2 magentafilter.rb //R_B
float3 tcol = colorInput.rgb;
float2 rednegative_mul = tcol.rg * (1.0 / (redNegativeAmount * TechniPower));
float2 greennegative_mul = tcol.rg * (1.0 / (greenNegativeAmount * TechniPower));
float2 bluenegative_mul = tcol.rb * (1.0 / (blueNegativeAmount * TechniPower));
float rednegative = dot( redorangefilter, rednegative_mul );
float greennegative = dot( greenfilter, greennegative_mul );
float bluenegative = dot( magentafilter2, bluenegative_mul );
float3 redoutput = rednegative.rrr + cyanfilter;
float3 greenoutput = greennegative.rrr + magentafilter;
float3 blueoutput = bluenegative.rrr + yellowfilter;
float3 result = redoutput * greenoutput * blueoutput;
colorInput.rgb = lerp(tcol, result, TechniAmount);
return colorInput;
}
float3 DPXPass(float3 InputColor){
float3x3 RGB =
float3x3(
2.67147117265996,-1.26723605786241,-0.410995602172227,
-1.02510702934664,1.98409116241089,0.0439502493584124,
0.0610009456429445,-0.223670750812863,1.15902104167061
);
float3x3 XYZ =
float3x3(
0.500303383543316,0.338097573222739,0.164589779545857,
0.257968894274758,0.676195259144706,0.0658358459823868,
0.0234517888692628,0.1126992737203,0.866839673124201
);
float DPXContrast = 0.1;
float DPXGamma = 1.0;
float RedCurve = DPXRed;
float GreenCurve = DPXGreen;
float BlueCurve = DPXBlue;
float3 RGB_Curve = float3(DPXRed,DPXGreen,DPXBlue);
float3 RGB_C = float3(DPXRedC,DPXGreenC,DPXBlueC);
float3 B = InputColor.rgb;
B = pow(B, 1.0/DPXGamma);
B = B * (1.0 - DPXContrast) + (0.5 * DPXContrast);
float3 Btemp = (1.0 / (1.0 + exp(RGB_Curve / 2.0)));
B = ((1.0 / (1.0 + exp(-RGB_Curve * (B - RGB_C)))) / (-2.0 * Btemp + 1.0)) + (-Btemp / (-2.0 * Btemp + 1.0));
float value = max(max(B.r, B.g), B.b);
float3 color = B / value;
color = saturate(color);
color = pow(color, 1.0/DPXColorGamma);
float3 c0 = color * value;
c0 = mul(XYZ, c0);
float luma = dot(c0, float3(0.30, 0.59, 0.11)); //Use BT 709 instead?
c0 = (1.0 - DPXSaturation) * luma + DPXSaturation * c0;
c0 = mul(RGB, c0);
InputColor.rgb = lerp(InputColor.rgb, c0, DPXBlend);
return InputColor;
}
float3 LiftGammaGainPass( float3 colorInput )
{
// -- Get input --
float3 color = colorInput.rgb;
// -- Lift --
color = color * (1.5-0.5 * RGB_Lift) + 0.5 * RGB_Lift - 0.5;
color = saturate(color); //isn't strictly necessary, but doesn't cost performance.
// -- Gain --
color *= RGB_Gain;
// -- Gamma --
colorInput.rgb = pow(color, 1.0 / RGB_Gamma); //Gamma
// -- Return output --
//return (colorInput);
return saturate(colorInput);
}
float3 TonemapPass( float3 colorInput )
{
float3 color = colorInput.rgb;
color = saturate(color - Defog * FogColor); // Defog
color *= pow(2.0f, Exposure); // Exposure
color = pow(color, Gamma); // Gamma -- roll into the first gamma correction in main.h ?
float lum = dot(LumCoeff, color.rgb);
float3 blend = lum.rrr; //dont use float3
float L = saturate( 10.0 * (lum - 0.45) );
float3 result1 = 2.0f * color.rgb * blend;
float3 result2 = 1.0f - 2.0f * (1.0f - blend) * (1.0f - color.rgb);
float3 newColor = lerp(result1, result2, L);
float3 A2 = Bleach * color.rgb; //why use a float for A2 here and then multiply by color.rgb (a float3)?
float3 mixRGB = A2 * newColor;
color.rgb += ((1.0f - A2) * mixRGB);
float3 middlegray = dot(color,(1.0/3.0)); //1fps slower than the original on nvidia, 2 fps faster on AMD
float3 diffcolor = color - middlegray; //float 3 here
colorInput.rgb = (color + diffcolor * Saturation)/(1+(diffcolor*Saturation)); //saturation
return colorInput;
}
float3 VibrancePass( float3 colorInput )
{
#define Vibrance_coeff float3(Vibrance_RGB_balance * Vibrance)
float3 color = colorInput; //original input color
float3 lumCoeff = float3(0.212656, 0.715158, 0.072186); //Values to calculate luma with
float luma = dot(LumCoeff, color.rgb); //calculate luma (grey)
float max_color = max(colorInput.r, max(colorInput.g,colorInput.b)); //Find the strongest color
float min_color = min(colorInput.r, min(colorInput.g,colorInput.b)); //Find the weakest color
float color_saturation = max_color - min_color; //The difference between the two is the saturation
color.rgb = lerp(luma, color.rgb, (1.0 + (Vibrance_coeff * (1.0 - (sign(Vibrance_coeff) * color_saturation))))); //extrapolate between luma and original by 1 + (1-saturation) - current
return color; //return the result
}
float3 CurvesPass( float3 colorInput )
{
float Curves_contrast_blend = Curves_contrast;
/*-----------------------------------------------------------.
/ Separation of Luma and Chroma /
'-----------------------------------------------------------*/
// -- Calculate Luma and Chroma if needed --
#if Curves_mode != 2
//calculate luma (grey)
float luma = dot(LumCoeff, colorInput.rgb);
//calculate chroma
float3 chroma = colorInput.rgb - luma;
#endif
// -- Which value to put through the contrast formula? --
// I name it x because makes it easier to copy-paste to Graphtoy or Wolfram Alpha or another graphing program
#if Curves_mode == 2
float3 x = colorInput.rgb; //if the curve should be applied to both Luma and Chroma
#elif Curves_mode == 1
float3 x = chroma; //if the curve should be applied to Chroma
x = x * 0.5 + 0.5; //adjust range of Chroma from -1 -> 1 to 0 -> 1
#else // Curves_mode == 0
float x = luma; //if the curve should be applied to Luma
#endif
/*-----------------------------------------------------------.
/ Contrast formulas /
'-----------------------------------------------------------*/
// -- Curve 1 --
#if Curves_formula == 1
x = sin(PI * 0.5 * x); // Sin - 721 amd fps, +vign 536 nv
x *= x;
//x = 0.5 - 0.5*cos(PI*x);
//x = 0.5 * -sin(PI * -x + (PI*0.5)) + 0.5;
#endif
// -- Curve 2 --
#if Curves_formula == 2
x = x - 0.5;
x = ( x / (0.5 + abs(x)) ) + 0.5;
//x = ( (x - 0.5) / (0.5 + abs(x-0.5)) ) + 0.5;
#endif
// -- Curve 3 --
#if Curves_formula == 3
//x = smoothstep(0.0,1.0,x); //smoothstep
x = x*x*(3.0-2.0*x); //faster smoothstep alternative - 776 amd fps, +vign 536 nv
//x = x - 2.0 * (x - 1.0) * x* (x- 0.5); //2.0 is contrast. Range is 0.0 to 2.0
#endif
// -- Curve 4 --
#if Curves_formula == 4
x = (1.0524 * exp(6.0 * x) - 1.05248) / (20.0855 + exp(6.0 * x)); //exp formula
#endif
// -- Curve 5 --
#if Curves_formula == 5
//x = 0.5 * (x + 3.0 * x * x - 2.0 * x * x * x); //a simplified catmull-rom (0,0,1,1) - btw smoothstep can also be expressed as a simplified catmull-rom using (1,0,1,0)
//x = (0.5 * x) + (1.5 -x) * x*x; //estrin form - faster version
x = x * (x * (1.5-x) + 0.5); //horner form - fastest version
Curves_contrast_blend = Curves_contrast * 2.0; //I multiply by two to give it a strength closer to the other curves.
#endif
// -- Curve 6 --
#if Curves_formula == 6
x = x*x*x*(x*(x*6.0 - 15.0) + 10.0); //Perlins smootherstep
#endif
// -- Curve 7 --
#if Curves_formula == 7
//x = ((x-0.5) / ((0.5/(4.0/3.0)) + abs((x-0.5)*1.25))) + 0.5;
x = x - 0.5;
x = x / ((abs(x)*1.25) + 0.375 ) + 0.5;
//x = ( (x-0.5) / ((abs(x-0.5)*1.25) + (0.5/(4.0/3.0))) ) + 0.5;
#endif
// -- Curve 8 --
#if Curves_formula == 8
x = (x * (x * (x * (x * (x * (x * (1.6 * x - 7.2) + 10.8) - 4.2) - 3.6) + 2.7) - 1.8) + 2.7) * x * x; //Techicolor Cinestyle - almost identical to curve 1
#endif
// -- Curve 9 --
#if Curves_formula == 9
x = -0.5 * (x*2.0-1.0) * (abs(x*2.0-1.0)-2.0) + 0.5; //parabola
#endif
// -- Curve 10 --
#if Curves_formula == 10 //Half-circles
#if Curves_mode == 0
float xstep = step(x,0.5);
float xstep_shift = (xstep - 0.5);
float shifted_x = x + xstep_shift;
#else
float3 xstep = step(x,0.5);
float3 xstep_shift = (xstep - 0.5);
float3 shifted_x = x + xstep_shift;
#endif
x = abs(xstep - sqrt(-shifted_x * shifted_x + shifted_x) ) - xstep_shift;
//x = abs(step(x,0.5)-sqrt(-(x+step(x,0.5)-0.5)*(x+step(x,0.5)-0.5)+(x+step(x,0.5)-0.5)))-(step(x,0.5)-0.5); //single line version of the above
//x = 0.5 + (sign(x-0.5)) * sqrt(0.25-(x-trunc(x*2))*(x-trunc(x*2))); //worse
/* // if/else - even worse
if (x-0.5)
x = 0.5-sqrt(0.25-x*x);
else
x = 0.5+sqrt(0.25-(x-1)*(x-1));
*/
//x = (abs(step(0.5,x)-clamp( 1-sqrt(1-abs(step(0.5,x)- frac(x*2%1)) * abs(step(0.5,x)- frac(x*2%1))),0 ,1))+ step(0.5,x) )*0.5; //worst so far
//TODO: Check if I could use an abs split instead of step. It might be more efficient
Curves_contrast_blend = Curves_contrast * 0.5; //I divide by two to give it a strength closer to the other curves.
#endif
// -- Curve 11 --
#if Curves_formula == 11 //Cubic catmull
float a = 1.00; //control point 1
float b = 0.00; //start point
float c = 1.00; //endpoint
float d = 0.20; //control point 2
x = 0.5 * ((-a + 3*b -3*c + d)*x*x*x + (2*a -5*b + 4*c - d)*x*x + (-a+c)*x + 2*b); //A customizable cubic catmull-rom spline
#endif
// -- Curve 12 --
#if Curves_formula == 12 //Cubic Bezier spline
float a = 0.00; //start point
float b = 0.00; //control point 1
float c = 1.00; //control point 2
float d = 1.00; //endpoint
float r = (1-x);
float r2 = r*r;
float r3 = r2 * r;
float x2 = x*x;
float x3 = x2*x;
//x = dot(float4(a,b,c,d),float4(r3,3*r2*x,3*r*x2,x3));
//x = a * r*r*r + r * (3 * b * r * x + 3 * c * x*x) + d * x*x*x;
//x = a*(1-x)*(1-x)*(1-x) +(1-x) * (3*b * (1-x) * x + 3 * c * x*x) + d * x*x*x;
x = a*(1-x)*(1-x)*(1-x) + 3*b*(1-x)*(1-x)*x + 3*c*(1-x)*x*x + d*x*x*x;
#endif
// -- Curve 13 --
#if Curves_formula == 13 //Cubic Bezier spline - alternative implementation.
float3 a = float3(0.00,0.00,0.00); //start point
float3 b = float3(0.25,0.15,0.85); //control point 1
float3 c = float3(0.75,0.85,0.15); //control point 2
float3 d = float3(1.00,1.00,1.00); //endpoint
float3 ab = lerp(a,b,x); // point between a and b
float3 bc = lerp(b,c,x); // point between b and c
float3 cd = lerp(c,d,x); // point between c and d
float3 abbc = lerp(ab,bc,x); // point between ab and bc
float3 bccd = lerp(bc,cd,x); // point between bc and cd
float3 dest = lerp(abbc,bccd,x); // point on the bezier-curve
x = dest;
#endif
// -- Curve 14 --
#if Curves_formula == 14
x = 1.0 / (1.0 + exp(-(x * 10.0 - 5.0))); //alternative exp formula
#endif
/*-----------------------------------------------------------.
/ Joining of Luma and Chroma /
'-----------------------------------------------------------*/
#if Curves_mode == 2 //Both Luma and Chroma
float3 color = x; //if the curve should be applied to both Luma and Chroma
colorInput.rgb = lerp(colorInput.rgb, color, Curves_contrast_blend); //Blend by Curves_contrast
#elif Curves_mode == 1 //Only Chroma
x = x * 2.0 - 1.0; //adjust the Chroma range back to -1 -> 1
float3 color = luma + x; //Luma + Chroma
colorInput.rgb = lerp(colorInput.rgb, color, Curves_contrast_blend); //Blend by Curves_contrast
#else // Curves_mode == 0 //Only Luma
x = lerp(luma, x, Curves_contrast_blend); //Blend by Curves_contrast
colorInput.rgb = x + chroma; //Luma + Chroma
#endif
//Return the result
return colorInput;
}
float3 SepiaPass( float3 colorInput )
{
float3 sepia = colorInput.rgb;
// calculating amounts of input, grey and sepia colors to blend and combine
float grey = dot(sepia, LumCoeff);
sepia *= ColorTone;
float3 blend2 = (grey * GreyPower) + (colorInput.rgb / (GreyPower + 1));
colorInput.rgb = lerp(blend2, sepia, SepiaPower);
// returning the final color
return colorInput;
}
float3 SkyrimTonemapPass( float3 color )
{
float grayadaptation = dot(color.xyz, LumCoeff);
#if (POSTPROCESS==1)
color.xyz = color.xyz / (grayadaptation * EAdaptationMaxV1 + EAdaptationMinV1);
float cgray = dot( color.xyz, LumCoeff);
cgray = pow(cgray, EContrastV1);
float3 poweredcolor = pow( abs(color.xyz), EColorSaturationV1);
float newgray = dot(poweredcolor.xyz, LumCoeff);
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)
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)
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 );
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
//tuned by the master himself for ME 1.4, thanks man!!!
//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////////////////////////////////////////////
float4 ncolor; //temporary variable for color adjustments
//begin pp code/////////////////////////////////////////////////
//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(saturate(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);
color.xyz /= grayadaptation*EAdaptationMaxV6+EAdaptationMinV6;
//rerun ppv2////////////////////////////////////////////////////
color.xyz *= EBrightnessV6;
xncol = normalize( color.xyz);
scl = color.xyz/xncol.xyz;
scl = saturate(scl);
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);
#endif
return color;
}
float3 MoodPass( float3 colorInput )
{
float3 colInput = colorInput;
float3 colMood = 1.0f;
colMood.r = moodR;
colMood.g = moodG;
colMood.b = moodB;
float fLum = ( colInput.r + colInput.g + colInput.b ) / 3;
colMood = lerp(0, colMood, saturate(fLum * 2.0));
colMood = lerp(colMood, 1, saturate(fLum - 0.5) * 2.0);
float3 colOutput = lerp(colInput, colMood, saturate(fLum * fRatio));
colorInput=max(0, colOutput);
return colorInput;
}
float3 CrossPass(float3 color)
{
float2 CrossMatrix [3] = {
float2 (1.03, 0.04),
float2 (1.09, 0.01),
float2 (0.78, 0.13),
};
float3 image1 = color;
float3 image2 = color;
float gray = dot(float3(0.5,0.5,0.5), image1);
image1 = lerp (gray, image1,CrossSaturation);
image1 = lerp (0.35, image1,CrossContrast);
image1 +=CrossBrightness;
image2.r = image1.r * CrossMatrix[0].x + CrossMatrix[0].y;
image2.g = image1.g * CrossMatrix[1].x + CrossMatrix[1].y;
image2.b = image1.b * CrossMatrix[2].x + CrossMatrix[2].y;
color = lerp(image1, image2, CrossAmount);
return color;
}
float3 FilmPass(float3 B)
{
float3 G = B;
float3 H = 0.01;
B = saturate(B);
B = pow(B, Linearization);
B = lerp(H, B, Contrast);
float A = dot(B.rgb, LumCoeff);
float3 D = A;
B = pow(B, 1.0 / BaseGamma);
float a = FRedCurve;
float b = FGreenCurve;
float c = FBlueCurve;
float d = BaseCurve;
float y = 1.0 / (1.0 + exp(a / 2.0));
float z = 1.0 / (1.0 + exp(b / 2.0));
float w = 1.0 / (1.0 + exp(c / 2.0));
float v = 1.0 / (1.0 + exp(d / 2.0));
float3 C = B;
D.r = (1.0 / (1.0 + exp(-a * (D.r - 0.5))) - y) / (1.0 - 2.0 * y);
D.g = (1.0 / (1.0 + exp(-b * (D.g - 0.5))) - z) / (1.0 - 2.0 * z);
D.b = (1.0 / (1.0 + exp(-c * (D.b - 0.5))) - w) / (1.0 - 2.0 * w);
D = pow(D, 1.0 / EffectGamma);
float3 Di = 1.0 - D;
D = lerp(D, Di, FBleach);
D.r = pow(abs(D.r), 1.0 / EffectGammaR);
D.g = pow(abs(D.g), 1.0 / EffectGammaG);
D.b = pow(abs(D.b), 1.0 / EffectGammaB);
if (D.r < 0.5)
C.r = (2.0 * D.r - 1.0) * (B.r - B.r * B.r) + B.r;
else
C.r = (2.0 * D.r - 1.0) * (sqrt(B.r) - B.r) + B.r;
if (D.g < 0.5)
C.g = (2.0 * D.g - 1.0) * (B.g - B.g * B.g) + B.g;
else
C.g = (2.0 * D.g - 1.0) * (sqrt(B.g) - B.g) + B.g;
//if (AgainstAllAutority)
if (D.b < 0.5)
C.b = (2.0 * D.b - 1.0) * (B.b - B.b * B.b) + B.b;
else
C.b = (2.0 * D.b - 1.0) * (sqrt(B.b) - B.b) + B.b;
float3 F = lerp(B, C, Strenght);
F = (1.0 / (1.0 + exp(-d * (F - 0.5))) - v) / (1.0 - 2.0 * v);
float r2R = 1.0 - FSaturation;
float g2R = 0.0 + FSaturation;
float b2R = 0.0 + FSaturation;
float r2G = 0.0 + FSaturation;
float g2G = (1.0 - Fade) - FSaturation;
float b2G = (0.0 + Fade) + FSaturation;
float r2B = 0.0 + FSaturation;
float g2B = (0.0 + Fade) + FSaturation;
float b2B = (1.0 - Fade) - FSaturation;