Skip to content

Commit

Permalink
Change conventions to snake-case
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Apr 9, 2022
1 parent 0ce4c8d commit 5afb008
Show file tree
Hide file tree
Showing 39 changed files with 2,170 additions and 2,700 deletions.
12 changes: 5 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ cEdgeDetection | Edge detection kernels (4 bilinear, 2 discrete)
cFilmGrain | Film grain without copying texture
cFrameBlending | Frame blending using the previous result
cGaussianBlur | HLSL implementation of RasterGrid's linear Gaussian blur
cHornSchunck | HLSL implementation of pyramidal Horn Schunck without filtering
cInterpolation | Optical flow frame blending
cLetterBox | LetterBox without copying textures
cLuminance | Various grayscale algoritms
cMedian | 3x3 median filter
cMotionBlur | Color motion blur
cMotionMask | Frame masking based on temporal derivative
cNoiseConvolution | Convolution using rotated gradient noise sampling
cOpticalFlow | HLSL implementation of pyramidal Horn Schunck
cOpticalFlow | HLSL implementation of pyramidal Horn Schunck with visualization
cOverlay | Simple backbuffer overlay
cPingPong | Gaussian blur approximation using ping-pong box blurs
cScale | Buffer scaling using vertex shaders
Expand All @@ -58,12 +57,11 @@ kVignette | Natural vignetting effect

Practice | Variable
-------- | --------
Prefix `_` | Global variables
Respectively suffix `VS` and `PS` | `PixelShader and VertexShader`
**ALLCAPS** | Semantics and state parameters
**Pascal_Case** | System-Value Semantics (`SV_Position`)
**PascalCase** | Namespaces, structs, methods, global objects, and local variables
**ALLCAPS** | System-Value semantics, state parameters
**Snake_Case** | Namespaces, structs, methods, texture objects, and local variables
**_Snake_Case** | Uniform variables
**SNAKE_CASE** | Macros and preprocessor defines
Suffix `VS` and `PS` | `PixelShader` and `VertexShader`

## Acknowledgements

Expand Down
18 changes: 9 additions & 9 deletions shaders/ReShade.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@
namespace ReShade
{
#if defined(__RESHADE_FXC__)
float GetAspectRatio() { return BUFFER_WIDTH * BUFFER_RCP_HEIGHT; }
float GetAspect_Ratio() { return BUFFER_WIDTH * BUFFER_RCP_HEIGHT; }
float2 GetPixelSize() { return float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); }
float2 GetScreenSize() { return float2(BUFFER_WIDTH, BUFFER_HEIGHT); }
#define AspectRatio GetAspectRatio()
#define PixelSize GetPixelSize()
#define ScreenSize GetScreenSize()
float2 GetScreen_Size() { return float2(BUFFER_WIDTH, BUFFER_HEIGHT); }
#define Aspect_Ratio GetAspect_Ratio()
#define Pixel_Size GetPixelSize()
#define Screen_Size GetScreen_Size()
#else
// These are deprecated and will be removed eventually.
static const float AspectRatio = BUFFER_WIDTH * BUFFER_RCP_HEIGHT;
static const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);
static const float2 ScreenSize = float2(BUFFER_WIDTH, BUFFER_HEIGHT);
static const float Aspect_Ratio = BUFFER_WIDTH * BUFFER_RCP_HEIGHT;
static const float2 Pixel_Size = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);
static const float2 Screen_Size = float2(BUFFER_WIDTH, BUFFER_HEIGHT);
#endif

// Global textures and samplers
Expand Down Expand Up @@ -118,7 +118,7 @@ namespace ReShade
}

// Vertex shader generating a triangle covering the entire screen
void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD0)
void Basic_VS(in uint id : SV_VERTEXID, out float4 position : SV_POSITION, out float2 texcoord : TEXCOORD0)
{
texcoord.x = (id == 2) ? 2.0 : 0.0;
texcoord.y = (id == 1) ? 2.0 : 0.0;
Expand Down
20 changes: 10 additions & 10 deletions shaders/buggyassshaderlmao.fx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

void PostProcessVS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float2 TexCoord : TEXCOORD0)
void Basic_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float2 Coord : TEXCOORD0)
{
TexCoord.x = (ID == 2) ? 2.0 : 0.0;
TexCoord.y = (ID == 1) ? 2.0 : 0.0;
Position = float4(TexCoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
Coord.x = (ID == 2) ? 2.0 : 0.0;
Coord.y = (ID == 1) ? 2.0 : 0.0;
Position = float4(Coord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

void ShaderPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0)
void ShaderPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
{
float2 PositionMod = Position.xy % 2.0;
OutputColor0.r = (PositionMod.x == 1.0 && PositionMod.y == 1.0) ? 1.0 : 0.0;
OutputColor0.g = (PositionMod.x == 0.0 && PositionMod.y == 1.0) ? 1.0 : 0.0;
OutputColor0.b = (PositionMod.x == 1.0 && PositionMod.y == 0.0) ? 1.0 : 0.0;
OutputColor0.a = (PositionMod.x == 0.0 && PositionMod.y == 0.0) ? 1.0 : 0.0;
Output_Color_0.r = (PositionMod.x == 1.0 && PositionMod.y == 1.0) ? 1.0 : 0.0;
Output_Color_0.g = (PositionMod.x == 0.0 && PositionMod.y == 1.0) ? 1.0 : 0.0;
Output_Color_0.b = (PositionMod.x == 1.0 && PositionMod.y == 0.0) ? 1.0 : 0.0;
Output_Color_0.a = (PositionMod.x == 0.0 && PositionMod.y == 0.0) ? 1.0 : 0.0;
}

technique Bug
{
pass
{
VertexShader = PostProcessVS;
VertexShader = Basic_VS;
PixelShader = ShaderPS;
}
}
36 changes: 18 additions & 18 deletions shaders/cAbberation.fx
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

uniform float2 _ShiftRed <
uniform float2 _Shift_Red <
ui_type = "drag";
> = -1.0;

uniform float2 _ShiftGreen <
uniform float2 _Shift_Green <
ui_type = "drag";
> = 0.0;

uniform float2 _ShiftBlue <
uniform float2 _Shift_Blue <
ui_type = "drag";
> = 1.0;

texture2D RenderColor : COLOR;
texture2D Render_Color : COLOR;

sampler2D SampleColor
sampler2D Sample_Color
{
Texture = RenderColor;
Texture = Render_Color;
MagFilter = LINEAR;
MinFilter = LINEAR;
MipFilter = LINEAR;
Expand All @@ -60,34 +60,34 @@ sampler2D SampleColor

// Vertex shaders

void PostProcessVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float2 TexCoord : TEXCOORD0)
void Basic_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float2 Coord : TEXCOORD0)
{
TexCoord.x = (ID == 2) ? 2.0 : 0.0;
TexCoord.y = (ID == 1) ? 2.0 : 0.0;
Position = float4(TexCoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
Coord.x = (ID == 2) ? 2.0 : 0.0;
Coord.y = (ID == 1) ? 2.0 : 0.0;
Position = float4(Coord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

// Pixel shaders

void AbberationPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0)
void Abberation_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
{
const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);
const float2 Pixel_Size = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);
// Shift red channel
OutputColor0.r = tex2D(SampleColor, TexCoord + _ShiftRed * PixelSize).r;
Output_Color_0.r = tex2D(Sample_Color, Coord + _Shift_Red * Pixel_Size).r;
// Keep green channel to the center
OutputColor0.g = tex2D(SampleColor, TexCoord + _ShiftGreen * PixelSize).g;
Output_Color_0.g = tex2D(Sample_Color, Coord + _Shift_Green * Pixel_Size).g;
// Shift blue channel
OutputColor0.b = tex2D(SampleColor, TexCoord + _ShiftBlue * PixelSize).b;
Output_Color_0.b = tex2D(Sample_Color, Coord + _Shift_Blue * Pixel_Size).b;
// Write alpha value
OutputColor0.a = 1.0;
Output_Color_0.a = 1.0;
}

technique cAbberation
{
pass
{
VertexShader = PostProcessVS;
PixelShader = AbberationPS;
VertexShader = Basic_VS;
PixelShader = Abberation_PS;
#if BUFFER_COLOR_BIT_DEPTH == 8
SRGBWriteEnable = TRUE;
#endif
Expand Down
58 changes: 29 additions & 29 deletions shaders/cAutoExposure.fx
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

uniform float _TimeRate <
uniform float _Time_Rate <
ui_label = "Smoothing";
ui_type = "drag";
ui_tooltip = "Exposure time smoothing";
ui_min = 0.0;
ui_max = 1.0;
> = 0.95;

uniform float _ManualBias <
uniform float _Manual_Bias <
ui_label = "Exposure";
ui_type = "drag";
ui_tooltip = "Optional manual bias ";
ui_min = 0.0;
> = 2.0;

texture2D RenderColor : COLOR;
texture2D Render_Color : COLOR;

sampler2D SampleColor
sampler2D Sample_Color
{
Texture = RenderColor;
Texture = Render_Color;
MagFilter = LINEAR;
MinFilter = LINEAR;
MipFilter = LINEAR;
Expand All @@ -61,62 +61,62 @@ sampler2D SampleColor
#endif
};

texture2D RenderLumaLOD
texture2D Render_Luma_LOD
{
Width = 256;
Height = 256;
MipLevels = 9;
Format = R16F;
};

sampler2D SampleLumaLOD
sampler2D Sample_Luma_LOD
{
Texture = RenderLumaLOD;
Texture = Render_Luma_LOD;
MagFilter = LINEAR;
MinFilter = LINEAR;
MipFilter = LINEAR;
};

// Vertex shaders

void PostProcessVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float2 TexCoord : TEXCOORD0)
void Basic_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float2 Coord : TEXCOORD0)
{
TexCoord.x = (ID == 2) ? 2.0 : 0.0;
TexCoord.y = (ID == 1) ? 2.0 : 0.0;
Position = float4(TexCoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
Coord.x = (ID == 2) ? 2.0 : 0.0;
Coord.y = (ID == 1) ? 2.0 : 0.0;
Position = float4(Coord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

// Pixel shaders

void BlitPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0)
void Blit_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
{
float4 Color = tex2D(SampleColor, TexCoord);
float4 Color = tex2D(Sample_Color, Coord);

// OutputColor.rgb = Output the highest brightness out of red/green/blue component
// OutputColor.a = Output the weight for temporal blending
OutputColor0 = float4(max(Color.r, max(Color.g, Color.b)).rrr, _TimeRate);
// Output_Color_0.rgb = Output the highest brightness out of red/green/blue component
// Output_Color_0.a = Output the weight for temporal blending
Output_Color_0 = float4(max(Color.r, max(Color.g, Color.b)).rrr, _Time_Rate);
}

void ExposurePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0)
void Exposure_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0)
{
// Average Luma = Average value (1x1) for all of the pixels
float AverageLuma = tex2Dlod(SampleLumaLOD, float4(TexCoord, 0.0, 8.0)).r;
float4 Color = tex2D(SampleColor, TexCoord);
float Average_Luma = tex2Dlod(Sample_Luma_LOD, float4(Coord, 0.0, 8.0)).r;
float4 Color = tex2D(Sample_Color, Coord);

// KeyValue is an exposure compensation curve
// Key_Value is an exposure compensation curve
// Source: https://knarkowicz.wordpress.com/2016/01/09/automatic-exposure/
float KeyValue = 1.03 - (2.0 / (log10(AverageLuma + 1.0) + 2.0));
float ExposureValue = log2(KeyValue / AverageLuma) + _ManualBias;
OutputColor0 = Color * exp2(ExposureValue);
float Key_Value = 1.03 - (2.0 / (log10(Average_Luma + 1.0) + 2.0));
float Exposure_Value = log2(Key_Value / Average_Luma) + _Manual_Bias;
Output_Color_0 = Color * exp2(Exposure_Value);
}

technique cAutoExposure
{
pass
{
VertexShader = PostProcessVS;
PixelShader = BlitPS;
RenderTarget = RenderLumaLOD;
VertexShader = Basic_VS;
PixelShader = Blit_PS;
RenderTarget = Render_Luma_LOD;
ClearRenderTargets = FALSE;
BlendEnable = TRUE;
BlendOp = ADD;
Expand All @@ -126,8 +126,8 @@ technique cAutoExposure

pass
{
VertexShader = PostProcessVS;
PixelShader = ExposurePS;
VertexShader = Basic_VS;
PixelShader = Exposure_PS;
#if BUFFER_COLOR_BIT_DEPTH == 8
SRGBWriteEnable = TRUE;
#endif
Expand Down
Loading

0 comments on commit 5afb008

Please sign in to comment.