-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathImage.fx
More file actions
175 lines (153 loc) · 3.83 KB
/
Image.fx
File metadata and controls
175 lines (153 loc) · 3.83 KB
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
/*------------------.
| :: Description :: |
'-------------------/
Display Image PS (version 1.2.7)
Copyright:
This code © 2019-2025 Jakub Maksymilian Fober
License:
This work is licensed under the Creative Commons
Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/4.0/
*/
/*-------------.
| :: Macros :: |
'-------------*/
// Image file name
#ifndef TEST_IMAGE_PATH
#define TEST_IMAGE_PATH "TestPattern.png"
#endif
// Image horizontal resolution
#ifndef TEST_IMAGE_SIZE_X
#define TEST_IMAGE_SIZE_X 1920
#endif
// Image vertical resolution
#ifndef TEST_IMAGE_SIZE_Y
#define TEST_IMAGE_SIZE_Y 1080
#endif
/*--------------.
| :: Commons :: |
'--------------*/
#include "ReShade.fxh"
#include "ReShadeUI.fxh"
#include "LinearGammaWorkflow.fxh"
#include "BlueNoiseDither.fxh"
/*-----------.
| :: Menu :: |
'-----------*/
uniform bool AspectCorrect
< __UNIFORM_INPUT_BOOL1
ui_label = "Original aspect ratio";
> = true;
uniform bool FillImage
< __UNIFORM_INPUT_BOOL1
ui_label = "Fill image";
> = false;
uniform float DimBackground
< __UNIFORM_SLIDER_FLOAT1
ui_min = 0.25; ui_max = 1f; ui_step = 0.01;
ui_label = "Dim background image";
> = 1f;
/*----------------.
| :: Functions :: |
'----------------*/
// Emulate bitwise XOR '^' for compatibility with older APi
bool xor(bool a, bool b)
{ return (a||b)-(a&&b); }
/*---------------.
| :: Textures :: |
'---------------*/
// Define image texture
texture TestImageTex
< source = TEST_IMAGE_PATH; >
{
Width = TEST_IMAGE_SIZE_X;
Height = TEST_IMAGE_SIZE_Y;
};
sampler TestImageSampler
{
Texture = TestImageTex;
SRGBTexture = true;
};
// Linear pixel step function for anti-aliasing by Jakub Max Fober
float Border(float2 coord)
{
// Get pixel size
float2 del = float2(ddx(coord.x), ddy(coord.y));
// Convert to centered coordinates
coord = 0.5-abs(coord-0.5);
// Scale to pixel size and clamp values
coord = saturate(coord/del);
// Combine masks
return min(coord.x, coord.y);
}
/*--------------.
| :: Shaders :: |
'--------------*/
// Draw Image
void ImagePS(
float4 pixelPos : SV_Position,
float2 texCoord : TEXCOORD,
out float3 color : SV_Target
)
{
color = tex2Dfetch(ReShade::BackBuffer, uint2(pixelPos.xy)).rgb;
color = GammaConvert::to_linear(color); // linear workflow
color *= DimBackground;
if (!AspectCorrect) // bypass aspect ratio correction
{
float4 TestImageTex = tex2D(TestImageSampler, texCoord);
color = lerp(color, TestImageTex.rgb, TestImageTex.a);
}
else // correct aspect ratio
{
// Gate test image aspect ratio
float ImageAspect = float(TEST_IMAGE_SIZE_X)/float(TEST_IMAGE_SIZE_Y);
// Test image aspect ratio
if (ReShade::AspectRatio == ImageAspect) // Same aspect ratio
{
float4 TestImageTex = tex2D(TestImageSampler, texCoord);
color = lerp(color, TestImageTex.rgb, TestImageTex.a);
}
else
{
if (xor(ReShade::AspectRatio > ImageAspect, FillImage)) // Image is narrower
texCoord.x = (texCoord.x-0.5)*ReShade::AspectRatio/ImageAspect+0.5;
else // Image is wider
texCoord.y = (texCoord.y-0.5)*ImageAspect/ReShade::AspectRatio+0.5;
// Sample test image
float4 TestImageTex = tex2D(TestImageSampler, texCoord);
// Blend image
color = lerp(
color,
TestImageTex.rgb,
min(Border(texCoord), TestImageTex.a)
);
}
}
color = GammaConvert::to_display(color);
color = BlueNoise::dither(color, uint2(pixelPos.xy)); // Dither
}
/* OUTPUT */
technique Image
<
ui_tooltip =
"Display image for testing.\n"
"\n"
"Source image can be changed with\n"
"following preprocessor definitions:\n"
"\n"
" TEST_IMAGE_PATH 'image.png'\n"
" TEST_IMAGE_SIZE_X 1440\n"
" TEST_IMAGE_SIZE_Y 1080\n"
"\n"
"This effect © 2019-2025 Jakub Maksymilian Fober\n"
"Licensed under CC BY-SA 4.0";
>
{
pass
{
VertexShader = PostProcessVS;
PixelShader = ImagePS;
}
}