forked from crosire/reshade-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prism.fx
133 lines (107 loc) · 3.37 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
125
126
127
128
129
130
131
132
133
/*
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.2.4
// inspired by Marty McFly YACA shader
////////////
/// MENU ///
////////////
#ifndef PrismLimit
#define PrismLimit 48 // Maximum sample count
#endif
#include "ReShadeUI.fxh"
uniform int Aberration < __UNIFORM_SLIDER_INT1
ui_label = "Aberration scale in pixels";
ui_min = -48; ui_max = 48;
> = 6;
uniform float Curve < __UNIFORM_SLIDER_FLOAT1
ui_label = "Aberration curve";
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";
ui_category = "Performance";
> = true;
uniform int SampleCount < __UNIFORM_SLIDER_INT1
ui_label = "Samples";
ui_tooltip = "Amount of samples (only even numbers are accepted, odd numbers will be clamped)";
ui_min = 6; ui_max = 32;
ui_category = "Performance";
> = 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
float Samples = Automatic ? max(6.0, 2.0 * ceil(abs(Aberration) * 0.5) + 2.0) : floor(SampleCount * 0.5) * 2.0;
// Clamp maximum sample count
Samples = min(Samples, PrismLimit);
// Calculate sample offset
float Sample = 1.0 / Samples;
// Convert UVs to centered coordinates with correct Aspect Ratio
float2 RadialCoord = texcoord - 0.5;
RadialCoord.x *= Aspect;
// Generate radial mask from center (0) to the corner of the screen (1)
float Mask = pow(2.0 * 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
{
BluredImage = 0.0;
for (float P = 0.0; P < Samples; P++)
{
float Progress = P / Samples;
float Offset = OffsetBase * (Progress - 0.5) + 1.0;
// Scale UVs at center
float2 Position = RadialCoord / Offset;
// Convert aspect ratio back to square
Position.x /= Aspect;
// Convert centered coordinates to UV
Position += 0.5;
// Multiply texture sample by HUE color
BluredImage += Spectrum(Progress) * tex2Dlod(SamplerColor, float4(Position, 0.0, 0.0)).rgb;
}
BluredImage *= 2.0 / Samples;
}
}
//////////////
/// OUTPUT ///
//////////////
technique ChromaticAberration < ui_label = "Chromatic Aberration"; >
{
pass
{
VertexShader = PostProcessVS;
PixelShader = ChromaticAberrationPS;
}
}