Repository navigation
Expand file tree
/
Copy pathPD80_06_Luma_Fade.fx
More file actions
153 lines (136 loc) · 5.9 KB
/
Copy pathPD80_06_Luma_Fade.fx
File metadata and controls
153 lines (136 loc) · 5.9 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
/*
Description : PD80 06 Luma Fade for Reshade https://reshade.me/
Author : prod80 (Bas Veth)
License : MIT, Copyright (c) 2020 prod80
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "ReShade.fxh"
#include "ReShadeUI.fxh"
namespace pd80_lumafade
{
//// UI ELEMENTS ////////////////////////////////////////////////////////////////
uniform float transition_speed <
ui_type = "slider";
ui_label = "Time Based Fade Speed";
ui_tooltip = "Time Based Fade Speed";
ui_category = "Scene Luminance Adaptation";
ui_min = 0.0f;
ui_max = 1.0f;
> = 0.5;
uniform float minlevel <
ui_label = "Pure Dark Scene Level";
ui_tooltip = "Pure Dark Scene Level";
ui_category = "Scene Luminance Adaptation";
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
> = 0.125;
uniform float maxlevel <
ui_label = "Pure Light Scene Level";
ui_tooltip = "Pure Light Scene Level";
ui_category = "Scene Luminance Adaptation";
ui_type = "slider";
ui_min = 0.0;
ui_max = 1.0;
> = 0.3;
//// TEXTURES ///////////////////////////////////////////////////////////////////
texture texLuma { Width = 256; Height = 256; Format = R16F; MipLevels = 8; };
texture texAvgLuma { Format = R16F; };
texture texPrevAvgLuma { Format = R16F; };
texture texPrevColor { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
//// SAMPLERS ///////////////////////////////////////////////////////////////////
sampler samplerLuma { Texture = texLuma; };
sampler samplerAvgLuma { Texture = texAvgLuma; };
sampler samplerPrevAvgLuma { Texture = texPrevAvgLuma; };
sampler samplerPrevColor { Texture = texPrevColor; };
//// DEFINES ////////////////////////////////////////////////////////////////////
uniform float Frametime < source = "frametime"; >;
//// FUNCTIONS //////////////////////////////////////////////////////////////////
float interpolate( float o, float n, float factor, float ft )
{
return lerp( o, n, 1.0f - exp( -factor * ft ));
}
//// PIXEL SHADERS //////////////////////////////////////////////////////////////
float PS_WriteLuma(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 color = tex2D( ReShade::BackBuffer, texcoord );
return dot( color.xyz, 0.333333f );
}
float PS_AvgLuma(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float luma = tex2Dlod( samplerLuma, float4( 0.5f, 0.5f, 0, 8 )).x;
float prevluma = tex2D( samplerPrevAvgLuma, float2( 0.5f, 0.5f )).x;
float factor = transition_speed * 4.0f + 1.0f;
return interpolate( prevluma, luma, factor, Frametime * 0.001f );
}
float4 PS_StorePrev(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
return tex2D( ReShade::BackBuffer, texcoord );
}
float PS_PrevAvgLuma(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
return tex2D( samplerAvgLuma, float2( 0.5f, 0.5f )).x;
}
float4 PS_LumaInterpolation(float4 pos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 newcol = tex2D( ReShade::BackBuffer, texcoord );
float4 oldcol = tex2D( samplerPrevColor, texcoord );
float luma = tex2D( samplerAvgLuma, float2( 0.5f, 0.5f )).x;
return lerp( oldcol, newcol, smoothstep( minlevel, maxlevel, luma ));
}
//// TECHNIQUES /////////////////////////////////////////////////////////////////
technique prod80_06_LumaFade_Start
< ui_tooltip = "Luma Fading Effects\n\n"
"This shader allows you to fade in and out ReShade effects based on scene luminance.\n"
"To use: put the Start technque before the shaders you want to enable in a BRIGHT scene and\n"
"put the End technique after those shaders. Then use the UI settings to manipulate the fading.";>
{
pass Luma
{
VertexShader = PostProcessVS;
PixelShader = PS_WriteLuma;
RenderTarget = texLuma;
}
pass AvgLuma
{
VertexShader = PostProcessVS;
PixelShader = PS_AvgLuma;
RenderTarget = texAvgLuma;
}
pass StoreColor
{
VertexShader = PostProcessVS;
PixelShader = PS_StorePrev;
RenderTarget = texPrevColor;
}
pass PreviousLuma
{
VertexShader = PostProcessVS;
PixelShader = PS_PrevAvgLuma;
RenderTarget = texPrevAvgLuma;
}
}
technique prod80_06_LumaFade_End
{
pass Combine
{
VertexShader = PostProcessVS;
PixelShader = PS_LumaInterpolation;
}
}
}