forked from crosire/reshade-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prism.fx
124 lines (103 loc) · 3.14 KB
/
Prism.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
/*
Copyright (c) 2018 Jacob Maximilian Fober
This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/.
*/
// Chromatic Aberration PS (Prism) v1.1.2
// inspired by Marty McFly YACA shader
////////////////////
/////// MENU ///////
////////////////////
uniform int Aberration <
ui_label = "Aberration scale in pixels";
ui_type = "drag";
ui_min = -16; ui_max = 48;
> = 6;
uniform float Curve <
ui_label = "Aberration curve";
ui_type = "drag";
ui_min = 0.0; ui_max = 4.0; ui_step = 0.01;
> = 1.0;
uniform bool Automatic <
ui_label = "Automatic sample count";
ui_tooltip = "Amount of samples will be adjusted automatically";
> = true;
uniform int SampleCount <
ui_label = "Samples";
ui_tooltip = "Amount of samples (only even numbers are accepted, odd numbers will be clamped)";
ui_type = "drag";
ui_min = 6; ui_max = 32;
> = 8;
//////////////////////
/////// SHADER ///////
//////////////////////
#include "ReShade.fxh"
// Special Hue generator by JMF
float3 Spectrum(float Hue)
{
float Hue4 = Hue * 4.0;
float3 HueColor = abs(Hue4 - float3(1.0, 2.0, 1.0));
HueColor = saturate(1.5 - HueColor);
HueColor.xz += saturate(Hue4 - 3.5);
HueColor.z = 1.0 - HueColor.z;
return HueColor;
}
// Define screen texture with mirror tiles
sampler SamplerColor
{
Texture = ReShade::BackBufferTex;
AddressU = MIRROR;
AddressV = MIRROR;
};
void ChromaticAberrationPS(float4 vois : SV_Position, float2 texcoord : TexCoord,
out float3 BluredImage : SV_Target)
{
// Grab Aspect Ratio
float Aspect = ReShade::AspectRatio;
// Grab Pixel V size
float Pixel = ReShade::PixelSize.y;
// Adjust number of samples
// IF Automatic IS True Ceil odd numbers to even with minimum 6, else Clamp odd numbers to even
int Samples = Automatic ? max(6, 2 * ceil(abs(Aberration) * 0.5) + 2) : floor(SampleCount * 0.5) * 2;
// Clamp maximum sample count
Samples = min(Samples, 48);
// Convert UVs to radial coordinates with correct Aspect Ratio
float2 RadialCoord = texcoord * 2.0 - 1.0;
RadialCoord.x *= Aspect;
// Generate radial mask from center (0) to the corner of the screen (1)
float Mask = pow(length(RadialCoord) * rsqrt(Aspect * Aspect + 1.0), Curve);
float OffsetBase = Mask * Aberration * Pixel * 2.0;
// Each loop represents one pass
if (abs(OffsetBase) < Pixel)
{
BluredImage = tex2D(SamplerColor, texcoord).rgb;
}
else
{
for (int P = 0; P < Samples && P <= 48; P++)
{
// Calculate current sample
float CurrentSample = float(P) / float(Samples);
float Offset = OffsetBase * CurrentSample + 1.0;
// Scale UVs at center
float2 Position = RadialCoord / Offset;
// Convert aspect ratio back to square
Position.x /= Aspect;
// Convert radial coordinates to UV
Position = Position * 0.5 + 0.5;
// Multiply texture sample by HUE color
BluredImage += Spectrum(CurrentSample) * tex2Dlod(SamplerColor, float4(Position, 0, 0)).rgb;
}
BluredImage = BluredImage / Samples * 2.0;
}
}
technique ChromaticAberration
{
pass
{
VertexShader = PostProcessVS;
PixelShader = ChromaticAberrationPS;
}
}