diff --git a/readme.md b/readme.md index 4a2ced0..23c5a1c 100644 --- a/readme.md +++ b/readme.md @@ -32,7 +32,6 @@ 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 @@ -40,7 +39,7 @@ 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 @@ -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 diff --git a/shaders/ReShade.fxh b/shaders/ReShade.fxh index 7802427..3c62dcd 100644 --- a/shaders/ReShade.fxh +++ b/shaders/ReShade.fxh @@ -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 @@ -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; diff --git a/shaders/buggyassshaderlmao.fx b/shaders/buggyassshaderlmao.fx index 0c19ac9..3c43777 100644 --- a/shaders/buggyassshaderlmao.fx +++ b/shaders/buggyassshaderlmao.fx @@ -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; } } diff --git a/shaders/cAbberation.fx b/shaders/cAbberation.fx index b05315e..e63d6ae 100644 --- a/shaders/cAbberation.fx +++ b/shaders/cAbberation.fx @@ -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; @@ -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 diff --git a/shaders/cAutoExposure.fx b/shaders/cAutoExposure.fx index 1c198a0..8149338 100644 --- a/shaders/cAutoExposure.fx +++ b/shaders/cAutoExposure.fx @@ -33,7 +33,7 @@ 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"; @@ -41,18 +41,18 @@ uniform float _TimeRate < 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; @@ -61,7 +61,7 @@ sampler2D SampleColor #endif }; -texture2D RenderLumaLOD +texture2D Render_Luma_LOD { Width = 256; Height = 256; @@ -69,9 +69,9 @@ texture2D RenderLumaLOD Format = R16F; }; -sampler2D SampleLumaLOD +sampler2D Sample_Luma_LOD { - Texture = RenderLumaLOD; + Texture = Render_Luma_LOD; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -79,44 +79,44 @@ sampler2D SampleLumaLOD // 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; @@ -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 diff --git a/shaders/cBloom.fx b/shaders/cBloom.fx index 1901bbf..f7d98d9 100644 --- a/shaders/cBloom.fx +++ b/shaders/cBloom.fx @@ -33,20 +33,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define BUFFER_SIZE_1 uint2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1) -#define BUFFER_SIZE_2 uint2(BUFFER_WIDTH >> 2, BUFFER_HEIGHT >> 2) -#define BUFFER_SIZE_3 uint2(BUFFER_WIDTH >> 3, BUFFER_HEIGHT >> 3) -#define BUFFER_SIZE_4 uint2(BUFFER_WIDTH >> 4, BUFFER_HEIGHT >> 4) -#define BUFFER_SIZE_5 uint2(BUFFER_WIDTH >> 5, BUFFER_HEIGHT >> 5) -#define BUFFER_SIZE_6 uint2(BUFFER_WIDTH >> 6, BUFFER_HEIGHT >> 6) -#define BUFFER_SIZE_7 uint2(BUFFER_WIDTH >> 7, BUFFER_HEIGHT >> 7) -#define BUFFER_SIZE_8 uint2(BUFFER_WIDTH >> 8, BUFFER_HEIGHT >> 8) +#define BUFFER_SIZE_1 int2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1) +#define BUFFER_SIZE_2 int2(BUFFER_WIDTH >> 2, BUFFER_HEIGHT >> 2) +#define BUFFER_SIZE_3 int2(BUFFER_WIDTH >> 3, BUFFER_HEIGHT >> 3) +#define BUFFER_SIZE_4 int2(BUFFER_WIDTH >> 4, BUFFER_HEIGHT >> 4) +#define BUFFER_SIZE_5 int2(BUFFER_WIDTH >> 5, BUFFER_HEIGHT >> 5) +#define BUFFER_SIZE_6 int2(BUFFER_WIDTH >> 6, BUFFER_HEIGHT >> 6) +#define BUFFER_SIZE_7 int2(BUFFER_WIDTH >> 7, BUFFER_HEIGHT >> 7) +#define BUFFER_SIZE_8 int2(BUFFER_WIDTH >> 8, BUFFER_HEIGHT >> 8) -namespace SharedResources +namespace Shared_Resources { namespace RGBA16F { - texture2D RenderCommon1 < pooled = true; > + texture2D Render_Common_1 < pooled = true; > { Width = BUFFER_SIZE_1.x; Height = BUFFER_SIZE_1.y; @@ -54,49 +54,49 @@ namespace SharedResources MipLevels = 8; }; - texture2D RenderCommon2 < pooled = true; > + texture2D Render_Common_2 < pooled = true; > { Width = BUFFER_SIZE_2.x; Height = BUFFER_SIZE_2.y; Format = RGBA16F; }; - texture2D RenderCommon3 < pooled = true; > + texture2D Render_Common_3 < pooled = true; > { Width = BUFFER_SIZE_3.x; Height = BUFFER_SIZE_3.y; Format = RGBA16F; }; - texture2D RenderCommon4 < pooled = true; > + texture2D Render_Common_4 < pooled = true; > { Width = BUFFER_SIZE_4.x; Height = BUFFER_SIZE_4.y; Format = RGBA16F; }; - texture2D RenderCommon5 < pooled = true; > + texture2D Render_Common_5 < pooled = true; > { Width = BUFFER_SIZE_5.x; Height = BUFFER_SIZE_5.y; Format = RGBA16F; }; - texture2D RenderCommon6 < pooled = true; > + texture2D Render_Common_6 < pooled = true; > { Width = BUFFER_SIZE_6.x; Height = BUFFER_SIZE_6.y; Format = RGBA16F; }; - texture2D RenderCommon7 < pooled = true; > + texture2D Render_Common_7 < pooled = true; > { Width = BUFFER_SIZE_7.x; Height = BUFFER_SIZE_7.y; Format = RGBA16F; }; - texture2D RenderCommon8 < pooled = true; > + texture2D Render_Common_8 < pooled = true; > { Width = BUFFER_SIZE_8.x; Height = BUFFER_SIZE_8.y; @@ -124,7 +124,7 @@ uniform float _Saturation < ui_label = "Saturation"; > = 1.0; -uniform float3 _ColorShift < +uniform float3 _Color_Shift < ui_type = "color"; ui_min = 0.0; ui_label = "Color Shift"; @@ -136,53 +136,53 @@ uniform float _Intensity < ui_label = "Color Intensity"; > = 1.0; -uniform float _Level6Weight < +uniform float _Level_6_Weight < ui_type = "drag"; ui_min = 0.0; ui_label = "Level 6 Weight"; ui_category = "Level Weights"; > = 1.0; -uniform float _Level5Weight < +uniform float _Level_5_Weight < ui_type = "drag"; ui_min = 0.0; ui_label = "Level 5 Weight"; ui_category = "Level Weights"; > = 1.0; -uniform float _Level4Weight < +uniform float _Level_4_Weight < ui_type = "drag"; ui_min = 0.0; ui_label = "Level 4 Weight"; ui_category = "Level Weights"; > = 1.0; -uniform float _Level3Weight < +uniform float _Level_3_Weight < ui_type = "drag"; ui_min = 0.0; ui_label = "Level 3 Weight"; ui_category = "Level Weights"; > = 1.0; -uniform float _Level2Weight < +uniform float _Level_2_Weight < ui_type = "drag"; ui_min = 0.0; ui_label = "Level 2 Weight"; ui_category = "Level Weights"; > = 1.0; -uniform float _Level1Weight < +uniform float _Level_1_Weight < ui_type = "drag"; ui_min = 0.0; ui_label = "Level 1 Weight"; ui_category = "Level Weights"; > = 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; @@ -191,65 +191,65 @@ sampler2D SampleColor #endif }; -sampler2D SampleCommon_RGBA16F_1 +sampler2D Sample_Common_RGBA16F_1 { - Texture = SharedResources::RGBA16F::RenderCommon1; + Texture = Shared_Resources::RGBA16F::Render_Common_1; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon_RGBA16F_2 +sampler2D Sample_Common_RGBA16F_2 { - Texture = SharedResources::RGBA16F::RenderCommon2; + Texture = Shared_Resources::RGBA16F::Render_Common_2; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon_RGBA16F_3 +sampler2D Sample_Common_RGBA16F_3 { - Texture = SharedResources::RGBA16F::RenderCommon3; + Texture = Shared_Resources::RGBA16F::Render_Common_3; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon_RGBA16F_4 +sampler2D Sample_Common_RGBA16F_4 { - Texture = SharedResources::RGBA16F::RenderCommon4; + Texture = Shared_Resources::RGBA16F::Render_Common_4; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon_RGBA16F_5 +sampler2D Sample_Common_RGBA16F_5 { - Texture = SharedResources::RGBA16F::RenderCommon5; + Texture = Shared_Resources::RGBA16F::Render_Common_5; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon_RGBA16F_6 +sampler2D Sample_Common_RGBA16F_6 { - Texture = SharedResources::RGBA16F::RenderCommon6; + Texture = Shared_Resources::RGBA16F::Render_Common_6; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon_RGBA16F_7 +sampler2D Sample_Common_RGBA16F_7 { - Texture = SharedResources::RGBA16F::RenderCommon7; + Texture = Shared_Resources::RGBA16F::Render_Common_7; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon_RGBA16F_8 +sampler2D Sample_Common_RGBA16F_8 { - Texture = SharedResources::RGBA16F::RenderCommon8; + Texture = Shared_Resources::RGBA16F::Render_Common_8; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -258,295 +258,295 @@ sampler2D SampleCommon_RGBA16F_8 // Vertex shaders // Sampling kernels: http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare -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 DownsampleVS(in uint ID, out float4 Position, out float4 TexCoord[4], float2 PixelSize) +void DownsampleVS(in uint ID, out float4 Position, out float4 Coord[4], float2 Pixel_Size) { - float2 TexCoord0; - PostProcessVS(ID, Position, TexCoord0); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); // Quadrant - TexCoord[0] = TexCoord0.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * PixelSize.xyxy; + Coord[0] = VS_Coord.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * Pixel_Size.xyxy; // Left column - TexCoord[1] = TexCoord0.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy; + Coord[1] = VS_Coord.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * Pixel_Size.xyyy; // Center column - TexCoord[2] = TexCoord0.xyyy + float4(0.0, 2.0, 0.0, -2.0) * PixelSize.xyyy; + Coord[2] = VS_Coord.xyyy + float4(0.0, 2.0, 0.0, -2.0) * Pixel_Size.xyyy; // Right column - TexCoord[3] = TexCoord0.xyyy + float4(2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy; + Coord[3] = VS_Coord.xyyy + float4(2.0, 2.0, 0.0, -2.0) * Pixel_Size.xyyy; } -void UpsampleVS(in uint ID, out float4 Position, out float4 TexCoord[3], float2 PixelSize) +void UpsampleVS(in uint ID, out float4 Position, out float4 Coord[3], float2 Pixel_Size) { - float2 TexCoord0; - PostProcessVS(ID, Position, TexCoord0); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); // Left column - TexCoord[0] = TexCoord0.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy; + Coord[0] = VS_Coord.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * Pixel_Size.xyyy; // Center column - TexCoord[1] = TexCoord0.xyyy + float4(0.0, 2.0, 0.0, -2.0) * PixelSize.xyyy; + Coord[1] = VS_Coord.xyyy + float4(0.0, 2.0, 0.0, -2.0) * Pixel_Size.xyyy; // Right column - TexCoord[2] = TexCoord0.xyyy + float4(2.0, 2.0, 0.0, -2.0) * PixelSize.xyyy; + Coord[2] = VS_Coord.xyyy + float4(2.0, 2.0, 0.0, -2.0) * Pixel_Size.xyyy; } -void DownsampleVS1(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Downsample_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_1); + DownsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_1); } -void DownsampleVS2(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Downsample_2_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_2); + DownsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_2); } -void DownsampleVS3(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Downsample_3_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_3); + DownsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_3); } -void DownsampleVS4(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Downsample_4_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_4); + DownsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_4); } -void DownsampleVS5(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Downsample_5_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_5); + DownsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_5); } -void DownsampleVS6(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Downsample_6_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_6); + DownsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_6); } -void DownsampleVS7(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Downsample_7_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_7); + DownsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_7); } -void UpsampleVS7(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[3] : TEXCOORD0) +void Upsample_7_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_7); + UpsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_7); } -void UpsampleVS6(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[3] : TEXCOORD0) +void Upsample_6_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_6); + UpsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_6); } -void UpsampleVS5(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[3] : TEXCOORD0) +void Upsample_5_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_5); + UpsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_5); } -void UpsampleVS4(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[3] : TEXCOORD0) +void Upsample_4_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_4); + UpsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_4); } -void UpsampleVS3(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[3] : TEXCOORD0) +void Upsample_3_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_3); + UpsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_3); } -void UpsampleVS2(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[3] : TEXCOORD0) +void Upsample_2_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_2); + UpsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_2); } -void UpsampleVS1(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[3] : TEXCOORD0) +void Upsample_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoord, 1.0 / BUFFER_SIZE_1); + UpsampleVS(ID, Position, Coord, 1.0 / BUFFER_SIZE_1); } // Pixel shaders // Thresholding: https://github.com/keijiro/Kino [MIT] // Tonemapping: https://github.com/TheRealMJP/BakingLab [MIT] -void Downsample(in sampler2D Source, in float4 TexCoord[4], out float4 Output) +void Downsample(in sampler2D Source, in float4 Coord[4], out float4 Output) { - // A0 B0 C0 + // A_0 B_0 C_0 // D0 D1 - // A1 B1 C1 + // A_1 B_1 C_1 // D2 D3 - // A2 B2 C2 + // A_2 B_2 C_2 - float4 D0 = tex2D(Source, TexCoord[0].xw); - float4 D1 = tex2D(Source, TexCoord[0].zw); - float4 D2 = tex2D(Source, TexCoord[0].xy); - float4 D3 = tex2D(Source, TexCoord[0].zy); + float4 D0 = tex2D(Source, Coord[0].xw); + float4 D1 = tex2D(Source, Coord[0].zw); + float4 D2 = tex2D(Source, Coord[0].xy); + float4 D3 = tex2D(Source, Coord[0].zy); - float4 A0 = tex2D(Source, TexCoord[1].xy); - float4 A1 = tex2D(Source, TexCoord[1].xz); - float4 A2 = tex2D(Source, TexCoord[1].xw); + float4 A_0 = tex2D(Source, Coord[1].xy); + float4 A_1 = tex2D(Source, Coord[1].xz); + float4 A_2 = tex2D(Source, Coord[1].xw); - float4 B0 = tex2D(Source, TexCoord[2].xy); - float4 B1 = tex2D(Source, TexCoord[2].xz); - float4 B2 = tex2D(Source, TexCoord[2].xw); + float4 B_0 = tex2D(Source, Coord[2].xy); + float4 B_1 = tex2D(Source, Coord[2].xz); + float4 B_2 = tex2D(Source, Coord[2].xw); - float4 C0 = tex2D(Source, TexCoord[3].xy); - float4 C1 = tex2D(Source, TexCoord[3].xz); - float4 C2 = tex2D(Source, TexCoord[3].xw); + float4 C_0 = tex2D(Source, Coord[3].xy); + float4 C_1 = tex2D(Source, Coord[3].xz); + float4 C_2 = tex2D(Source, Coord[3].xw); const float2 Weights = float2(0.5, 0.125) / 4.0; Output = (D0 + D1 + D2 + D3) * Weights.x; - Output += (A0 + B0 + A1 + B1) * Weights.y; - Output += (B0 + C0 + B1 + C1) * Weights.y; - Output += (A1 + B1 + A2 + B2) * Weights.y; - Output += (B1 + C1 + B2 + C2) * Weights.y; + Output += (A_0 + B_0 + A_1 + B_1) * Weights.y; + Output += (B_0 + C_0 + B_1 + C_1) * Weights.y; + Output += (A_1 + B_1 + A_2 + B_2) * Weights.y; + Output += (B_1 + C_1 + B_2 + C_2) * Weights.y; } -void Upsample(in sampler2D Source, in float4 TexCoord[3], in float Weight, out float4 Output) +void Upsample(in sampler2D Source, in float4 Coord[3], in float Weight, out float4 Output) { - // A0 B0 C0 - // A1 B1 C1 - // A2 B2 C2 + // A_0 B_0 C_0 + // A_1 B_1 C_1 + // A_2 B_2 C_2 - float4 A0 = tex2D(Source, TexCoord[0].xy); - float4 A1 = tex2D(Source, TexCoord[0].xz); - float4 A2 = tex2D(Source, TexCoord[0].xw); + float4 A_0 = tex2D(Source, Coord[0].xy); + float4 A_1 = tex2D(Source, Coord[0].xz); + float4 A_2 = tex2D(Source, Coord[0].xw); - float4 B0 = tex2D(Source, TexCoord[1].xy); - float4 B1 = tex2D(Source, TexCoord[1].xz); - float4 B2 = tex2D(Source, TexCoord[1].xw); + float4 B_0 = tex2D(Source, Coord[1].xy); + float4 B_1 = tex2D(Source, Coord[1].xz); + float4 B_2 = tex2D(Source, Coord[1].xw); - float4 C0 = tex2D(Source, TexCoord[2].xy); - float4 C1 = tex2D(Source, TexCoord[2].xz); - float4 C2 = tex2D(Source, TexCoord[2].xw); + float4 C_0 = tex2D(Source, Coord[2].xy); + float4 C_1 = tex2D(Source, Coord[2].xz); + float4 C_2 = tex2D(Source, Coord[2].xw); - Output = (A0 + C0 + A2 + C2) * 1.0; - Output += (A1 + B0 + C1 + B2) * 2.0; - Output += B1 * 4.0; + Output = (A_0 + C_0 + A_2 + C_2) * 1.0; + Output += (A_1 + B_0 + C_1 + B_2) * 2.0; + Output += B_1 * 4.0; Output *= (1.0 / 16.0); Output.a = abs(Weight); } -float Med3(float x, float y, float z) +float Median_3(float x, float y, float z) { return max(min(x, y), min(max(x, y), z)); } -void PrefilterPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Prefilter_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { const float Knee = mad(_Threshold, _Smooth, 1e-5f); const float3 Curve = float3(_Threshold - Knee, Knee * 2.0, 0.25 / Knee); - float4 Color = tex2D(SampleColor, TexCoord); + float4 Color = tex2D(Sample_Color, Coord); // Under-threshold - float Brightness = Med3(Color.r, Color.g, Color.b); - float ResponseCurve = clamp(Brightness - Curve.x, 0.0, Curve.y); - ResponseCurve = Curve.z * ResponseCurve * ResponseCurve; + float Brightness = Median_3(Color.r, Color.g, Color.b); + float Response_Curve = clamp(Brightness - Curve.x, 0.0, Curve.y); + Response_Curve = Curve.z * Response_Curve * Response_Curve; // Combine and apply the brightness response curve - Color = Color * max(ResponseCurve, Brightness - _Threshold) / max(Brightness, 1e-10); - Brightness = Med3(Color.r, Color.g, Color.b); - OutputColor0 = saturate(lerp(Brightness, Color.rgb, _Saturation)) * _ColorShift; + Color = Color * max(Response_Curve, Brightness - _Threshold) / max(Brightness, 1e-10); + Brightness = Median_3(Color.r, Color.g, Color.b); + Output_Color_0 = saturate(lerp(Brightness, Color.rgb, _Saturation)) * _Color_Shift; // Set alpha to 1.0 so we can see the complete results in ReShade's statistics - OutputColor0.a = 1.0; + Output_Color_0.a = 1.0; } // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT -static const float3x3 ACESInputMat = float3x3( +static const float3x3 ACES_Input_Mat = float3x3( 0.59719, 0.35458, 0.04823, 0.07600, 0.90834, 0.01566, 0.02840, 0.13383, 0.83777 ); // ODT_SAT => XYZ => D60_2_D65 => sRGB -static const float3x3 ACESOutputMat = float3x3( +static const float3x3 ACES_Output_Mat = float3x3( 1.60475, -0.53108, -0.07367, -0.10208, 1.10813, -0.00605, -0.00327, -0.07276, 1.07602 ); -float3 RRTAndODTFit(float3 v) +float3 RRT_ODT_Fit(float3 v) { float3 a = v * (v + 0.0245786f) - 0.000090537f; float3 b = v * (0.983729f * v + 0.4329510f) + 0.238081f; return a / b; } -void DownsamplePS1(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_1_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Downsample(SampleCommon_RGBA16F_1, TexCoord, OutputColor0); + Downsample(Sample_Common_RGBA16F_1, Coord, Output_Color_0); } -void DownsamplePS2(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_2_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Downsample(SampleCommon_RGBA16F_2, TexCoord, OutputColor0); + Downsample(Sample_Common_RGBA16F_2, Coord, Output_Color_0); } -void DownsamplePS3(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_3_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Downsample(SampleCommon_RGBA16F_3, TexCoord, OutputColor0); + Downsample(Sample_Common_RGBA16F_3, Coord, Output_Color_0); } -void DownsamplePS4(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_4_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Downsample(SampleCommon_RGBA16F_4, TexCoord, OutputColor0); + Downsample(Sample_Common_RGBA16F_4, Coord, Output_Color_0); } -void DownsamplePS5(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_5_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Downsample(SampleCommon_RGBA16F_5, TexCoord, OutputColor0); + Downsample(Sample_Common_RGBA16F_5, Coord, Output_Color_0); } -void DownsamplePS6(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_6_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Downsample(SampleCommon_RGBA16F_6, TexCoord, OutputColor0); + Downsample(Sample_Common_RGBA16F_6, Coord, Output_Color_0); } -void DownsamplePS7(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_7_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Downsample(SampleCommon_RGBA16F_7, TexCoord, OutputColor0); + Downsample(Sample_Common_RGBA16F_7, Coord, Output_Color_0); } -void UpsamplePS7(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_7_PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Upsample(SampleCommon_RGBA16F_8, TexCoord, _Level6Weight, OutputColor0); + Upsample(Sample_Common_RGBA16F_8, Coord, _Level_6_Weight, Output_Color_0); } -void UpsamplePS6(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_6_PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Upsample(SampleCommon_RGBA16F_7, TexCoord, _Level5Weight, OutputColor0); + Upsample(Sample_Common_RGBA16F_7, Coord, _Level_5_Weight, Output_Color_0); } -void UpsamplePS5(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_5_PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Upsample(SampleCommon_RGBA16F_6, TexCoord, _Level4Weight, OutputColor0); + Upsample(Sample_Common_RGBA16F_6, Coord, _Level_4_Weight, Output_Color_0); } -void UpsamplePS4(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_4_PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Upsample(SampleCommon_RGBA16F_5, TexCoord, _Level3Weight, OutputColor0); + Upsample(Sample_Common_RGBA16F_5, Coord, _Level_3_Weight, Output_Color_0); } -void UpsamplePS3(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_3_PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Upsample(SampleCommon_RGBA16F_4, TexCoord, _Level2Weight, OutputColor0); + Upsample(Sample_Common_RGBA16F_4, Coord, _Level_2_Weight, Output_Color_0); } -void UpsamplePS2(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_2_PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Upsample(SampleCommon_RGBA16F_3, TexCoord, _Level1Weight, OutputColor0); + Upsample(Sample_Common_RGBA16F_3, Coord, _Level_1_Weight, Output_Color_0); } -void UpsamplePS1(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_1_PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - Upsample(SampleCommon_RGBA16F_2, TexCoord, 0.0, OutputColor0); + Upsample(Sample_Common_RGBA16F_2, Coord, 0.0, Output_Color_0); } -void CompositePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Composite_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - float4 Src = tex2D(SampleCommon_RGBA16F_1, TexCoord); + float4 Src = tex2D(Sample_Common_RGBA16F_1, Coord); Src *= _Intensity; - Src = mul(ACESInputMat, Src.rgb); - Src = RRTAndODTFit(Src.rgb); - Src = saturate(mul(ACESOutputMat, Src.rgb)); - OutputColor0 = Src; + Src = mul(ACES_Input_Mat, Src.rgb); + Src = RRT_ODT_Fit(Src.rgb); + Src = saturate(mul(ACES_Output_Mat, Src.rgb)); + Output_Color_0 = Src; } /* [ TECHNIQUE ] */ @@ -555,65 +555,65 @@ technique cBloom { pass { - VertexShader = PostProcessVS; - PixelShader = PrefilterPS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon1; + VertexShader = Basic_VS; + PixelShader = Prefilter_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_1; } pass { - VertexShader = DownsampleVS1; - PixelShader = DownsamplePS1; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon2; + VertexShader = Downsample_1_VS; + PixelShader = Downsample_1_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_2; } pass { - VertexShader = DownsampleVS2; - PixelShader = DownsamplePS2; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon3; + VertexShader = Downsample_2_VS; + PixelShader = Downsample_2_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_3; } pass { - VertexShader = DownsampleVS3; - PixelShader = DownsamplePS3; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon4; + VertexShader = Downsample_3_VS; + PixelShader = Downsample_3_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_4; } pass { - VertexShader = DownsampleVS4; - PixelShader = DownsamplePS4; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon5; + VertexShader = Downsample_4_VS; + PixelShader = Downsample_4_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_5; } pass { - VertexShader = DownsampleVS5; - PixelShader = DownsamplePS5; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon6; + VertexShader = Downsample_5_VS; + PixelShader = Downsample_5_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_6; } pass { - VertexShader = DownsampleVS6; - PixelShader = DownsamplePS6; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon7; + VertexShader = Downsample_6_VS; + PixelShader = Downsample_6_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_7; } pass { - VertexShader = DownsampleVS7; - PixelShader = DownsamplePS7; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon8; + VertexShader = Downsample_7_VS; + PixelShader = Downsample_7_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_8; } pass { - VertexShader = UpsampleVS7; - PixelShader = UpsamplePS7; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon7; + VertexShader = Upsample_7_VS; + PixelShader = Upsample_7_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_7; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; @@ -623,9 +623,9 @@ technique cBloom pass { - VertexShader = UpsampleVS6; - PixelShader = UpsamplePS6; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon6; + VertexShader = Upsample_6_VS; + PixelShader = Upsample_6_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_6; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; @@ -635,9 +635,9 @@ technique cBloom pass { - VertexShader = UpsampleVS5; - PixelShader = UpsamplePS5; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon5; + VertexShader = Upsample_5_VS; + PixelShader = Upsample_5_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_5; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; @@ -647,9 +647,9 @@ technique cBloom pass { - VertexShader = UpsampleVS4; - PixelShader = UpsamplePS4; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon4; + VertexShader = Upsample_4_VS; + PixelShader = Upsample_4_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_4; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; @@ -659,9 +659,9 @@ technique cBloom pass { - VertexShader = UpsampleVS3; - PixelShader = UpsamplePS3; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon3; + VertexShader = Upsample_3_VS; + PixelShader = Upsample_3_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_3; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; @@ -671,9 +671,9 @@ technique cBloom pass { - VertexShader = UpsampleVS2; - PixelShader = UpsamplePS2; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon2; + VertexShader = Upsample_2_VS; + PixelShader = Upsample_2_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_2; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; @@ -683,15 +683,15 @@ technique cBloom pass { - VertexShader = UpsampleVS1; - PixelShader = UpsamplePS1; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon1; + VertexShader = Upsample_1_VS; + PixelShader = Upsample_1_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_1; } pass { - VertexShader = PostProcessVS; - PixelShader = CompositePS; + VertexShader = Basic_VS; + PixelShader = Composite_PS; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; diff --git a/shaders/cBlur.fx b/shaders/cBlur.fx index 92698f0..c97e626 100644 --- a/shaders/cBlur.fx +++ b/shaders/cBlur.fx @@ -33,11 +33,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace SharedResources +namespace Shared_Resources { namespace RGBA8 { - texture2D RenderCommon1 < pooled = true; > + texture2D Render_Common_1 < pooled = true; > { Width = BUFFER_WIDTH >> 1; Height = BUFFER_HEIGHT >> 1; @@ -65,11 +65,11 @@ uniform int _Samples < ui_min = 0; > = 16; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -78,9 +78,9 @@ sampler2D SampleColor #endif }; -sampler2D SampleCommon_RGBA8_1 +sampler2D Sample_Common_RGBA8_1 { - Texture = SharedResources::RGBA8::RenderCommon1; + Texture = Shared_Resources::RGBA8::Render_Common_1; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -91,77 +91,77 @@ sampler2D SampleCommon_RGBA8_1 // 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 // Repurposed Wojciech Sterna's shadow sampling code as a screen-space convolution // http://maxest.gct-game.net/content/chss.pdf -void VogelSample(int Index, int SamplesCount, float Phi, out float2 OutputValue) +void Vogel_Sample(int Index, int Samples_Count, float Phi, out float2 Output) { - const float GoldenAngle = 2.4; - float Radius = sqrt(float(Index) + 0.5) * rsqrt(float(SamplesCount)); - float Theta = float(Index) * GoldenAngle + Phi; - - float2 SineCosine; - SineCosine[0] = sin(Theta); - SineCosine[1] = cos(Theta); - OutputValue = Radius * SineCosine; + const float Golden_Angle = 2.4; + float Radius = sqrt(float(Index) + 0.5) * rsqrt(float(Samples_Count)); + float Theta = float(Index) * Golden_Angle + Phi; + + float2 Sine_Cosine; + Sine_Cosine[0] = sin(Theta); + Sine_Cosine[1] = cos(Theta); + Output = Radius * Sine_Cosine; } -void VogelBlur(sampler2D Source, float2 TexCoord, float2 ScreenSize, float Radius, int Samples, float Phi, out float4 OutputColor) +void VogelBlur(sampler2D Source, float2 Coord, float2 Screen_Size, float Radius, int Samples, float Phi, out float4 Output_Color) { // Initialize variables we need to accumulate samples and calculate offsets - float2 Output; - float2 Offset; + float2 Output = 0.0; + float2 Offset = 0.0; // LOD calculation to fill in the gaps between samples const float Pi = 3.1415926535897932384626433832795; - float SampleArea = Pi * (Radius * Radius) / float(Samples); - float LOD = max(0.0, 0.5 * log2(SampleArea)); + float Sample_Area = Pi * (Radius * Radius) / float(Samples); + float LOD = max(0.0, 0.5 * log2(Sample_Area)); // Offset and weighting attributes - float2 PixelSize = 1.0 / ldexp(ScreenSize, -LOD); + float2 Pixel_Size = 1.0 / ldexp(Screen_Size, -LOD); float Weight = 1.0 / (float(Samples) + 1.0); for(int i = 0; i < Samples; i++) { - VogelSample(i, Samples, Phi, Offset); - OutputColor += tex2Dlod(Source, float4(TexCoord + (Offset * PixelSize), 0.0, LOD)) * Weight; + Vogel_Sample(i, Samples, Phi, Offset); + Output_Color += tex2Dlod(Source, float4(Coord + (Offset * Pixel_Size), 0.0, LOD)) * Weight; } } -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) { - OutputColor0 = tex2D(SampleColor, TexCoord); + Output_Color_0 = tex2D(Sample_Color, Coord); } -void VogelConvolutionPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Vogel_Convolution_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - VogelBlur(SampleCommon_RGBA8_1, TexCoord, uint2(BUFFER_WIDTH / 2, BUFFER_HEIGHT / 2), _Radius, _Samples, _Offset, OutputColor0); + VogelBlur(Sample_Common_RGBA8_1, Coord, int2(BUFFER_WIDTH / 2, BUFFER_HEIGHT / 2), _Radius, _Samples, _Offset, Output_Color_0); } technique cBlur { - pass GenerateMipLevels + pass Generate_Mip_Levels { - VertexShader = PostProcessVS; - PixelShader = BlitPS; - RenderTarget0 = SharedResources::RGBA8::RenderCommon1; + VertexShader = Basic_VS; + PixelShader = Blit_PS; + RenderTarget0 = Shared_Resources::RGBA8::Render_Common_1; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif } - pass VogelBlur + pass Vogel_Blur { - VertexShader = PostProcessVS; - PixelShader = VogelConvolutionPS; + VertexShader = Basic_VS; + PixelShader = Vogel_Convolution_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cCheckerBoard.fx b/shaders/cCheckerBoard.fx index ca234f2..e1007f7 100644 --- a/shaders/cCheckerBoard.fx +++ b/shaders/cCheckerBoard.fx @@ -33,47 +33,47 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -uniform float4 _Color1 < +uniform float4 _Color_1 < ui_min = 0.0; ui_label = "Color 1"; ui_type = "color"; > = 1.0; -uniform float4 _Color2 < +uniform float4 _Color_2 < ui_min = 0.0; ui_label = "Color 2"; ui_type = "color"; > = 0.0; -uniform bool _InvertCheckerboard < +uniform bool _Invert_Checkerboard < ui_type = "radio"; ui_label = "Invert Checkerboard Pattern"; > = false; // 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 CheckerBoardPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Checkerboard_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - float4 CheckerBoard = frac(dot(Position.xy, 0.5)) * 2.0; - CheckerBoard = _InvertCheckerboard ? 1.0 - CheckerBoard : CheckerBoard; - OutputColor0 = CheckerBoard == 1.0 ? _Color1 : _Color2; + float4 Checkerboard = frac(dot(Position.xy, 0.5)) * 2.0; + Checkerboard = _Invert_Checkerboard ? 1.0 - Checkerboard : Checkerboard; + Output_Color_0 = Checkerboard == 1.0 ? _Color_1 : _Color_2; } technique cCheckerBoard { pass { - VertexShader = PostProcessVS; - PixelShader = CheckerBoardPS; + VertexShader = Basic_VS; + PixelShader = Checkerboard_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cColorBlendOp.fx b/shaders/cColorBlendOp.fx index dc8288f..4c01738 100644 --- a/shaders/cColorBlendOp.fx +++ b/shaders/cColorBlendOp.fx @@ -31,21 +31,21 @@ uniform float4 _Color < // Vertex shaders -void PostProcessVS(in uint ID : SV_VertexID, out float4 Position : SV_Position) +void Basic_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION) { // Clip a triangle twice the screen's size to make a quad - float2 TexCoord = 0.0; - 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); + float2 Coord = 0.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 ColorPS(in float4 Position : SV_Position, out float4 OutputColor0 : SV_Target0) +void Color_PS(in float4 Position : SV_POSITION, out float4 Output_Color_0 : SV_TARGET0) { // Fill this quad with a color - OutputColor0 = _Color; + Output_Color_0 = _Color; } // Use BlendOp to multiple the backbuffer with this quad's color @@ -53,8 +53,8 @@ technique cColorBlendOp { pass { - VertexShader = PostProcessVS; - PixelShader = ColorPS; + VertexShader = Basic_VS; + PixelShader = Color_PS; BlendEnable = TRUE; BlendOp = ADD; SrcBlend = DESTCOLOR; diff --git a/shaders/cColorNormalization.fx b/shaders/cColorNormalization.fx index dfeeb56..c6ee5cc 100644 --- a/shaders/cColorNormalization.fx +++ b/shaders/cColorNormalization.fx @@ -40,11 +40,11 @@ uniform int _Select < ui_tooltip = "Select Chromaticity"; > = 0; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -55,49 +55,49 @@ 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 NormalizationPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float3 OutputColor0 : SV_Target0) +void Normalization_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float3 Output_Color_0 : SV_TARGET0) { - OutputColor0 = 0.0; + Output_Color_0 = 0.0; const float Minima = exp2(-10.0); - float3 Color = max(tex2D(SampleColor, TexCoord).rgb, Minima); + float3 Color = max(tex2D(Sample_Color, Coord).rgb, Minima); switch(_Select) { case 0: // Length (RG) - OutputColor0.rg = saturate(normalize(Color).rg); + Output_Color_0.rg = saturate(normalize(Color).rg); break; case 1: // Length (RGB) - OutputColor0 = saturate(normalize(Color)); + Output_Color_0 = saturate(normalize(Color)); break; case 2: // Average (RG) - OutputColor0.rg = saturate(Color.rg / dot(Color, 1.0 / 3.0)); + Output_Color_0.rg = saturate(Color.rg / dot(Color, 1.0 / 3.0)); break; case 3: // Average (RGB) - OutputColor0 = saturate(Color / dot(Color, 1.0 / 3.0)); + Output_Color_0 = saturate(Color / dot(Color, 1.0 / 3.0)); break; case 4: // Sum (RG) - OutputColor0.rg = saturate(Color.rg / dot(Color, 1.0)); + Output_Color_0.rg = saturate(Color.rg / dot(Color, 1.0)); break; case 5: // Sum (RGB) - OutputColor0 = saturate(Color / dot(Color, 1.0)); + Output_Color_0 = saturate(Color / dot(Color, 1.0)); break; case 6: // Max (RG) - OutputColor0.rg = saturate(Color.rg / max(max(Color.r, Color.g), Color.b)); + Output_Color_0.rg = saturate(Color.rg / max(max(Color.r, Color.g), Color.b)); break; case 7: // Max (RGB) - OutputColor0 = saturate(Color / max(max(Color.r, Color.g), Color.b)); + Output_Color_0 = saturate(Color / max(max(Color.r, Color.g), Color.b)); break; default: // No Chromaticity - OutputColor0 = Color; + Output_Color_0 = Color; break; } } @@ -106,8 +106,8 @@ technique cNormalizedColor { pass { - VertexShader = PostProcessVS; - PixelShader = NormalizationPS; + VertexShader = Basic_VS; + PixelShader = Normalization_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cDefault.fx b/shaders/cDefault.fx index be166fc..f759303 100644 --- a/shaders/cDefault.fx +++ b/shaders/cDefault.fx @@ -35,16 +35,16 @@ // Vertex shaders -void PostProcessVS(out float4 Position : SV_Position) +void Basic_VS(out float4 Position : SV_POSITION) { - Position = float4(0.0, 0.0, 0.0, 0.0); + Position = 0.0; } // Pixel shaders -void PostProcessPS(out float4 OutputColor0 : SV_Target0) +void Basic_PS(out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = float4(0.0, 0.0, 0.0, 0.0); + Output_Color_0 = 0.0; } technique cDefault @@ -52,7 +52,7 @@ technique cDefault pass { VertexCount = 0; - VertexShader = PostProcessVS; - PixelShader = PostProcessPS; + VertexShader = Basic_VS; + PixelShader = Basic_PS; } } diff --git a/shaders/cDualFilter.fx b/shaders/cDualFilter.fx index ea62846..67714c6 100644 --- a/shaders/cDualFilter.fx +++ b/shaders/cDualFilter.fx @@ -33,17 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define BUFFER_SIZE_0 uint2(BUFFER_WIDTH, BUFFER_HEIGHT) -#define BUFFER_SIZE_1 uint2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1) -#define BUFFER_SIZE_2 uint2(BUFFER_WIDTH >> 2, BUFFER_HEIGHT >> 2) -#define BUFFER_SIZE_3 uint2(BUFFER_WIDTH >> 3, BUFFER_HEIGHT >> 3) -#define BUFFER_SIZE_4 uint2(BUFFER_WIDTH >> 4, BUFFER_HEIGHT >> 4) +#define BUFFER_SIZE_0 int2(BUFFER_WIDTH, BUFFER_HEIGHT) +#define BUFFER_SIZE_1 int2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1) +#define BUFFER_SIZE_2 int2(BUFFER_WIDTH >> 2, BUFFER_HEIGHT >> 2) +#define BUFFER_SIZE_3 int2(BUFFER_WIDTH >> 3, BUFFER_HEIGHT >> 3) +#define BUFFER_SIZE_4 int2(BUFFER_WIDTH >> 4, BUFFER_HEIGHT >> 4) -namespace SharedResources +namespace Shared_Resources { namespace RGBA16F { - texture2D RenderCommon1 < pooled = true; > + texture2D Render_Common_1 < pooled = true; > { Width = BUFFER_SIZE_1.x; Height = BUFFER_SIZE_1.y; @@ -51,21 +51,21 @@ namespace SharedResources MipLevels = 8; }; - texture2D RenderCommon2 < pooled = true; > + texture2D Render_Common_2 < pooled = true; > { Width = BUFFER_SIZE_2.x; Height = BUFFER_SIZE_2.y; Format = RGBA16F; }; - texture2D RenderCommon3 < pooled = true; > + texture2D Render_Common_3 < pooled = true; > { Width = BUFFER_SIZE_3.x; Height = BUFFER_SIZE_3.y; Format = RGBA16F; }; - texture2D RenderCommon4 < pooled = true; > + texture2D Render_Common_4 < pooled = true; > { Width = BUFFER_SIZE_4.x; Height = BUFFER_SIZE_4.y; @@ -74,11 +74,11 @@ namespace SharedResources } } -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -87,33 +87,33 @@ sampler2D SampleColor #endif }; -sampler2D SampleCommon1 +sampler2D Sample_Common_1 { - Texture = SharedResources::RGBA16F::RenderCommon1; + Texture = Shared_Resources::RGBA16F::Render_Common_1; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon2 +sampler2D Sample_Common_2 { - Texture = SharedResources::RGBA16F::RenderCommon2; + Texture = Shared_Resources::RGBA16F::Render_Common_2; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon3 +sampler2D Sample_Common_3 { - Texture = SharedResources::RGBA16F::RenderCommon3; + Texture = Shared_Resources::RGBA16F::Render_Common_3; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; -sampler2D SampleCommon4 +sampler2D Sample_Common_4 { - Texture = SharedResources::RGBA16F::RenderCommon4; + Texture = Shared_Resources::RGBA16F::Render_Common_4; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -121,14 +121,14 @@ sampler2D SampleCommon4 // Shader properties -uniform int _DownsampleMethod < +uniform int _Downsample_Method < ui_type = "combo"; ui_items = " 2x2 Box\0 3x3 Tent\0 Jorge\0 Kawase\0"; ui_label = "Downsample kernel"; ui_tooltip = "Downsampling Method"; > = 0; -uniform int _UpsampleMethod < +uniform int _Upsample_Method < ui_type = "combo"; ui_items = " 2x2 Box\0 3x3 Tent\0 Kawase\0"; ui_label = "Upsample kernel"; @@ -137,100 +137,100 @@ uniform int _UpsampleMethod < // Vertex shaders -void PostProcessVS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float2 TexCoord : TEXCOORD0) +void Basic_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout 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 DownsampleVS(in uint ID, inout float4 Position, inout float4 TexCoords[4], float2 TexelSize) +void DownsampleVS(in uint ID, inout float4 Position, inout float4 Coords[4], float2 Texel_Size) { - float2 VSTexCoord; - PostProcessVS(ID, Position, VSTexCoord); - switch(_DownsampleMethod) + float2 VS_Coord;; + Basic_VS(ID, Position, VS_Coord); + switch(_Downsample_Method) { case 0: // 4x4 Box - TexCoords[0] = VSTexCoord.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * TexelSize.xyxy; + Coords[0] = VS_Coord.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * Texel_Size.xyxy; break; case 1: // 6x6 Tent - TexCoords[0] = VSTexCoord.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * TexelSize.xyyy; - TexCoords[1] = VSTexCoord.xyyy + float4(0.0, 2.0, 0.0, -2.0) * TexelSize.xyyy; - TexCoords[2] = VSTexCoord.xyyy + float4(2.0, 2.0, 0.0, -2.0) * TexelSize.xyyy; + Coords[0] = VS_Coord.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * Texel_Size.xyyy; + Coords[1] = VS_Coord.xyyy + float4(0.0, 2.0, 0.0, -2.0) * Texel_Size.xyyy; + Coords[2] = VS_Coord.xyyy + float4(2.0, 2.0, 0.0, -2.0) * Texel_Size.xyyy; break; case 2: // Jorge - TexCoords[0] = VSTexCoord.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * TexelSize.xyxy; - TexCoords[1] = VSTexCoord.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * TexelSize.xyyy; - TexCoords[2] = VSTexCoord.xyyy + float4(0.0, 2.0, 0.0, -2.0) * TexelSize.xyyy; - TexCoords[3] = VSTexCoord.xyyy + float4(2.0, 2.0, 0.0, -2.0) * TexelSize.xyyy; + Coords[0] = VS_Coord.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * Texel_Size.xyxy; + Coords[1] = VS_Coord.xyyy + float4(-2.0, 2.0, 0.0, -2.0) * Texel_Size.xyyy; + Coords[2] = VS_Coord.xyyy + float4(0.0, 2.0, 0.0, -2.0) * Texel_Size.xyyy; + Coords[3] = VS_Coord.xyyy + float4(2.0, 2.0, 0.0, -2.0) * Texel_Size.xyyy; break; case 3: // Kawase - TexCoords[0] = VSTexCoord.xyxy; - TexCoords[1] = VSTexCoord.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * TexelSize.xyxy; + Coords[0] = VS_Coord.xyxy; + Coords[1] = VS_Coord.xyxy + float4(-1.0, -1.0, 1.0, 1.0) * Texel_Size.xyxy; break; } } -void UpsampleVS(in uint ID, inout float4 Position, inout float4 TexCoords[3], float2 TexelSize) +void UpsampleVS(in uint ID, inout float4 Position, inout float4 Coords[3], float2 Texel_Size) { - float2 VSTexCoord; - PostProcessVS(ID, Position, VSTexCoord); - switch(_UpsampleMethod) + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + switch(_Upsample_Method) { case 0: // 4x4 Box - TexCoords[0] = VSTexCoord.xyxy + float4(-0.5, -0.5, 0.5, 0.5) * TexelSize.xyxy; + Coords[0] = VS_Coord.xyxy + float4(-0.5, -0.5, 0.5, 0.5) * Texel_Size.xyxy; break; case 1: // 6x6 Tent - TexCoords[0] = VSTexCoord.xyyy + float4(-1.0, 1.0, 0.0, -1.0) * TexelSize.xyyy; - TexCoords[1] = VSTexCoord.xyyy + float4(0.0, 1.0, 0.0, -1.0) * TexelSize.xyyy; - TexCoords[2] = VSTexCoord.xyyy + float4(1.0, 1.0, 0.0, -1.0) * TexelSize.xyyy; + Coords[0] = VS_Coord.xyyy + float4(-1.0, 1.0, 0.0, -1.0) * Texel_Size.xyyy; + Coords[1] = VS_Coord.xyyy + float4(0.0, 1.0, 0.0, -1.0) * Texel_Size.xyyy; + Coords[2] = VS_Coord.xyyy + float4(1.0, 1.0, 0.0, -1.0) * Texel_Size.xyyy; break; case 2: // Kawase - TexCoords[0] = VSTexCoord.xyxy + float4(-0.5, -0.5, 0.5, 0.5) * TexelSize.xyxy; - TexCoords[1] = VSTexCoord.xxxy + float4(1.0, 0.0, -1.0, 0.0) * TexelSize.xxxy; - TexCoords[2] = VSTexCoord.xyyy + float4(0.0, 1.0, 0.0, -1.0) * TexelSize.xyyy; + Coords[0] = VS_Coord.xyxy + float4(-0.5, -0.5, 0.5, 0.5) * Texel_Size.xyxy; + Coords[1] = VS_Coord.xxxy + float4(1.0, 0.0, -1.0, 0.0) * Texel_Size.xxxy; + Coords[2] = VS_Coord.xyyy + float4(0.0, 1.0, 0.0, -1.0) * Texel_Size.xyyy; break; } } -void Downsample1VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[4] : TEXCOORD0) +void Downsample_1_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_0); + DownsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_0); } -void Downsample2VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[4] : TEXCOORD0) +void Downsample_2_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_1); + DownsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_1); } -void Downsample3VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[4] : TEXCOORD0) +void Downsample_3_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_2); + DownsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_2); } -void Downsample4VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[4] : TEXCOORD0) +void Downsample_4_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[4] : TEXCOORD0) { - DownsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_3); + DownsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_3); } -void Upsample3VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[3] : TEXCOORD0) +void Upsample_3_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_4); + UpsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_4); } -void Upsample2VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[3] : TEXCOORD0) +void Upsample_2_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_3); + UpsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_3); } -void Upsample1VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[3] : TEXCOORD0) +void Upsample_1_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_2); + UpsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_2); } -void Upsample0VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[3] : TEXCOORD0) +void Upsample_0_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[3] : TEXCOORD0) { - UpsampleVS(ID, Position, TexCoords, 1.0 / BUFFER_SIZE_1); + UpsampleVS(ID, Position, Coords, 1.0 / BUFFER_SIZE_1); } // Pixel Shaders @@ -239,230 +239,230 @@ void Upsample0VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, // 3: https://community.arm.com/cfs-file/__key/communityserver-blogs-components-weblogfiles/00-00-00-20-66/siggraph2015_2D00_mmg_2D00_marius_2D00_slides.pdf // More: https://github.com/powervr-graphics/Native_SDK -void DownsamplePS(in sampler2D Source, in float4 TexCoords[4], out float4 OutputColor) +void DownsamplePS(in sampler2D Source, in float4 Coords[4], out float4 Output_Color) { - OutputColor = 0.0; + Output_Color = 0.0; - float4 A0, A1, A2, A3, - B0, B1, B2, B3, - C0, C1, C2, C3, + float4 A_0, A_1, A_2, A_3, + B_0, B_1, B_2, B_3, + C_0, C_1, C_2, C_3, D0, D1, D2, D3; - switch(_DownsampleMethod) + switch(_Downsample_Method) { case 0: // 2x2 Box - OutputColor += tex2D(Source, TexCoords[0].xw); - OutputColor += tex2D(Source, TexCoords[0].zw); - OutputColor += tex2D(Source, TexCoords[0].xy); - OutputColor += tex2D(Source, TexCoords[0].zy); - OutputColor = OutputColor / 4.0; + Output_Color += tex2D(Source, Coords[0].xw); + Output_Color += tex2D(Source, Coords[0].zw); + Output_Color += tex2D(Source, Coords[0].xy); + Output_Color += tex2D(Source, Coords[0].zy); + Output_Color = Output_Color / 4.0; break; case 1: // 3x3 Tent // Sampler locations - // A0 B0 C0 - // A1 B1 C1 - // A2 B2 C2 - A0 = tex2D(Source, TexCoords[0].xy); - A1 = tex2D(Source, TexCoords[0].xz); - A2 = tex2D(Source, TexCoords[0].xw); - - B0 = tex2D(Source, TexCoords[1].xy); - B1 = tex2D(Source, TexCoords[1].xz); - B2 = tex2D(Source, TexCoords[1].xw); - - C0 = tex2D(Source, TexCoords[2].xy); - C1 = tex2D(Source, TexCoords[2].xz); - C2 = tex2D(Source, TexCoords[2].xw); - - OutputColor += ((A0 + C0 + A2 + C2) * 1.0); - OutputColor += ((B0 + A1 + C1 + B2) * 2.0); - OutputColor += (B1 * 4.0); - OutputColor = OutputColor / 16.0; + // A_0 B_0 C_0 + // A_1 B_1 C_1 + // A_2 B_2 C_2 + A_0 = tex2D(Source, Coords[0].xy); + A_1 = tex2D(Source, Coords[0].xz); + A_2 = tex2D(Source, Coords[0].xw); + + B_0 = tex2D(Source, Coords[1].xy); + B_1 = tex2D(Source, Coords[1].xz); + B_2 = tex2D(Source, Coords[1].xw); + + C_0 = tex2D(Source, Coords[2].xy); + C_1 = tex2D(Source, Coords[2].xz); + C_2 = tex2D(Source, Coords[2].xw); + + Output_Color += ((A_0 + C_0 + A_2 + C_2) * 1.0); + Output_Color += ((B_0 + A_1 + C_1 + B_2) * 2.0); + Output_Color += (B_1 * 4.0); + Output_Color = Output_Color / 16.0; break; case 2: // Jorge // Sampler locations - // A0 B0 C0 + // A_0 B_0 C_0 // D0 D1 - // A1 B1 C1 + // A_1 B_1 C_1 // D2 D3 - // A2 B2 C2 - D0 = tex2D(Source, TexCoords[0].xw); - D1 = tex2D(Source, TexCoords[0].zw); - D2 = tex2D(Source, TexCoords[0].xy); - D3 = tex2D(Source, TexCoords[0].zy); + // A_2 B_2 C_2 + D0 = tex2D(Source, Coords[0].xw); + D1 = tex2D(Source, Coords[0].zw); + D2 = tex2D(Source, Coords[0].xy); + D3 = tex2D(Source, Coords[0].zy); - A0 = tex2D(Source, TexCoords[1].xy); - A1 = tex2D(Source, TexCoords[1].xz); - A2 = tex2D(Source, TexCoords[1].xw); + A_0 = tex2D(Source, Coords[1].xy); + A_1 = tex2D(Source, Coords[1].xz); + A_2 = tex2D(Source, Coords[1].xw); - B0 = tex2D(Source, TexCoords[2].xy); - B1 = tex2D(Source, TexCoords[2].xz); - B2 = tex2D(Source, TexCoords[2].xw); + B_0 = tex2D(Source, Coords[2].xy); + B_1 = tex2D(Source, Coords[2].xz); + B_2 = tex2D(Source, Coords[2].xw); - C0 = tex2D(Source, TexCoords[3].xy); - C1 = tex2D(Source, TexCoords[3].xz); - C2 = tex2D(Source, TexCoords[3].xw); + C_0 = tex2D(Source, Coords[3].xy); + C_1 = tex2D(Source, Coords[3].xz); + C_2 = tex2D(Source, Coords[3].xw); const float2 Weights = float2(0.5, 0.125) / 4.0; - OutputColor += (D0 + D1 + D2 + D3) * Weights.x; - OutputColor += (A0 + B0 + A1 + B1) * Weights.y; - OutputColor += (B0 + C0 + B1 + C1) * Weights.y; - OutputColor += (A1 + B1 + A2 + B2) * Weights.y; - OutputColor += (B1 + C1 + B2 + C2) * Weights.y; + Output_Color += (D0 + D1 + D2 + D3) * Weights.x; + Output_Color += (A_0 + B_0 + A_1 + B_1) * Weights.y; + Output_Color += (B_0 + C_0 + B_1 + C_1) * Weights.y; + Output_Color += (A_1 + B_1 + A_2 + B_2) * Weights.y; + Output_Color += (B_1 + C_1 + B_2 + C_2) * Weights.y; break; case 3: // Kawase - OutputColor += tex2D(Source, TexCoords[0].xy) * 4.0; - OutputColor += tex2D(Source, TexCoords[1].xw); - OutputColor += tex2D(Source, TexCoords[1].zw); - OutputColor += tex2D(Source, TexCoords[1].xy); - OutputColor += tex2D(Source, TexCoords[1].zy); - OutputColor = OutputColor / 8.0; + Output_Color += tex2D(Source, Coords[0].xy) * 4.0; + Output_Color += tex2D(Source, Coords[1].xw); + Output_Color += tex2D(Source, Coords[1].zw); + Output_Color += tex2D(Source, Coords[1].xy); + Output_Color += tex2D(Source, Coords[1].zy); + Output_Color = Output_Color / 8.0; break; } - OutputColor.a = 1.0; + Output_Color.a = 1.0; } -void UpsamplePS(in sampler2D Source, in float4 TexCoords[3], out float4 OutputColor) +void UpsamplePS(in sampler2D Source, in float4 Coords[3], out float4 Output_Color) { - OutputColor = 0.0; + Output_Color = 0.0; - switch(_UpsampleMethod) + switch(_Upsample_Method) { case 0: // 2x2 Box - OutputColor += tex2D(Source, TexCoords[0].xw); - OutputColor += tex2D(Source, TexCoords[0].zw); - OutputColor += tex2D(Source, TexCoords[0].xy); - OutputColor += tex2D(Source, TexCoords[0].zy); - OutputColor = OutputColor / 4.0; + Output_Color += tex2D(Source, Coords[0].xw); + Output_Color += tex2D(Source, Coords[0].zw); + Output_Color += tex2D(Source, Coords[0].xy); + Output_Color += tex2D(Source, Coords[0].zy); + Output_Color = Output_Color / 4.0; break; case 1: // 3x3 Tent // Sample locations: - // A0 B0 C0 - // A1 B1 C1 - // A2 B2 C2 - float4 A0 = tex2D(Source, TexCoords[0].xy); - float4 A1 = tex2D(Source, TexCoords[0].xz); - float4 A2 = tex2D(Source, TexCoords[0].xw); - float4 B0 = tex2D(Source, TexCoords[1].xy); - float4 B1 = tex2D(Source, TexCoords[1].xz); - float4 B2 = tex2D(Source, TexCoords[1].xw); - float4 C0 = tex2D(Source, TexCoords[2].xy); - float4 C1 = tex2D(Source, TexCoords[2].xz); - float4 C2 = tex2D(Source, TexCoords[2].xw); - OutputColor = (((A0 + C0 + A2 + C2) * 1.0) + ((B0 + A1 + C1 + B2) * 2.0) + (B1 * 4.0)) / 16.0; + // A_0 B_0 C_0 + // A_1 B_1 C_1 + // A_2 B_2 C_2 + float4 A_0 = tex2D(Source, Coords[0].xy); + float4 A_1 = tex2D(Source, Coords[0].xz); + float4 A_2 = tex2D(Source, Coords[0].xw); + float4 B_0 = tex2D(Source, Coords[1].xy); + float4 B_1 = tex2D(Source, Coords[1].xz); + float4 B_2 = tex2D(Source, Coords[1].xw); + float4 C_0 = tex2D(Source, Coords[2].xy); + float4 C_1 = tex2D(Source, Coords[2].xz); + float4 C_2 = tex2D(Source, Coords[2].xw); + Output_Color = (((A_0 + C_0 + A_2 + C_2) * 1.0) + ((B_0 + A_1 + C_1 + B_2) * 2.0) + (B_1 * 4.0)) / 16.0; break; case 2: // Kawase - OutputColor += tex2D(Source, TexCoords[0].xw) * 2.0; - OutputColor += tex2D(Source, TexCoords[0].zw) * 2.0; - OutputColor += tex2D(Source, TexCoords[0].xy) * 2.0; - OutputColor += tex2D(Source, TexCoords[0].zy) * 2.0; - OutputColor += tex2D(Source, TexCoords[1].xw); - OutputColor += tex2D(Source, TexCoords[1].zw); - OutputColor += tex2D(Source, TexCoords[2].xy); - OutputColor += tex2D(Source, TexCoords[2].xw); - OutputColor = OutputColor / 12.0; + Output_Color += tex2D(Source, Coords[0].xw) * 2.0; + Output_Color += tex2D(Source, Coords[0].zw) * 2.0; + Output_Color += tex2D(Source, Coords[0].xy) * 2.0; + Output_Color += tex2D(Source, Coords[0].zy) * 2.0; + Output_Color += tex2D(Source, Coords[1].xw); + Output_Color += tex2D(Source, Coords[1].zw); + Output_Color += tex2D(Source, Coords[2].xy); + Output_Color += tex2D(Source, Coords[2].xw); + Output_Color = Output_Color / 12.0; break; } - OutputColor.a = 1.0; + Output_Color.a = 1.0; } -void Downsample1PS(in float4 Position : SV_Position, in float4 TexCoords[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_1_PS(in float4 Position : SV_POSITION, in float4 Coords[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - DownsamplePS(SampleColor, TexCoords, OutputColor0); + DownsamplePS(Sample_Color, Coords, Output_Color_0); } -void Downsample2PS(in float4 Position : SV_Position, in float4 TexCoords[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_2_PS(in float4 Position : SV_POSITION, in float4 Coords[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - DownsamplePS(SampleCommon1, TexCoords, OutputColor0); + DownsamplePS(Sample_Common_1, Coords, Output_Color_0); } -void Downsample3PS(in float4 Position : SV_Position, in float4 TexCoords[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_3_PS(in float4 Position : SV_POSITION, in float4 Coords[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - DownsamplePS(SampleCommon2, TexCoords, OutputColor0); + DownsamplePS(Sample_Common_2, Coords, Output_Color_0); } -void Downsample4PS(in float4 Position : SV_Position, in float4 TexCoords[4] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Downsample_4_PS(in float4 Position : SV_POSITION, in float4 Coords[4] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - DownsamplePS(SampleCommon3, TexCoords, OutputColor0); + DownsamplePS(Sample_Common_3, Coords, Output_Color_0); } -void Upsample3PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_3_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - UpsamplePS(SampleCommon4, TexCoords, OutputColor0); + UpsamplePS(Sample_Common_4, Coords, Output_Color_0); } -void Upsample2PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_2_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - UpsamplePS(SampleCommon3, TexCoords, OutputColor0); + UpsamplePS(Sample_Common_3, Coords, Output_Color_0); } -void Upsample1PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_1_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - UpsamplePS(SampleCommon2, TexCoords, OutputColor0); + UpsamplePS(Sample_Common_2, Coords, Output_Color_0); } -void Upsample0PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Upsample_0_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - UpsamplePS(SampleCommon1, TexCoords, OutputColor0); + UpsamplePS(Sample_Common_1, Coords, Output_Color_0); } technique cDualFilter { pass { - VertexShader = Downsample1VS; - PixelShader = Downsample1PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon1; + VertexShader = Downsample_1_VS; + PixelShader = Downsample_1_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_1; } pass { - VertexShader = Downsample2VS; - PixelShader = Downsample2PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon2; + VertexShader = Downsample_2_VS; + PixelShader = Downsample_2_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_2; } pass { - VertexShader = Downsample3VS; - PixelShader = Downsample3PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon3; + VertexShader = Downsample_3_VS; + PixelShader = Downsample_3_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_3; } pass { - VertexShader = Downsample4VS; - PixelShader = Downsample4PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon4; + VertexShader = Downsample_4_VS; + PixelShader = Downsample_4_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_4; } pass { - VertexShader = Upsample3VS; - PixelShader = Upsample3PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon3; + VertexShader = Upsample_3_VS; + PixelShader = Upsample_3_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_3; } pass { - VertexShader = Upsample2VS; - PixelShader = Upsample2PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon2; + VertexShader = Upsample_2_VS; + PixelShader = Upsample_2_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_2; } pass { - VertexShader = Upsample1VS; - PixelShader = Upsample1PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon1; + VertexShader = Upsample_1_VS; + PixelShader = Upsample_1_PS; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_1; } pass { - VertexShader = Upsample0VS; - PixelShader = Upsample0PS; + VertexShader = Upsample_0_VS; + PixelShader = Upsample_0_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cEdgeDetection.fx b/shaders/cEdgeDetection.fx index 0d6e2f2..b364927 100644 --- a/shaders/cEdgeDetection.fx +++ b/shaders/cEdgeDetection.fx @@ -40,32 +40,32 @@ uniform int _Method < ui_tooltip = "Method Edge Detection"; > = 0; -uniform bool _ScaleGradients < +uniform bool _Scale < ui_label = "Scale Gradients to [-1, 1] range"; ui_type = "radio"; > = true; -uniform bool _NormalizeGradients < +uniform bool _Normalize < ui_label = "Normalize Gradients"; ui_type = "radio"; > = true; -uniform bool _NormalGradients < +uniform bool _Normal < ui_label = "Scale Gradients to [0, 1] range"; ui_type = "radio"; > = true; -uniform float _NormalizeWeight < +uniform float _Normalize_Weight < ui_label = "Normalize Weight"; ui_type = "drag"; ui_min = 0.0; > = 0.1; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -76,176 +76,176 @@ 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); } -void EdgeDetectionVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) +void Edge_Detection_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - const float2 PixelSize = 1.0 / uint2(BUFFER_WIDTH, BUFFER_HEIGHT); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + const float2 Pixel_Size = 1.0 / int2(BUFFER_WIDTH, BUFFER_HEIGHT); - TexCoords[0] = 0.0; - TexCoords[1] = 0.0; - TexCoords[2] = 0.0; + Coords[0] = 0.0; + Coords[1] = 0.0; + Coords[2] = 0.0; switch(_Method) { case 0: // Fwidth - TexCoords[0].xy = VSTexCoord; + Coords[0].xy = VS_Coord; break; case 1: // Bilinear 3x3 Laplacian - TexCoords[0].xy = VSTexCoord; - TexCoords[1] = VSTexCoord.xyxy + (float4(-0.5, -0.5, 0.5, 0.5) * PixelSize.xyxy); + Coords[0].xy = VS_Coord; + Coords[1] = VS_Coord.xyxy + (float4(-0.5, -0.5, 0.5, 0.5) * Pixel_Size.xyxy); break; case 2: // Bilinear 3x3 Sobel - TexCoords[0] = VSTexCoord.xyxy + (float4(-0.5, -0.5, 0.5, 0.5) * PixelSize.xyxy); + Coords[0] = VS_Coord.xyxy + (float4(-0.5, -0.5, 0.5, 0.5) * Pixel_Size.xyxy); break; case 3: // Bilinear 5x5 Prewitt - TexCoords[0] = VSTexCoord.xyyy + (float4(-1.5, 1.5, 0.0, -1.5) * PixelSize.xyyy); - TexCoords[1] = VSTexCoord.xyyy + (float4( 0.0, 1.5, 0.0, -1.5) * PixelSize.xyyy); - TexCoords[2] = VSTexCoord.xyyy + (float4( 1.5, 1.5, 0.0, -1.5) * PixelSize.xyyy); + Coords[0] = VS_Coord.xyyy + (float4(-1.5, 1.5, 0.0, -1.5) * Pixel_Size.xyyy); + Coords[1] = VS_Coord.xyyy + (float4( 0.0, 1.5, 0.0, -1.5) * Pixel_Size.xyyy); + Coords[2] = VS_Coord.xyyy + (float4( 1.5, 1.5, 0.0, -1.5) * Pixel_Size.xyyy); break; case 4: // Bilinear 5x5 Sobel - TexCoords[0] = VSTexCoord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) * PixelSize.xxyy); - TexCoords[1] = VSTexCoord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) * PixelSize.xxyy); + Coords[0] = VS_Coord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) * Pixel_Size.xxyy); + Coords[1] = VS_Coord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) * Pixel_Size.xxyy); break; case 5: // 3x3 Prewitt - TexCoords[0] = VSTexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - TexCoords[1] = VSTexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - TexCoords[2] = VSTexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); + Coords[0] = VS_Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Coords[1] = VS_Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Coords[2] = VS_Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); break; case 6: // 3x3 Scharr - TexCoords[0] = VSTexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - TexCoords[1] = VSTexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - TexCoords[2] = VSTexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); + Coords[0] = VS_Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Coords[1] = VS_Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Coords[2] = VS_Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); break; } } -void EdgeOperator(in sampler2D Source, in float4 TexCoords[3], inout float4 Ix, inout float4 Iy, inout float4 Gradient) +void Edge_Operator(in sampler2D Source, in float4 Coords[3], inout float4 Ix, inout float4 Iy, inout float4 Gradient) { - float4 A0, B0, C0; - float4 A1, B1, C1; - float4 A2, B2, C2; + float4 A_0, B_0, C_0; + float4 A_1, B_1, C_1; + float4 A_2, B_2, C_2; switch(_Method) { case 0: // Fwidth - A0 = tex2D(Source, TexCoords[0].xy); + A_0 = tex2D(Source, Coords[0].xy); - Ix = ddx(A0); - Iy = ddy(A0); + Ix = ddx(A_0); + Iy = ddy(A_0); break; case 1: // Bilinear 3x3 Laplacian - // A0 C0 - // B1 - // A2 C2 - A0 = tex2D(Source, TexCoords[1].xw); // <-0.5, +0.5> - C0 = tex2D(Source, TexCoords[1].zw); // <+0.5, +0.5> - B1 = tex2D(Source, TexCoords[0].xy); // < 0.0, 0.0> - A2 = tex2D(Source, TexCoords[1].xy); // <-0.5, -0.5> - C2 = tex2D(Source, TexCoords[1].zy); // <+0.5, -0.5> - - Gradient = (A0 + C0 + A2 + C2) - (B1 * 4.0); + // A_0 C_0 + // B_1 + // A_2 C_2 + A_0 = tex2D(Source, Coords[1].xw); // <-0.5, +0.5> + C_0 = tex2D(Source, Coords[1].zw); // <+0.5, +0.5> + B_1 = tex2D(Source, Coords[0].xy); // < 0.0, 0.0> + A_2 = tex2D(Source, Coords[1].xy); // <-0.5, -0.5> + C_2 = tex2D(Source, Coords[1].zy); // <+0.5, -0.5> + + Gradient = (A_0 + C_0 + A_2 + C_2) - (B_1 * 4.0); break; case 2: // Bilinear 3x3 Sobel - A0 = tex2D(Source, TexCoords[0].xw).rgb; // <-0.5, +0.5> - C0 = tex2D(Source, TexCoords[0].zw).rgb; // <+0.5, +0.5> - A2 = tex2D(Source, TexCoords[0].xy).rgb; // <-0.5, -0.5> - C2 = tex2D(Source, TexCoords[0].zy).rgb; // <+0.5, -0.5> + A_0 = tex2D(Source, Coords[0].xw).rgb; // <-0.5, +0.5> + C_0 = tex2D(Source, Coords[0].zw).rgb; // <+0.5, +0.5> + A_2 = tex2D(Source, Coords[0].xy).rgb; // <-0.5, -0.5> + C_2 = tex2D(Source, Coords[0].zy).rgb; // <+0.5, -0.5> - Ix = ((C0 + C2) - (A0 + A2)) * 4.0; - Iy = ((A0 + C0) - (A2 + C2)) * 4.0; + Ix = ((C_0 + C_2) - (A_0 + A_2)) * 4.0; + Iy = ((A_0 + C_0) - (A_2 + C_2)) * 4.0; break; case 3: // Bilinear 5x5 Prewitt - // A0 B0 C0 - // A1 C1 - // A2 B2 C2 - A0 = tex2D(Source, TexCoords[0].xy) * 4.0; // <-1.5, +1.5> - A1 = tex2D(Source, TexCoords[0].xz) * 2.0; // <-1.5, 0.0> - A2 = tex2D(Source, TexCoords[0].xw) * 4.0; // <-1.5, -1.5> - B0 = tex2D(Source, TexCoords[1].xy) * 2.0; // < 0.0, +1.5> - B2 = tex2D(Source, TexCoords[1].xw) * 2.0; // < 0.0, -1.5> - C0 = tex2D(Source, TexCoords[2].xy) * 4.0; // <+1.5, +1.5> - C1 = tex2D(Source, TexCoords[2].xz) * 2.0; // <+1.5, 0.0> - C2 = tex2D(Source, TexCoords[2].xw) * 4.0; // <+1.5, -1.5> + // A_0 B_0 C_0 + // A_1 C_1 + // A_2 B_2 C_2 + A_0 = tex2D(Source, Coords[0].xy) * 4.0; // <-1.5, +1.5> + A_1 = tex2D(Source, Coords[0].xz) * 2.0; // <-1.5, 0.0> + A_2 = tex2D(Source, Coords[0].xw) * 4.0; // <-1.5, -1.5> + B_0 = tex2D(Source, Coords[1].xy) * 2.0; // < 0.0, +1.5> + B_2 = tex2D(Source, Coords[1].xw) * 2.0; // < 0.0, -1.5> + C_0 = tex2D(Source, Coords[2].xy) * 4.0; // <+1.5, +1.5> + C_1 = tex2D(Source, Coords[2].xz) * 2.0; // <+1.5, 0.0> + C_2 = tex2D(Source, Coords[2].xw) * 4.0; // <+1.5, -1.5> // -1 -1 0 +1 +1 // -1 -1 0 +1 +1 // -1 -1 0 +1 +1 // -1 -1 0 +1 +1 // -1 -1 0 +1 +1 - Ix = (C0 + C1 + C2) - (A0 + A1 + A2); + Ix = (C_0 + C_1 + C_2) - (A_0 + A_1 + A_2); // +1 +1 +1 +1 +1 // +1 +1 +1 +1 +1 // 0 0 0 0 0 // -1 -1 -1 -1 -1 // -1 -1 -1 -1 -1 - Iy = (A0 + B0 + C0) - (A2 + B2 + C2); + Iy = (A_0 + B_0 + C_0) - (A_2 + B_2 + C_2); break; case 4: // Bilinear 5x5 Sobel by CeeJayDK - // B1 B2 - // A0 A1 - // A2 B0 - // C0 C1 - A0 = tex2D(Source, TexCoords[0].xw) * 4.0; // <-1.5, +0.5> - A1 = tex2D(Source, TexCoords[0].yw) * 4.0; // <+1.5, +0.5> - A2 = tex2D(Source, TexCoords[0].xz) * 4.0; // <-1.5, -0.5> - B0 = tex2D(Source, TexCoords[0].yz) * 4.0; // <+1.5, -0.5> - B1 = tex2D(Source, TexCoords[1].xw) * 4.0; // <-0.5, +1.5> - B2 = tex2D(Source, TexCoords[1].yw) * 4.0; // <+0.5, +1.5> - C0 = tex2D(Source, TexCoords[1].xz) * 4.0; // <-0.5, -1.5> - C1 = tex2D(Source, TexCoords[1].yz) * 4.0; // <+0.5, -1.5> + // B_1 B_2 + // A_0 A_1 + // A_2 B_0 + // C_0 C_1 + A_0 = tex2D(Source, Coords[0].xw) * 4.0; // <-1.5, +0.5> + A_1 = tex2D(Source, Coords[0].yw) * 4.0; // <+1.5, +0.5> + A_2 = tex2D(Source, Coords[0].xz) * 4.0; // <-1.5, -0.5> + B_0 = tex2D(Source, Coords[0].yz) * 4.0; // <+1.5, -0.5> + B_1 = tex2D(Source, Coords[1].xw) * 4.0; // <-0.5, +1.5> + B_2 = tex2D(Source, Coords[1].yw) * 4.0; // <+0.5, +1.5> + C_0 = tex2D(Source, Coords[1].xz) * 4.0; // <-0.5, -1.5> + C_1 = tex2D(Source, Coords[1].yz) * 4.0; // <+0.5, -1.5> // -1 0 +1 // -1 -2 0 +2 +1 // -2 -2 0 +2 +2 // -1 -2 0 +2 +1 // -1 0 +1 - Ix = (B2 + A1 + B0 + C1) - (B1 + A0 + A2 + C0); + Ix = (B_2 + A_1 + B_0 + C_1) - (B_1 + A_0 + A_2 + C_0); // +1 +2 +1 // +1 +2 +2 +2 +1 // 0 0 0 0 0 // -1 -2 -2 -2 -1 // -1 -2 -1 - Iy = (A0 + B1 + B2 + A1) - (A2 + C0 + C1 + B0); + Iy = (A_0 + B_1 + B_2 + A_1) - (A_2 + C_0 + C_1 + B_0); break; case 5: // 3x3 Prewitt - // A0 B0 C0 - // A1 C1 - // A2 B2 C2 - A0 = tex2D(SampleColor, TexCoords[0].xy); - A1 = tex2D(SampleColor, TexCoords[0].xz); - A2 = tex2D(SampleColor, TexCoords[0].xw); - B0 = tex2D(SampleColor, TexCoords[1].xy); - B2 = tex2D(SampleColor, TexCoords[1].xw); - C0 = tex2D(SampleColor, TexCoords[2].xy); - C1 = tex2D(SampleColor, TexCoords[2].xz); - C2 = tex2D(SampleColor, TexCoords[2].xw); - - Ix = (C0 + C1 + C2) - (A0 + A1 + A2); - Iy = (A0 + B0 + C0) - (A2 + B2 + C2); + // A_0 B_0 C_0 + // A_1 C_1 + // A_2 B_2 C_2 + A_0 = tex2D(Sample_Color, Coords[0].xy); + A_1 = tex2D(Sample_Color, Coords[0].xz); + A_2 = tex2D(Sample_Color, Coords[0].xw); + B_0 = tex2D(Sample_Color, Coords[1].xy); + B_2 = tex2D(Sample_Color, Coords[1].xw); + C_0 = tex2D(Sample_Color, Coords[2].xy); + C_1 = tex2D(Sample_Color, Coords[2].xz); + C_2 = tex2D(Sample_Color, Coords[2].xw); + + Ix = (C_0 + C_1 + C_2) - (A_0 + A_1 + A_2); + Iy = (A_0 + B_0 + C_0) - (A_2 + B_2 + C_2); break; case 6: // 3x3 Scharr { - A0 = tex2D(SampleColor, TexCoords[0].xy) * 3.0; - A1 = tex2D(SampleColor, TexCoords[0].xz) * 10.0; - A2 = tex2D(SampleColor, TexCoords[0].xw) * 3.0; - B0 = tex2D(SampleColor, TexCoords[1].xy) * 10.0; - B2 = tex2D(SampleColor, TexCoords[1].xw) * 10.0; - C0 = tex2D(SampleColor, TexCoords[2].xy) * 3.0; - C1 = tex2D(SampleColor, TexCoords[2].xz) * 10.0; - C2 = tex2D(SampleColor, TexCoords[2].xw) * 3.0; - - Ix = (C0 + C1 + C2) - (A0 + A1 + A2); - Iy = (A0 + B0 + C0) - (A2 + B2 + C2); + A_0 = tex2D(Sample_Color, Coords[0].xy) * 3.0; + A_1 = tex2D(Sample_Color, Coords[0].xz) * 10.0; + A_2 = tex2D(Sample_Color, Coords[0].xw) * 3.0; + B_0 = tex2D(Sample_Color, Coords[1].xy) * 10.0; + B_2 = tex2D(Sample_Color, Coords[1].xw) * 10.0; + C_0 = tex2D(Sample_Color, Coords[2].xy) * 3.0; + C_1 = tex2D(Sample_Color, Coords[2].xz) * 10.0; + C_2 = tex2D(Sample_Color, Coords[2].xw) * 3.0; + + Ix = (C_0 + C_1 + C_2) - (A_0 + A_1 + A_2); + Iy = (A_0 + B_0 + C_0) - (A_2 + B_2 + C_2); break; } } @@ -256,11 +256,11 @@ float max3(float3 Input) return max(max(Input.r, Input.g), Input.b); } -void EdgeDetectionPS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Edge_Detection_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = 1.0; + Output_Color_0 = 1.0; float4 Ix, Iy, Gradient; - EdgeOperator(SampleColor, TexCoords, Ix, Iy, Gradient); + Edge_Operator(Sample_Color, Coords, Ix, Iy, Gradient); float ScaleWeight = 1.0; @@ -289,23 +289,23 @@ void EdgeDetectionPS(in float4 Position : SV_Position, in float4 TexCoords[3] : break; } - Ix = (_ScaleGradients) ? Ix / ScaleWeight : Ix; - Iy = (_ScaleGradients) ? Iy / ScaleWeight : Iy; + Ix = (_Scale) ? Ix / ScaleWeight : Ix; + Iy = (_Scale) ? Iy / ScaleWeight : Iy; - Ix = (_NormalizeGradients) ? Ix / sqrt(dot(Ix.rgb, Ix.rgb) + _NormalizeWeight) : Ix; - Iy = (_NormalizeGradients) ? Iy / sqrt(dot(Iy.rgb, Iy.rgb) + _NormalizeWeight) : Iy; + Ix = (_Normalize) ? Ix / sqrt(dot(Ix.rgb, Ix.rgb) + _Normalize_Weight) : Ix; + Iy = (_Normalize) ? Iy / sqrt(dot(Iy.rgb, Iy.rgb) + _Normalize_Weight) : Iy; // Output Results if(_Method == 1) // Laplacian { - OutputColor0 = length(Gradient.rgb); + Output_Color_0 = length(Gradient.rgb); } else // Edge detection { - OutputColor0.rg = float2(dot(Ix.rgb, 1.0 / 3.0), dot(Iy.rgb, 1.0 / 3.0)); - OutputColor0.b = (_NormalGradients) ? 1.0 : 0.0; - OutputColor0 = (_NormalGradients) ? OutputColor0 * 0.5 + 0.5 : OutputColor0; + Output_Color_0.rg = float2(dot(Ix.rgb, 1.0 / 3.0), dot(Iy.rgb, 1.0 / 3.0)); + Output_Color_0.b = (_Normal) ? 1.0 : 0.0; + Output_Color_0 = (_Normal) ? Output_Color_0 * 0.5 + 0.5 : Output_Color_0; } } @@ -313,8 +313,8 @@ technique cEdgeDetection { pass { - VertexShader = EdgeDetectionVS; - PixelShader = EdgeDetectionPS; + VertexShader = Edge_Detection_VS; + PixelShader = Edge_Detection_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cFilmGrain.fx b/shaders/cFilmGrain.fx index 2690bb5..5af762d 100644 --- a/shaders/cFilmGrain.fx +++ b/shaders/cFilmGrain.fx @@ -52,38 +52,38 @@ uniform float _Time < source = "timer"; >; // 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 // "Well ill believe it when i see it." // Yoinked code by Luluco250 (RIP) [https://www.shadertoy.com/view/4t2fRz] [MIT] -float GaussianWeight(float x, float Sigma) +float Gaussian_Weight(float x, float Sigma) { const float Pi = 3.14159265359; Sigma = Sigma * Sigma; return rsqrt(Pi * Sigma) * exp(-((x * x) / (2.0 * Sigma))); } -void FilmGrainPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Film_Grain_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { float Time = rcp(1e+3 / _Time) * _Speed; float Seed = dot(Position.xy, float2(12.9898, 78.233)); float Noise = frac(sin(Seed) * 43758.5453 + Time); - OutputColor0 = GaussianWeight(Noise, _Variance) * _Intensity; + Output_Color_0 = Gaussian_Weight(Noise, _Variance) * _Intensity; } technique cFilmGrain { pass { - VertexShader = PostProcessVS; - PixelShader = FilmGrainPS; + VertexShader = Basic_VS; + PixelShader = Film_Grain_PS; // (Shader[Src] * SrcBlend) + (Buffer[Dest] * DestBlend) // This shader: (Shader[Src] * (1.0 - Buffer[Dest])) + Buffer[Dest] BlendEnable = TRUE; diff --git a/shaders/cFrameBlending.fx b/shaders/cFrameBlending.fx index 09f7c31..2153e67 100644 --- a/shaders/cFrameBlending.fx +++ b/shaders/cFrameBlending.fx @@ -33,18 +33,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -uniform float _BlendFactor < +uniform float _Blend_Factor < ui_label = "Blend Factor"; ui_type = "slider"; ui_min = 0.0; ui_max = 1.0; > = 0.5; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -53,16 +53,16 @@ sampler2D SampleColor #endif }; -texture2D RenderCopy +texture2D Render_Copy { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; }; -sampler2D SampleCopy +sampler2D Sample_Copy { - Texture = RenderCopy; + Texture = Render_Copy; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -73,34 +73,34 @@ sampler2D SampleCopy // 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 BlendPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Blend_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Copy backbuffer to a that continuously blends with its previous result - OutputColor0 = float4(tex2D(SampleColor, TexCoord).rgb, _BlendFactor); + Output_Color_0 = float4(tex2D(Sample_Color, Coord).rgb, _Blend_Factor); } -void DisplayPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Display_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Display the buffer - OutputColor0 = tex2D(SampleCopy, TexCoord); + Output_Color_0 = tex2D(Sample_Copy, Coord); } technique cFrameBlending { pass { - VertexShader = PostProcessVS; - PixelShader = BlendPS; - RenderTarget0 = RenderCopy; + VertexShader = Basic_VS; + PixelShader = Blend_PS; + RenderTarget0 = Render_Copy; ClearRenderTargets = FALSE; BlendEnable = TRUE; BlendOp = ADD; @@ -113,8 +113,8 @@ technique cFrameBlending pass { - VertexShader = PostProcessVS; - PixelShader = DisplayPS; + VertexShader = Basic_VS; + PixelShader = Display_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cGaussianBlur.fx b/shaders/cGaussianBlur.fx index c39d015..36a9362 100644 --- a/shaders/cGaussianBlur.fx +++ b/shaders/cGaussianBlur.fx @@ -38,11 +38,11 @@ uniform float _Sigma < ui_min = 0.0; > = 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; @@ -53,74 +53,74 @@ 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 // Linear Gaussian blur based on https://www.rastergrid.com/blog/2010/09/efficient-Gaussian-blur-with-linear-sampling/ -float Gaussian(float PixelIndex, float Sigma) +float Gaussian(float Pixel_Index, float Sigma) { const float Pi = 3.1415926535897932384626433832795f; float Output = rsqrt(2.0 * Pi * (Sigma * Sigma)); - return Output * exp(-(PixelIndex * PixelIndex) / (2.0 * Sigma * Sigma)); + return Output * exp(-(Pixel_Index * Pixel_Index) / (2.0 * Sigma * Sigma)); } -void GaussianBlur(in float2 TexCoord, in bool Horizontal, out float4 OutputColor0) +void Gaussian_Blur(in float2 Coord, in bool Is_Horizontal, out float4 Output_Color_0) { - float2 Direction = Horizontal ? float2(1.0, 0.0) : float2(0.0, 1.0); - float2 PixelSize = (1.0 / float2(BUFFER_WIDTH, BUFFER_HEIGHT)) * Direction; - float KernelSize = _Sigma * 3.0; + float2 Direction = Is_Horizontal ? float2(1.0, 0.0) : float2(0.0, 1.0); + float2 Pixel_Size = (1.0 / float2(BUFFER_WIDTH, BUFFER_HEIGHT)) * Direction; + float Kernel_Size = _Sigma * 3.0; if(_Sigma == 0.0) { - OutputColor0 = tex2Dlod(SampleColor, float4(TexCoord, 0.0, 0.0)); + Output_Color_0 = tex2Dlod(Sample_Color, float4(Coord, 0.0, 0.0)); } else { // Sample and weight center first to get even number sides - float TotalWeight = Gaussian(0.0, _Sigma); - float4 OutputColor = tex2D(SampleColor, TexCoord) * TotalWeight; + float Total_Weight = Gaussian(0.0, _Sigma); + float4 Output_Color = tex2D(Sample_Color, Coord) * Total_Weight; - for(float i = 1.0; i < KernelSize; i += 2.0) + for(float i = 1.0; i < Kernel_Size; i += 2.0) { - float Offset1 = i; - float Offset2 = i + 1.0; - float Weight1 = Gaussian(Offset1, _Sigma); - float Weight2 = Gaussian(Offset2, _Sigma); - float LinearWeight = Weight1 + Weight2; - float LinearOffset = ((Offset1 * Weight1) + (Offset2 * Weight2)) / LinearWeight; - - OutputColor += tex2Dlod(SampleColor, float4(TexCoord - LinearOffset * PixelSize, 0.0, 0.0)) * LinearWeight; - OutputColor += tex2Dlod(SampleColor, float4(TexCoord + LinearOffset * PixelSize, 0.0, 0.0)) * LinearWeight; - TotalWeight += LinearWeight * 2.0; + float Offset_1 = i; + float Offset_2 = i + 1.0; + float Weight_1 = Gaussian(Offset_1, _Sigma); + float Weight_2 = Gaussian(Offset_2, _Sigma); + float Linear_Weight = Weight_1 + Weight_2; + float Linear_Offset = ((Offset_1 * Weight_1) + (Offset_2 * Weight_2)) / Linear_Weight; + + Output_Color += tex2Dlod(Sample_Color, float4(Coord - Linear_Offset * Pixel_Size, 0.0, 0.0)) * Linear_Weight; + Output_Color += tex2Dlod(Sample_Color, float4(Coord + Linear_Offset * Pixel_Size, 0.0, 0.0)) * Linear_Weight; + Total_Weight += Linear_Weight * 2.0; } // Normalize intensity to prevent altered output - OutputColor0 = OutputColor / TotalWeight; + Output_Color_0 = Output_Color / Total_Weight; } } -void HorizontalGaussianBlurPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Horizontal_Gaussian_Blur_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(TexCoord, true, OutputColor0); + Gaussian_Blur(Coord, true, Output_Color_0); } -void VerticalGaussianBlurPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Vertical_Gaussian_Blur_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(TexCoord, false, OutputColor0); + Gaussian_Blur(Coord, false, Output_Color_0); } technique cHorizontalGaussianBlur { pass { - VertexShader = PostProcessVS; - PixelShader = HorizontalGaussianBlurPS; + VertexShader = Basic_VS; + PixelShader = Horizontal_Gaussian_Blur_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif @@ -131,8 +131,8 @@ technique cVerticalGaussianBlur { pass { - VertexShader = PostProcessVS; - PixelShader = VerticalGaussianBlurPS; + VertexShader = Basic_VS; + PixelShader = Vertical_Gaussian_Blur_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cHornSchunck.fx b/shaders/cHornSchunck.fx deleted file mode 100644 index 6386b73..0000000 --- a/shaders/cHornSchunck.fx +++ /dev/null @@ -1,528 +0,0 @@ - -/* - Basic pyramidal Horn Schunck without pre and post filtering - - BSD 3-Clause License - - Copyright (c) 2022, Paul Dang - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#if RENDER_HIGH_QUALITY == 1 - #define SCREEN_SIZE uint2(BUFFER_WIDTH * 2, BUFFER_HEIGHT * 2) -#else - #define SCREEN_SIZE uint2(BUFFER_WIDTH, BUFFER_HEIGHT) -#endif - -namespace HornSchunck -{ - //Shader properties - - uniform float _Blend < - ui_type = "slider"; - ui_category = "Optical flow"; - ui_label = "Blending"; - ui_min = 0.0; - ui_max = 1.0; - > = 0.8; - - uniform float _Constraint < - ui_type = "drag"; - ui_category = "Optical flow"; - ui_label = "Constraint"; - ui_tooltip = "Higher = Smoother flow"; - > = 1.0; - - uniform float _MipBias < - ui_type = "drag"; - ui_category = "Optical flow"; - ui_label = "Mipmap bias"; - ui_tooltip = "Higher = Less spatial noise"; - > = 0.0; - - uniform bool _NormalizedShading < - ui_type = "radio"; - ui_category = "Velocity shading"; - ui_label = "Normalize velocity shading"; - > = true; - - // Textures and samplers - - texture2D RenderColor : COLOR; - - sampler2D SampleColor - { - Texture = RenderColor; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - #if BUFFER_COLOR_BIT_DEPTH == 8 - SRGBTexture = TRUE; - #endif - }; - - texture2D RenderCommon1a < pooled = true; > - { - Width = SCREEN_SIZE.x / 2; - Height = SCREEN_SIZE.y / 2; - Format = RG16F; - MipLevels = 8; - }; - - sampler2D SampleCommon1a - { - Texture = RenderCommon1a; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon1b < pooled = true; > - { - Width = SCREEN_SIZE.x / 2; - Height = SCREEN_SIZE.y / 2; - Format = RGBA16F; - MipLevels = 8; - }; - - sampler2D SampleCommon1b - { - Texture = RenderCommon1b; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon1d < pooled = false; > - { - Width = SCREEN_SIZE.x / 2; - Height = SCREEN_SIZE.y / 2; - Format = RG16F; - MipLevels = 8; - }; - - sampler2D SampleCommon1d - { - Texture = RenderCommon1d; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon8 < pooled = true; > - { - Width = SCREEN_SIZE.x / 256; - Height = SCREEN_SIZE.y / 256; - Format = RG16F; - }; - - sampler2D SampleCommon8 - { - Texture = RenderCommon8; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon7 < pooled = true; > - { - Width = SCREEN_SIZE.x / 128; - Height = SCREEN_SIZE.y / 128; - Format = RG16F; - }; - - sampler2D SampleCommon7 - { - Texture = RenderCommon7; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon6 < pooled = true; > - { - Width = SCREEN_SIZE.x / 64; - Height = SCREEN_SIZE.y / 64; - Format = RG16F; - }; - - sampler2D SampleCommon6 - { - Texture = RenderCommon6; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon5 < pooled = true; > - { - Width = SCREEN_SIZE.x / 32; - Height = SCREEN_SIZE.y / 32; - Format = RG16F; - }; - - sampler2D SampleCommon5 - { - Texture = RenderCommon5; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon4 < pooled = true; > - { - Width = SCREEN_SIZE.x / 16; - Height = SCREEN_SIZE.y / 16; - Format = RG16F; - }; - - sampler2D SampleCommon4 - { - Texture = RenderCommon4; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon3 < pooled = true; > - { - Width = SCREEN_SIZE.x / 8; - Height = SCREEN_SIZE.y / 8; - Format = RG16F; - }; - - sampler2D SampleCommon3 - { - Texture = RenderCommon3; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon2 < pooled = true; > - { - Width = SCREEN_SIZE.x / 4; - Height = SCREEN_SIZE.y / 4; - Format = RG16F; - }; - - sampler2D SampleCommon2 - { - Texture = RenderCommon2; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - texture2D RenderCommon1c - { - Width = SCREEN_SIZE.x / 2; - Height = SCREEN_SIZE.y / 2; - Format = RG16F; - }; - - sampler2D SampleCommon1c - { - Texture = RenderCommon1c; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - sampler2D SampleColorGamma - { - Texture = RenderColor; - MagFilter = LINEAR; - MinFilter = LINEAR; - MipFilter = LINEAR; - }; - - // Vertex shaders - - void PostProcessVS(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; - Position = TexCoord.xyxy * float4(2.0, -2.0, 0.0, 0.0) + float4(-1.0, 1.0, 0.0, 1.0); - } - - void DerivativesVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 Offsets : TEXCOORD0) - { - float2 TexCoord0; - PostProcessVS(ID, Position, TexCoord0); - const float2 PixelSize = 1.0 / uint2(SCREEN_SIZE.x / 2, SCREEN_SIZE.y / 2); - Offsets = TexCoord0.xyxy + (float4(0.5, 0.5, -0.5, -0.5) * PixelSize.xyxy); - } - - // Pixel shaders - - /* - Pyramidal Horn-Schunck optical flow - + Horn-Schunck: https://dspace.mit.edu/handle/1721.1/6337 (Page 8) - + Pyramid process: https://www.youtube.com/watch?v=4v_keMNROv4 - - Modifications - + Compute averages with a 7x7 low-pass tent filter - + Estimate features in 2-dimensional chromaticity - + Use pyramid process to get initial values from neighboring pixels - + Use symmetric Gauss-Seidel to solve linear equation at Page 8 - */ - - static const int MaxLevel = 7; - - void OpticalFlow(in float2 TexCoord, in float2 UV, in float Level, out float2 DUV) - { - const float Alpha = max(ldexp(_Constraint * 1e-5, Level - MaxLevel), 1e-7); - float2 CurrentFrame = tex2D(SampleCommon1a, TexCoord).xy; - float2 PreviousFrame = tex2D(SampleCommon1d, TexCoord).xy; - - // SpatialI = - float4 SpatialI = tex2D(SampleCommon1b, TexCoord); - float2 TemporalI = CurrentFrame - PreviousFrame; - - /* - We solve for X[N] (UV) - Matrix => Horn–Schunck Matrix => Horn–Schunck Equation => Solving Equation - - Matrix - [A11 A12] [X1] = [B1] - [A21 A22] [X2] = [B2] - - Horn–Schunck Matrix - [(Ix^2 + a) (IxIy)] [U] = [aU - IxIt] - [(IxIy) (Iy^2 + a)] [V] = [aV - IyIt] - - Horn–Schunck Equation - (Ix^2 + a)U + IxIyV = aU - IxIt - IxIyU + (Iy^2 + a)V = aV - IyIt - - Solving Equation - U = ((aU - IxIt) - IxIyV) / (Ix^2 + a) - V = ((aV - IxIt) - IxIyu) / (Iy^2 + a) - */ - - // A11 = 1.0 / (Rx^2 + Gx^2 + a) - // A22 = 1.0 / (Ry^2 + Gy^2 + a) - // Aij = Rxy + Gxy - float A11 = 1.0 / (dot(SpatialI.xy, SpatialI.xy) + Alpha); - float A22 = 1.0 / (dot(SpatialI.zw, SpatialI.zw) + Alpha); - float Aij = dot(SpatialI.xy, SpatialI.zw); - - // B1 = Rxt + Gxt - // B2 = Ryt + Gyt - float B1 = dot(SpatialI.xy, TemporalI); - float B2 = dot(SpatialI.zw, TemporalI); - - // Gauss-Seidel (forward sweep, from 1...N) - DUV.x = A11 * ((Alpha * UV.x - B1) - (UV.y * Aij)); - DUV.y = A22 * ((Alpha * UV.y - B2) - (DUV.x * Aij)); - } - - void NormalizePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputColor0 : SV_Target0) - { - const float Minima = exp2(-10.0); - float3 Color = max(tex2D(SampleColor, TexCoord).rgb, Minima); - OutputColor0 = saturate(Color.xy / dot(Color, 1.0)); - } - - void DerivativesZPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputColor0 : SV_Target0) - { - float2 CurrentFrame = tex2D(SampleCommon1a, TexCoord).xy; - float2 PreviousFrame = tex2D(SampleCommon1d, TexCoord).xy; - OutputColor0 = CurrentFrame - PreviousFrame; - } - - void DerivativesXYPS(in float4 Position : SV_Position, in float4 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) - { - float2 Sample0 = tex2D(SampleCommon1a, TexCoord.zy).xy; // (-x, +y) - float2 Sample1 = tex2D(SampleCommon1a, TexCoord.xy).xy; // (+x, +y) - float2 Sample2 = tex2D(SampleCommon1a, TexCoord.zw).xy; // (-x, -y) - float2 Sample3 = tex2D(SampleCommon1a, TexCoord.xw).xy; // (+x, -y) - OutputColor0.xy = ((Sample3 + Sample1) - (Sample2 + Sample0)); - OutputColor0.zw = ((Sample2 + Sample3) - (Sample0 + Sample1)); - OutputColor0 = OutputColor0 * 4.0; - } - - void EstimateLevel8PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputEstimation : SV_Target0) - { - OpticalFlow(TexCoord, 0.0, 7.0, OutputEstimation); - } - - void EstimateLevel7PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputEstimation : SV_Target0) - { - OpticalFlow(TexCoord, tex2D(SampleCommon8, TexCoord).xy, 6.0, OutputEstimation); - } - - void EstimateLevel6PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputEstimation : SV_Target0) - { - OpticalFlow(TexCoord, tex2D(SampleCommon7, TexCoord).xy, 5.0, OutputEstimation); - } - - void EstimateLevel5PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputEstimation : SV_Target0) - { - OpticalFlow(TexCoord, tex2D(SampleCommon6, TexCoord).xy, 4.0, OutputEstimation); - } - - void EstimateLevel4PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputEstimation : SV_Target0) - { - OpticalFlow(TexCoord, tex2D(SampleCommon5, TexCoord).xy, 3.0, OutputEstimation); - } - - void EstimateLevel3PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputEstimation : SV_Target0) - { - OpticalFlow(TexCoord, tex2D(SampleCommon4, TexCoord).xy, 2.0, OutputEstimation); - } - - void EstimateLevel2PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputEstimation : SV_Target0) - { - OpticalFlow(TexCoord, tex2D(SampleCommon3, TexCoord).xy, 1.0, OutputEstimation); - } - - void EstimateLevel1PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0, out float4 OutputColor1 : SV_Target1) - { - OpticalFlow(TexCoord, tex2D(SampleCommon2, TexCoord).xy, 0.0, OutputColor0.xy); - OutputColor0.ba = (0.0, _Blend); - - // Copy current convolved result to use at next frame - OutputColor1 = tex2D(SampleCommon1a, TexCoord).rg; - OutputColor1.ba = 0.0; - } - - void VelocityShadingPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target) - { - float2 Velocity = tex2Dlod(SampleCommon1c, float4(TexCoord, 0.0, _MipBias)).xy; - - if(_NormalizedShading) - { - float VelocityLength = saturate(rsqrt(dot(Velocity, Velocity))); - OutputColor0.rg = (Velocity * VelocityLength) * 0.5 + 0.5; - OutputColor0.b = -dot(OutputColor0.rg, 1.0) * 0.5 + 1.0; - OutputColor0.rgb /= max(max(OutputColor0.x, OutputColor0.y), OutputColor0.z); - OutputColor0.a = 1.0; - } - else - { - OutputColor0 = float4(Velocity, 0.0, 1.0); - } - } - - technique cHornSchunck - { - // Normalize current frame - - pass - { - VertexShader = PostProcessVS; - PixelShader = NormalizePS; - RenderTarget0 = RenderCommon1a; - } - - // Construct pyramids - - pass - { - VertexShader = DerivativesVS; - PixelShader = DerivativesXYPS; - RenderTarget0 = RenderCommon1b; - } - - // Pyramidal estimation - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel8PS; - RenderTarget0 = RenderCommon8; - } - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel7PS; - RenderTarget0 = RenderCommon7; - } - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel6PS; - RenderTarget0 = RenderCommon6; - } - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel5PS; - RenderTarget0 = RenderCommon5; - } - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel4PS; - RenderTarget0 = RenderCommon4; - } - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel3PS; - RenderTarget0 = RenderCommon3; - } - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel2PS; - RenderTarget0 = RenderCommon2; - } - - pass - { - VertexShader = PostProcessVS; - PixelShader = EstimateLevel1PS; - RenderTarget0 = RenderCommon1c; - - // Copy previous frame - RenderTarget1 = RenderCommon1d; - ClearRenderTargets = FALSE; - BlendEnable = TRUE; - BlendOp = ADD; - SrcBlend = INVSRCALPHA; - DestBlend = SRCALPHA; - } - - // Render result - - pass - { - VertexShader = PostProcessVS; - PixelShader = VelocityShadingPS; - } - } -} diff --git a/shaders/cInterpolation.fx b/shaders/cInterpolation.fx index 65fe504..b83928d 100644 --- a/shaders/cInterpolation.fx +++ b/shaders/cInterpolation.fx @@ -39,7 +39,7 @@ #define BUFFER_SIZE_3 int2(SIZE >> 4) #define BUFFER_SIZE_4 int2(SIZE >> 6) -namespace SharedResources +namespace Shared_Resources { // Store convoluted normalized frame 1 and 3 @@ -125,7 +125,7 @@ namespace cInterpolation ui_max = 2.0; > = 1.0; - uniform float _MipBias < + uniform float _Mip_Bias < ui_type = "drag"; ui_category = "Optical flow"; ui_label = "Optical flow mipmap bias"; @@ -240,14 +240,14 @@ namespace cInterpolation // 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); } - static const float2 BlurOffsets[8] = + static const float2 Blur_Offsets[8] = { float2(0.0, 0.0), float2(0.0, 1.4850045), @@ -259,71 +259,71 @@ namespace cInterpolation float2(0.0, 13.368189) }; - void Blur_0_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[8] : TEXCOORD0) + void Blur_0_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[8] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xyxy; + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xyxy; for(int i = 1; i < 8; i++) { - TexCoords[i].xy = VSTexCoord.xy - (BlurOffsets[i].yx / BUFFER_SIZE_1); - TexCoords[i].zw = VSTexCoord.xy + (BlurOffsets[i].yx / BUFFER_SIZE_1); + Coords[i].xy = VS_Coord.xy - (Blur_Offsets[i].yx / BUFFER_SIZE_1); + Coords[i].zw = VS_Coord.xy + (Blur_Offsets[i].yx / BUFFER_SIZE_1); } } - void Blur_1_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[8] : TEXCOORD0) + void Blur_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[8] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xyxy; + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xyxy; for(int i = 1; i < 8; i++) { - TexCoords[i].xy = VSTexCoord.xy - (BlurOffsets[i].xy / BUFFER_SIZE_1); - TexCoords[i].zw = VSTexCoord.xy + (BlurOffsets[i].xy / BUFFER_SIZE_1); + Coords[i].xy = VS_Coord.xy - (Blur_Offsets[i].xy / BUFFER_SIZE_1); + Coords[i].zw = VS_Coord.xy + (Blur_Offsets[i].xy / BUFFER_SIZE_1); } } - void Sample_3x3_VS(in uint ID : SV_VertexID, in float2 TexelSize, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_VS(in uint ID : SV_VERTEXID, in float2 Texel_Size, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { float2 VS_TexCoord = 0.0; - PostProcessVS(ID, Position, VS_TexCoord); + Basic_VS(ID, Position, VS_TexCoord); // Sample locations: // [0].xy [1].xy [2].xy // [0].xz [1].xz [2].xz // [0].xw [1].xw [2].xw - TexCoords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); - TexCoords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); - TexCoords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); + Coords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); + Coords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); + Coords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); } - void Sample_3x3_1_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_1, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_1, Position, Coords); } - void Sample_3x3_2_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_2_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_2, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_2, Position, Coords); } - void Sample_3x3_3_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_3_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_3, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_3, Position, Coords); } - void Sample_3x3_4_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_4_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_4, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_4, Position, Coords); } - void Derivatives_VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[2] : TEXCOORD0) + void Derivatives_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[2] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) / BUFFER_SIZE_1.xxyy); - TexCoords[1] = VSTexCoord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) / BUFFER_SIZE_1.xxyy); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) / BUFFER_SIZE_1.xxyy); + Coords[1] = VS_Coord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) / BUFFER_SIZE_1.xxyy); } // Pixel Shaders @@ -340,19 +340,19 @@ namespace cInterpolation ... and so forth */ - void Store_Frame_3_PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Store_Frame_3_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Sample_Frame_2, TexCoord); + Output_Color_0 = tex2D(Sample_Frame_2, Coord); } - void Store_Frame_2_PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Store_Frame_2_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Sample_Frame_1, TexCoord); + Output_Color_0 = tex2D(Sample_Frame_1, Coord); } - void Current_Frame_1_PS(float4 Position : SV_Position, in float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Current_Frame_1_PS(float4 Position : SV_POSITION, in float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Sample_Color, TexCoord); + Output_Color_0 = tex2D(Sample_Color, Coord); } /* @@ -360,15 +360,15 @@ namespace cInterpolation 2. Filter incoming frame */ - void Normalize_Frame_PS(in float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Normalize_Frame_PS(in float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - float4 Frame1 = tex2D(Sample_Frame_1, TexCoord); - float4 Frame3 = tex2D(Sample_Frame_3, TexCoord); - Color.xy = saturate(Frame1.xy / dot(Frame1.rgb, 1.0)); - Color.zw = saturate(Frame3.xy / dot(Frame3.rgb, 1.0)); + float4 Frame_1 = tex2D(Sample_Frame_1, Coord); + float4 Frame_3 = tex2D(Sample_Frame_3, Coord); + Output_Color_0.xy = saturate(Frame_1.xy / dot(Frame_1.rgb, 1.0)); + Output_Color_0.zw = saturate(Frame_3.xy / dot(Frame_3.rgb, 1.0)); } - static const float BlurWeights[8] = + static const float Blur_Weights[8] = { 0.079788454, 0.15186256, @@ -380,79 +380,79 @@ namespace cInterpolation 0.0042996835 }; - void GaussianBlur(in sampler2D Source, in float4 TexCoords[8], out float4 Color) + void Gaussian_Blur(in sampler2D Source, in float4 Coords[8], out float4 Output_Color_0) { - float TotalWeights = BlurWeights[0]; - Color = (tex2D(Source, TexCoords[0].xy) * BlurWeights[0]); + float Total_Weights = Blur_Weights[0]; + Output_Color_0 = (tex2D(Source, Coords[0].xy) * Blur_Weights[0]); for(int i = 1; i < 8; i++) { - Color += (tex2D(Source, TexCoords[i].xy) * BlurWeights[i]); - Color += (tex2D(Source, TexCoords[i].zw) * BlurWeights[i]); - TotalWeights += (BlurWeights[i] * 2.0); + Output_Color_0 += (tex2D(Source, Coords[i].xy) * Blur_Weights[i]); + Output_Color_0 += (tex2D(Source, Coords[i].zw) * Blur_Weights[i]); + Total_Weights += (Blur_Weights[i] * 2.0); } - Color = Color / TotalWeights; + Output_Color_0 = Output_Color_0 / Total_Weights; } - void Pre_Blur_0_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Pre_Blur_0_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Sample_Normalized_Frame, TexCoords, Color); + Gaussian_Blur(Sample_Normalized_Frame, Coords, Output_Color_0); } - void Pre_Blur_1_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Pre_Blur_1_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(SharedResources::Sample_Common_1, TexCoords, Color); + Gaussian_Blur(Shared_Resources::Sample_Common_1, Coords, Output_Color_0); } - void Derivatives_PS(in float4 Position : SV_Position, in float4 TexCoords[2] : TEXCOORD0, out float4 Color : SV_Target0) + void Derivatives_PS(in float4 Position : SV_POSITION, in float4 Coords[2] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Bilinear 5x5 Sobel by CeeJayDK - // B1 B2 - // A0 A1 - // A2 B0 - // C0 C1 - float2 A0 = tex2D(Sample_Normalized_Frame, TexCoords[0].xw).xy * 4.0; // <-1.5, +0.5> - float2 A1 = tex2D(Sample_Normalized_Frame, TexCoords[0].yw).xy * 4.0; // <+1.5, +0.5> - float2 A2 = tex2D(Sample_Normalized_Frame, TexCoords[0].xz).xy * 4.0; // <-1.5, -0.5> - float2 B0 = tex2D(Sample_Normalized_Frame, TexCoords[0].yz).xy * 4.0; // <+1.5, -0.5> - float2 B1 = tex2D(Sample_Normalized_Frame, TexCoords[1].xw).xy * 4.0; // <-0.5, +1.5> - float2 B2 = tex2D(Sample_Normalized_Frame, TexCoords[1].yw).xy * 4.0; // <+0.5, +1.5> - float2 C0 = tex2D(Sample_Normalized_Frame, TexCoords[1].xz).xy * 4.0; // <-0.5, -1.5> - float2 C1 = tex2D(Sample_Normalized_Frame, TexCoords[1].yz).xy * 4.0; // <+0.5, -1.5> + // B_1 B_2 + // A_0 A_1 + // A_2 B_0 + // C_0 C_1 + float2 A_0 = tex2D(Sample_Normalized_Frame, Coords[0].xw).xy * 4.0; // <-1.5, +0.5> + float2 A_1 = tex2D(Sample_Normalized_Frame, Coords[0].yw).xy * 4.0; // <+1.5, +0.5> + float2 A_2 = tex2D(Sample_Normalized_Frame, Coords[0].xz).xy * 4.0; // <-1.5, -0.5> + float2 B_0 = tex2D(Sample_Normalized_Frame, Coords[0].yz).xy * 4.0; // <+1.5, -0.5> + float2 B_1 = tex2D(Sample_Normalized_Frame, Coords[1].xw).xy * 4.0; // <-0.5, +1.5> + float2 B_2 = tex2D(Sample_Normalized_Frame, Coords[1].yw).xy * 4.0; // <+0.5, +1.5> + float2 C_0 = tex2D(Sample_Normalized_Frame, Coords[1].xz).xy * 4.0; // <-0.5, -1.5> + float2 C_1 = tex2D(Sample_Normalized_Frame, Coords[1].yz).xy * 4.0; // <+0.5, -1.5> // -1 0 +1 // -1 -2 0 +2 +1 // -2 -2 0 +2 +2 // -1 -2 0 +2 +1 // -1 0 +1 - Color.xy = ((B2 + A1 + B0 + C1) - (B1 + A0 + A2 + C0)) / 12.0; + Output_Color_0.xy = ((B_2 + A_1 + B_0 + C_1) - (B_1 + A_0 + A_2 + C_0)) / 12.0; // +1 +2 +1 // +1 +2 +2 +2 +1 // 0 0 0 0 0 // -1 -2 -2 -2 -1 // -1 -2 -1 - Color.zw = ((A0 + B1 + B2 + A1) - (A2 + C0 + C1 + B0)) / 12.0; - Color.xz *= rsqrt(dot(Color.xz, Color.xz) + 1.0); - Color.yw *= rsqrt(dot(Color.yw, Color.yw) + 1.0); + Output_Color_0.zw = ((A_0 + B_1 + B_2 + A_1) - (A_2 + C_0 + C_1 + B_0)) / 12.0; + Output_Color_0.xz *= rsqrt(dot(Output_Color_0.xz, Output_Color_0.xz) + 1.0); + Output_Color_0.yw *= rsqrt(dot(Output_Color_0.yw, Output_Color_0.yw) + 1.0); } - #define MaxLevel 7 + #define Max_Level 7 #define E 1e-4 - void CoarseOpticalFlowTV(in float2 TexCoord, in float Level, in float2 UV, out float2 OpticalFlow) + void Coarse_Optical_Flow_TV(in float2 Coord, in float Level, in float2 UV, out float2 Optical_Flow) { - OpticalFlow = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7); + Optical_Flow = 0.0; + const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7); - float4 Frames = tex2Dlod(Sample_Normalized_Frame, float4(TexCoord, 0.0, Level)); + float4 Frames = tex2Dlod(Sample_Normalized_Frame, float4(Coord, 0.0, Level)); // - float4 SD = tex2Dlod(SharedResources::Sample_Common_1, float4(TexCoord, 0.0, Level)); + float4 S_D = tex2Dlod(Shared_Resources::Sample_Common_1, float4(Coord, 0.0, Level)); // - float2 TD = Frames.xy - Frames.zw; + float2 T_D = Frames.xy - Frames.zw; // Calculate constancy term float C = 0.0; @@ -462,128 +462,128 @@ namespace cInterpolation // Calculate forward motion vectors - C = dot(TD, 1.0); + C = dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); - Aii.x = 1.0 / (C * dot(SD.xy, SD.xy) + Alpha); - Aii.y = 1.0 / (C * dot(SD.zw, SD.zw) + Alpha); + Aii.x = 1.0 / (C * dot(S_D.xy, S_D.xy) + Alpha); + Aii.y = 1.0 / (C * dot(S_D.zw, S_D.zw) + Alpha); - Aij = C * dot(SD.xy, SD.zw); + Aij = C * dot(S_D.xy, S_D.zw); - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); - OpticalFlow.x = Aii.x * ((Alpha * UV.x) - (Aij * UV.y) - Bi.x); - OpticalFlow.y = Aii.y * ((Alpha * UV.y) - (Aij * OpticalFlow.x) - Bi.y); + Optical_Flow.x = Aii.x * ((Alpha * UV.x) - (Aij * UV.y) - Bi.x); + Optical_Flow.y = Aii.y * ((Alpha * UV.y) - (Aij * Optical_Flow.x) - Bi.y); } - void ProcessGradAvg(in float2 SampleNW, - in float2 SampleNE, - in float2 SampleSW, - in float2 SampleSE, - out float Grad, - out float2 Avg) + void ProcessGradAvg(in float2 Sample_NW, + in float2 Sample_NE, + in float2 Sample_SW, + in float2 Sample_SE, + out float Gradient, + out float2 Average) { // NW NE // SW SE - float4 GradUV = 0.0; - GradUV.xy = (SampleNW + SampleSW) - (SampleNE + SampleSE); // - GradUV.zw = (SampleNW + SampleNE) - (SampleSW + SampleSE); // - GradUV = GradUV * 0.5; - Grad = rsqrt((dot(GradUV.xzyw, GradUV.xzyw) * 0.25) + (E * E)); - Avg = (SampleNW + SampleNE + SampleSW + SampleSE) * 0.25; + float4 Sq_Gradient_UV = 0.0; + Sq_Gradient_UV.xy = (Sample_NW + Sample_SW) - (Sample_NE + Sample_SE); // + Sq_Gradient_UV.zw = (Sample_NW + Sample_NE) - (Sample_SW + Sample_SE); // + Sq_Gradient_UV = Sq_Gradient_UV * 0.5; + Gradient = rsqrt((dot(Sq_Gradient_UV.xzyw, Sq_Gradient_UV.xzyw) * 0.25) + (E * E)); + Average = (Sample_NW + Sample_NE + Sample_SW + Sample_SE) * 0.25; } - void ProcessArea(in float2 SampleUV[9], - inout float4 UVGrad, - inout float2 CenterAvg, - inout float2 UVAvg) + void ProcessArea(in float2 Sample_UV[9], + inout float4 UV_Gradient, + inout float2 Center_Average, + inout float2 UV_Average) { - float CenterGrad = 0.0; - float4 AreaGrad = 0.0; - float2 AreaAvg[4]; - float4 GradUV = 0.0; - float SqGradUV = 0.0; + float Center_Gradient = 0.0; + float4 Area_Gradient = 0.0; + float2 Area_Average[4]; + float4 Gradient_UV = 0.0; + float SqGradient_UV = 0.0; // Center smoothness gradient and average // 0 3 6 // 1 4 7 // 2 5 8 - GradUV.xy = (SampleUV[0] + (SampleUV[1] * 2.0) + SampleUV[2]) - (SampleUV[6] + (SampleUV[7] * 2.0) + SampleUV[8]); // - GradUV.zw = (SampleUV[0] + (SampleUV[3] * 2.0) + SampleUV[6]) - (SampleUV[2] + (SampleUV[5] * 2.0) + SampleUV[8]); // - SqGradUV = dot(GradUV.xzyw / 4.0, GradUV.xzyw / 4.0) * 0.25; - CenterGrad = rsqrt(SqGradUV + (E * E)); + Gradient_UV.xy = (Sample_UV[0] + (Sample_UV[1] * 2.0) + Sample_UV[2]) - (Sample_UV[6] + (Sample_UV[7] * 2.0) + Sample_UV[8]); // + Gradient_UV.zw = (Sample_UV[0] + (Sample_UV[3] * 2.0) + Sample_UV[6]) - (Sample_UV[2] + (Sample_UV[5] * 2.0) + Sample_UV[8]); // + SqGradient_UV = dot(Gradient_UV.xzyw / 4.0, Gradient_UV.xzyw / 4.0) * 0.25; + Center_Gradient = rsqrt(SqGradient_UV + (E * E)); - CenterAvg += ((SampleUV[0] + SampleUV[6] + SampleUV[2] + SampleUV[8]) * 1.0); - CenterAvg += ((SampleUV[3] + SampleUV[1] + SampleUV[7] + SampleUV[5]) * 2.0); - CenterAvg += (SampleUV[4] * 4.0); - CenterAvg = CenterAvg / 16.0; + Center_Average += ((Sample_UV[0] + Sample_UV[6] + Sample_UV[2] + Sample_UV[8]) * 1.0); + Center_Average += ((Sample_UV[3] + Sample_UV[1] + Sample_UV[7] + Sample_UV[5]) * 2.0); + Center_Average += (Sample_UV[4] * 4.0); + Center_Average = Center_Average / 16.0; // North-west gradient and average // 0 3 . // 1 4 . // . . . - ProcessGradAvg(SampleUV[0], SampleUV[3], SampleUV[1], SampleUV[4], AreaGrad[0], AreaAvg[0]); + ProcessGradAvg(Sample_UV[0], Sample_UV[3], Sample_UV[1], Sample_UV[4], Area_Gradient[0], Area_Average[0]); // North-east gradient and average // . 3 6 // . 4 7 // . . . - ProcessGradAvg(SampleUV[3], SampleUV[6], SampleUV[4], SampleUV[7], AreaGrad[1], AreaAvg[1]); + ProcessGradAvg(Sample_UV[3], Sample_UV[6], Sample_UV[4], Sample_UV[7], Area_Gradient[1], Area_Average[1]); // South-west gradient and average // . . . // 1 4 . // 2 5 . - ProcessGradAvg(SampleUV[1], SampleUV[4], SampleUV[2], SampleUV[5], AreaGrad[2], AreaAvg[2]); + ProcessGradAvg(Sample_UV[1], Sample_UV[4], Sample_UV[2], Sample_UV[5], Area_Gradient[2], Area_Average[2]); // South-east and average // . . . // . 4 7 // . 5 8 - ProcessGradAvg(SampleUV[4], SampleUV[7], SampleUV[5], SampleUV[8], AreaGrad[3], AreaAvg[3]); + ProcessGradAvg(Sample_UV[4], Sample_UV[7], Sample_UV[5], Sample_UV[8], Area_Gradient[3], Area_Average[3]); - UVGrad = 0.5 * (CenterGrad + AreaGrad); - UVAvg = (AreaGrad[0] * AreaAvg[0]) + (AreaGrad[1] * AreaAvg[1]) + (AreaGrad[2] * AreaAvg[2]) + (AreaGrad[3] * AreaAvg[3]); + UV_Gradient = 0.5 * (Center_Gradient + Area_Gradient); + UV_Average = (Area_Gradient[0] * Area_Average[0]) + (Area_Gradient[1] * Area_Average[1]) + (Area_Gradient[2] * Area_Average[2]) + (Area_Gradient[3] * Area_Average[3]); } - void OpticalFlowTV(in sampler2D SourceUV, in float4 TexCoords[3], in float Level, out float2 OpticalFlow) + void Optical_Flow_TV(in sampler2D SourceUV, in float4 Coords[3], in float Level, out float2 Optical_Flow) { - OpticalFlow = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7); + Optical_Flow = 0.0; + const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7); // Load textures - float4 Frames = tex2Dlod(Sample_Normalized_Frame, float4(TexCoords[1].xz, 0.0, Level)); + float4 Frames = tex2Dlod(Sample_Normalized_Frame, float4(Coords[1].xz, 0.0, Level)); // - float4 SD = tex2Dlod(SharedResources::Sample_Common_1, float4(TexCoords[1].xz, 0.0, Level)); + float4 S_D = tex2Dlod(Shared_Resources::Sample_Common_1, float4(Coords[1].xz, 0.0, Level)); // - float2 TD = Frames.xy - Frames.zw; + float2 T_D = Frames.xy - Frames.zw; // Optical flow calculation - float2 SampleUV[9]; - float4 UVGrad = 0.0; - float2 CenterAvg = 0.0; - float2 UVAvg = 0.0; + float2 Sample_UV[9]; + float4 UV_Gradient = 0.0; + float2 Center_Average = 0.0; + float2 UV_Average = 0.0; - // SampleUV[i] + // Sample_UV[i] // 0 3 6 // 1 4 7 // 2 5 8 - SampleUV[0] = tex2D(SourceUV, TexCoords[0].xy).xy; - SampleUV[1] = tex2D(SourceUV, TexCoords[0].xz).xy; - SampleUV[2] = tex2D(SourceUV, TexCoords[0].xw).xy; - SampleUV[3] = tex2D(SourceUV, TexCoords[1].xy).xy; - SampleUV[4] = tex2D(SourceUV, TexCoords[1].xz).xy; - SampleUV[5] = tex2D(SourceUV, TexCoords[1].xw).xy; - SampleUV[6] = tex2D(SourceUV, TexCoords[2].xy).xy; - SampleUV[7] = tex2D(SourceUV, TexCoords[2].xz).xy; - SampleUV[8] = tex2D(SourceUV, TexCoords[2].xw).xy; - - ProcessArea(SampleUV, UVGrad, CenterAvg, UVAvg); + Sample_UV[0] = tex2D(SourceUV, Coords[0].xy).xy; + Sample_UV[1] = tex2D(SourceUV, Coords[0].xz).xy; + Sample_UV[2] = tex2D(SourceUV, Coords[0].xw).xy; + Sample_UV[3] = tex2D(SourceUV, Coords[1].xy).xy; + Sample_UV[4] = tex2D(SourceUV, Coords[1].xz).xy; + Sample_UV[5] = tex2D(SourceUV, Coords[1].xw).xy; + Sample_UV[6] = tex2D(SourceUV, Coords[2].xy).xy; + Sample_UV[7] = tex2D(SourceUV, Coords[2].xz).xy; + Sample_UV[8] = tex2D(SourceUV, Coords[2].xw).xy; + + ProcessArea(Sample_UV, UV_Gradient, Center_Average, UV_Average); float C = 0.0; float2 Aii = 0.0; @@ -592,52 +592,52 @@ namespace cInterpolation // Calculate forward motion vectors - C = dot(SD.xyzw, CenterAvg.xyxy) + dot(TD, 1.0); + C = dot(S_D.xyzw, Center_Average.xyxy) + dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); - Aii.x = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.xy, SD.xy))); - Aii.y = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.zw, SD.zw))); + Aii.x = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.xy, S_D.xy))); + Aii.y = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.zw, S_D.zw))); - Aij = C * dot(SD.xy, SD.zw); + Aij = C * dot(S_D.xy, S_D.zw); - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); - OpticalFlow.x = Aii.x * ((Alpha * UVAvg.x) - (Aij * CenterAvg.y) - Bi.x); - OpticalFlow.y = Aii.y * ((Alpha * UVAvg.y) - (Aij * OpticalFlow.x) - Bi.y); + Optical_Flow.x = Aii.x * ((Alpha * UV_Average.x) - (Aij * Center_Average.y) - Bi.x); + Optical_Flow.y = Aii.y * ((Alpha * UV_Average.y) - (Aij * Optical_Flow.x) - Bi.y); } - void Level_4_PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 Color : SV_Target0) + void Level_4_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float2 Color : SV_TARGET0) { - CoarseOpticalFlowTV(TexCoord, 6.5, 0.0, Color); + Coarse_Optical_Flow_TV(Coord, 6.5, 0.0, Color); } - void Level_3_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 Color : SV_Target0) + void Level_3_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Color : SV_TARGET0) { - OpticalFlowTV(SharedResources::Sample_Common_4, TexCoords, 4.5, Color); + Optical_Flow_TV(Shared_Resources::Sample_Common_4, Coords, 4.5, Color); } - void Level_2_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 Color : SV_Target0) + void Level_2_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Color : SV_TARGET0) { - OpticalFlowTV(SharedResources::Sample_Common_3, TexCoords, 2.5, Color); + Optical_Flow_TV(Shared_Resources::Sample_Common_3, Coords, 2.5, Color); } - void Level_1_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 Color : SV_Target0) + void Level_1_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SharedResources::Sample_Common_2, TexCoords, 0.5, Color.rg); - Color.ba = float2(0.0, 1.0); + Optical_Flow_TV(Shared_Resources::Sample_Common_2, Coords, 0.5, Output_Color_0.rg); + Output_Color_0.ba = float2(0.0, 1.0); } - void Post_Blur_0_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Post_Blur_0_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(SharedResources::Sample_Common_1, TexCoords, Color); - Color.a = 1.0; + Gaussian_Blur(Shared_Resources::Sample_Common_1, Coords, Output_Color_0); + Output_Color_0.a = 1.0; } - void Post_Blur_1_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Post_Blur_1_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Sample_Normalized_Frame, TexCoords, Color); - Color.a = 1.0; + Gaussian_Blur(Sample_Normalized_Frame, Coords, Output_Color_0); + Output_Color_0.a = 1.0; } /* @@ -652,27 +652,27 @@ namespace cInterpolation return min(max(min(a, b), c), max(a, b)); } - void Interpolate_PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 Color : SV_Target0) + void Interpolate_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - float2 TexelSize = 1.0 / BUFFER_SIZE_1; - float2 MotionVectors = tex2Dlod(SharedResources::Sample_Common_1, float4(TexCoord, 0.0, _MipBias)).xy * TexelSize.xy; + float2 Texel_Size = 1.0 / BUFFER_SIZE_1; + float2 Motion_Vectors = tex2Dlod(Shared_Resources::Sample_Common_1, float4(Coord, 0.0, _Mip_Bias)).xy * Texel_Size.xy; - float4 StaticLeft = tex2D(Sample_Frame_3, TexCoord); - float4 StaticRight = tex2D(Sample_Frame_1, TexCoord); - float4 DynamicLeft = tex2D(Sample_Frame_3, TexCoord + MotionVectors); - float4 DynamicRight = tex2D(Sample_Frame_1, TexCoord - MotionVectors); + float4 Static_Left = tex2D(Sample_Frame_3, Coord); + float4 Static_Right = tex2D(Sample_Frame_1, Coord); + float4 Dynamic_Left = tex2D(Sample_Frame_3, Coord + Motion_Vectors); + float4 Dynamic_Right = tex2D(Sample_Frame_1, Coord - Motion_Vectors); - float4 StaticAverage = lerp(StaticLeft, StaticRight, 0.5); - float4 DynamicAverage = lerp(DynamicLeft, DynamicRight, 0.5); + float4 Static_Average = lerp(Static_Left, Static_Right, 0.5); + float4 Dynamic_Average = lerp(Dynamic_Left, Dynamic_Right, 0.5); - float4 StaticMedian = Median(StaticLeft, StaticRight, DynamicAverage); - float4 DynamicMedian = Median(StaticAverage, DynamicLeft, DynamicRight); - float4 MotionFilter = lerp(StaticAverage, DynamicAverage, DynamicMedian); + float4 Static_Median = Median(Static_Left, Static_Right, Dynamic_Average); + float4 Dynamic_Median = Median(Static_Average, Dynamic_Left, Dynamic_Right); + float4 Motion_Filter = lerp(Static_Average, Dynamic_Average, Dynamic_Median); - float4 CascadedMedian = Median(StaticMedian, MotionFilter, DynamicMedian); + float4 Cascaded_Median = Median(Static_Median, Motion_Filter, Dynamic_Median); - Color = lerp(CascadedMedian, DynamicAverage, 0.5); - Color.a = 1.0; + Output_Color_0 = lerp(Cascaded_Median, Dynamic_Average, 0.5); + Output_Color_0.a = 1.0; } /* @@ -687,21 +687,21 @@ namespace cInterpolation pass Store_Frame_3 { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Store_Frame_3_PS; RenderTarget = Render_Frame_3; } pass Store_Frame_2 { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Store_Frame_2_PS; RenderTarget = Render_Frame_2; } pass Store_Frame_1 { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Current_Frame_1_PS; RenderTarget = Render_Frame_1; } @@ -710,7 +710,7 @@ namespace cInterpolation pass Normalize_Frame { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Normalize_Frame_PS; RenderTarget0 = Render_Normalized_Frame; } @@ -721,7 +721,7 @@ namespace cInterpolation { VertexShader = Blur_0_VS; PixelShader = Pre_Blur_0_PS; - RenderTarget0 = SharedResources::Render_Common_1; + RenderTarget0 = Shared_Resources::Render_Common_1; } pass Blur1 @@ -737,37 +737,37 @@ namespace cInterpolation { VertexShader = Derivatives_VS; PixelShader = Derivatives_PS; - RenderTarget0 = SharedResources::Render_Common_1; + RenderTarget0 = Shared_Resources::Render_Common_1; } // Trilinear Optical Flow, calculate 2 levels at a time pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Level_4_PS; - RenderTarget0 = SharedResources::Render_Common_4; + RenderTarget0 = Shared_Resources::Render_Common_4; } pass { VertexShader = Sample_3x3_4_VS; PixelShader = Level_3_PS; - RenderTarget0 = SharedResources::Render_Common_3; + RenderTarget0 = Shared_Resources::Render_Common_3; } pass { VertexShader = Sample_3x3_3_VS; PixelShader = Level_2_PS; - RenderTarget0 = SharedResources::Render_Common_2; + RenderTarget0 = Shared_Resources::Render_Common_2; } pass { VertexShader = Sample_3x3_2_VS; PixelShader = Level_1_PS; - RenderTarget0 = SharedResources::Render_Common_1; + RenderTarget0 = Shared_Resources::Render_Common_1; } // Gaussian blur @@ -783,14 +783,14 @@ namespace cInterpolation { VertexShader = Blur_1_VS; PixelShader = Post_Blur_1_PS; - RenderTarget0 = SharedResources::Render_Common_1; + RenderTarget0 = Shared_Resources::Render_Common_1; } // Interpolate pass Interpolate { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Interpolate_PS; RenderTarget0 = Render_Interpolated_Frame; } diff --git a/shaders/cLetterBox.fx b/shaders/cLetterBox.fx index 909cbbd..f0f7d04 100644 --- a/shaders/cLetterBox.fx +++ b/shaders/cLetterBox.fx @@ -41,30 +41,30 @@ uniform float2 _Scale < // 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 LetterboxPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor : SV_Target0) +void Letterbox_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color : SV_TARGET0) { // Output a rectangle const float2 Scale = -_Scale * 0.5 + 0.5; - float2 Shaper = step(Scale, TexCoord); - Shaper *= step(Scale, 1.0 - TexCoord); - OutputColor = Shaper.xxxx * Shaper.yyyy; + float2 Shaper = step(Scale, Coord); + Shaper *= step(Scale, 1.0 - Coord); + Output_Color = Shaper.xxxx * Shaper.yyyy; } technique cLetterBox { pass { - VertexShader = PostProcessVS; - PixelShader = LetterboxPS; + VertexShader = Basic_VS; + PixelShader = Letterbox_PS; // Blend the rectangle with the backbuffer ClearRenderTargets = FALSE; BlendEnable = TRUE; diff --git a/shaders/cLuminance.fx b/shaders/cLuminance.fx index 74c0b69..d213932 100644 --- a/shaders/cLuminance.fx +++ b/shaders/cLuminance.fx @@ -40,11 +40,11 @@ uniform int _Select < ui_tooltip = "Select Luminance"; > = 0; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -55,50 +55,50 @@ 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 LuminancePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Luminance_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); switch(_Select) { case 0: // Average - OutputColor0 = dot(Color.rgb, 1.0 / 3.0); + Output_Color_0 = dot(Color.rgb, 1.0 / 3.0); break; case 1: // Sum - OutputColor0 = dot(Color.rgb, 1.0); + Output_Color_0 = dot(Color.rgb, 1.0); break; case 2: // Min - OutputColor0 = min(Color.r, min(Color.g, Color.b)); + Output_Color_0 = min(Color.r, min(Color.g, Color.b)); break; case 3: // Median - OutputColor0 = max(min(Color.r, Color.g), min(max(Color.r, Color.g), Color.b)); + Output_Color_0 = max(min(Color.r, Color.g), min(max(Color.r, Color.g), Color.b)); break; case 4: // Max - OutputColor0 = max(Color.r, max(Color.g, Color.b)); + Output_Color_0 = max(Color.r, max(Color.g, Color.b)); break; case 5: // Length - OutputColor0 = length(Color.rgb); + Output_Color_0 = length(Color.rgb); break; case 6: // Clamped Length - OutputColor0 = length(Color.rgb) * rsqrt(3.0); + Output_Color_0 = length(Color.rgb) * rsqrt(3.0); break; default: - OutputColor0 = Color; + Output_Color_0 = Color; break; } } @@ -107,8 +107,8 @@ technique cLuminance { pass { - VertexShader = PostProcessVS; - PixelShader = LuminancePS; + VertexShader = Basic_VS; + PixelShader = Luminance_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cMedian.fx b/shaders/cMedian.fx index 99d8a9f..535989c 100644 --- a/shaders/cMedian.fx +++ b/shaders/cMedian.fx @@ -33,11 +33,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -46,29 +46,29 @@ sampler2D SampleColor #endif }; -void MedianOffsets(in float2 TexCoord, in float2 PixelSize, out float4 SampleOffsets[3]) +void Median_Offsets(in float2 Coord, in float2 Pixel_Size, out float4 Sample_Offsets[3]) { // Sample locations: // [0].xy [1].xy [2].xy // [0].xz [1].xz [2].xz // [0].xw [1].xw [2].xw - SampleOffsets[0] = TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - SampleOffsets[1] = TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - SampleOffsets[2] = TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); + Sample_Offsets[0] = Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Sample_Offsets[1] = Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Sample_Offsets[2] = Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); } -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 = TexCoord.xyxy * float4(2.0, -2.0, 0.0, 0.0) + float4(-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 = Coord.xyxy * float4(2.0, -2.0, 0.0, 0.0) + float4(-1.0, 1.0, 0.0, 1.0); } -void MedianVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 Offsets[3] : TEXCOORD0) +void Median_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Offsets[3] : TEXCOORD0) { - float2 TexCoord0; - PostProcessVS(ID, Position, TexCoord0); - MedianOffsets(TexCoord0, 1.0 / (float2(BUFFER_WIDTH, BUFFER_HEIGHT)), Offsets); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Median_Offsets(VS_Coord, 1.0 / (float2(BUFFER_WIDTH, BUFFER_HEIGHT)), Offsets); } // Math functions: https://github.com/microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/Shaders/DoFMedianFilterCS.hlsl @@ -83,49 +83,49 @@ float4 Min3(float4 a, float4 b, float4 c) return min(min(a, b), c); } -float4 Med3(float4 a, float4 b, float4 c) +float4 Median_3(float4 a, float4 b, float4 c) { return clamp(a, min(b, c), max(b, c)); } -float4 Med9(float4 x0, float4 x1, float4 x2, +float4 Median_9(float4 x0, float4 x1, float4 x2, float4 x3, float4 x4, float4 x5, float4 x6, float4 x7, float4 x8) { float4 A = Max3(Min3(x0, x1, x2), Min3(x3, x4, x5), Min3(x6, x7, x8)); float4 B = Min3(Max3(x0, x1, x2), Max3(x3, x4, x5), Max3(x6, x7, x8)); - float4 C = Med3(Med3(x0, x1, x2), Med3(x3, x4, x5), Med3(x6, x7, x8)); - return Med3(A, B, C); + float4 C = Median_3(Median_3(x0, x1, x2), Median_3(x3, x4, x5), Median_3(x6, x7, x8)); + return Median_3(A, B, C); } -void MedianPS(in float4 Position : SV_Position, in float4 Offsets[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Median_PS(in float4 Position : SV_POSITION, in float4 Offsets[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Sample locations: // [0].xy [1].xy [2].xy // [0].xz [1].xz [2].xz // [0].xw [1].xw [2].xw - float4 OutputColor = 0.0; + float4 Output_Color = 0.0; float4 Sample[9]; - Sample[0] = tex2D(SampleColor, Offsets[0].xy); - Sample[1] = tex2D(SampleColor, Offsets[1].xy); - Sample[2] = tex2D(SampleColor, Offsets[2].xy); - Sample[3] = tex2D(SampleColor, Offsets[0].xz); - Sample[4] = tex2D(SampleColor, Offsets[1].xz); - Sample[5] = tex2D(SampleColor, Offsets[2].xz); - Sample[6] = tex2D(SampleColor, Offsets[0].xw); - Sample[7] = tex2D(SampleColor, Offsets[1].xw); - Sample[8] = tex2D(SampleColor, Offsets[2].xw); - OutputColor0 = Med9(Sample[0], Sample[1], Sample[2], - Sample[3], Sample[4], Sample[5], - Sample[6], Sample[7], Sample[8]); + Sample[0] = tex2D(Sample_Color, Offsets[0].xy); + Sample[1] = tex2D(Sample_Color, Offsets[1].xy); + Sample[2] = tex2D(Sample_Color, Offsets[2].xy); + Sample[3] = tex2D(Sample_Color, Offsets[0].xz); + Sample[4] = tex2D(Sample_Color, Offsets[1].xz); + Sample[5] = tex2D(Sample_Color, Offsets[2].xz); + Sample[6] = tex2D(Sample_Color, Offsets[0].xw); + Sample[7] = tex2D(Sample_Color, Offsets[1].xw); + Sample[8] = tex2D(Sample_Color, Offsets[2].xw); + Output_Color_0 = Median_9(Sample[0], Sample[1], Sample[2], + Sample[3], Sample[4], Sample[5], + Sample[6], Sample[7], Sample[8]); } technique cMedian { pass { - VertexShader = MedianVS; - PixelShader = MedianPS; + VertexShader = Median_VS; + PixelShader = Median_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cMotionBlur.fx b/shaders/cMotionBlur.fx index e532df1..26bd8ae 100644 --- a/shaders/cMotionBlur.fx +++ b/shaders/cMotionBlur.fx @@ -39,7 +39,7 @@ #define BUFFER_SIZE_3 int2(SIZE >> 4) #define BUFFER_SIZE_4 int2(SIZE >> 6) -namespace Shared_Resources_MotionBlur +namespace Shared_Resources_Motion_Blur { // Store convoluted normalized frame 1 and 3 @@ -151,7 +151,7 @@ namespace Shared_Resources_MotionBlur }; } -namespace MotionBlur +namespace Motion_Blur { // Shader properties @@ -163,14 +163,14 @@ namespace MotionBlur ui_max = 2.0; > = 1.0; - uniform float _MipBias < + uniform float _Mip_Bias < ui_type = "drag"; ui_category = "Optical flow"; ui_label = "Optical flow mipmap bias"; ui_min = 0.0; > = 2.5; - uniform float _BlendFactor < + uniform float _Blend_Factor < ui_type = "slider"; ui_category = "Optical flow"; ui_label = "Temporal Blending Factor"; @@ -187,7 +187,7 @@ namespace MotionBlur ui_max = 1.0; > = 0.5; - uniform float _TargetFrameRate < + uniform float _Target_Frame_Rate < ui_type = "drag"; ui_category = "Main"; ui_label = "Target Frame-Rate"; @@ -202,7 +202,7 @@ namespace MotionBlur > = false; - uniform float _FrameTime < source = "frametime"; >; + uniform float _Frame_Time < source = "frametime"; >; texture2D Render_Color : COLOR; @@ -256,14 +256,14 @@ namespace MotionBlur // 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); } - static const float2 BlurOffsets[8] = + static const float2 Blur_Offsets[8] = { float2(0.0, 0.0), float2(0.0, 1.4850045), @@ -275,87 +275,87 @@ namespace MotionBlur float2(0.0, 13.368189) }; - void Blur_0_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[8] : TEXCOORD0) + void Blur_0_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[8] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xyxy; + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xyxy; for(int i = 1; i < 8; i++) { - TexCoords[i].xy = VSTexCoord.xy - (BlurOffsets[i].yx / BUFFER_SIZE_1); - TexCoords[i].zw = VSTexCoord.xy + (BlurOffsets[i].yx / BUFFER_SIZE_1); + Coords[i].xy = VS_Coord.xy - (Blur_Offsets[i].yx / BUFFER_SIZE_1); + Coords[i].zw = VS_Coord.xy + (Blur_Offsets[i].yx / BUFFER_SIZE_1); } } - void Blur_1_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[8] : TEXCOORD0) + void Blur_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[8] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xyxy; + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xyxy; for(int i = 1; i < 8; i++) { - TexCoords[i].xy = VSTexCoord.xy - (BlurOffsets[i].xy / BUFFER_SIZE_1); - TexCoords[i].zw = VSTexCoord.xy + (BlurOffsets[i].xy / BUFFER_SIZE_1); + Coords[i].xy = VS_Coord.xy - (Blur_Offsets[i].xy / BUFFER_SIZE_1); + Coords[i].zw = VS_Coord.xy + (Blur_Offsets[i].xy / BUFFER_SIZE_1); } } - void Sample_3x3_VS(in uint ID : SV_VertexID, in float2 TexelSize, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_VS(in uint ID : SV_VERTEXID, in float2 Texel_Size, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { float2 VS_TexCoord = 0.0; - PostProcessVS(ID, Position, VS_TexCoord); + Basic_VS(ID, Position, VS_TexCoord); // Sample locations: // [0].xy [1].xy [2].xy // [0].xz [1].xz [2].xz // [0].xw [1].xw [2].xw - TexCoords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); - TexCoords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); - TexCoords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); + Coords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); + Coords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); + Coords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); } - void Sample_3x3_1_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_1, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_1, Position, Coords); } - void Sample_3x3_2_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_2_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_2, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_2, Position, Coords); } - void Sample_3x3_3_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_3_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_3, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_3, Position, Coords); } - void Sample_3x3_4_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_4_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_4, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_4, Position, Coords); } - void Derivatives_VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[2] : TEXCOORD0) + void Derivatives_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[2] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) / BUFFER_SIZE_1.xxyy); - TexCoords[1] = VSTexCoord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) / BUFFER_SIZE_1.xxyy); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) / BUFFER_SIZE_1.xxyy); + Coords[1] = VS_Coord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) / BUFFER_SIZE_1.xxyy); } // Pixel Shaders - void Normalize_Frame_PS(in float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float2 Color : SV_Target0) + void Normalize_Frame_PS(in float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float2 Color : SV_TARGET0) { - float4 Frame = max(tex2D(Sample_Color, TexCoord), exp2(-10.0)); + float4 Frame = max(tex2D(Sample_Color, Coord), exp2(-10.0)); Color.xy = saturate(Frame.xy / dot(Frame.rgb, 1.0)); } - void Blit_Frame_PS(in float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Blit_Frame_PS(in float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Shared_Resources_MotionBlur::Sample_Common_0, TexCoord); + Output_Color_0 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_0, Coord); } - static const float BlurWeights[8] = + static const float Blur_Weights[8] = { 0.079788454, 0.15186256, @@ -367,81 +367,81 @@ namespace MotionBlur 0.0042996835 }; - void GaussianBlur(in sampler2D Source, in float4 TexCoords[8], out float4 Color) + void Gaussian_Blur(in sampler2D Source, in float4 Coords[8], out float4 Output_Color_0) { - float TotalWeights = BlurWeights[0]; - Color = (tex2D(Source, TexCoords[0].xy) * BlurWeights[0]); + float Total_Weights = Blur_Weights[0]; + Output_Color_0 = (tex2D(Source, Coords[0].xy) * Blur_Weights[0]); for(int i = 1; i < 8; i++) { - Color += (tex2D(Source, TexCoords[i].xy) * BlurWeights[i]); - Color += (tex2D(Source, TexCoords[i].zw) * BlurWeights[i]); - TotalWeights += (BlurWeights[i] * 2.0); + Output_Color_0 += (tex2D(Source, Coords[i].xy) * Blur_Weights[i]); + Output_Color_0 += (tex2D(Source, Coords[i].zw) * Blur_Weights[i]); + Total_Weights += (Blur_Weights[i] * 2.0); } - Color = Color / TotalWeights; + Output_Color_0 = Output_Color_0 / Total_Weights; } - void Pre_Blur_0_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Pre_Blur_0_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords, Color); + Gaussian_Blur(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords, Output_Color_0); } - void Pre_Blur_1_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Pre_Blur_1_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Shared_Resources_MotionBlur::Sample_Common_1_B, TexCoords, Color); + Gaussian_Blur(Shared_Resources_Motion_Blur::Sample_Common_1_B, Coords, Output_Color_0); } - void Derivatives_PS(in float4 Position : SV_Position, in float4 TexCoords[2] : TEXCOORD0, out float4 Color : SV_Target0) + void Derivatives_PS(in float4 Position : SV_POSITION, in float4 Coords[2] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Bilinear 5x5 Sobel by CeeJayDK - // B1 B2 - // A0 A1 - // A2 B0 - // C0 C1 - float2 A0 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[0].xw).xy * 4.0; // <-1.5, +0.5> - float2 A1 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[0].yw).xy * 4.0; // <+1.5, +0.5> - float2 A2 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[0].xz).xy * 4.0; // <-1.5, -0.5> - float2 B0 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[0].yz).xy * 4.0; // <+1.5, -0.5> - float2 B1 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[1].xw).xy * 4.0; // <-0.5, +1.5> - float2 B2 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[1].yw).xy * 4.0; // <+0.5, +1.5> - float2 C0 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[1].xz).xy * 4.0; // <-0.5, -1.5> - float2 C1 = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords[1].yz).xy * 4.0; // <+0.5, -1.5> + // B_1 B_2 + // A_0 A_1 + // A_2 B_0 + // C_0 C_1 + float2 A_0 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[0].xw).xy * 4.0; // <-1.5, +0.5> + float2 A_1 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[0].yw).xy * 4.0; // <+1.5, +0.5> + float2 A_2 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[0].xz).xy * 4.0; // <-1.5, -0.5> + float2 B_0 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[0].yz).xy * 4.0; // <+1.5, -0.5> + float2 B_1 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[1].xw).xy * 4.0; // <-0.5, +1.5> + float2 B_2 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[1].yw).xy * 4.0; // <+0.5, +1.5> + float2 C_0 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[1].xz).xy * 4.0; // <-0.5, -1.5> + float2 C_1 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords[1].yz).xy * 4.0; // <+0.5, -1.5> // -1 0 +1 // -1 -2 0 +2 +1 // -2 -2 0 +2 +2 // -1 -2 0 +2 +1 // -1 0 +1 - Color.xy = ((B2 + A1 + B0 + C1) - (B1 + A0 + A2 + C0)) / 12.0; + Output_Color_0.xy = ((B_2 + A_1 + B_0 + C_1) - (B_1 + A_0 + A_2 + C_0)) / 12.0; // +1 +2 +1 // +1 +2 +2 +2 +1 // 0 0 0 0 0 // -1 -2 -2 -2 -1 // -1 -2 -1 - Color.zw = ((A0 + B1 + B2 + A1) - (A2 + C0 + C1 + B0)) / 12.0; - Color.xz *= rsqrt(dot(Color.xz, Color.xz) + 1.0); - Color.yw *= rsqrt(dot(Color.yw, Color.yw) + 1.0); + Output_Color_0.zw = ((A_0 + B_1 + B_2 + A_1) - (A_2 + C_0 + C_1 + B_0)) / 12.0; + Output_Color_0.xz *= rsqrt(dot(Output_Color_0.xz, Output_Color_0.xz) + 1.0); + Output_Color_0.yw *= rsqrt(dot(Output_Color_0.yw, Output_Color_0.yw) + 1.0); } - #define MaxLevel 7 + #define Max_Level 7 #define E 2e-3 - void CoarseOpticalFlowTV(in float2 TexCoord, in float Level, in float2 UV, out float2 OpticalFlow) + void Coarse_Optical_Flow_TV(in float2 Coord, in float Level, in float2 UV, out float2 Optical_Flow) { - OpticalFlow = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-3, Level - MaxLevel), 1e-7); + Optical_Flow = 0.0; + const float Alpha = max(ldexp(_Constraint * 1e-3, Level - Max_Level), 1e-7); // Load textures - float2 Current = tex2Dlod(Shared_Resources_MotionBlur::Sample_Common_1_A, float4(TexCoord, 0.0, Level)).xy; - float2 Previous = tex2Dlod(Sample_Common_1_P, float4(TexCoord, 0.0, Level)).xy; + float2 Current = tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_A, float4(Coord, 0.0, Level)).xy; + float2 Previous = tex2Dlod(Sample_Common_1_P, float4(Coord, 0.0, Level)).xy; // - float4 SD = tex2Dlod(Shared_Resources_MotionBlur::Sample_Common_1_B, float4(TexCoord, 0.0, Level)); + float4 S_D = tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_B, float4(Coord, 0.0, Level)); // - float2 TD = Current - Previous; + float2 T_D = Current - Previous; // Calculate constancy term float C = 0.0; @@ -451,128 +451,128 @@ namespace MotionBlur // Calculate forward motion vectors - C = dot(TD, 1.0); + C = dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); - Aii.x = 1.0 / (C * dot(SD.xy, SD.xy) + Alpha); - Aii.y = 1.0 / (C * dot(SD.zw, SD.zw) + Alpha); + Aii.x = 1.0 / (C * dot(S_D.xy, S_D.xy) + Alpha); + Aii.y = 1.0 / (C * dot(S_D.zw, S_D.zw) + Alpha); - Aij = C * dot(SD.xy, SD.zw); + Aij = C * dot(S_D.xy, S_D.zw); - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); - OpticalFlow.x = Aii.x * ((Alpha * UV.x) - (Aij * UV.y) - Bi.x); - OpticalFlow.y = Aii.y * ((Alpha * UV.y) - (Aij * OpticalFlow.x) - Bi.y); + Optical_Flow.x = Aii.x * ((Alpha * UV.x) - (Aij * UV.y) - Bi.x); + Optical_Flow.y = Aii.y * ((Alpha * UV.y) - (Aij * Optical_Flow.x) - Bi.y); } - void ProcessGradAvg(in float2 SampleNW, - in float2 SampleNE, - in float2 SampleSW, - in float2 SampleSE, - out float Grad, - out float2 Avg) + void ProcessGradAvg(in float2 Sample_NW, + in float2 Sample_NE, + in float2 Sample_SW, + in float2 Sample_SE, + out float Gradient, + out float2 Average) { // NW NE // SW SE - float4 GradUV = 0.0; - GradUV.xy = (SampleNW + SampleSW) - (SampleNE + SampleSE); // - GradUV.zw = (SampleNW + SampleNE) - (SampleSW + SampleSE); // - GradUV = GradUV * 0.5; - Grad = rsqrt((dot(GradUV.xzyw, GradUV.xzyw) * 0.25) + (E * E)); - Avg = (SampleNW + SampleNE + SampleSW + SampleSE) * 0.25; + float4 Sq_Gradient_UV = 0.0; + Sq_Gradient_UV.xy = (Sample_NW + Sample_SW) - (Sample_NE + Sample_SE); // + Sq_Gradient_UV.zw = (Sample_NW + Sample_NE) - (Sample_SW + Sample_SE); // + Sq_Gradient_UV = Sq_Gradient_UV * 0.5; + Gradient = rsqrt((dot(Sq_Gradient_UV.xzyw, Sq_Gradient_UV.xzyw) * 0.25) + (E * E)); + Average = (Sample_NW + Sample_NE + Sample_SW + Sample_SE) * 0.25; } - void ProcessArea(in float2 SampleUV[9], - inout float4 UVGrad, - inout float2 CenterAvg, - inout float2 UVAvg) + void ProcessArea(in float2 Sample_UV[9], + inout float4 UV_Gradient, + inout float2 Center_Average, + inout float2 UV_Average) { - float CenterGrad = 0.0; - float4 AreaGrad = 0.0; - float2 AreaAvg[4]; - float4 GradUV = 0.0; - float SqGradUV = 0.0; + float Center_Gradient = 0.0; + float4 Area_Gradient = 0.0; + float2 Area_Average[4]; + float4 Gradient_UV = 0.0; + float Sq_Gradient_UV = 0.0; // Center smoothness gradient and average // 0 3 6 // 1 4 7 // 2 5 8 - GradUV.xy = (SampleUV[0] + (SampleUV[1] * 2.0) + SampleUV[2]) - (SampleUV[6] + (SampleUV[7] * 2.0) + SampleUV[8]); // - GradUV.zw = (SampleUV[0] + (SampleUV[3] * 2.0) + SampleUV[6]) - (SampleUV[2] + (SampleUV[5] * 2.0) + SampleUV[8]); // - SqGradUV = dot(GradUV.xzyw / 4.0, GradUV.xzyw / 4.0) * 0.25; - CenterGrad = rsqrt(SqGradUV + (E * E)); + Gradient_UV.xy = (Sample_UV[0] + (Sample_UV[1] * 2.0) + Sample_UV[2]) - (Sample_UV[6] + (Sample_UV[7] * 2.0) + Sample_UV[8]); // + Gradient_UV.zw = (Sample_UV[0] + (Sample_UV[3] * 2.0) + Sample_UV[6]) - (Sample_UV[2] + (Sample_UV[5] * 2.0) + Sample_UV[8]); // + Sq_Gradient_UV = dot(Gradient_UV.xzyw / 4.0, Gradient_UV.xzyw / 4.0) * 0.25; + Center_Gradient = rsqrt(Sq_Gradient_UV + (E * E)); - CenterAvg += ((SampleUV[0] + SampleUV[6] + SampleUV[2] + SampleUV[8]) * 1.0); - CenterAvg += ((SampleUV[3] + SampleUV[1] + SampleUV[7] + SampleUV[5]) * 2.0); - CenterAvg += (SampleUV[4] * 4.0); - CenterAvg = CenterAvg / 16.0; + Center_Average += ((Sample_UV[0] + Sample_UV[6] + Sample_UV[2] + Sample_UV[8]) * 1.0); + Center_Average += ((Sample_UV[3] + Sample_UV[1] + Sample_UV[7] + Sample_UV[5]) * 2.0); + Center_Average += (Sample_UV[4] * 4.0); + Center_Average = Center_Average / 16.0; // North-west gradient and average // 0 3 . // 1 4 . // . . . - ProcessGradAvg(SampleUV[0], SampleUV[3], SampleUV[1], SampleUV[4], AreaGrad[0], AreaAvg[0]); + ProcessGradAvg(Sample_UV[0], Sample_UV[3], Sample_UV[1], Sample_UV[4], Area_Gradient[0], Area_Average[0]); // North-east gradient and average // . 3 6 // . 4 7 // . . . - ProcessGradAvg(SampleUV[3], SampleUV[6], SampleUV[4], SampleUV[7], AreaGrad[1], AreaAvg[1]); + ProcessGradAvg(Sample_UV[3], Sample_UV[6], Sample_UV[4], Sample_UV[7], Area_Gradient[1], Area_Average[1]); // South-west gradient and average // . . . // 1 4 . // 2 5 . - ProcessGradAvg(SampleUV[1], SampleUV[4], SampleUV[2], SampleUV[5], AreaGrad[2], AreaAvg[2]); + ProcessGradAvg(Sample_UV[1], Sample_UV[4], Sample_UV[2], Sample_UV[5], Area_Gradient[2], Area_Average[2]); // South-east and average // . . . // . 4 7 // . 5 8 - ProcessGradAvg(SampleUV[4], SampleUV[7], SampleUV[5], SampleUV[8], AreaGrad[3], AreaAvg[3]); + ProcessGradAvg(Sample_UV[4], Sample_UV[7], Sample_UV[5], Sample_UV[8], Area_Gradient[3], Area_Average[3]); - UVGrad = 0.5 * (CenterGrad + AreaGrad); - UVAvg = (AreaGrad[0] * AreaAvg[0]) + (AreaGrad[1] * AreaAvg[1]) + (AreaGrad[2] * AreaAvg[2]) + (AreaGrad[3] * AreaAvg[3]); + UV_Gradient = 0.5 * (Center_Gradient + Area_Gradient); + UV_Average = (Area_Gradient[0] * Area_Average[0]) + (Area_Gradient[1] * Area_Average[1]) + (Area_Gradient[2] * Area_Average[2]) + (Area_Gradient[3] * Area_Average[3]); } - void OpticalFlowTV(in sampler2D SourceUV, in float4 TexCoords[3], in float Level, out float2 OpticalFlow) + void Optical_Flow_TV(in sampler2D SourceUV, in float4 Coords[3], in float Level, out float2 Optical_Flow) { - OpticalFlow = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-3, Level - MaxLevel), 1e-7); + Optical_Flow = 0.0; + const float Alpha = max(ldexp(_Constraint * 1e-3, Level - Max_Level), 1e-7); // Load textures - float2 Current = tex2Dlod(Shared_Resources_MotionBlur::Sample_Common_1_A, float4(TexCoords[1].xz, 0.0, Level)).xy; - float2 Previous = tex2Dlod(Sample_Common_1_P, float4(TexCoords[1].xz, 0.0, Level)).xy; + float2 Current = tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_A, float4(Coords[1].xz, 0.0, Level)).xy; + float2 Previous = tex2Dlod(Sample_Common_1_P, float4(Coords[1].xz, 0.0, Level)).xy; // - float4 SD = tex2Dlod(Shared_Resources_MotionBlur::Sample_Common_1_B, float4(TexCoords[1].xz, 0.0, Level)); + float4 S_D = tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_B, float4(Coords[1].xz, 0.0, Level)); // - float2 TD = Current - Previous; + float2 T_D = Current - Previous; // Optical flow calculation - float2 SampleUV[9]; - float4 UVGrad = 0.0; - float2 CenterAvg = 0.0; - float2 UVAvg = 0.0; + float2 Sample_UV[9]; + float4 UV_Gradient = 0.0; + float2 Center_Average = 0.0; + float2 UV_Average = 0.0; - // SampleUV[i] + // Sample_UV[i] // 0 3 6 // 1 4 7 // 2 5 8 - SampleUV[0] = tex2D(SourceUV, TexCoords[0].xy).xy; - SampleUV[1] = tex2D(SourceUV, TexCoords[0].xz).xy; - SampleUV[2] = tex2D(SourceUV, TexCoords[0].xw).xy; - SampleUV[3] = tex2D(SourceUV, TexCoords[1].xy).xy; - SampleUV[4] = tex2D(SourceUV, TexCoords[1].xz).xy; - SampleUV[5] = tex2D(SourceUV, TexCoords[1].xw).xy; - SampleUV[6] = tex2D(SourceUV, TexCoords[2].xy).xy; - SampleUV[7] = tex2D(SourceUV, TexCoords[2].xz).xy; - SampleUV[8] = tex2D(SourceUV, TexCoords[2].xw).xy; - - ProcessArea(SampleUV, UVGrad, CenterAvg, UVAvg); + Sample_UV[0] = tex2D(SourceUV, Coords[0].xy).xy; + Sample_UV[1] = tex2D(SourceUV, Coords[0].xz).xy; + Sample_UV[2] = tex2D(SourceUV, Coords[0].xw).xy; + Sample_UV[3] = tex2D(SourceUV, Coords[1].xy).xy; + Sample_UV[4] = tex2D(SourceUV, Coords[1].xz).xy; + Sample_UV[5] = tex2D(SourceUV, Coords[1].xw).xy; + Sample_UV[6] = tex2D(SourceUV, Coords[2].xy).xy; + Sample_UV[7] = tex2D(SourceUV, Coords[2].xz).xy; + Sample_UV[8] = tex2D(SourceUV, Coords[2].xw).xy; + + ProcessArea(Sample_UV, UV_Gradient, Center_Average, UV_Average); float C = 0.0; float2 Aii = 0.0; @@ -581,97 +581,97 @@ namespace MotionBlur // Calculate forward motion vectors - C = dot(SD.xyzw, CenterAvg.xyxy) + dot(TD, 1.0); + C = dot(S_D.xyzw, Center_Average.xyxy) + dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); - Aii.x = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.xy, SD.xy))); - Aii.y = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.zw, SD.zw))); + Aii.x = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.xy, S_D.xy))); + Aii.y = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.zw, S_D.zw))); - Aij = C * dot(SD.xy, SD.zw); + Aij = C * dot(S_D.xy, S_D.zw); - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); - OpticalFlow.x = Aii.x * ((Alpha * UVAvg.x) - (Aij * CenterAvg.y) - Bi.x); - OpticalFlow.y = Aii.y * ((Alpha * UVAvg.y) - (Aij * OpticalFlow.x) - Bi.y); + Optical_Flow.x = Aii.x * ((Alpha * UV_Average.x) - (Aij * Center_Average.y) - Bi.x); + Optical_Flow.y = Aii.y * ((Alpha * UV_Average.y) - (Aij * Optical_Flow.x) - Bi.y); } - void Level_4_PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 Color : SV_Target0) + void Level_4_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float2 Color : SV_TARGET0) { - CoarseOpticalFlowTV(TexCoord, 6.5, 0.0, Color); + Coarse_Optical_Flow_TV(Coord, 6.5, 0.0, Color); } - void Level_3_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 Color : SV_Target0) + void Level_3_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Color : SV_TARGET0) { - OpticalFlowTV(Shared_Resources_MotionBlur::Sample_Common_4, TexCoords, 4.5, Color); + Optical_Flow_TV(Shared_Resources_Motion_Blur::Sample_Common_4, Coords, 4.5, Color); } - void Level_2_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 Color : SV_Target0) + void Level_2_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Color : SV_TARGET0) { - OpticalFlowTV(Shared_Resources_MotionBlur::Sample_Common_3, TexCoords, 2.5, Color); + Optical_Flow_TV(Shared_Resources_Motion_Blur::Sample_Common_3, Coords, 2.5, Color); } - void Level_1_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 Color : SV_Target0) + void Level_1_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(Shared_Resources_MotionBlur::Sample_Common_2, TexCoords, 0.5, Color.rg); - Color.ba = float2(0.0, _BlendFactor); + Optical_Flow_TV(Shared_Resources_Motion_Blur::Sample_Common_2, Coords, 0.5, Output_Color_0.rg); + Output_Color_0.ba = float2(0.0, _Blend_Factor); } - void Blit_Previous_PS(in float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Blit_Previous_PS(in float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoord); + Output_Color_0 = tex2D(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coord); } - void Post_Blur_0_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Post_Blur_0_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Sample_Optical_Flow, TexCoords, Color); - Color.a = 1.0; + Gaussian_Blur(Sample_Optical_Flow, Coords, Output_Color_0); + Output_Color_0.a = 1.0; } - void Post_Blur_1_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Post_Blur_1_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Shared_Resources_MotionBlur::Sample_Common_1_A, TexCoords, Color); - Color.a = 1.0; + Gaussian_Blur(Shared_Resources_Motion_Blur::Sample_Common_1_A, Coords, Output_Color_0); + Output_Color_0.a = 1.0; } - void MotionBlurPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target) + void Motion_BlurPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_Target) { - OutputColor0 = 0.0; + Output_Color_0 = 0.0; const int Samples = 4; float Noise = frac(52.9829189 * frac(dot(Position.xy, float2(0.06711056, 0.00583715)))); - float FrameRate = 1e+3 / _FrameTime; - float FrameTimeRatio = _TargetFrameRate / FrameRate; - float2 Velocity = (tex2Dlod(Shared_Resources_MotionBlur::Sample_Common_1_B, float4(TexCoord, 0.0, _MipBias)).xy / BUFFER_SIZE_1) * _Scale; - Velocity /= (_FrameRateScaling) ? FrameTimeRatio : 1.0; + float Frame_Rate = 1e+3 / _Frame_Time; + float Frame_Time_Ratio = _Target_Frame_Rate / Frame_Rate; + float2 Velocity = (tex2Dlod(Shared_Resources_Motion_Blur::Sample_Common_1_B, float4(Coord, 0.0, _Mip_Bias)).xy / BUFFER_SIZE_1) * _Scale; + Velocity /= (_FrameRateScaling) ? Frame_Time_Ratio : 1.0; for(int k = 0; k < Samples; ++k) { float2 Offset = Velocity * (Noise + k); - OutputColor0 += tex2D(Sample_Color, (TexCoord + Offset)); - OutputColor0 += tex2D(Sample_Color, (TexCoord - Offset)); + Output_Color_0 += tex2D(Sample_Color, (Coord + Offset)); + Output_Color_0 += tex2D(Sample_Color, (Coord - Offset)); } - OutputColor0 /= (Samples * 2.0); + Output_Color_0 /= (Samples * 2.0); } - technique cMotionBlur + technique cMotion_Blur { // Normalize current frame pass Normalize_Frame { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Normalize_Frame_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_0; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_0; } pass Blit { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Blit_Frame_PS; - RenderTarget = Shared_Resources_MotionBlur::Render_Common_1_A; + RenderTarget = Shared_Resources_Motion_Blur::Render_Common_1_A; } // Gaussian blur @@ -680,14 +680,14 @@ namespace MotionBlur { VertexShader = Blur_0_VS; PixelShader = Pre_Blur_0_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_1_B; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_1_B; } pass Blur1 { VertexShader = Blur_1_VS; PixelShader = Pre_Blur_1_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_1_A; // Save this to store later + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_1_A; // Save this to store later } // Calculate spatial derivative pyramid @@ -696,30 +696,30 @@ namespace MotionBlur { VertexShader = Derivatives_VS; PixelShader = Derivatives_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_1_B; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_1_B; } // Trilinear Optical Flow, calculate 2 levels at a time pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Level_4_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_4; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_4; } pass { VertexShader = Sample_3x3_4_VS; PixelShader = Level_3_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_3; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_3; } pass { VertexShader = Sample_3x3_3_VS; PixelShader = Level_2_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_2; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_2; } pass @@ -738,7 +738,7 @@ namespace MotionBlur pass Blit { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Blit_Previous_PS; RenderTarget = Render_Common_1_P; } @@ -749,22 +749,22 @@ namespace MotionBlur { VertexShader = Blur_0_VS; PixelShader = Post_Blur_0_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_1_A; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_1_A; } pass Blur1 { VertexShader = Blur_1_VS; PixelShader = Post_Blur_1_PS; - RenderTarget0 = Shared_Resources_MotionBlur::Render_Common_1_B; + RenderTarget0 = Shared_Resources_Motion_Blur::Render_Common_1_B; } // Motion blur pass { - VertexShader = PostProcessVS; - PixelShader = MotionBlurPS; + VertexShader = Basic_VS; + PixelShader = Motion_BlurPS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cMotionMask.fx b/shaders/cMotionMask.fx index 4ee31fb..6210b40 100644 --- a/shaders/cMotionMask.fx +++ b/shaders/cMotionMask.fx @@ -35,7 +35,7 @@ namespace FrameDifference { - uniform float _BlendFactor < + uniform float _Blend_Factor < ui_type = "slider"; ui_label = "Temporal blending factor"; ui_min = 0.0; @@ -68,11 +68,11 @@ namespace FrameDifference ui_label = "Normalize Input"; > = false; - texture2D RenderColor : COLOR; + texture2D Render_Color : COLOR; - sampler2D SampleColor + sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -128,76 +128,76 @@ namespace FrameDifference // 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 = TexCoord.xyxy * float4(2.0, -2.0, 0.0, 0.0) + float4(-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 = Coord.xyxy * float4(2.0, -2.0, 0.0, 0.0) + float4(-1.0, 1.0, 0.0, 1.0); } // Pixel shaders - void BlitPS0(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void BlitPS0(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - float3 Color = max(tex2D(SampleColor, TexCoord).rgb, exp2(-10.0)); - OutputColor0 = (_NormalizeInput) ? saturate(Color.xy / dot(Color, 1.0)) : max(max(Color.r, Color.g), Color.b); + float3 Color = max(tex2D(Sample_Color, Coord).rgb, exp2(-10.0)); + Output_Color_0 = (_NormalizeInput) ? saturate(Color.xy / dot(Color, 1.0)) : max(max(Color.r, Color.g), Color.b); } - void DifferencePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void DifferencePS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { float Difference = 0.0; if(_NormalizeInput) { - float2 Current = tex2D(SampleCurrent, TexCoord).rg; - float2 Previous = tex2D(SamplePrevious, TexCoord).rg; + float2 Current = tex2D(SampleCurrent, Coord).rg; + float2 Previous = tex2D(SamplePrevious, Coord).rg; Difference = abs(dot(Current - Previous, 1.0)) * _DifferenceWeight; } else { - float Current = tex2D(SampleCurrent, TexCoord).r; - float Previous = tex2D(SamplePrevious, TexCoord).r; + float Current = tex2D(SampleCurrent, Coord).r; + float Previous = tex2D(SamplePrevious, Coord).r; Difference = abs(Current - Previous) * _DifferenceWeight; } if (Difference <= _MinThreshold) { - OutputColor0 = 0.0; + Output_Color_0 = 0.0; } else if (Difference > _MaxThreshold) { - OutputColor0 = 1.0; + Output_Color_0 = 1.0; } else { - OutputColor0 = Difference; + Output_Color_0 = Difference; } - OutputColor0.a = _BlendFactor; + Output_Color_0.a = _Blend_Factor; } - void OutputPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void OutputPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = tex2D(SampleDifference, TexCoord).r; + Output_Color_0 = tex2D(SampleDifference, Coord).r; } - void BlitPS1(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void BlitPS1(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = tex2D(SampleCurrent, TexCoord); + Output_Color_0 = tex2D(SampleCurrent, Coord); } technique cFrameDifference { pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = BlitPS0; RenderTarget0 = RenderCurrent; } pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = DifferencePS; RenderTarget0 = RenderDifference; ClearRenderTargets = FALSE; @@ -209,7 +209,7 @@ namespace FrameDifference pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = OutputPS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; @@ -218,7 +218,7 @@ namespace FrameDifference pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = BlitPS1; RenderTarget0 = RenderPrevious; } diff --git a/shaders/cNoiseConvolution.fx b/shaders/cNoiseConvolution.fx index db52304..9d4a77a 100644 --- a/shaders/cNoiseConvolution.fx +++ b/shaders/cNoiseConvolution.fx @@ -46,11 +46,11 @@ uniform int _Samples < ui_min = 0; > = 8; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -61,11 +61,11 @@ 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 @@ -74,7 +74,7 @@ void PostProcessVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, static const float Pi = 3.1415926535897932384626433832795; -float2 VogelSample(int Index, int SamplesCount) +float2 Vogel_Sample(int Index, int SamplesCount) { const float GoldenAngle = Pi * (3.0 - sqrt(5.0)); float Radius = sqrt(float(Index) + 0.5) * rsqrt(float(SamplesCount)); @@ -91,11 +91,11 @@ float GradientNoise(float2 Position) return frac(Numbers.z * frac(dot(Position.xy, Numbers.xy))); } -void NoiseConvolutionPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void NoiseConvolutionPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = 0.0; + Output_Color_0 = 0.0; - const float2 PixelSize = 1.0 / uint2(BUFFER_WIDTH, BUFFER_HEIGHT); + const float2 Pixel_Size = 1.0 / int2(BUFFER_WIDTH, BUFFER_HEIGHT); float Noise = 2.0 * Pi * GradientNoise(Position.xy); float2 Rotation = 0.0; @@ -106,18 +106,18 @@ void NoiseConvolutionPS(in float4 Position : SV_Position, in float2 TexCoord : T for(int i = 0; i < _Samples; i++) { - float2 SampleOffset = mul(VogelSample(i, _Samples) * _Radius, RotationMatrix); - OutputColor0 += tex2Dlod(SampleColor, float4(TexCoord.xy + (SampleOffset * PixelSize), 0.0, 0.0)); + float2 SampleOffset = mul(Vogel_Sample(i, _Samples) * _Radius, RotationMatrix); + Output_Color_0 += tex2Dlod(Sample_Color, float4(Coord.xy + (SampleOffset * Pixel_Size), 0.0, 0.0)); } - OutputColor0 = OutputColor0 / _Samples; + Output_Color_0 = Output_Color_0 / _Samples; } technique cNoiseConvolution { pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = NoiseConvolutionPS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; diff --git a/shaders/cOpticalFlow.fx b/shaders/cOpticalFlow.fx index 069aa9b..f3cadbf 100644 --- a/shaders/cOpticalFlow.fx +++ b/shaders/cOpticalFlow.fx @@ -151,7 +151,7 @@ namespace Shared_Resources_OpticalFlow }; } -namespace OpticalFlow +namespace Optical_Flow { // Shader properties @@ -163,14 +163,14 @@ namespace OpticalFlow ui_max = 2.0; > = 1.0; - uniform float _MipBias < + uniform float _Mip_Bias < ui_type = "drag"; ui_category = "Optical flow"; ui_label = "Optical flow mipmap bias"; ui_min = 0.0; > = 0.0; - uniform float _BlendFactor < + uniform float _Blend_Factor < ui_type = "slider"; ui_category = "Optical flow"; ui_label = "Temporal Blending Factor"; @@ -178,13 +178,13 @@ namespace OpticalFlow ui_Max = 0.9; > = 0.1; - uniform bool _NormalizedShading < + uniform bool _Normalized_Shading < ui_type = "radio"; ui_category = "Velocity shading"; ui_label = "Normalize velocity shading"; > = true; - uniform float3 _BaseColorShift < + uniform float3 _Backgound_Color_Shift < ui_type = "color"; ui_category = "Velocity streaming"; ui_label = "Background color shift"; @@ -192,13 +192,13 @@ namespace OpticalFlow ui_max = 1.0; > = 0.0; - uniform float3 _LineColorShift < + uniform float3 _Line_Color_Shift < ui_type = "color"; ui_category = "Velocity streaming"; ui_label = "Line color shifting"; > = 1.0; - uniform float _LineOpacity < + uniform float _Line_Opacity < ui_type = "slider"; ui_category = "Velocity streaming"; ui_label = "Line opacity"; @@ -206,20 +206,20 @@ namespace OpticalFlow ui_max = 1.0; > = 1.0; - uniform bool _BackgroundColor < + uniform bool _Background_Color < ui_type = "radio"; ui_category = "Velocity streaming"; ui_label = "Plain base color"; > = false; - uniform bool _NormalDirection < + uniform bool _Normal_Direction < ui_type = "radio"; ui_category = "Velocity streaming"; ui_label = "Normalize direction"; ui_tooltip = "Normalize direction"; > = false; - uniform bool _ScaleLineVelocity < + uniform bool _Scale_Line_Velocity < ui_type = "radio"; ui_category = "Velocity streaming"; ui_label = "Scale velocity color"; @@ -294,16 +294,16 @@ namespace OpticalFlow // Optical flow visualization #if RENDER_VELOCITY_STREAMS - texture2D RenderLines + texture2D Render_Lines { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; }; - sampler2D SampleLines + sampler2D Sample_Lines { - Texture = RenderLines; + Texture = Render_Lines; AddressU = MIRROR; AddressV = MIRROR; MagFilter = LINEAR; @@ -312,7 +312,7 @@ namespace OpticalFlow }; #endif - sampler2D SampleColorGamma + sampler2D Sample_Color_Gamma { Texture = Render_Color; AddressU = MIRROR; @@ -324,14 +324,14 @@ namespace OpticalFlow // 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); } - static const float2 BlurOffsets[8] = + static const float2 Blur_Offsets[8] = { float2(0.0, 0.0), float2(0.0, 1.4850045), @@ -343,81 +343,81 @@ namespace OpticalFlow float2(0.0, 13.368189) }; - void Blur_0_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[8] : TEXCOORD0) + void Blur_0_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[8] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xyxy; + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xyxy; for(int i = 1; i < 8; i++) { - TexCoords[i].xy = VSTexCoord.xy - (BlurOffsets[i].yx / BUFFER_SIZE_1); - TexCoords[i].zw = VSTexCoord.xy + (BlurOffsets[i].yx / BUFFER_SIZE_1); + Coords[i].xy = VS_Coord.xy - (Blur_Offsets[i].yx / BUFFER_SIZE_1); + Coords[i].zw = VS_Coord.xy + (Blur_Offsets[i].yx / BUFFER_SIZE_1); } } - void Blur_1_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[8] : TEXCOORD0) + void Blur_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[8] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xyxy; + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xyxy; for(int i = 1; i < 8; i++) { - TexCoords[i].xy = VSTexCoord.xy - (BlurOffsets[i].xy / BUFFER_SIZE_1); - TexCoords[i].zw = VSTexCoord.xy + (BlurOffsets[i].xy / BUFFER_SIZE_1); + Coords[i].xy = VS_Coord.xy - (Blur_Offsets[i].xy / BUFFER_SIZE_1); + Coords[i].zw = VS_Coord.xy + (Blur_Offsets[i].xy / BUFFER_SIZE_1); } } - void Sample_3x3_VS(in uint ID : SV_VertexID, in float2 TexelSize, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_VS(in uint ID : SV_VERTEXID, in float2 Texel_Size, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { float2 VS_TexCoord = 0.0; - PostProcessVS(ID, Position, VS_TexCoord); + Basic_VS(ID, Position, VS_TexCoord); // Sample locations: // [0].xy [1].xy [2].xy // [0].xz [1].xz [2].xz // [0].xw [1].xw [2].xw - TexCoords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); - TexCoords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); - TexCoords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / TexelSize.xyyy); + Coords[0] = VS_TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); + Coords[1] = VS_TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); + Coords[2] = VS_TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) / Texel_Size.xyyy); } - void Sample_3x3_1_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_1_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_1, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_1, Position, Coords); } - void Sample_3x3_2_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_2_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_2, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_2, Position, Coords); } - void Sample_3x3_3_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_3_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_3, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_3, Position, Coords); } - void Sample_3x3_4_VS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoords[3] : TEXCOORD0) + void Sample_3x3_4_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coords[3] : TEXCOORD0) { - Sample_3x3_VS(ID, BUFFER_SIZE_4, Position, TexCoords); + Sample_3x3_VS(ID, BUFFER_SIZE_4, Position, Coords); } - void Derivatives_VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[2] : TEXCOORD0) + void Derivatives_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[2] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - TexCoords[0] = VSTexCoord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) / BUFFER_SIZE_1.xxyy); - TexCoords[1] = VSTexCoord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) / BUFFER_SIZE_1.xxyy); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Coords[0] = VS_Coord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) / BUFFER_SIZE_1.xxyy); + Coords[1] = VS_Coord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) / BUFFER_SIZE_1.xxyy); } - void VelocityStreamsVS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float2 Velocity : TEXCOORD0) + void Velocity_Streams_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float2 Velocity : TEXCOORD0) { - int LineID = ID / 2; // Line Index - int VertexID = ID % 2; // Vertex Index within the line (0 = start, 1 = end) + int Line_ID = ID / 2; // Line Index + int Vertex_ID = ID % 2; // Vertex Index within the line (0 = start, 1 = end) // Get Row (x) and Column (y) position - int Row = LineID / LINES_X; - int Column = LineID - LINES_X * Row; + int Row = Line_ID / LINES_X; + int Column = Line_ID - LINES_X * Row; // Compute origin (line-start) const float2 Spacing = float2(SPACE_X, SPACE_Y); @@ -425,11 +425,11 @@ namespace OpticalFlow float2 Origin = Offset + float2(Column, Row) * Spacing; // Get velocity from texture at origin location - const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); - float2 VelocityCoord; - VelocityCoord.xy = Origin.xy * PixelSize.xy; - VelocityCoord.y = 1.0 - VelocityCoord.y; - Velocity = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(VelocityCoord, 0.0, _MipBias)).xy; + const float2 Pixel_Size = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); + float2 Velocity_Coord = 0.0; + Velocity_Coord.xy = Origin.xy * Pixel_Size.xy; + Velocity_Coord.y = 1.0 - Velocity_Coord.y; + Velocity = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(Velocity_Coord, 0.0, _Mip_Bias)).xy; // Scale velocity float2 Direction = Velocity * VELOCITY_SCALE; @@ -440,41 +440,41 @@ namespace OpticalFlow // Color for fragmentshader Velocity = Direction * 0.2; - // Compute current vertex position (based on VertexID) - float2 VertexPosition = 0.0; + // Compute current vertex position (based on Vertex_ID) + float2 Vertex_Position = 0.0; - if(_NormalDirection) + if(_Normal_Direction) { // Lines: Normal to velocity direction Direction *= 0.5; - float2 DirectionNormal = float2(Direction.y, -Direction.x); - VertexPosition = Origin + Direction - DirectionNormal + DirectionNormal * VertexID * 2; + float2 Direction_Normal = float2(Direction.y, -Direction.x); + Vertex_Position = Origin + Direction - Direction_Normal + Direction_Normal * Vertex_ID * 2; } else { // Lines: Velocity direction - VertexPosition = Origin + Direction * VertexID; + Vertex_Position = Origin + Direction * Vertex_ID; } // Finish vertex position - float2 VertexPositionNormal = (VertexPosition + 0.5) * PixelSize; // [0, 1] - Position = float4(VertexPositionNormal * 2.0 - 1.0, 0.0, 1.0); // ndc: [-1, +1] + float2 Vertex_Position_Normal = (Vertex_Position + 0.5) * Pixel_Size; // [0, 1] + Position = float4(Vertex_Position_Normal * 2.0 - 1.0, 0.0, 1.0); // ndc: [-1, +1] } // Pixel Shaders - void Normalize_Frame_PS(in float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float2 Color : SV_Target0) + void Normalize_Frame_PS(in float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float2 Color : SV_TARGET0) { - float4 Frame = max(tex2D(Sample_Color, TexCoord), exp2(-10.0)); + float4 Frame = max(tex2D(Sample_Color, Coord), exp2(-10.0)); Color.xy = saturate(Frame.xy / dot(Frame.rgb, 1.0)); } - void Blit_Frame_PS(in float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Blit_Frame_PS(in float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Shared_Resources_OpticalFlow::Sample_Common_0, TexCoord); + Output_Color_0 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_0, Coord); } - static const float BlurWeights[8] = + static const float Blur_Weights[8] = { 0.079788454, 0.15186256, @@ -486,81 +486,81 @@ namespace OpticalFlow 0.0042996835 }; - void GaussianBlur(in sampler2D Source, in float4 TexCoords[8], out float4 Color) + void Gaussian_Blur(in sampler2D Source, in float4 Coords[8], out float4 Output_Color_0) { - float TotalWeights = BlurWeights[0]; - Color = (tex2D(Source, TexCoords[0].xy) * BlurWeights[0]); + float Total_Weights = Blur_Weights[0]; + Output_Color_0 = (tex2D(Source, Coords[0].xy) * Blur_Weights[0]); for(int i = 1; i < 8; i++) { - Color += (tex2D(Source, TexCoords[i].xy) * BlurWeights[i]); - Color += (tex2D(Source, TexCoords[i].zw) * BlurWeights[i]); - TotalWeights += (BlurWeights[i] * 2.0); + Output_Color_0 += (tex2D(Source, Coords[i].xy) * Blur_Weights[i]); + Output_Color_0 += (tex2D(Source, Coords[i].zw) * Blur_Weights[i]); + Total_Weights += (Blur_Weights[i] * 2.0); } - Color = Color / TotalWeights; + Output_Color_0 = Output_Color_0 / Total_Weights; } - void Pre_Blur_0_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Pre_Blur_0_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords, Color); + Gaussian_Blur(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords, Output_Color_0); } - void Pre_Blur_1_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Pre_Blur_1_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Shared_Resources_OpticalFlow::Sample_Common_1_B, TexCoords, Color); + Gaussian_Blur(Shared_Resources_OpticalFlow::Sample_Common_1_B, Coords, Output_Color_0); } - void Derivatives_PS(in float4 Position : SV_Position, in float4 TexCoords[2] : TEXCOORD0, out float4 Color : SV_Target0) + void Derivatives_PS(in float4 Position : SV_POSITION, in float4 Coords[2] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Bilinear 5x5 Sobel by CeeJayDK - // B1 B2 - // A0 A1 - // A2 B0 - // C0 C1 - float2 A0 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[0].xw).xy * 4.0; // <-1.5, +0.5> - float2 A1 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[0].yw).xy * 4.0; // <+1.5, +0.5> - float2 A2 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[0].xz).xy * 4.0; // <-1.5, -0.5> - float2 B0 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[0].yz).xy * 4.0; // <+1.5, -0.5> - float2 B1 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[1].xw).xy * 4.0; // <-0.5, +1.5> - float2 B2 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[1].yw).xy * 4.0; // <+0.5, +1.5> - float2 C0 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[1].xz).xy * 4.0; // <-0.5, -1.5> - float2 C1 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords[1].yz).xy * 4.0; // <+0.5, -1.5> + // B_1 B_2 + // A_0 A_1 + // A_2 B_0 + // C_0 C_1 + float2 A_0 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[0].xw).xy * 4.0; // <-1.5, +0.5> + float2 A_1 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[0].yw).xy * 4.0; // <+1.5, +0.5> + float2 A_2 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[0].xz).xy * 4.0; // <-1.5, -0.5> + float2 B_0 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[0].yz).xy * 4.0; // <+1.5, -0.5> + float2 B_1 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[1].xw).xy * 4.0; // <-0.5, +1.5> + float2 B_2 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[1].yw).xy * 4.0; // <+0.5, +1.5> + float2 C_0 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[1].xz).xy * 4.0; // <-0.5, -1.5> + float2 C_1 = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords[1].yz).xy * 4.0; // <+0.5, -1.5> // -1 0 +1 // -1 -2 0 +2 +1 // -2 -2 0 +2 +2 // -1 -2 0 +2 +1 // -1 0 +1 - Color.xy = ((B2 + A1 + B0 + C1) - (B1 + A0 + A2 + C0)) / 12.0; + Output_Color_0.xy = ((B_2 + A_1 + B_0 + C_1) - (B_1 + A_0 + A_2 + C_0)) / 12.0; // +1 +2 +1 // +1 +2 +2 +2 +1 // 0 0 0 0 0 // -1 -2 -2 -2 -1 // -1 -2 -1 - Color.zw = ((A0 + B1 + B2 + A1) - (A2 + C0 + C1 + B0)) / 12.0; - Color.xz *= rsqrt(dot(Color.xz, Color.xz) + 1.0); - Color.yw *= rsqrt(dot(Color.yw, Color.yw) + 1.0); + Output_Color_0.zw = ((A_0 + B_1 + B_2 + A_1) - (A_2 + C_0 + C_1 + B_0)) / 12.0; + Output_Color_0.xz *= rsqrt(dot(Output_Color_0.xz, Output_Color_0.xz) + 1.0); + Output_Color_0.yw *= rsqrt(dot(Output_Color_0.yw, Output_Color_0.yw) + 1.0); } - #define MaxLevel 7 + #define Max_Level 7 #define E 1e-4 - void CoarseOpticalFlowTV(in float2 TexCoord, in float Level, in float2 UV, out float2 OpticalFlow) + void Coarse_Optical_Flow_TV(in float2 Coord, in float Level, in float2 UV, out float2 Optical_Flow) { - OpticalFlow = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7); + Optical_Flow = 0.0; + const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7); // Load textures - float2 Current = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_A, float4(TexCoord, 0.0, Level)).xy; - float2 Previous = tex2Dlod(Sample_Common_1_P, float4(TexCoord, 0.0, Level)).xy; + float2 Current = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_A, float4(Coord, 0.0, Level)).xy; + float2 Previous = tex2Dlod(Sample_Common_1_P, float4(Coord, 0.0, Level)).xy; // - float4 SD = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(TexCoord, 0.0, Level)); + float4 S_D = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(Coord, 0.0, Level)); // - float2 TD = Current - Previous; + float2 T_D = Current - Previous; // Calculate constancy term float C = 0.0; @@ -570,128 +570,128 @@ namespace OpticalFlow // Calculate forward motion vectors - C = dot(TD, 1.0); + C = dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); - Aii.x = 1.0 / (C * dot(SD.xy, SD.xy) + Alpha); - Aii.y = 1.0 / (C * dot(SD.zw, SD.zw) + Alpha); + Aii.x = 1.0 / (C * dot(S_D.xy, S_D.xy) + Alpha); + Aii.y = 1.0 / (C * dot(S_D.zw, S_D.zw) + Alpha); - Aij = C * dot(SD.xy, SD.zw); + Aij = C * dot(S_D.xy, S_D.zw); - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); - OpticalFlow.x = Aii.x * ((Alpha * UV.x) - (Aij * UV.y) - Bi.x); - OpticalFlow.y = Aii.y * ((Alpha * UV.y) - (Aij * OpticalFlow.x) - Bi.y); + Optical_Flow.x = Aii.x * ((Alpha * UV.x) - (Aij * UV.y) - Bi.x); + Optical_Flow.y = Aii.y * ((Alpha * UV.y) - (Aij * Optical_Flow.x) - Bi.y); } - void ProcessGradAvg(in float2 SampleNW, - in float2 SampleNE, - in float2 SampleSW, - in float2 SampleSE, - out float Grad, - out float2 Avg) + void ProcessGradAvg(in float2 Sample_NW, + in float2 Sample_NE, + in float2 Sample_SW, + in float2 Sample_SE, + out float Gradient, + out float2 Average) { // NW NE // SW SE - float4 GradUV = 0.0; - GradUV.xy = (SampleNW + SampleSW) - (SampleNE + SampleSE); // - GradUV.zw = (SampleNW + SampleNE) - (SampleSW + SampleSE); // - GradUV = GradUV * 0.5; - Grad = rsqrt((dot(GradUV.xzyw, GradUV.xzyw) * 0.25) + (E * E)); - Avg = (SampleNW + SampleNE + SampleSW + SampleSE) * 0.25; + float4 Sq_Gradient_UV = 0.0; + Sq_Gradient_UV.xy = (Sample_NW + Sample_SW) - (Sample_NE + Sample_SE); // + Sq_Gradient_UV.zw = (Sample_NW + Sample_NE) - (Sample_SW + Sample_SE); // + Sq_Gradient_UV = Sq_Gradient_UV * 0.5; + Gradient = rsqrt((dot(Sq_Gradient_UV.xzyw, Sq_Gradient_UV.xzyw) * 0.25) + (E * E)); + Average = (Sample_NW + Sample_NE + Sample_SW + Sample_SE) * 0.25; } - void ProcessArea(in float2 SampleUV[9], - inout float4 UVGrad, - inout float2 CenterAvg, - inout float2 UVAvg) + void ProcessArea(in float2 Sample_UV[9], + inout float4 UV_Gradient, + inout float2 Center_Average, + inout float2 UV_Average) { - float CenterGrad = 0.0; - float4 AreaGrad = 0.0; - float2 AreaAvg[4]; - float4 GradUV = 0.0; - float SqGradUV = 0.0; + float Center_Gradient = 0.0; + float4 Area_Gradient = 0.0; + float2 Area_Average[4]; + float4 Gradient_UV = 0.0; + float Sq_Gradient_UV = 0.0; // Center smoothness gradient and average // 0 3 6 // 1 4 7 // 2 5 8 - GradUV.xy = (SampleUV[0] + (SampleUV[1] * 2.0) + SampleUV[2]) - (SampleUV[6] + (SampleUV[7] * 2.0) + SampleUV[8]); // - GradUV.zw = (SampleUV[0] + (SampleUV[3] * 2.0) + SampleUV[6]) - (SampleUV[2] + (SampleUV[5] * 2.0) + SampleUV[8]); // - SqGradUV = dot(GradUV.xzyw / 4.0, GradUV.xzyw / 4.0) * 0.25; - CenterGrad = rsqrt(SqGradUV + (E * E)); + Gradient_UV.xy = (Sample_UV[0] + (Sample_UV[1] * 2.0) + Sample_UV[2]) - (Sample_UV[6] + (Sample_UV[7] * 2.0) + Sample_UV[8]); // + Gradient_UV.zw = (Sample_UV[0] + (Sample_UV[3] * 2.0) + Sample_UV[6]) - (Sample_UV[2] + (Sample_UV[5] * 2.0) + Sample_UV[8]); // + Sq_Gradient_UV = dot(Gradient_UV.xzyw / 4.0, Gradient_UV.xzyw / 4.0) * 0.25; + Center_Gradient = rsqrt(Sq_Gradient_UV + (E * E)); - CenterAvg += ((SampleUV[0] + SampleUV[6] + SampleUV[2] + SampleUV[8]) * 1.0); - CenterAvg += ((SampleUV[3] + SampleUV[1] + SampleUV[7] + SampleUV[5]) * 2.0); - CenterAvg += (SampleUV[4] * 4.0); - CenterAvg = CenterAvg / 16.0; + Center_Average += ((Sample_UV[0] + Sample_UV[6] + Sample_UV[2] + Sample_UV[8]) * 1.0); + Center_Average += ((Sample_UV[3] + Sample_UV[1] + Sample_UV[7] + Sample_UV[5]) * 2.0); + Center_Average += (Sample_UV[4] * 4.0); + Center_Average = Center_Average / 16.0; // North-west gradient and average // 0 3 . // 1 4 . // . . . - ProcessGradAvg(SampleUV[0], SampleUV[3], SampleUV[1], SampleUV[4], AreaGrad[0], AreaAvg[0]); + ProcessGradAvg(Sample_UV[0], Sample_UV[3], Sample_UV[1], Sample_UV[4], Area_Gradient[0], Area_Average[0]); // North-east gradient and average // . 3 6 // . 4 7 // . . . - ProcessGradAvg(SampleUV[3], SampleUV[6], SampleUV[4], SampleUV[7], AreaGrad[1], AreaAvg[1]); + ProcessGradAvg(Sample_UV[3], Sample_UV[6], Sample_UV[4], Sample_UV[7], Area_Gradient[1], Area_Average[1]); // South-west gradient and average // . . . // 1 4 . // 2 5 . - ProcessGradAvg(SampleUV[1], SampleUV[4], SampleUV[2], SampleUV[5], AreaGrad[2], AreaAvg[2]); + ProcessGradAvg(Sample_UV[1], Sample_UV[4], Sample_UV[2], Sample_UV[5], Area_Gradient[2], Area_Average[2]); // South-east and average // . . . // . 4 7 // . 5 8 - ProcessGradAvg(SampleUV[4], SampleUV[7], SampleUV[5], SampleUV[8], AreaGrad[3], AreaAvg[3]); + ProcessGradAvg(Sample_UV[4], Sample_UV[7], Sample_UV[5], Sample_UV[8], Area_Gradient[3], Area_Average[3]); - UVGrad = 0.5 * (CenterGrad + AreaGrad); - UVAvg = (AreaGrad[0] * AreaAvg[0]) + (AreaGrad[1] * AreaAvg[1]) + (AreaGrad[2] * AreaAvg[2]) + (AreaGrad[3] * AreaAvg[3]); + UV_Gradient = 0.5 * (Center_Gradient + Area_Gradient); + UV_Average = (Area_Gradient[0] * Area_Average[0]) + (Area_Gradient[1] * Area_Average[1]) + (Area_Gradient[2] * Area_Average[2]) + (Area_Gradient[3] * Area_Average[3]); } - void OpticalFlowTV(in sampler2D SourceUV, in float4 TexCoords[3], in float Level, out float2 OpticalFlow) + void Optical_Flow_TV(in sampler2D SourceUV, in float4 Coords[3], in float Level, out float2 Optical_Flow) { - OpticalFlow = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7); + Optical_Flow = 0.0; + const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7); // Load textures - float2 Current = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_A, float4(TexCoords[1].xz, 0.0, Level)).xy; - float2 Previous = tex2Dlod(Sample_Common_1_P, float4(TexCoords[1].xz, 0.0, Level)).xy; + float2 Current = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_A, float4(Coords[1].xz, 0.0, Level)).xy; + float2 Previous = tex2Dlod(Sample_Common_1_P, float4(Coords[1].xz, 0.0, Level)).xy; // - float4 SD = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(TexCoords[1].xz, 0.0, Level)); + float4 S_D = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(Coords[1].xz, 0.0, Level)); // - float2 TD = Current - Previous; + float2 T_D = Current - Previous; // Optical flow calculation - float2 SampleUV[9]; - float4 UVGrad = 0.0; - float2 CenterAvg = 0.0; - float2 UVAvg = 0.0; + float2 Sample_UV[9]; + float4 UV_Gradient = 0.0; + float2 Center_Average = 0.0; + float2 UV_Average = 0.0; - // SampleUV[i] + // Sample_UV[i] // 0 3 6 // 1 4 7 // 2 5 8 - SampleUV[0] = tex2D(SourceUV, TexCoords[0].xy).xy; - SampleUV[1] = tex2D(SourceUV, TexCoords[0].xz).xy; - SampleUV[2] = tex2D(SourceUV, TexCoords[0].xw).xy; - SampleUV[3] = tex2D(SourceUV, TexCoords[1].xy).xy; - SampleUV[4] = tex2D(SourceUV, TexCoords[1].xz).xy; - SampleUV[5] = tex2D(SourceUV, TexCoords[1].xw).xy; - SampleUV[6] = tex2D(SourceUV, TexCoords[2].xy).xy; - SampleUV[7] = tex2D(SourceUV, TexCoords[2].xz).xy; - SampleUV[8] = tex2D(SourceUV, TexCoords[2].xw).xy; - - ProcessArea(SampleUV, UVGrad, CenterAvg, UVAvg); + Sample_UV[0] = tex2D(SourceUV, Coords[0].xy).xy; + Sample_UV[1] = tex2D(SourceUV, Coords[0].xz).xy; + Sample_UV[2] = tex2D(SourceUV, Coords[0].xw).xy; + Sample_UV[3] = tex2D(SourceUV, Coords[1].xy).xy; + Sample_UV[4] = tex2D(SourceUV, Coords[1].xz).xy; + Sample_UV[5] = tex2D(SourceUV, Coords[1].xw).xy; + Sample_UV[6] = tex2D(SourceUV, Coords[2].xy).xy; + Sample_UV[7] = tex2D(SourceUV, Coords[2].xz).xy; + Sample_UV[8] = tex2D(SourceUV, Coords[2].xw).xy; + + ProcessArea(Sample_UV, UV_Gradient, Center_Average, UV_Average); float C = 0.0; float2 Aii = 0.0; @@ -700,92 +700,92 @@ namespace OpticalFlow // Calculate forward motion vectors - C = dot(SD.xyzw, CenterAvg.xyxy) + dot(TD, 1.0); + C = dot(S_D.xyzw, Center_Average.xyxy) + dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); - Aii.x = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.xy, SD.xy))); - Aii.y = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.zw, SD.zw))); + Aii.x = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.xy, S_D.xy))); + Aii.y = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.zw, S_D.zw))); - Aij = C * dot(SD.xy, SD.zw); + Aij = C * dot(S_D.xy, S_D.zw); - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); - OpticalFlow.x = Aii.x * ((Alpha * UVAvg.x) - (Aij * CenterAvg.y) - Bi.x); - OpticalFlow.y = Aii.y * ((Alpha * UVAvg.y) - (Aij * OpticalFlow.x) - Bi.y); + Optical_Flow.x = Aii.x * ((Alpha * UV_Average.x) - (Aij * Center_Average.y) - Bi.x); + Optical_Flow.y = Aii.y * ((Alpha * UV_Average.y) - (Aij * Optical_Flow.x) - Bi.y); } - void Level_4_PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 Color : SV_Target0) + void Level_4_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float2 Color : SV_TARGET0) { - CoarseOpticalFlowTV(TexCoord, 6.5, 0.0, Color); + Coarse_Optical_Flow_TV(Coord, 6.5, 0.0, Color); } - void Level_3_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 Color : SV_Target0) + void Level_3_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Color : SV_TARGET0) { - OpticalFlowTV(Shared_Resources_OpticalFlow::Sample_Common_4, TexCoords, 4.5, Color); + Optical_Flow_TV(Shared_Resources_OpticalFlow::Sample_Common_4, Coords, 4.5, Color); } - void Level_2_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 Color : SV_Target0) + void Level_2_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Color : SV_TARGET0) { - OpticalFlowTV(Shared_Resources_OpticalFlow::Sample_Common_3, TexCoords, 2.5, Color); + Optical_Flow_TV(Shared_Resources_OpticalFlow::Sample_Common_3, Coords, 2.5, Color); } - void Level_1_PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 Color : SV_Target0) + void Level_1_PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(Shared_Resources_OpticalFlow::Sample_Common_2, TexCoords, 0.5, Color.rg); - Color.ba = float2(0.0, _BlendFactor); + Optical_Flow_TV(Shared_Resources_OpticalFlow::Sample_Common_2, Coords, 0.5, Output_Color_0.rg); + Output_Color_0.ba = float2(0.0, _Blend_Factor); } - void Blit_Previous_PS(in float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Blit_Previous_PS(in float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoord); + Output_Color_0 - tex2D(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coord); } - void Post_Blur_0_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Post_Blur_0_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Sample_Optical_Flow, TexCoords, Color); - Color.a = 1.0; + Gaussian_Blur(Sample_Optical_Flow, Coords, Output_Color_0); + Output_Color_0.a = 1.0; } - void Post_Blur_1_PS(in float4 Position : SV_Position, in float4 TexCoords[8] : TEXCOORD0, out float4 Color : SV_Target0) + void Post_Blur_1_PS(in float4 Position : SV_POSITION, in float4 Coords[8] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - GaussianBlur(Shared_Resources_OpticalFlow::Sample_Common_1_A, TexCoords, Color); - Color.a = 1.0; + Gaussian_Blur(Shared_Resources_OpticalFlow::Sample_Common_1_A, Coords, Output_Color_0); + Output_Color_0.a = 1.0; } - void VelocityShadingPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target) + void Velocity_Shading_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_Target) { - float2 Velocity = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(TexCoord, 0.0, _MipBias)).xy; + float2 Velocity = tex2Dlod(Shared_Resources_OpticalFlow::Sample_Common_1_B, float4(Coord, 0.0, _Mip_Bias)).xy; - if(_NormalizedShading) + if(_Normalized_Shading) { - float VelocityLength = saturate(rsqrt(dot(Velocity, Velocity))); - OutputColor0.rg = (Velocity * VelocityLength) * 0.5 + 0.5; - OutputColor0.b = -dot(OutputColor0.rg, 1.0) * 0.5 + 1.0; - OutputColor0.rgb /= max(max(OutputColor0.x, OutputColor0.y), OutputColor0.z); - OutputColor0.a = 1.0; + float Velocity_Length = saturate(rsqrt(dot(Velocity, Velocity))); + Output_Color_0.rg = (Velocity * Velocity_Length) * 0.5 + 0.5; + Output_Color_0.b = -dot(Output_Color_0.rg, 1.0) * 0.5 + 1.0; + Output_Color_0.rgb /= max(max(Output_Color_0.x, Output_Color_0.y), Output_Color_0.z); + Output_Color_0.a = 1.0; } else { - OutputColor0 = float4(Velocity, 0.0, 1.0); + Output_Color_0 = float4(Velocity, 0.0, 1.0); } } #if RENDER_VELOCITY_STREAMS - void VelocityStreamsPS(in float4 Position : SV_Position, in float2 Velocity : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void Velocity_Streams_PS(in float4 Position : SV_POSITION, in float2 Velocity : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0.rg = (_ScaleLineVelocity) ? (Velocity.xy / (length(Velocity) * VELOCITY_SCALE * 0.05)) : normalize(Velocity.xy); - OutputColor0.rg = OutputColor0.xy * 0.5 + 0.5; - OutputColor0.b = -dot(OutputColor0.rg, 1.0) * 0.5 + 1.0; - OutputColor0.rgb /= max(max(OutputColor0.x, OutputColor0.y), OutputColor0.z); - OutputColor0.a = 1.0; + Output_Color_0.rg = (_Scale_Line_Velocity) ? (Velocity.xy / (length(Velocity) * VELOCITY_SCALE * 0.05)) : normalize(Velocity.xy); + Output_Color_0.rg = Output_Color_0.xy * 0.5 + 0.5; + Output_Color_0.b = -dot(Output_Color_0.rg, 1.0) * 0.5 + 1.0; + Output_Color_0.rgb /= max(max(Output_Color_0.x, Output_Color_0.y), Output_Color_0.z); + Output_Color_0.a = 1.0; } - void VelocityStreamsDisplayPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float3 OutputColor0 : SV_Target0) + void Velocity_Streams_Display_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float3 Output_Color_0 : SV_TARGET0) { - float4 Lines = tex2D(SampleLines, TexCoord); - float3 MainColor = (_BackgroundColor) ? _BaseColorShift : tex2D(SampleColorGamma, TexCoord).rgb * _BaseColorShift; - OutputColor0 = lerp(MainColor, Lines.rgb * _LineColorShift, Lines.aaa * _LineOpacity); + float4 Lines = tex2D(Sample_Lines, Coord); + float3 Main_Color = (_Background_Color) ? _Backgound_Color_Shift : tex2D(Sample_Color_Gamma, Coord).rgb * _Backgound_Color_Shift; + Output_Color_0 = lerp(Main_Color, Lines.rgb * _Line_Color_Shift, Lines.aaa * _Line_Opacity); } #endif @@ -795,14 +795,14 @@ namespace OpticalFlow pass Normalize_Frame { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Normalize_Frame_PS; RenderTarget0 = Shared_Resources_OpticalFlow::Render_Common_0; } pass Blit { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Blit_Frame_PS; RenderTarget = Shared_Resources_OpticalFlow::Render_Common_1_A; } @@ -836,7 +836,7 @@ namespace OpticalFlow pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Level_4_PS; RenderTarget0 = Shared_Resources_OpticalFlow::Render_Common_4; } @@ -871,7 +871,7 @@ namespace OpticalFlow pass Blit { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Blit_Previous_PS; RenderTarget = Render_Common_1_P; } @@ -900,23 +900,23 @@ namespace OpticalFlow { PrimitiveTopology = LINELIST; VertexCount = NUM_LINES * 2; - VertexShader = VelocityStreamsVS; - PixelShader = VelocityStreamsPS; + VertexShader = Velocity_Streams_VS; + PixelShader = Velocity_Streams_PS; ClearRenderTargets = TRUE; - RenderTarget0 = RenderLines; + RenderTarget0 = Render_Lines; } pass { - VertexShader = PostProcessVS; - PixelShader = VelocityStreamsDisplayPS; + VertexShader = Basic_VS; + PixelShader = Velocity_Streams_Display_PS; ClearRenderTargets = FALSE; } #else pass { - VertexShader = PostProcessVS; - PixelShader = VelocityShadingPS; + VertexShader = Basic_VS; + PixelShader = Velocity_Shading_PS; } #endif } diff --git a/shaders/cOverlay.fx b/shaders/cOverlay.fx index 1c68b75..e2e1f4c 100644 --- a/shaders/cOverlay.fx +++ b/shaders/cOverlay.fx @@ -33,28 +33,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -uniform float2 _TexScale < +uniform float2 _Tex_Scale < ui_label = "Scale"; ui_category = "Texture"; ui_type = "drag"; ui_step = 0.001; > = 1.0; -uniform float2 _TexOffset < +uniform float2 _Tex_Offset < ui_label = "Offset"; ui_category = "Texture"; ui_type = "drag"; ui_step = 0.001; > = float2(0.0, 0.0); -uniform float2 _MaskScale < +uniform float2 _Mask_Scale < ui_type = "drag"; ui_label = "Scale"; ui_category = "Mask"; ui_min = 0.0; > = float2(0.0, 0.0); -uniform float2 _MaskOffset < +uniform float2 _Mask_Offset < ui_type = "drag"; ui_label = "Scale"; ui_category = "Mask"; @@ -65,11 +65,11 @@ uniform float2 _MaskOffset < #define ENABLE_POINT_SAMPLING 0 #endif -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; AddressU = MIRROR; AddressV = MIRROR; #if ENABLE_POINT_SAMPLING @@ -86,41 +86,41 @@ sampler2D SampleColor #endif }; -void OverlayVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord : TEXCOORD0) +void Overlay_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord : TEXCOORD0) { - TexCoord = 0.0; - TexCoord.x = (ID == 2) ? 2.0 : 0.0; - TexCoord.y = (ID == 1) ? 2.0 : 0.0; - Position = float4(TexCoord.xy * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); + Coord = 0.0; + Coord.x = (ID == 2) ? 2.0 : 0.0; + Coord.y = (ID == 1) ? 2.0 : 0.0; + Position = float4(Coord.xy * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); // Scale texture coordinates from [0, 1] to [-1, 1] range - TexCoord.zw = TexCoord.xy * 2.0 - 1.0; + Coord.zw = Coord.xy * 2.0 - 1.0; // Scale and offset in [-1, 1] range - TexCoord.zw = TexCoord.zw * _TexScale + _TexOffset; + Coord.zw = Coord.zw * _Tex_Scale + _Tex_Offset; // Scale texture coordinates from [-1, 1] to [0, 1] range - TexCoord.zw = TexCoord.zw * 0.5 + 0.5; + Coord.zw = Coord.zw * 0.5 + 0.5; } -void OverlayPS(in float4 Position : SV_Position, in float4 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Overlay_PS(in float4 Position : SV_POSITION, in float4 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - float4 InputColor = tex2D(SampleColor, TexCoord.zw); + float4 Color = tex2D(Sample_Color, Coord.zw); // Output a rectangle - float2 MaskCoord = TexCoord.xy; - float2 Scale = -_MaskScale * 0.5 + 0.5; - float2 Shaper = step(Scale, MaskCoord.xy) * step(Scale, 1.0 - MaskCoord.xy); + float2 Mask_Coord = Coord.xy; + float2 Scale = -_Mask_Scale * 0.5 + 0.5; + float2 Shaper = step(Scale, Mask_Coord.xy) * step(Scale, 1.0 - Mask_Coord.xy); float Crop = Shaper.x * Shaper.y; - OutputColor0.rgb = InputColor.rgb; - OutputColor0.a = Crop; + Output_Color_0.rgb = Color.rgb; + Output_Color_0.a = Crop; } technique cOverlay { pass { - VertexShader = OverlayVS; - PixelShader = OverlayPS; + VertexShader = Overlay_VS; + PixelShader = Overlay_PS; // Blend the rectangle with the backbuffer ClearRenderTargets = FALSE; BlendEnable = TRUE; diff --git a/shaders/cPingPong.fx b/shaders/cPingPong.fx index 7a8b4fb..6473eef 100644 --- a/shaders/cPingPong.fx +++ b/shaders/cPingPong.fx @@ -42,11 +42,11 @@ uniform int _Radius < #define ENABLE_PINGPONG 1 #endif -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -55,16 +55,16 @@ sampler2D SampleColor #endif }; -texture2D RenderBufferA +texture2D Render_Buffer_A { Width = BUFFER_WIDTH / 2; Height = BUFFER_HEIGHT / 2; Format = RGBA8; }; -sampler2D SampleBufferA +sampler2D Sample_Buffer_A { - Texture = RenderBufferA; + Texture = Render_Buffer_A; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -73,16 +73,16 @@ sampler2D SampleBufferA #endif }; -texture2D RenderBufferB +texture2D Render_Buffer_B { Width = BUFFER_WIDTH / 2; Height = BUFFER_HEIGHT / 2; Format = RGBA8; }; -sampler2D SampleBufferB +sampler2D Sample_Buffer_B { - Texture = RenderBufferB; + Texture = Render_Buffer_B; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -93,11 +93,11 @@ sampler2D SampleBufferB // 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 @@ -115,11 +115,11 @@ void PostProcessVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, 3. The way the player hits the ball (PixelShader) This shader's technique is an example of the 2 steps above - Pregame: Set up 2 players (RenderBufferA and RenderBufferB) - PingPong1: RenderBufferA hits (HorizontalBlurPS0) to RenderBufferB - PingPong2: RenderBufferB hits (VerticalBlurPS0) to RenderBufferA - PingPong3: RenderBufferA hits (HorizontalBlurPS1) to RenderBufferB - PingPong4: RenderBufferB hits (VerticalBlurPS1) to RenderBufferA + Pregame: Set up 2 players (Render_Buffer_A and Render_Buffer_B) + PingPong1: Render_Buffer_A hits (Horizontal_Blur_0_PS) to Render_Buffer_B + PingPong2: Render_Buffer_B hits (Vertical_Blur_0_PS) to Render_Buffer_A + PingPong3: Render_Buffer_A hits (Horizontal_Blur_1_PS) to Render_Buffer_B + PingPong4: Render_Buffer_B hits (Vertical_Blur_1_PS) to Render_Buffer_A "Why two textures? Can't we just read and write to one texture"? Unfortunately we cannot sample from and to memory at the same time @@ -131,57 +131,57 @@ void PostProcessVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, components that do not need pingponging (see my motion shaders as an example of this) */ -float4 GaussianBlur(sampler2D Source, float2 TexCoord, const float2 Direction) +float4 Gaussian_Blur(sampler2D Source, float2 Coord, const float2 Direction) { - float4 Output; - const float2 PixelSize = (2.0 / float2(BUFFER_WIDTH, BUFFER_HEIGHT)) * Direction; + float4 Output = 0.0; + const float2 Pixel_Size = (2.0 / float2(BUFFER_WIDTH, BUFFER_HEIGHT)) * Direction; const float Weight = 1.0 / _Radius; for(float Index = -_Radius + 0.5; Index <= _Radius; Index += 2.0) { - Output += tex2Dlod(Source, float4(TexCoord + Index * PixelSize, 0.0, 0.0)) * Weight; + Output += tex2Dlod(Source, float4(Coord + Index * Pixel_Size, 0.0, 0.0)) * Weight; } return Output; } -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) { - OutputColor0 = tex2D(SampleColor, TexCoord); + Output_Color_0 = tex2D(Sample_Color, Coord); } -void HorizontalBlurPS0(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Horizontal_Blur_0_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = GaussianBlur(SampleBufferA, TexCoord, float2(1.0, 0.0)); + Output_Color_0 = Gaussian_Blur(Sample_Buffer_A, Coord, float2(1.0, 0.0)); } -void VerticalBlurPS0(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Vertical_Blur_0_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = GaussianBlur(SampleBufferB, TexCoord, float2(0.0, 1.0)); + Output_Color_0 = Gaussian_Blur(Sample_Buffer_B, Coord, float2(0.0, 1.0)); } -void HorizontalBlurPS1(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Horizontal_Blur_1_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = GaussianBlur(SampleBufferA, TexCoord, float2(1.0, 0.0)); + Output_Color_0 = Gaussian_Blur(Sample_Buffer_A, Coord, float2(1.0, 0.0)); } -void VerticalBlurPS1(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Vertical_Blur_1_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = GaussianBlur(SampleBufferB, TexCoord, float2(0.0, 1.0)); + Output_Color_0 = Gaussian_Blur(Sample_Buffer_B, Coord, float2(0.0, 1.0)); } -void OutputPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void OutputPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = tex2D(SampleBufferA, TexCoord); + Output_Color_0 = tex2D(Sample_Buffer_A, Coord); } technique cPingPong { pass { - VertexShader = PostProcessVS; - PixelShader = BlitPS; - RenderTarget0 = RenderBufferA; + VertexShader = Basic_VS; + PixelShader = Blit_PS; + RenderTarget0 = Render_Buffer_A; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif @@ -189,9 +189,9 @@ technique cPingPong pass PingPong1 { - VertexShader = PostProcessVS; - PixelShader = HorizontalBlurPS0; - RenderTarget0 = RenderBufferB; + VertexShader = Basic_VS; + PixelShader = Horizontal_Blur_0_PS; + RenderTarget0 = Render_Buffer_B; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif @@ -199,9 +199,9 @@ technique cPingPong pass PingPong2 { - VertexShader = PostProcessVS; - PixelShader = VerticalBlurPS0; - RenderTarget0 = RenderBufferA; + VertexShader = Basic_VS; + PixelShader = Vertical_Blur_0_PS; + RenderTarget0 = Render_Buffer_A; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif @@ -210,9 +210,9 @@ technique cPingPong #if ENABLE_PINGPONG pass PingPong3 { - VertexShader = PostProcessVS; - PixelShader = HorizontalBlurPS1; - RenderTarget0 = RenderBufferB; + VertexShader = Basic_VS; + PixelShader = Horizontal_Blur_1_PS; + RenderTarget0 = Render_Buffer_B; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif @@ -220,9 +220,9 @@ technique cPingPong pass PingPong4 { - VertexShader = PostProcessVS; - PixelShader = VerticalBlurPS1; - RenderTarget0 = RenderBufferA; + VertexShader = Basic_VS; + PixelShader = Vertical_Blur_1_PS; + RenderTarget0 = Render_Buffer_A; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif @@ -231,7 +231,7 @@ technique cPingPong pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = OutputPS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; diff --git a/shaders/cSMAA.fx b/shaders/cSMAA.fx index 2e9a6b2..2965092 100644 --- a/shaders/cSMAA.fx +++ b/shaders/cSMAA.fx @@ -107,12 +107,12 @@ sampler2D searchSampler struct v2f_1 { - float4 vpos : SV_Position; + float4 vpos : SV_POSITION; float2 uv0 : TEXCOORD0; float4 uv1[3] : TEXCOORD1; }; -v2f_1 SMAAEdgeDetectionWrapVS(in uint id : SV_VertexID) +v2f_1 SMAAEdgeDetectionWrapVS(in uint id : SV_VERTEXID) { v2f_1 o; @@ -186,12 +186,12 @@ float2 SMAAEdgeDetectionWrapPS(v2f_1 input) : SV_Target struct v2f_2 { - float4 vpos : SV_Position; + float4 vpos : SV_POSITION; float4 uv0 : TEXCOORD0; float4 uv1[3] : TEXCOORD1; }; -v2f_2 SMAABlendingWeightCalculationWrapVS(in uint id : SV_VertexID) +v2f_2 SMAABlendingWeightCalculationWrapVS(in uint id : SV_VERTEXID) { v2f_2 o; float2 coord; @@ -297,12 +297,12 @@ float4 SMAABlendingWeightCalculationWrapPS(v2f_2 input) : SV_Target struct v2f_3 { - float4 vpos : SV_Position; + float4 vpos : SV_POSITION; float2 uv0 : TEXCOORD0; float4 uv1 : TEXCOORD1; }; -v2f_3 SMAANeighborhoodBlendingWrapVS(in uint id : SV_VertexID) +v2f_3 SMAANeighborhoodBlendingWrapVS(in uint id : SV_VERTEXID) { v2f_3 o; float2 coord; diff --git a/shaders/cSMAA.fxh b/shaders/cSMAA.fxh index 6e559f5..357d9ce 100644 --- a/shaders/cSMAA.fxh +++ b/shaders/cSMAA.fxh @@ -86,7 +86,7 @@ void SMAAMovc(bool4 cond, inout float4 variable, float4 value) } /* - Horizontal/Vertical Search Functions + Is_Horizontal/Vertical Search Functions This allows to determine how much length should we add in the last step of the searches. It takes the bilinearly interpolated edge (see @@ -115,7 +115,7 @@ float SMAASearchLength( sampler2D searchTex, float2 e, float offset) } -/* Horizontal/vertical search functions for the 2nd pass. */ +/* Is_Horizontal/vertical search functions for the 2nd pass. */ float SMAASearchXLeft(sampler2D edgesTex, sampler2D searchTex, float2 texcoord, float end) { diff --git a/shaders/cScale.fx b/shaders/cScale.fx index 62eeb2f..b8a9d6d 100644 --- a/shaders/cScale.fx +++ b/shaders/cScale.fx @@ -49,11 +49,11 @@ uniform float2 _Offset < #define ENABLE_POINT_SAMPLING 0 #endif -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; AddressU = MIRROR; AddressV = MIRROR; #if ENABLE_POINT_SAMPLING @@ -70,31 +70,31 @@ sampler2D SampleColor #endif }; -void ScaleVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float2 TexCoord : TEXCOORD0) +void Scale_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); // Scale texture coordinates from [0, 1] to [-1, 1] range - TexCoord = TexCoord * 2.0 - 1.0; + Coord = Coord * 2.0 - 1.0; // Scale and offset in [-1, 1] range - TexCoord = TexCoord * _Scale + _Offset; + Coord = Coord * _Scale + _Offset; // Scale texture coordinates from [-1, 1] to [0, 1] range - TexCoord = TexCoord * 0.5 + 0.5; + Coord = Coord * 0.5 + 0.5; } -void ScalePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Scale_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = tex2D(SampleColor, TexCoord); + Output_Color_0 = tex2D(Sample_Color, Coord); } technique cScale { pass { - VertexShader = ScaleVS; - PixelShader = ScalePS; + VertexShader = Scale_VS; + PixelShader = Scale_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cShard.fx b/shaders/cShard.fx index f350b6e..067b32a 100644 --- a/shaders/cShard.fx +++ b/shaders/cShard.fx @@ -37,11 +37,11 @@ uniform float _Weight < 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; @@ -52,34 +52,34 @@ sampler2D SampleColor // Vertex shaders -void ShardVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float2 TexCoord : TEXCOORD0, out float4 Offset : TEXCOORD1) +void Shard_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float2 Coord : TEXCOORD0, out float4 Offset : TEXCOORD1) { - 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); - const float2 pSize = 0.5 / float2(BUFFER_WIDTH, BUFFER_HEIGHT); - Offset = TexCoord.xyxy + float4(-pSize, pSize); + 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); + const float2 Pixel_Size = 0.5 / float2(BUFFER_WIDTH, BUFFER_HEIGHT); + Offset = Coord.xyxy + float4(-Pixel_Size, Pixel_Size); } /* [ Pixel Shaders ] */ -void ShardPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, in float4 Offset : TEXCOORD1, out float4 OutputColor0 : SV_Target0) +void Shard_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, in float4 Offset : TEXCOORD1, out float4 Output_Color_0 : SV_TARGET0) { - float4 OriginalSample = tex2D(SampleColor, TexCoord); - float4 BlurSample; - BlurSample += tex2D(SampleColor, Offset.xw) * 0.25; - BlurSample += tex2D(SampleColor, Offset.zw) * 0.25; - BlurSample += tex2D(SampleColor, Offset.xy) * 0.25; - BlurSample += tex2D(SampleColor, Offset.zy) * 0.25; - OutputColor0 = OriginalSample + (OriginalSample - BlurSample) * _Weight; + float4 Original_Sample = tex2D(Sample_Color, Coord); + float4 Blur_Sample = 0.0; + Blur_Sample += tex2D(Sample_Color, Offset.xw) * 0.25; + Blur_Sample += tex2D(Sample_Color, Offset.zw) * 0.25; + Blur_Sample += tex2D(Sample_Color, Offset.xy) * 0.25; + Blur_Sample += tex2D(Sample_Color, Offset.zy) * 0.25; + Output_Color_0 = Original_Sample + (Original_Sample - Blur_Sample) * _Weight; } technique cShard { pass { - VertexShader = ShardVS; - PixelShader = ShardPS; + VertexShader = Shard_VS; + PixelShader = Shard_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cSimplexNoise.fx b/shaders/cSimplexNoise.fx index 94135a6..9127485 100644 --- a/shaders/cSimplexNoise.fx +++ b/shaders/cSimplexNoise.fx @@ -35,11 +35,11 @@ uniform float Time < source = "timer"; >; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -50,11 +50,11 @@ 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 @@ -82,121 +82,121 @@ void PostProcessVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, THE SOFTWARE. */ -float2 Mod289(float2 x) +float2 Mod_289(float2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } -float3 Mod289(float3 x) +float3 Mod_289(float3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } -float4 Mod289(float4 x) +float4 Mod_289(float4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } float2 Permute(float2 x) { - return Mod289(((x * 34.0) + 10.0)* x); + return Mod_289(((x * 34.0) + 10.0)* x); } float4 Permute(float4 x) { - return Mod289(((x * 34.0) + 10.0) * x); + return Mod_289(((x * 34.0) + 10.0) * x); } -float4 TaylorInvSqrt(float4 r) +float4 Taylor_Inverse_Sqrt(float4 r) { return 1.79284291400159 - 0.85373472095314 * r; } -float SimplexNoise(float3 V) +float Simplex_Noise(float3 V) { const float2 C = float2(1.0 / 6.0, 1.0 / 3.0); const float4 D = float4(0.0, 0.5, 1.0, 2.0); // First corner float3 I = floor(V + dot(V, C.yyy)); - float3 X0 = V - I + dot(I, C.xxx); + float3 X_0 = V - I + dot(I, C.xxx); // Other corners - float3 G = step(X0.yzx, X0.xyz); + float3 G = step(X_0.yzx, X_0.xyz); float3 L = 1.0 - G; - float3 I1 = min(G.xyz, L.zxy); - float3 I2 = max(G.xyz, L.zxy); + float3 I_1 = min(G.xyz, L.zxy); + float3 I_2 = max(G.xyz, L.zxy); - // X0 = X0 - 0.0 + 0.0 * C.xxx; - // X1 = X0 - I1 + 1.0 * C.xxx; - // X2 = X0 - I2 + 2.0 * C.xxx; - // X3 = X0 - 1.0 + 3.0 * C.xxx; - float3 X1 = X0 - I1 + C.xxx; - float3 X2 = X0 - I2 + C.yyy; // 2.0*C.x = 1/3 = C.y - float3 X3 = X0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y + // X_0 = X_0 - 0.0 + 0.0 * C.xxx; + // X_1 = X_0 - I_1 + 1.0 * C.xxx; + // X_2 = X_0 - I_2 + 2.0 * C.xxx; + // X_3 = X_0 - 1.0 + 3.0 * C.xxx; + float3 X_1 = X_0 - I_1 + C.xxx; + float3 X_2 = X_0 - I_2 + C.yyy; // 2.0*C.x = 1/3 = C.y + float3 X_3 = X_0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y // Permutations - I = Mod289(I); - float4 P = Permute(Permute(Permute(I.z + float4(0.0, I1.z, I2.z, 1.0)) - + I.y + float4(0.0, I1.y, I2.y, 1.0)) - + I.x + float4(0.0, I1.x, I2.x, 1.0)); + I = Mod_289(I); + float4 P = Permute(Permute(Permute(I.z + float4(0.0, I_1.z, I_2.z, 1.0)) + + I.y + float4(0.0, I_1.y, I_2.y, 1.0)) + + I.x + float4(0.0, I_1.x, I_2.x, 1.0)); // Gradients: 7x7 points over a square, mapped onto an octahedron. // The ring size 17*17 = 289 is close to a multiple of 49 (49 * 6 = 294) float N_ = 0.142857142857; // 1.0 / 7.0 - float3 NS = N_ * D.wyz - D.xzx; + float3 N_S = N_ * D.wyz - D.xzx; - float4 J = P - 49.0 * floor(P * NS.z * NS.z); // mod(P, 7 * 7) + float4 J = P - 49.0 * floor(P * N_S.z * N_S.z); // mod(P, 7 * 7) - float4 X_ = floor(J * NS.z); + float4 X_ = floor(J * N_S.z); float4 Y_ = floor(J - 7.0 * X_); // mod(J, N) - float4 X = X_ * NS.x + NS.yyyy; - float4 Y = Y_ * NS.x + NS.yyyy; + float4 X = X_ * N_S.x + N_S.yyyy; + float4 Y = Y_ * N_S.x + N_S.yyyy; float4 H = 1.0 - abs(X) - abs(Y); - float4 B0 = float4(X.xy, Y.xy); - float4 B1 = float4(X.zw, Y.zw); + float4 B_0 = float4(X.xy, Y.xy); + float4 B_1 = float4(X.zw, Y.zw); - // float4 S0 = float4(lessThan(B0, 0.0)) * 2.0 - 1.0; - // float4 S1 = float4(lessThan(B1, 0.0)) * 2.0 - 1.0; - float4 S0 = floor(B0) * 2.0 + 1.0; - float4 S1 = floor(B1) * 2.0 + 1.0; + // float4 S_0 = float4(lessThan(B_0, 0.0)) * 2.0 - 1.0; + // float4 S_1 = float4(lessThan(B_1, 0.0)) * 2.0 - 1.0; + float4 S_0 = floor(B_0) * 2.0 + 1.0; + float4 S_1 = floor(B_1) * 2.0 + 1.0; float4 Sh = -step(H, 0.0); - float4 A0 = B0.xzyw + S0.xzyw * Sh.xxyy; - float4 A1 = B1.xzyw + S1.xzyw * Sh.zzww; + float4 A_0 = B_0.xzyw + S_0.xzyw * Sh.xxyy; + float4 A_1 = B_1.xzyw + S_1.xzyw * Sh.zzww; - float3 P0 = float3(A0.xy, H.x); - float3 P1 = float3(A0.zw, H.y); - float3 P2 = float3(A1.xy, H.z); - float3 P3 = float3(A1.zw, H.w); + float3 P_0 = float3(A_0.xy, H.x); + float3 P_1 = float3(A_0.zw, H.y); + float3 P_2 = float3(A_1.xy, H.z); + float3 P_3 = float3(A_1.zw, H.w); //Normalise gradients - float4 Norm = TaylorInvSqrt(float4(dot(P0, P0), dot(P1, P1), dot(P2, P2), dot(P3, P3))); - P0 *= Norm.x; - P1 *= Norm.y; - P2 *= Norm.z; - P3 *= Norm.w; + float4 Norm = Taylor_Inverse_Sqrt(float4(dot(P_0, P_0), dot(P_1, P_1), dot(P_2, P_2), dot(P_3, P_3))); + P_0 *= Norm.x; + P_1 *= Norm.y; + P_2 *= Norm.z; + P_3 *= Norm.w; // Mix final noise value - float4 M = max(0.5 - float4(dot(X0,X0), dot(X1,X1), dot(X2,X2), dot(X3,X3)), 0.0); + float4 M = max(0.5 - float4(dot(X_0,X_0), dot(X_1,X_1), dot(X_2,X_2), dot(X_3,X_3)), 0.0); M = M * M; - return 105.0 * dot(M * M, float4(dot(P0, X0), dot(P1, X1), dot(P2, X2), dot(P3, X3))); + return 105.0 * dot(M * M, float4(dot(P_0, X_0), dot(P_1, X_1), dot(P_2, X_2), dot(P_3, X_3))); } -void SimplexNoisePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Simplex_Noise_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - float3 Value3 = float3(Position.xy / 2.0, Time / min(BUFFER_WIDTH, BUFFER_HEIGHT)); - OutputColor0 = SimplexNoise(Value3) * 0.5 + 0.5; + float3 Value_3 = float3(Position.xy / 2.0, Time / min(BUFFER_WIDTH, BUFFER_HEIGHT)); + Output_Color_0 = Simplex_Noise(Value_3) * 0.5 + 0.5; } technique cSimplexNoise { pass { - VertexShader = PostProcessVS; - PixelShader = SimplexNoisePS; + VertexShader = Basic_VS; + PixelShader = Simplex_Noise_PS; BlendEnable = TRUE; BlendOp = ADD; SrcBlend = ONE; diff --git a/shaders/cSrcDestBlend.fx b/shaders/cSrcDestBlend.fx index 808635e..cf5c5ff 100644 --- a/shaders/cSrcDestBlend.fx +++ b/shaders/cSrcDestBlend.fx @@ -39,16 +39,16 @@ uniform int _Blend < ui_items = " Add\0 Subtract\0 Multiply\0 Min\0 Max\0 Screen\0 Lerp\0"; > = 0; -uniform float _LerpWeight < +uniform float _Lerp_Weight < ui_label = "Lerp Weight"; ui_type = "slider"; > = 0.5; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -57,16 +57,16 @@ sampler2D SampleColor #endif }; -texture2D RenderCopy +texture2D Render_Copy { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; }; -sampler2D SampleCopy +sampler2D Sample_Copy { - Texture = RenderCopy; + Texture = Render_Copy; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -77,50 +77,50 @@ sampler2D SampleCopy // 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) { - OutputColor0 = tex2D(SampleColor, TexCoord); + Output_Color_0 = tex2D(Sample_Color, Coord); } -void BlendPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Blend_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - float4 Src = tex2D(SampleCopy, TexCoord); - float4 Dest = tex2D(SampleColor, TexCoord); + float4 Src = tex2D(Sample_Copy, Coord); + float4 Dest = tex2D(Sample_Color, Coord); switch(_Blend) { case 0: // Add - OutputColor0 = Src + Dest; + Output_Color_0 = Src + Dest; break; case 1: // Subtract - OutputColor0 = Src - Dest; + Output_Color_0 = Src - Dest; break; case 2: // Multiply - OutputColor0 = Src * Dest; + Output_Color_0 = Src * Dest; break; case 3: // Min - OutputColor0 = min(Src, Dest); + Output_Color_0 = min(Src, Dest); break; case 4: // Max - OutputColor0 = max(Src, Dest); + Output_Color_0 = max(Src, Dest); break; case 5: // Screen - OutputColor0 = (Src + Dest) - (Src * Dest); + Output_Color_0 = (Src + Dest) - (Src * Dest); break; case 6: // Lerp - OutputColor0 = lerp(Src, Dest, _LerpWeight); + Output_Color_0 = lerp(Src, Dest, _Lerp_Weight); break; default: - OutputColor0 = Dest; + Output_Color_0 = Dest; break; } } @@ -129,9 +129,9 @@ technique cCopyBuffer { pass { - VertexShader = PostProcessVS; - PixelShader = BlitPS; - RenderTarget0 = RenderCopy; + VertexShader = Basic_VS; + PixelShader = Blit_PS; + RenderTarget0 = Render_Copy; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif @@ -142,8 +142,8 @@ technique cBlendBuffer { pass { - VertexShader = PostProcessVS; - PixelShader = BlendPS; + VertexShader = Basic_VS; + PixelShader = Blend_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/cThreePointStorage.fx b/shaders/cThreePointStorage.fx index f679fd6..376a628 100644 --- a/shaders/cThreePointStorage.fx +++ b/shaders/cThreePointStorage.fx @@ -33,7 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -namespace ThreePointStorage +namespace Three_Point_Storage { // Consideration: Use A8 channel for difference requirement (normalize BW image) @@ -95,11 +95,11 @@ namespace ThreePointStorage MipFilter = LINEAR; }; - 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); } /* @@ -114,19 +114,19 @@ namespace ThreePointStorage ... and so forth */ - void Store_Frame_3_PS(float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Store_Frame_3_PS(float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Sample_Frame_2, TexCoord); + Output_Color_0 = tex2D(Sample_Frame_2, Coord); } - void Store_Frame_2_PS(float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Store_Frame_2_PS(float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Sample_Frame_1, TexCoord); + Output_Color_0 = tex2D(Sample_Frame_1, Coord); } - void Current_Frame_1_PS(float4 Position : SV_Position, float2 TexCoord : TEXCOORD, out float4 Color : SV_Target0) + void Current_Frame_1_PS(float4 Position : SV_POSITION, float2 Coord : TEXCOORD, out float4 Output_Color_0 : SV_TARGET0) { - Color = tex2D(Sample_Color, TexCoord); + Output_Color_0 = tex2D(Sample_Color, Coord); } /* @@ -139,21 +139,21 @@ namespace ThreePointStorage { pass Store_Frame_3 { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Store_Frame_3_PS; RenderTarget = Render_Frame_3; } pass Store_Frame_2 { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Store_Frame_2_PS; RenderTarget = Render_Frame_2; } pass Store_Frame_1 { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Current_Frame_1_PS; RenderTarget = Render_Frame_1; } diff --git a/shaders/cThreshold.fx b/shaders/cThreshold.fx index a739dfc..6c3881c 100644 --- a/shaders/cThreshold.fx +++ b/shaders/cThreshold.fx @@ -57,11 +57,11 @@ uniform float _Intensity < ui_label = "Intensity"; > = 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; @@ -72,43 +72,43 @@ 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); } -float Med3(float x, float y, float z) +float Median_3(float x, float y, float z) { return max(min(x, y), min(max(x, y), z)); } // Pixel shaders -void ThresholdPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Threshold_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { const float Knee = mad(_Threshold, _Smooth, 1e-5f); const float3 Curve = float3(_Threshold - Knee, Knee * 2.0, 0.25 / Knee); - float4 Color = tex2D(SampleColor, TexCoord); + float4 Color = tex2D(Sample_Color, Coord); // Under-threshold - float Brightness = Med3(Color.r, Color.g, Color.b); - float ResponseCurve = clamp(Brightness - Curve.x, 0.0, Curve.y); - ResponseCurve = Curve.z * ResponseCurve * ResponseCurve; + float Brightness = Median_3(Color.r, Color.g, Color.b); + float Response_Curve = clamp(Brightness - Curve.x, 0.0, Curve.y); + Response_Curve = Curve.z * Response_Curve * Response_Curve; // Combine and apply the brightness response curve - Color = Color * max(ResponseCurve, Brightness - _Threshold) / max(Brightness, 1e-10); - Brightness = Med3(Color.r, Color.g, Color.b); - OutputColor0 = saturate(lerp(Brightness, Color, _Saturation) * _Intensity); + Color = Color * max(Response_Curve, Brightness - _Threshold) / max(Brightness, 1e-10); + Brightness = Median_3(Color.r, Color.g, Color.b); + Output_Color_0 = saturate(lerp(Brightness, Color, _Saturation) * _Intensity); } technique cThreshold { pass { - VertexShader = PostProcessVS; - PixelShader = ThresholdPS; + VertexShader = Basic_VS; + PixelShader = Threshold_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/kContour.fx b/shaders/kContour.fx index 043120f..d42b8ca 100644 --- a/shaders/kContour.fx +++ b/shaders/kContour.fx @@ -39,25 +39,25 @@ uniform float _Threshold < ui_min = 0.0; ui_max = 1.0; > = 0.05f; -uniform float _InvRange < +uniform float _Inverse_Range < ui_label = "Inverse Range"; ui_type = "slider"; ui_min = 0.0; ui_max = 1.0; > = 0.05f; -uniform float _ColorSensitivity < +uniform float _Color_Sensitivity < ui_label = "Color Sensitivity"; ui_type = "slider"; ui_min = 0.0; ui_max = 1.0; > = 0.0f; -uniform float4 _FrontColor < +uniform float4 _Front_Color < ui_label = "Front Color"; ui_type = "color"; ui_min = 0.0; ui_max = 1.0; > = float4(1.0, 1.0, 1.0, 1.0); -uniform float4 _BackColor < +uniform float4 _Back_Color < ui_label = "Back Color"; ui_type = "color"; ui_min = 0.0; ui_max = 1.0; @@ -70,22 +70,22 @@ uniform int _Select < ui_tooltip = "Select Edge Detection"; > = 0; -uniform bool _NormalizeOutput < +uniform bool _Normalize_Output < ui_label = "Normalize Output"; ui_type = "radio"; > = true; -uniform float _NormalWeight < +uniform float _Normalize_Weight < ui_label = "Normal Weight"; ui_type = "drag"; ui_min = 0.0; > = 0.1; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -96,158 +96,158 @@ 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); } -void ContourVS(in uint ID : SV_VertexID, out float4 Position : SV_Position, out float4 TexCoord[4] : TEXCOORD0) +void Contour_VS(in uint ID : SV_VERTEXID, out float4 Position : SV_POSITION, out float4 Coord[4] : TEXCOORD0) { - float2 TexCoord0; - PostProcessVS(ID, Position, TexCoord0); - const float2 PixelSize = 1.0 / float2(BUFFER_WIDTH, BUFFER_HEIGHT); - TexCoord[0] = TexCoord0.xyyy + float4(-PixelSize.x, +PixelSize.y, 0.0, -PixelSize.y); - TexCoord[1] = TexCoord0.xyyy + float4(0.0, +PixelSize.y, 0.0, -PixelSize.y); - TexCoord[2] = TexCoord0.xyyy + float4(+PixelSize.x, +PixelSize.y, 0.0, -PixelSize.y); - TexCoord[3] = TexCoord0.xyxy + float4(PixelSize, -PixelSize) * 0.5; + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + const float2 Pixel_Size = 1.0 / float2(BUFFER_WIDTH, BUFFER_HEIGHT); + Coord[0] = VS_Coord.xyyy + float4(-Pixel_Size.x, Pixel_Size.y, 0.0, -Pixel_Size.y); + Coord[1] = VS_Coord.xyyy + float4(0.0, Pixel_Size.y, 0.0, -Pixel_Size.y); + Coord[2] = VS_Coord.xyyy + float4(Pixel_Size.x, Pixel_Size.y, 0.0, -Pixel_Size.y); + Coord[3] = VS_Coord.xyxy + float4(Pixel_Size, -Pixel_Size) * 0.5; } -float3 NormalizeOutput(float3 Input) +float3 Normalize_Output(float3 Input) { - return (_NormalizeOutput) ? Input * rsqrt(dot(Input, Input) + _NormalWeight) : Input; + return (_Normalize_Output) ? Input * rsqrt(dot(Input, Input) + _Normalize_Weight) : Input; } float Magnitude(float3 X, float3 Y) { - X = NormalizeOutput(X); - Y = NormalizeOutput(Y); + X = Normalize_Output(X); + Y = Normalize_Output(Y); return sqrt(dot(X, X) + dot(Y, Y)); } // Pixel shaders // Contour pass: https://github.com/keijiro/KinoContour [MIT] -void ContourPS(in float4 Position : SV_Position, in float4 TexCoord[4] : TEXCOORD0, out float3 OutputColor0 : SV_Target0) +void Contour_PS(in float4 Position : SV_POSITION, in float4 Coord[4] : TEXCOORD0, out float3 Output_Color_0 : SV_TARGET0) { /* - A0 B0 C0 - A1 B1 C1 - A2 B2 C2 + A_0 B_0 C_0 + A_1 B_1 C_1 + A_2 B_2 C_2 */ - float3 A0 = tex2D(SampleColor, TexCoord[0].xy).rgb; - float3 A1 = tex2D(SampleColor, TexCoord[0].xz).rgb; - float3 A2 = tex2D(SampleColor, TexCoord[0].xw).rgb; + float3 A_0 = tex2D(Sample_Color, Coord[0].xy).rgb; + float3 A_1 = tex2D(Sample_Color, Coord[0].xz).rgb; + float3 A_2 = tex2D(Sample_Color, Coord[0].xw).rgb; - float3 B0 = tex2D(SampleColor, TexCoord[1].xy).rgb; - float3 B1 = tex2D(SampleColor, TexCoord[1].xz).rgb; - float3 B2 = tex2D(SampleColor, TexCoord[1].xw).rgb; + float3 B_0 = tex2D(Sample_Color, Coord[1].xy).rgb; + float3 B_1 = tex2D(Sample_Color, Coord[1].xz).rgb; + float3 B_2 = tex2D(Sample_Color, Coord[1].xw).rgb; - float3 C0 = tex2D(SampleColor, TexCoord[2].xy).rgb; - float3 C1 = tex2D(SampleColor, TexCoord[2].xz).rgb; - float3 C2 = tex2D(SampleColor, TexCoord[2].xw).rgb; + float3 C_0 = tex2D(Sample_Color, Coord[2].xy).rgb; + float3 C_1 = tex2D(Sample_Color, Coord[2].xz).rgb; + float3 C_2 = tex2D(Sample_Color, Coord[2].xw).rgb; - float3 BilinearSample0, BilinearSample1, BilinearSample2, BilinearSample3; + float3 Bilinear_Sample_0, Bilinear_Sample_1, Bilinear_Sample_2, Bilinear_Sample_3; float3 Ix, Iy, Edge; switch(_Select) { case 0: // fwidth() - Ix = NormalizeOutput(ddx(B1)); - Iy = NormalizeOutput(ddy(B1)); + Ix = Normalize_Output(ddx(B_1)); + Iy = Normalize_Output(ddy(B_1)); Edge = Magnitude(Ix, Iy); break; case 1: // Laplacian - BilinearSample0 = tex2D(SampleColor, TexCoord[3].zy).rgb; // (-x, +y) - BilinearSample1 = tex2D(SampleColor, TexCoord[3].xy).rgb; // (+x, +y) - BilinearSample2 = tex2D(SampleColor, TexCoord[3].zw).rgb; // (-x, -y) - BilinearSample3 = tex2D(SampleColor, TexCoord[3].xw).rgb; // (+x, -y) - Edge = (BilinearSample0 + BilinearSample1 + BilinearSample2 + BilinearSample3) - (B1 * 4.0); - Edge = NormalizeOutput(Edge); + Bilinear_Sample_0 = tex2D(Sample_Color, Coord[3].zy).rgb; // (-x, +y) + Bilinear_Sample_1 = tex2D(Sample_Color, Coord[3].xy).rgb; // (+x, +y) + Bilinear_Sample_2 = tex2D(Sample_Color, Coord[3].zw).rgb; // (-x, -y) + Bilinear_Sample_3 = tex2D(Sample_Color, Coord[3].xw).rgb; // (+x, -y) + Edge = (Bilinear_Sample_0 + Bilinear_Sample_1 + Bilinear_Sample_2 + Bilinear_Sample_3) - (B_1 * 4.0); + Edge = Normalize_Output(Edge); Edge = length(Edge) / sqrt(3.0); break; case 2: // Sobel - Ix = (-A0 + ((-A1 * 2.0) + -A2)) + (C0 + (C1 * 2.0) + C2); - Iy = (-A0 + ((-B0 * 2.0) + -C0)) + (A2 + (B2 * 2.0) + C2); + Ix = (-A_0 + ((-A_1 * 2.0) + -A_2)) + (C_0 + (C_1 * 2.0) + C_2); + Iy = (-A_0 + ((-B_0 * 2.0) + -C_0)) + (A_2 + (B_2 * 2.0) + C_2); Edge = Magnitude(Ix, Iy); break; case 3: // Prewitt - Ix = (-A0 - A1 - A2) + (C0 + C1 + C2); - Iy = (-A0 - B0 - C0) + (A2 + B2 + C2); + Ix = (-A_0 - A_1 - A_2) + (C_0 + C_1 + C_2); + Iy = (-A_0 - B_0 - C_0) + (A_2 + B_2 + C_2); Edge = Magnitude(Ix, Iy); break; case 4: // Robert's Cross - Ix = C0 - B1; - Iy = B0 - C1; + Ix = C_0 - B_1; + Iy = B_0 - C_1; Edge = Magnitude(Ix, Iy); break; case 5: // Scharr - Ix += A0 * -3.0; - Ix += A1 * -10.0; - Ix += A2 * -3.0; - Ix += C0 * 3.0; - Ix += C1 * 10.0; - Ix += C2 * 3.0; - - Iy += A0 * 3.0; - Iy += B0 * 10.0; - Iy += C0 * 3.0; - Iy += A2 * -3.0; - Iy += B2 * -10.0; - Iy += C2 * -3.0; + Ix += A_0 * -3.0; + Ix += A_1 * -10.0; + Ix += A_2 * -3.0; + Ix += C_0 * 3.0; + Ix += C_1 * 10.0; + Ix += C_2 * 3.0; + + Iy += A_0 * 3.0; + Iy += B_0 * 10.0; + Iy += C_0 * 3.0; + Iy += A_2 * -3.0; + Iy += B_2 * -10.0; + Iy += C_2 * -3.0; Edge = Magnitude(Ix, Iy); break; case 6: // Kayyali - float3 Cross = (A0 * 6.0) + (C0 * -6.0) + (A2 * -6.0) + (C2 * 6.0); + float3 Cross = (A_0 * 6.0) + (C_0 * -6.0) + (A_2 * -6.0) + (C_2 * 6.0); Edge = Magnitude(Cross, -Cross); break; case 7: // Kroon - Ix += A0 * -17.0; - Ix += A1 * -61.0; - Ix += A2 * -17.0; - Ix += C0 * 17.0; - Ix += C1 * 61.0; - Ix += C2 * 17.0; - - Iy += A0 * 17.0; - Iy += B0 * 61.0; - Iy += C0 * 17.0; - Iy += A2 * -17.0; - Iy += B2 * -61.0; - Iy += C2 * -17.0; + Ix += A_0 * -17.0; + Ix += A_1 * -61.0; + Ix += A_2 * -17.0; + Ix += C_0 * 17.0; + Ix += C_1 * 61.0; + Ix += C_2 * 17.0; + + Iy += A_0 * 17.0; + Iy += B_0 * 61.0; + Iy += C_0 * 17.0; + Iy += A_2 * -17.0; + Iy += B_2 * -61.0; + Iy += C_2 * -17.0; Edge = Magnitude(Ix, Iy); break; case 8: // Bilinear Sobel - BilinearSample0 = tex2D(SampleColor, TexCoord[3].zy).rgb; // (-x, +y) - BilinearSample1 = tex2D(SampleColor, TexCoord[3].xy).rgb; // (+x, +y) - BilinearSample2 = tex2D(SampleColor, TexCoord[3].zw).rgb; // (-x, -y) - BilinearSample3 = tex2D(SampleColor, TexCoord[3].xw).rgb; // (+x, -y) - Ix = ((-BilinearSample2 + -BilinearSample0) + (BilinearSample3 + BilinearSample1)) * 4.0; - Iy = ((BilinearSample2 + BilinearSample3) + (-BilinearSample0 + -BilinearSample1)) * 4.0; + Bilinear_Sample_0 = tex2D(Sample_Color, Coord[3].zy).rgb; // (-x, +y) + Bilinear_Sample_1 = tex2D(Sample_Color, Coord[3].xy).rgb; // (+x, +y) + Bilinear_Sample_2 = tex2D(Sample_Color, Coord[3].zw).rgb; // (-x, -y) + Bilinear_Sample_3 = tex2D(Sample_Color, Coord[3].xw).rgb; // (+x, -y) + Ix = ((-Bilinear_Sample_2 + -Bilinear_Sample_0) + (Bilinear_Sample_3 + Bilinear_Sample_1)) * 4.0; + Iy = ((Bilinear_Sample_2 + Bilinear_Sample_3) + (-Bilinear_Sample_0 + -Bilinear_Sample_1)) * 4.0; Edge = Magnitude(Ix, Iy); break; default: - Edge = tex2D(SampleColor, TexCoord[1].xz).rgb; + Edge = tex2D(Sample_Color, Coord[1].xz).rgb; break; } // Thresholding - Edge = Edge * _ColorSensitivity; - Edge = saturate((Edge - _Threshold) * _InvRange); - float3 Base = tex2D(SampleColor, TexCoord[1].xz).rgb; - float3 ColorBackground = lerp(Base, _BackColor.rgb, _BackColor.a); - OutputColor0 = lerp(ColorBackground, _FrontColor.rgb, Edge * _FrontColor.a); + Edge = Edge * _Color_Sensitivity; + Edge = saturate((Edge - _Threshold) * _Inverse_Range); + float3 Base = tex2D(Sample_Color, Coord[1].xz).rgb; + float3 Color_Background = lerp(Base, _Back_Color.rgb, _Back_Color.a); + Output_Color_0 = lerp(Color_Background, _Front_Color.rgb, Edge * _Front_Color.a); } technique KinoContour { pass { - VertexShader = ContourVS; - PixelShader = ContourPS; + VertexShader = Contour_VS; + PixelShader = Contour_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/kDatamosh.fx b/shaders/kDatamosh.fx index ccfc99b..7cd2d7b 100644 --- a/shaders/kDatamosh.fx +++ b/shaders/kDatamosh.fx @@ -35,21 +35,21 @@ // Shared textures -#define BUFFER_SIZE_0 uint2(BUFFER_WIDTH >> 0, BUFFER_HEIGHT >> 0) -#define BUFFER_SIZE_1 uint2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1) -#define BUFFER_SIZE_2 uint2(BUFFER_WIDTH >> 2, BUFFER_HEIGHT >> 2) -#define BUFFER_SIZE_3 uint2(BUFFER_WIDTH >> 3, BUFFER_HEIGHT >> 3) -#define BUFFER_SIZE_4 uint2(BUFFER_WIDTH >> 4, BUFFER_HEIGHT >> 4) -#define BUFFER_SIZE_5 uint2(BUFFER_WIDTH >> 5, BUFFER_HEIGHT >> 5) -#define BUFFER_SIZE_6 uint2(BUFFER_WIDTH >> 6, BUFFER_HEIGHT >> 6) -#define BUFFER_SIZE_7 uint2(BUFFER_WIDTH >> 7, BUFFER_HEIGHT >> 7) -#define BUFFER_SIZE_8 uint2(BUFFER_WIDTH >> 8, BUFFER_HEIGHT >> 8) - -namespace SharedResources +#define BUFFER_SIZE_0 int2(BUFFER_WIDTH >> 0, BUFFER_HEIGHT >> 0) +#define BUFFER_SIZE_1 int2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1) +#define BUFFER_SIZE_2 int2(BUFFER_WIDTH >> 2, BUFFER_HEIGHT >> 2) +#define BUFFER_SIZE_3 int2(BUFFER_WIDTH >> 3, BUFFER_HEIGHT >> 3) +#define BUFFER_SIZE_4 int2(BUFFER_WIDTH >> 4, BUFFER_HEIGHT >> 4) +#define BUFFER_SIZE_5 int2(BUFFER_WIDTH >> 5, BUFFER_HEIGHT >> 5) +#define BUFFER_SIZE_6 int2(BUFFER_WIDTH >> 6, BUFFER_HEIGHT >> 6) +#define BUFFER_SIZE_7 int2(BUFFER_WIDTH >> 7, BUFFER_HEIGHT >> 7) +#define BUFFER_SIZE_8 int2(BUFFER_WIDTH >> 8, BUFFER_HEIGHT >> 8) + +namespace Shared_Resources { namespace RGBA16F { - texture2D RenderCommon1 < pooled = true; > + texture2D Render_Common_1 < pooled = true; > { Width = BUFFER_SIZE_1.x; Height = BUFFER_SIZE_1.y; @@ -60,7 +60,7 @@ namespace SharedResources namespace RG16F { - texture2D RenderCommon1 < pooled = true; > + texture2D Render_Common_1 < pooled = true; > { Width = BUFFER_SIZE_1.x; Height = BUFFER_SIZE_1.y; @@ -68,49 +68,49 @@ namespace SharedResources MipLevels = 8; }; - texture2D RenderCommon2 < pooled = true; > + texture2D Render_Common_2 < pooled = true; > { Width = BUFFER_SIZE_2.x; Height = BUFFER_SIZE_2.y; Format = RG16F; }; - texture2D RenderCommon3 < pooled = true; > + texture2D Render_Common_3 < pooled = true; > { Width = BUFFER_SIZE_3.x; Height = BUFFER_SIZE_3.y; Format = RG16F; }; - texture2D RenderCommon4 < pooled = true; > + texture2D Render_Common_4 < pooled = true; > { Width = BUFFER_SIZE_4.x; Height = BUFFER_SIZE_4.y; Format = RG16F; }; - texture2D RenderCommon5 < pooled = true; > + texture2D Render_Common_5 < pooled = true; > { Width = BUFFER_SIZE_5.x; Height = BUFFER_SIZE_5.y; Format = RG16F; }; - texture2D RenderCommon6 < pooled = true; > + texture2D Render_Common_6 < pooled = true; > { Width = BUFFER_SIZE_6.x; Height = BUFFER_SIZE_6.y; Format = RG16F; }; - texture2D RenderCommon7 < pooled = true; > + texture2D Render_Common_7 < pooled = true; > { Width = BUFFER_SIZE_7.x; Height = BUFFER_SIZE_7.y; Format = RG16F; }; - texture2D RenderCommon8 < pooled = true; > + texture2D Render_Common_8 < pooled = true; > { Width = BUFFER_SIZE_8.x; Height = BUFFER_SIZE_8.y; @@ -119,7 +119,7 @@ namespace SharedResources } } -namespace OpticalFlow +namespace Optical_Flow { // Shader properties @@ -184,7 +184,7 @@ namespace OpticalFlow ui_min = 0.0; > = 1.0; - uniform float _BlendFactor < + uniform float _Blend_Factor < ui_category = "Motion Vectors"; ui_type = "drag"; ui_label = "Temporal Smoothing"; @@ -193,7 +193,7 @@ namespace OpticalFlow ui_max = 1.0; > = 0.25; - uniform float _MipBias < + uniform float _Mip_Bias < ui_category = "Motion Vectors"; ui_type = "drag"; ui_label = "Blockiness"; @@ -213,11 +213,11 @@ namespace OpticalFlow // Textures and samplers - texture2D RenderColor : COLOR; + texture2D Render_Color : COLOR; - sampler2D SampleColor + sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; AddressU = MIRROR; AddressV = MIRROR; MagFilter = LINEAR; @@ -228,17 +228,17 @@ namespace OpticalFlow #endif }; - sampler2D SampleCommon_RG16F_1a + sampler2D Sample_Common_RG16F_1a { - Texture = SharedResources::RG16F::RenderCommon1; + Texture = Shared_Resources::RG16F::Render_Common_1; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; - sampler2D SampleCommon_RGBA16F_1a + sampler2D Sample_Common_RGBA16F_1a { - Texture = SharedResources::RGBA16F::RenderCommon1; + Texture = Shared_Resources::RGBA16F::Render_Common_1; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -260,57 +260,57 @@ namespace OpticalFlow MipFilter = LINEAR; }; - sampler2D SampleCommon_RG16F_8 + sampler2D Sample_Common_RG16F_8 { - Texture = SharedResources::RG16F::RenderCommon8; + Texture = Shared_Resources::RG16F::Render_Common_8; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; - sampler2D SampleCommon_RG16F_7 + sampler2D Sample_Common_RG16F_7 { - Texture = SharedResources::RG16F::RenderCommon7; + Texture = Shared_Resources::RG16F::Render_Common_7; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; - sampler2D SampleCommon_RG16F_6 + sampler2D Sample_Common_RG16F_6 { - Texture = SharedResources::RG16F::RenderCommon6; + Texture = Shared_Resources::RG16F::Render_Common_6; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; - sampler2D SampleCommon_RG16F_5 + sampler2D Sample_Common_RG16F_5 { - Texture = SharedResources::RG16F::RenderCommon5; + Texture = Shared_Resources::RG16F::Render_Common_5; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; - sampler2D SampleCommon_RG16F_4 + sampler2D Sample_Common_RG16F_4 { - Texture = SharedResources::RG16F::RenderCommon4; + Texture = Shared_Resources::RG16F::Render_Common_4; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; - sampler2D SampleCommon_RG16F_3 + sampler2D Sample_Common_RG16F_3 { - Texture = SharedResources::RG16F::RenderCommon3; + Texture = Shared_Resources::RG16F::Render_Common_3; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; }; - sampler2D SampleCommon_RG16F_2 + sampler2D Sample_Common_RG16F_2 { - Texture = SharedResources::RG16F::RenderCommon2; + Texture = Shared_Resources::RG16F::Render_Common_2; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -332,7 +332,7 @@ namespace OpticalFlow sampler2D SampleVectorsPost { - Texture = SharedResources::RGBA16F::RenderCommon1; + Texture = Shared_Resources::RGBA16F::Render_Common_1; MagFilter = _FILTER; MinFilter = _FILTER; }; @@ -373,101 +373,101 @@ namespace OpticalFlow // Vertex shaders - void MedianOffsets(in float2 TexCoord, in float2 PixelSize, inout float4 SampleOffsets[3]) + void Median_Offsets(in float2 Coord, in float2 Pixel_Size, inout float4 Sample_Offsets[3]) { // Sample locations: // [0].xy [1].xy [2].xy // [0].xz [1].xz [2].xz // [0].xw [1].xw [2].xw - SampleOffsets[0] = TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - SampleOffsets[1] = TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); - SampleOffsets[2] = TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * PixelSize.xyyy); + Sample_Offsets[0] = Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Sample_Offsets[1] = Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); + Sample_Offsets[2] = Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * Pixel_Size.xyyy); } - void TentOffsets(in float2 TexCoord, in float2 TexelSize, inout float4 SampleOffsets[3]) + void TentOffsets(in float2 Coord, in float2 Texel_Size, inout float4 Sample_Offsets[3]) { // Sample locations: // [0].xy [1].xy [2].xy // [0].xz [1].xz [2].xz // [0].xw [1].xw [2].xw - SampleOffsets[0] = TexCoord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * TexelSize.xyyy); - SampleOffsets[1] = TexCoord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * TexelSize.xyyy); - SampleOffsets[2] = TexCoord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * TexelSize.xyyy); + Sample_Offsets[0] = Coord.xyyy + (float4(-1.0, 1.0, 0.0, -1.0) * Texel_Size.xyyy); + Sample_Offsets[1] = Coord.xyyy + (float4(0.0, 1.0, 0.0, -1.0) * Texel_Size.xyyy); + Sample_Offsets[2] = Coord.xyyy + (float4(1.0, 1.0, 0.0, -1.0) * Texel_Size.xyyy); } - void PostProcessVS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float2 TexCoord : TEXCOORD0) + void Basic_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float2 Coord : TEXCOORD0) { - TexCoord.x = (ID == 2) ? 2.0 : 0.0; - TexCoord.y = (ID == 1) ? 2.0 : 0.0; - Position = TexCoord.xyxy * float4(2.0, -2.0, 0.0, 0.0) + float4(-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 = Coord.xyxy * float4(2.0, -2.0, 0.0, 0.0) + float4(-1.0, 1.0, 0.0, 1.0); } - void MedianVS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 Offsets[3] : TEXCOORD0) + void Median_VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Offsets[3] : TEXCOORD0) { - float2 TexCoord0; - PostProcessVS(ID, Position, TexCoord0); - MedianOffsets(TexCoord0, 1.0 / uint2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1), Offsets); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + Median_Offsets(VS_Coord, 1.0 / int2(BUFFER_WIDTH >> 1, BUFFER_HEIGHT >> 1), Offsets); } - void TentFilterVS(in uint ID, in float2 TexelSize, inout float4 Position, inout float4 Offsets[3]) + void TentFilterVS(in uint ID, in float2 Texel_Size, inout float4 Position, inout float4 Offsets[3]) { - float2 TexCoord0 = 0.0; - PostProcessVS(ID, Position, TexCoord0); - TentOffsets(TexCoord0, TexelSize, Offsets); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + TentOffsets(VS_Coord, Texel_Size, Offsets); } - void TentFilter0VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter0VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_0, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_0, Position, Coord); } - void TentFilter1VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter1VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_1, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_1, Position, Coord); } - void TentFilter2VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter2VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_2, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_2, Position, Coord); } - void TentFilter3VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter3VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_3, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_3, Position, Coord); } - void TentFilter4VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter4VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_4, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_4, Position, Coord); } - void TentFilter5VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter5VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_5, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_5, Position, Coord); } - void TentFilter6VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter6VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_6, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_6, Position, Coord); } - void TentFilter7VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter7VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_7, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_7, Position, Coord); } - void TentFilter8VS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoord[3] : TEXCOORD0) + void TentFilter8VS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coord[3] : TEXCOORD0) { - TentFilterVS(ID, 1.0 / BUFFER_SIZE_8, Position, TexCoord); + TentFilterVS(ID, 1.0 / BUFFER_SIZE_8, Position, Coord); } - void DerivativesVS(in uint ID : SV_VertexID, inout float4 Position : SV_Position, inout float4 TexCoords[2] : TEXCOORD0) + void DerivativesVS(in uint ID : SV_VERTEXID, inout float4 Position : SV_POSITION, inout float4 Coords[2] : TEXCOORD0) { - float2 VSTexCoord = 0.0; - PostProcessVS(ID, Position, VSTexCoord); - const float2 PixelSize = 1.0 / BUFFER_SIZE_1; - TexCoords[0] = VSTexCoord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) * PixelSize.xxyy); - TexCoords[1] = VSTexCoord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) * PixelSize.xxyy); + float2 VS_Coord = 0.0; + Basic_VS(ID, Position, VS_Coord); + const float2 Pixel_Size = 1.0 / BUFFER_SIZE_1; + Coords[0] = VS_Coord.xxyy + (float4(-1.5, 1.5, -0.5, 0.5) * Pixel_Size.xxyy); + Coords[1] = VS_Coord.xxyy + (float4(-0.5, 0.5, -1.5, 1.5) * Pixel_Size.xxyy); } // Pixel shaders @@ -484,25 +484,25 @@ namespace OpticalFlow return min(min(a, b), c); } - float4 Med3(float4 a, float4 b, float4 c) + float4 Median_3(float4 a, float4 b, float4 c) { return clamp(a, min(b, c), max(b, c)); } - float4 Med9(float4 x0, float4 x1, float4 x2, + float4 Median_9(float4 x0, float4 x1, float4 x2, float4 x3, float4 x4, float4 x5, float4 x6, float4 x7, float4 x8) { float4 A = Max3(Min3(x0, x1, x2), Min3(x3, x4, x5), Min3(x6, x7, x8)); float4 B = Min3(Max3(x0, x1, x2), Max3(x3, x4, x5), Max3(x6, x7, x8)); - float4 C = Med3(Med3(x0, x1, x2), Med3(x3, x4, x5), Med3(x6, x7, x8)); - return Med3(A, B, C); + float4 C = Median_3(Median_3(x0, x1, x2), Median_3(x3, x4, x5), Median_3(x6, x7, x8)); + return Median_3(A, B, C); } - float4 Chroma(in sampler2D Source, in float2 TexCoord) + float4 Chroma(in sampler2D Source, in float2 Coord) { float4 Color; - Color = tex2D(Source, TexCoord); + Color = tex2D(Source, Coord); Color = max(Color, exp2(-10.0)); return saturate(Color / dot(Color.rgb, 1.0)); } @@ -510,19 +510,19 @@ namespace OpticalFlow float4 TentFilterPS(sampler2D Source, float4 Offsets[3]) { // Sample locations: - // A0 B0 C0 - // A1 B1 C1 - // A2 B2 C2 - float4 A0 = tex2D(Source, Offsets[0].xy); - float4 A1 = tex2D(Source, Offsets[0].xz); - float4 A2 = tex2D(Source, Offsets[0].xw); - float4 B0 = tex2D(Source, Offsets[1].xy); - float4 B1 = tex2D(Source, Offsets[1].xz); - float4 B2 = tex2D(Source, Offsets[1].xw); - float4 C0 = tex2D(Source, Offsets[2].xy); - float4 C1 = tex2D(Source, Offsets[2].xz); - float4 C2 = tex2D(Source, Offsets[2].xw); - return (((A0 + C0 + A2 + C2) * 1.0) + ((B0 + A1 + C1 + B2) * 2.0) + (B1 * 4.0)) / 16.0; + // A_0 B_0 C_0 + // A_1 B_1 C_1 + // A_2 B_2 C_2 + float4 A_0 = tex2D(Source, Offsets[0].xy); + float4 A_1 = tex2D(Source, Offsets[0].xz); + float4 A_2 = tex2D(Source, Offsets[0].xw); + float4 B_0 = tex2D(Source, Offsets[1].xy); + float4 B_1 = tex2D(Source, Offsets[1].xz); + float4 B_2 = tex2D(Source, Offsets[1].xw); + float4 C_0 = tex2D(Source, Offsets[2].xy); + float4 C_1 = tex2D(Source, Offsets[2].xz); + float4 C_2 = tex2D(Source, Offsets[2].xw); + return (((A_0 + C_0 + A_2 + C_2) * 1.0) + ((B_0 + A_1 + C_1 + B_2) * 2.0) + (B_1 * 4.0)) / 16.0; } /* @@ -540,8 +540,8 @@ namespace OpticalFlow Matrix => Horn–Schunck Matrix => Horn–Schunck Equation => Solving Equation Matrix - [A11 A12] [X1] = [B1] - [A21 A22] [X2] = [B2] + [A11 A12] [X1] = [B_1] + [A21 A22] [X2] = [B_2] Horn–Schunck Matrix [(Ix^2 + a) (IxIy)] [U] = [aU - IxIt] @@ -570,322 +570,322 @@ namespace OpticalFlow THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - #define MaxLevel 7 + #define Max_Level 7 #define E _Smoothness * 2e-2 - void CoarseOpticalFlowTV(in float2 TexCoord, in float Level, in float2 UV, out float2 DUV) + void Coarse_Optical_Flow_TV(in float2 Coord, in float Level, in float2 UV, out float2 DUV) { DUV = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7); + const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7); - float2 CurrentFrame = tex2D(SampleCommon_RG16F_1a, TexCoord).xy; - float2 PreviousFrame = tex2D(SamplePreviousBuffer, TexCoord).xy; + float2 CurrentFrame = tex2D(Sample_Common_RG16F_1a, Coord).xy; + float2 PreviousFrame = tex2D(SamplePreviousBuffer, Coord).xy; // - float4 SD = tex2D(SampleCommon_RGBA16F_1a, TexCoord); + float4 S_D = tex2D(Sample_Common_RGBA16F_1a, Coord); // - float2 TD = CurrentFrame - PreviousFrame; + float2 T_D = CurrentFrame - PreviousFrame; // Calculate constancy term float C = 0.0; - C = dot(TD, 1.0); + C = dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); float2 Aii = 0.0; - Aii.x = 1.0 / (C * dot(SD.xy, SD.xy) + Alpha); - Aii.y = 1.0 / (C * dot(SD.zw, SD.zw) + Alpha); - float Aij = C * dot(SD.xy, SD.zw); + Aii.x = 1.0 / (C * dot(S_D.xy, S_D.xy) + Alpha); + Aii.y = 1.0 / (C * dot(S_D.zw, S_D.zw) + Alpha); + float Aij = C * dot(S_D.xy, S_D.zw); float2 Bi = 0.0; - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); // Gauss-Seidel (forward sweep, from 1...N) DUV.x = Aii.x * ((Alpha * UV.x) - (Aij * UV.y) - Bi.x); DUV.y = Aii.y * ((Alpha * UV.y) - (Aij * DUV.x) - Bi.y); } - void ProcessGradAvg(in float2 SampleNW, - in float2 SampleNE, - in float2 SampleSW, - in float2 SampleSE, - out float Grad, - out float2 Avg) + void ProcessGradAvg(in float2 Sample_NW, + in float2 Sample_NE, + in float2 Sample_SW, + in float2 Sample_SE, + out float Gradient, + out float2 Average) { // NW NE // SW SE - float4 GradUV = 0.0; - GradUV.xy = (SampleNW + SampleSW) - (SampleNE + SampleSE); // - GradUV.zw = (SampleNW + SampleNE) - (SampleSW + SampleSE); // - GradUV = GradUV * 0.5; - Grad = rsqrt((dot(GradUV.xzyw, GradUV.xzyw) * 0.25) + (E * E)); - Avg = (SampleNW + SampleNE + SampleSW + SampleSE) * 0.25; + float4 Sq_Gradient_UV = 0.0; + Sq_Gradient_UV.xy = (Sample_NW + Sample_SW) - (Sample_NE + Sample_SE); // + Sq_Gradient_UV.zw = (Sample_NW + Sample_NE) - (Sample_SW + Sample_SE); // + Sq_Gradient_UV = Sq_Gradient_UV * 0.5; + Gradient = rsqrt((dot(Sq_Gradient_UV.xzyw, Sq_Gradient_UV.xzyw) * 0.25) + (E * E)); + Average = (Sample_NW + Sample_NE + Sample_SW + Sample_SE) * 0.25; } - void ProcessArea(in float2 SampleUV[9], - inout float4 UVGrad, - inout float2 CenterAvg, - inout float2 UVAvg) + void ProcessArea(in float2 Sample_UV[9], + inout float4 UV_Gradient, + inout float2 Center_Average, + inout float2 UV_Average) { - float CenterGrad = 0.0; - float4 AreaGrad = 0.0; - float2 AreaAvg[4]; - float4 GradUV = 0.0; + float Center_Gradient = 0.0; + float4 Area_Gradient = 0.0; + float2 Area_Average[4]; + float4 Sq_Gradient_UV = 0.0; float SqGradUV = 0.0; // Center smoothness gradient and average // 0 3 6 // 1 4 7 // 2 5 8 - GradUV.xy = (SampleUV[0] + (SampleUV[1] * 2.0) + SampleUV[2]) - (SampleUV[6] + (SampleUV[7] * 2.0) + SampleUV[8]); // - GradUV.zw = (SampleUV[0] + (SampleUV[3] * 2.0) + SampleUV[6]) - (SampleUV[2] + (SampleUV[5] * 2.0) + SampleUV[8]); // - SqGradUV = dot(GradUV.xzyw / 4.0, GradUV.xzyw / 4.0) * 0.25; - CenterGrad = rsqrt(SqGradUV + (E * E)); + Sq_Gradient_UV.xy = (Sample_UV[0] + (Sample_UV[1] * 2.0) + Sample_UV[2]) - (Sample_UV[6] + (Sample_UV[7] * 2.0) + Sample_UV[8]); // + Sq_Gradient_UV.zw = (Sample_UV[0] + (Sample_UV[3] * 2.0) + Sample_UV[6]) - (Sample_UV[2] + (Sample_UV[5] * 2.0) + Sample_UV[8]); // + SqGradUV = dot(Sq_Gradient_UV.xzyw / 4.0, Sq_Gradient_UV.xzyw / 4.0) * 0.25; + Center_Gradient = rsqrt(SqGradUV + (E * E)); - CenterAvg += ((SampleUV[0] + SampleUV[6] + SampleUV[2] + SampleUV[8]) * 1.0); - CenterAvg += ((SampleUV[3] + SampleUV[1] + SampleUV[7] + SampleUV[5]) * 2.0); - CenterAvg += (SampleUV[4] * 4.0); - CenterAvg = CenterAvg / 16.0; + Center_Average += ((Sample_UV[0] + Sample_UV[6] + Sample_UV[2] + Sample_UV[8]) * 1.0); + Center_Average += ((Sample_UV[3] + Sample_UV[1] + Sample_UV[7] + Sample_UV[5]) * 2.0); + Center_Average += (Sample_UV[4] * 4.0); + Center_Average = Center_Average / 16.0; // North-west gradient and average // 0 3 . // 1 4 . // . . . - ProcessGradAvg(SampleUV[0], SampleUV[3], SampleUV[1], SampleUV[4], AreaGrad[0], AreaAvg[0]); + ProcessGradAvg(Sample_UV[0], Sample_UV[3], Sample_UV[1], Sample_UV[4], Area_Gradient[0], Area_Average[0]); // North-east gradient and average // . 3 6 // . 4 7 // . . . - ProcessGradAvg(SampleUV[3], SampleUV[6], SampleUV[4], SampleUV[7], AreaGrad[1], AreaAvg[1]); + ProcessGradAvg(Sample_UV[3], Sample_UV[6], Sample_UV[4], Sample_UV[7], Area_Gradient[1], Area_Average[1]); // South-west gradient and average // . . . // 1 4 . // 2 5 . - ProcessGradAvg(SampleUV[1], SampleUV[4], SampleUV[2], SampleUV[5], AreaGrad[2], AreaAvg[2]); + ProcessGradAvg(Sample_UV[1], Sample_UV[4], Sample_UV[2], Sample_UV[5], Area_Gradient[2], Area_Average[2]); // South-east and average // . . . // . 4 7 // . 5 8 - ProcessGradAvg(SampleUV[4], SampleUV[7], SampleUV[5], SampleUV[8], AreaGrad[3], AreaAvg[3]); + ProcessGradAvg(Sample_UV[4], Sample_UV[7], Sample_UV[5], Sample_UV[8], Area_Gradient[3], Area_Average[3]); - UVGrad = 0.5 * (CenterGrad + AreaGrad); - UVAvg = (AreaGrad[0] * AreaAvg[0]) + (AreaGrad[1] * AreaAvg[1]) + (AreaGrad[2] * AreaAvg[2]) + (AreaGrad[3] * AreaAvg[3]); + UV_Gradient = 0.5 * (Center_Gradient + Area_Gradient); + UV_Average = (Area_Gradient[0] * Area_Average[0]) + (Area_Gradient[1] * Area_Average[1]) + (Area_Gradient[2] * Area_Average[2]) + (Area_Gradient[3] * Area_Average[3]); } - void OpticalFlowTV(in sampler2D SourceUV, in float4 TexCoords[3], in float Level, out float2 DUV) + void Optical_Flow_TV(in sampler2D SourceUV, in float4 Coords[3], in float Level, out float2 DUV) { DUV = 0.0; - const float Alpha = max(ldexp(_Constraint * 1e-4, Level - MaxLevel), 1e-7); + const float Alpha = max(ldexp(_Constraint * 1e-4, Level - Max_Level), 1e-7); // Load textures - float2 CurrentFrame = tex2D(SampleCommon_RG16F_1a, TexCoords[1].xz).xy; - float2 PreviousFrame = tex2D(SamplePreviousBuffer, TexCoords[1].xz).xy; - float4 SD = tex2D(SampleCommon_RGBA16F_1a, TexCoords[1].xz); // - float2 TD = CurrentFrame - PreviousFrame; // + float2 CurrentFrame = tex2D(Sample_Common_RG16F_1a, Coords[1].xz).xy; + float2 PreviousFrame = tex2D(SamplePreviousBuffer, Coords[1].xz).xy; + float4 S_D = tex2D(Sample_Common_RGBA16F_1a, Coords[1].xz); // + float2 T_D = CurrentFrame - PreviousFrame; // // Optical flow calculation - float2 SampleUV[9]; - float4 UVGrad = 0.0; - float2 CenterAvg = 0.0; - float2 UVAvg = 0.0; + float2 Sample_UV[9]; + float4 UV_Gradient = 0.0; + float2 Center_Average = 0.0; + float2 UV_Average = 0.0; - // SampleUV[i] + // Sample_UV[i] // 0 3 6 // 1 4 7 // 2 5 8 - SampleUV[0] = tex2D(SourceUV, TexCoords[0].xy).xy; - SampleUV[1] = tex2D(SourceUV, TexCoords[0].xz).xy; - SampleUV[2] = tex2D(SourceUV, TexCoords[0].xw).xy; - SampleUV[3] = tex2D(SourceUV, TexCoords[1].xy).xy; - SampleUV[4] = tex2D(SourceUV, TexCoords[1].xz).xy; - SampleUV[5] = tex2D(SourceUV, TexCoords[1].xw).xy; - SampleUV[6] = tex2D(SourceUV, TexCoords[2].xy).xy; - SampleUV[7] = tex2D(SourceUV, TexCoords[2].xz).xy; - SampleUV[8] = tex2D(SourceUV, TexCoords[2].xw).xy; - - ProcessArea(SampleUV, UVGrad, CenterAvg, UVAvg); + Sample_UV[0] = tex2D(SourceUV, Coords[0].xy).xy; + Sample_UV[1] = tex2D(SourceUV, Coords[0].xz).xy; + Sample_UV[2] = tex2D(SourceUV, Coords[0].xw).xy; + Sample_UV[3] = tex2D(SourceUV, Coords[1].xy).xy; + Sample_UV[4] = tex2D(SourceUV, Coords[1].xz).xy; + Sample_UV[5] = tex2D(SourceUV, Coords[1].xw).xy; + Sample_UV[6] = tex2D(SourceUV, Coords[2].xy).xy; + Sample_UV[7] = tex2D(SourceUV, Coords[2].xz).xy; + Sample_UV[8] = tex2D(SourceUV, Coords[2].xw).xy; + + ProcessArea(Sample_UV, UV_Gradient, Center_Average, UV_Average); // Calculate constancy term float C = 0.0; - C = dot(SD, CenterAvg.xyxy) + dot(TD, 1.0); + C = dot(S_D, Center_Average.xyxy) + dot(T_D, 1.0); C = rsqrt(C * C + (E * E)); float2 Aii = 0.0; - Aii.x = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.xy, SD.xy))); - Aii.y = 1.0 / (dot(UVGrad, 1.0) * Alpha + (C * dot(SD.zw, SD.zw))); - float Aij = dot(SD.xy, SD.zw); + Aii.x = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.xy, S_D.xy))); + Aii.y = 1.0 / (dot(UV_Gradient, 1.0) * Alpha + (C * dot(S_D.zw, S_D.zw))); + float Aij = dot(S_D.xy, S_D.zw); float2 Bi = 0.0; - Bi.x = C * dot(SD.xy, TD); - Bi.y = C * dot(SD.zw, TD); + Bi.x = C * dot(S_D.xy, T_D); + Bi.y = C * dot(S_D.zw, T_D); // Gauss-Seidel (forward sweep, from 1...N) - DUV.x = Aii.x * ((Alpha * UVAvg.x) - (C * Aij * CenterAvg.y) - Bi.x); - DUV.y = Aii.y * ((Alpha * UVAvg.y) - (C * Aij * DUV.x) - Bi.y); + DUV.x = Aii.x * ((Alpha * UV_Average.x) - (C * Aij * Center_Average.y) - Bi.x); + DUV.y = Aii.y * ((Alpha * UV_Average.y) - (C * Aij * DUV.x) - Bi.y); } - void NormalizePS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void NormalizePS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Sample locations: - // A0 B0 C0 - // A1 B1 C1 - // A2 B2 C2 - float4 A0 = Chroma(SampleColor, TexCoords[0].xy); - float4 A1 = Chroma(SampleColor, TexCoords[0].xz); - float4 A2 = Chroma(SampleColor, TexCoords[0].xw); - float4 B0 = Chroma(SampleColor, TexCoords[1].xy); - float4 B1 = Chroma(SampleColor, TexCoords[1].xz); - float4 B2 = Chroma(SampleColor, TexCoords[1].xw); - float4 C0 = Chroma(SampleColor, TexCoords[2].xy); - float4 C1 = Chroma(SampleColor, TexCoords[2].xz); - float4 C2 = Chroma(SampleColor, TexCoords[2].xw); - OutputColor0 = Med9(A0, B0, C0, - A1, B1, C1, - A2, B2, C2); + // A_0 B_0 C_0 + // A_1 B_1 C_1 + // A_2 B_2 C_2 + float4 A_0 = Chroma(Sample_Color, Coords[0].xy); + float4 A_1 = Chroma(Sample_Color, Coords[0].xz); + float4 A_2 = Chroma(Sample_Color, Coords[0].xw); + float4 B_0 = Chroma(Sample_Color, Coords[1].xy); + float4 B_1 = Chroma(Sample_Color, Coords[1].xz); + float4 B_2 = Chroma(Sample_Color, Coords[1].xw); + float4 C_0 = Chroma(Sample_Color, Coords[2].xy); + float4 C_1 = Chroma(Sample_Color, Coords[2].xz); + float4 C_2 = Chroma(Sample_Color, Coords[2].xw); + Output_Color_0 = Median_9(A_0, B_0, C_0, + A_1, B_1, C_1, + A_2, B_2, C_2); } - void PreDownsample2PS(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PreDownsample2PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_1a, TexCoord); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_1a, Coord); } - void PreDownsample3PS(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PreDownsample3PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_2, TexCoord); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_2, Coord); } - void PreDownsample4PS(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PreDownsample4PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_3, TexCoord); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_3, Coord); } - void PreUpsample3PS(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PreUpsample3PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_4, TexCoord); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_4, Coord); } - void PreUpsample2PS(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PreUpsample2PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_3, TexCoord); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_3, Coord); } - void PreUpsample1PS(in float4 Position : SV_Position, in float4 TexCoord[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PreUpsample1PS(in float4 Position : SV_POSITION, in float4 Coord[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_2, TexCoord); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_2, Coord); } - void DerivativesPS(in float4 Position : SV_Position, in float4 TexCoords[2] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void DerivativesPS(in float4 Position : SV_POSITION, in float4 Coords[2] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Bilinear 5x5 Sobel by CeeJayDK - // B1 B2 - // A0 A1 - // A2 B0 - // C0 C1 - float2 A0 = tex2D(SampleCommon_RG16F_1a, TexCoords[0].xw).xy * 4.0; // <-1.5, +0.5> - float2 A1 = tex2D(SampleCommon_RG16F_1a, TexCoords[0].yw).xy * 4.0; // <+1.5, +0.5> - float2 A2 = tex2D(SampleCommon_RG16F_1a, TexCoords[0].xz).xy * 4.0; // <-1.5, -0.5> - float2 B0 = tex2D(SampleCommon_RG16F_1a, TexCoords[0].yz).xy * 4.0; // <+1.5, -0.5> - float2 B1 = tex2D(SampleCommon_RG16F_1a, TexCoords[1].xw).xy * 4.0; // <-0.5, +1.5> - float2 B2 = tex2D(SampleCommon_RG16F_1a, TexCoords[1].yw).xy * 4.0; // <+0.5, +1.5> - float2 C0 = tex2D(SampleCommon_RG16F_1a, TexCoords[1].xz).xy * 4.0; // <-0.5, -1.5> - float2 C1 = tex2D(SampleCommon_RG16F_1a, TexCoords[1].yz).xy * 4.0; // <+0.5, -1.5> + // B_1 B_2 + // A_0 A_1 + // A_2 B_0 + // C_0 C_1 + float2 A_0 = tex2D(Sample_Common_RG16F_1a, Coords[0].xw).xy * 4.0; // <-1.5, +0.5> + float2 A_1 = tex2D(Sample_Common_RG16F_1a, Coords[0].yw).xy * 4.0; // <+1.5, +0.5> + float2 A_2 = tex2D(Sample_Common_RG16F_1a, Coords[0].xz).xy * 4.0; // <-1.5, -0.5> + float2 B_0 = tex2D(Sample_Common_RG16F_1a, Coords[0].yz).xy * 4.0; // <+1.5, -0.5> + float2 B_1 = tex2D(Sample_Common_RG16F_1a, Coords[1].xw).xy * 4.0; // <-0.5, +1.5> + float2 B_2 = tex2D(Sample_Common_RG16F_1a, Coords[1].yw).xy * 4.0; // <+0.5, +1.5> + float2 C_0 = tex2D(Sample_Common_RG16F_1a, Coords[1].xz).xy * 4.0; // <-0.5, -1.5> + float2 C_1 = tex2D(Sample_Common_RG16F_1a, Coords[1].yz).xy * 4.0; // <+0.5, -1.5> // -1 0 +1 // -1 -2 0 +2 +1 // -2 -2 0 +2 +2 // -1 -2 0 +2 +1 // -1 0 +1 - OutputColor0.xy = ((B2 + A1 + B0 + C1) - (B1 + A0 + A2 + C0)) / 12.0; + Output_Color_0.xy = ((B_2 + A_1 + B_0 + C_1) - (B_1 + A_0 + A_2 + C_0)) / 12.0; // +1 +2 +1 // +1 +2 +2 +2 +1 // 0 0 0 0 0 // -1 -2 -2 -2 -1 // -1 -2 -1 - OutputColor0.zw = ((A0 + B1 + B2 + A1) - (A2 + C0 + C1 + B0)) / 12.0; - OutputColor0.xz *= rsqrt(dot(OutputColor0.xz, OutputColor0.xz) + 1.0); - OutputColor0.yw *= rsqrt(dot(OutputColor0.yw, OutputColor0.yw) + 1.0); + Output_Color_0.zw = ((A_0 + B_1 + B_2 + A_1) - (A_2 + C_0 + C_1 + B_0)) / 12.0; + Output_Color_0.xz *= rsqrt(dot(Output_Color_0.xz, Output_Color_0.xz) + 1.0); + Output_Color_0.yw *= rsqrt(dot(Output_Color_0.yw, Output_Color_0.yw) + 1.0); } - void EstimateLevel8PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float2 OutputColor0 : SV_Target0) + void EstimateLevel8PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float2 Output_Color_0 : SV_TARGET0) { - CoarseOpticalFlowTV(TexCoord, 7.0, 0.0, OutputColor0); + Coarse_Optical_Flow_TV(Coord, 7.0, 0.0, Output_Color_0); } - void EstimateLevel7PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 OutputColor0 : SV_Target0) + void EstimateLevel7PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SampleCommon_RG16F_8, TexCoords, 6.0, OutputColor0); + Optical_Flow_TV(Sample_Common_RG16F_8, Coords, 6.0, Output_Color_0); } - void EstimateLevel6PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 OutputColor0 : SV_Target0) + void EstimateLevel6PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SampleCommon_RG16F_7, TexCoords, 5.0, OutputColor0); + Optical_Flow_TV(Sample_Common_RG16F_7, Coords, 5.0, Output_Color_0); } - void EstimateLevel5PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 OutputColor0 : SV_Target0) + void EstimateLevel5PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SampleCommon_RG16F_6, TexCoords, 4.0, OutputColor0); + Optical_Flow_TV(Sample_Common_RG16F_6, Coords, 4.0, Output_Color_0); } - void EstimateLevel4PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 OutputColor0 : SV_Target0) + void EstimateLevel4PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SampleCommon_RG16F_5, TexCoords, 3.0, OutputColor0); + Optical_Flow_TV(Sample_Common_RG16F_5, Coords, 3.0, Output_Color_0); } - void EstimateLevel3PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 OutputColor0 : SV_Target0) + void EstimateLevel3PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SampleCommon_RG16F_4, TexCoords, 2.0, OutputColor0); + Optical_Flow_TV(Sample_Common_RG16F_4, Coords, 2.0, Output_Color_0); } - void EstimateLevel2PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float2 OutputColor0 : SV_Target0) + void EstimateLevel2PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float2 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SampleCommon_RG16F_3, TexCoords, 1.0, OutputColor0); + Optical_Flow_TV(Sample_Common_RG16F_3, Coords, 1.0, Output_Color_0); } - void EstimateLevel1PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void EstimateLevel1PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OpticalFlowTV(SampleCommon_RG16F_2, TexCoords, 0.0, OutputColor0.xy); - OutputColor0.xy *= float2(1.0, -1.0); - OutputColor0.ba = (0.0, _BlendFactor); + Optical_Flow_TV(Sample_Common_RG16F_2, Coords, 0.0, Output_Color_0.xy); + Output_Color_0.xy *= float2(1.0, -1.0); + Output_Color_0.ba = (0.0, _Blend_Factor); } - void PostDownsample2PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PostDownsample2PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleVectors, TexCoords); + Output_Color_0 = TentFilterPS(SampleVectors, Coords); } - void PostDownsample3PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PostDownsample3PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_2, TexCoords); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_2, Coords); } - void PostDownsample4PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PostDownsample4PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_3, TexCoords); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_3, Coords); } - void PostUpsample3PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PostUpsample3PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_4, TexCoords); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_4, Coords); } - void PostUpsample2PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void PostUpsample2PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_3, TexCoords); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_3, Coords); } - void PostUpsample1PS(in float4 Position : SV_Position, in float4 TexCoords[3] : TEXCOORD0, out float4 OutputColor0 : SV_Target0, out float4 OutputColor1 : SV_Target1) + void PostUpsample1PS(in float4 Position : SV_POSITION, in float4 Coords[3] : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0, out float4 Output_Color_1 : SV_TARGET1) { - OutputColor0 = TentFilterPS(SampleCommon_RG16F_2, TexCoords); + Output_Color_0 = TentFilterPS(Sample_Common_RG16F_2, Coords); // Copy current convolved result to use at next frame - OutputColor1 = tex2D(SampleCommon_RG16F_1a, TexCoords[1].xz).rg; + Output_Color_1 = tex2D(Sample_Common_RG16F_1a, Coords[1].xz).rg; } /* @@ -917,32 +917,32 @@ namespace OpticalFlow For more information, please refer to */ - float RandomNoise(float2 TexCoord) + float RandomNoise(float2 Coord) { - float f = dot(float2(12.9898, 78.233), TexCoord); + float f = dot(float2(12.9898, 78.233), Coord); return frac(43758.5453 * sin(f)); } - void AccumulatePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void AccumulatePS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { float Quality = 1.0 - _Entropy; float2 Time = float2(_Time, 0.0); // Random numbers float3 Random; - Random.x = RandomNoise(TexCoord.xy + Time.xy); - Random.y = RandomNoise(TexCoord.xy + Time.yx); - Random.z = RandomNoise(TexCoord.yx - Time.xx); + Random.x = RandomNoise(Coord.xy + Time.xy); + Random.y = RandomNoise(Coord.xy + Time.yx); + Random.z = RandomNoise(Coord.yx - Time.xx); // Motion vector - float2 MotionVectors = tex2Dlod(SampleVectorsPost, float4(TexCoord, 0.0, _MipBias)).xy; - MotionVectors = MotionVectors * BUFFER_SIZE_1; // Normalized screen space -> Pixel coordinates - MotionVectors *= _Scale; - MotionVectors += (Random.xy - 0.5) * _Diffusion; // Small random displacement (diffusion) - MotionVectors = round(MotionVectors); // Pixel perfect snapping + float2 Motion_Vectors = tex2Dlod(SampleVectorsPost, float4(Coord, 0.0, _Mip_Bias)).xy; + Motion_Vectors = Motion_Vectors * BUFFER_SIZE_1; // Normalized screen space -> Pixel coordinates + Motion_Vectors *= _Scale; + Motion_Vectors += (Random.xy - 0.5) * _Diffusion; // Small random displacement (diffusion) + Motion_Vectors = round(Motion_Vectors); // Pixel perfect snapping // Accumulates the amount of motion. - float MotionVectorLength = length(MotionVectors); + float MotionVectorLength = length(Motion_Vectors); // - Simple update float UpdateAccumulation = min(MotionVectorLength, _BlockSize) * 0.005; @@ -952,11 +952,11 @@ namespace OpticalFlow float ResetAccumulation = saturate(Random.z * 0.5 + Quality); // - Reset if the amount of motion is larger than the block size. - OutputColor0.rgb = MotionVectorLength > _BlockSize ? ResetAccumulation : UpdateAccumulation; - OutputColor0.a = MotionVectorLength > _BlockSize ? 0.0 : 1.0; + Output_Color_0.rgb = MotionVectorLength > _BlockSize ? ResetAccumulation : UpdateAccumulation; + Output_Color_0.a = MotionVectorLength > _BlockSize ? 0.0 : 1.0; } - void DatamoshPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void DatamoshPS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { const float2 DisplacementTexel = 1.0 / BUFFER_SIZE_1; const float Quality = 1.0 - _Entropy; @@ -964,28 +964,28 @@ namespace OpticalFlow // Random numbers float2 Time = float2(_Time, 0.0); float3 Random; - Random.x = RandomNoise(TexCoord.xy + Time.xy); - Random.y = RandomNoise(TexCoord.xy + Time.yx); - Random.z = RandomNoise(TexCoord.yx - Time.xx); + Random.x = RandomNoise(Coord.xy + Time.xy); + Random.y = RandomNoise(Coord.xy + Time.yx); + Random.z = RandomNoise(Coord.yx - Time.xx); - float2 MotionVectors = tex2Dlod(SampleVectorsPost, float4(TexCoord, 0.0, _MipBias)).xy; - MotionVectors *= _Scale; + float2 Motion_Vectors = tex2Dlod(SampleVectorsPost, float4(Coord, 0.0, _Mip_Bias)).xy; + Motion_Vectors *= _Scale; - float4 Source = tex2D(SampleColor, TexCoord); // Color from the original image - float Displacement = tex2D(SampleAccumulation, TexCoord).r; // Displacement vector - float4 Working = tex2D(SampleFeedback, TexCoord - MotionVectors * DisplacementTexel); + float4 Source = tex2D(Sample_Color, Coord); // Color from the original image + float Displacement = tex2D(SampleAccumulation, Coord).r; // Displacement vector + float4 Working = tex2D(SampleFeedback, Coord - Motion_Vectors * DisplacementTexel); - MotionVectors *= uint2(BUFFER_WIDTH, BUFFER_HEIGHT); // Normalized screen space -> Pixel coordinates - MotionVectors += (Random.xy - 0.5) * _Diffusion; // Small random displacement (diffusion) - MotionVectors = round(MotionVectors); // Pixel perfect snapping - MotionVectors *= (1.0 / uint2(BUFFER_WIDTH, BUFFER_HEIGHT)); // Pixel coordinates -> Normalized screen space + Motion_Vectors *= int2(BUFFER_WIDTH, BUFFER_HEIGHT); // Normalized screen space -> Pixel coordinates + Motion_Vectors += (Random.xy - 0.5) * _Diffusion; // Small random displacement (diffusion) + Motion_Vectors = round(Motion_Vectors); // Pixel perfect snapping + Motion_Vectors *= (1.0 / int2(BUFFER_WIDTH, BUFFER_HEIGHT)); // Pixel coordinates -> Normalized screen space // Generate some pseudo random numbers. - float RandomMotion = RandomNoise(TexCoord + length(MotionVectors)); + float RandomMotion = RandomNoise(Coord + length(Motion_Vectors)); float4 RandomNumbers = frac(float4(1.0, 17.37135, 841.4272, 3305.121) * RandomMotion); // Generate noise patterns that look like DCT bases. - float2 Frequency = TexCoord * DisplacementTexel * (RandomNumbers.x * 80.0 / _Contrast); + float2 Frequency = Coord * DisplacementTexel * (RandomNumbers.x * 80.0 / _Contrast); // - Basis wave (vertical or horizontal) float DCT = cos(lerp(Frequency.x, Frequency.y, 0.5 < RandomNumbers.y)); // - Random amplitude (the high freq, the less amp) @@ -998,12 +998,12 @@ namespace OpticalFlow ConditionalWeight = lerp(ConditionalWeight, 1.0, RandomNumbers.w < lerp(0.2, 1.0, Quality) * (Displacement > 1.0 - 1e-3)); // - If the conditions above are not met, choose work. - OutputColor0 = lerp(Working, Source, ConditionalWeight); + Output_Color_0 = lerp(Working, Source, ConditionalWeight); } - void Copy0PS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) + void Copy0PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - OutputColor0 = tex2D(SampleColor, TexCoord); + Output_Color_0 = tex2D(Sample_Color, Coord); } technique KinoDatamosh @@ -1012,9 +1012,9 @@ namespace OpticalFlow pass { - VertexShader = MedianVS; + VertexShader = Median_VS; PixelShader = NormalizePS; - RenderTarget0 = SharedResources::RG16F::RenderCommon1; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_1; } // Pre-process dual-filter blur @@ -1023,42 +1023,42 @@ namespace OpticalFlow { VertexShader = TentFilter1VS; PixelShader = PreDownsample2PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon2; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_2; } pass { VertexShader = TentFilter2VS; PixelShader = PreDownsample3PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon3; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_3; } pass { VertexShader = TentFilter3VS; PixelShader = PreDownsample4PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon4; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_4; } pass { VertexShader = TentFilter4VS; PixelShader = PreUpsample3PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon3; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_3; } pass { VertexShader = TentFilter3VS; PixelShader = PreUpsample2PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon2; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_2; } pass { VertexShader = TentFilter2VS; PixelShader = PreUpsample1PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon1; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_1; } // Construct pyramids @@ -1067,58 +1067,58 @@ namespace OpticalFlow { VertexShader = DerivativesVS; PixelShader = DerivativesPS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon1; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_1; } // Pyramidal estimation pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = EstimateLevel8PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon8; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_8; } pass { VertexShader = TentFilter8VS; PixelShader = EstimateLevel7PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon7; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_7; } pass { VertexShader = TentFilter7VS; PixelShader = EstimateLevel6PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon6; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_6; } pass { VertexShader = TentFilter6VS; PixelShader = EstimateLevel5PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon5; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_5; } pass { VertexShader = TentFilter5VS; PixelShader = EstimateLevel4PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon4; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_4; } pass { VertexShader = TentFilter4VS; PixelShader = EstimateLevel3PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon3; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_3; } pass { VertexShader = TentFilter3VS; PixelShader = EstimateLevel2PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon2; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_2; } pass @@ -1139,42 +1139,42 @@ namespace OpticalFlow { VertexShader = TentFilter1VS; PixelShader = PostDownsample2PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon2; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_2; } pass { VertexShader = TentFilter2VS; PixelShader = PostDownsample3PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon3; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_3; } pass { VertexShader = TentFilter3VS; PixelShader = PostDownsample4PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon4; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_4; } pass { VertexShader = TentFilter4VS; PixelShader = PostUpsample3PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon3; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_3; } pass { VertexShader = TentFilter3VS; PixelShader = PostUpsample2PS; - RenderTarget0 = SharedResources::RG16F::RenderCommon2; + RenderTarget0 = Shared_Resources::RG16F::Render_Common_2; } pass { VertexShader = TentFilter2VS; PixelShader = PostUpsample1PS; - RenderTarget0 = SharedResources::RGBA16F::RenderCommon1; + RenderTarget0 = Shared_Resources::RGBA16F::Render_Common_1; // Copy previous frame RenderTarget1 = RenderPreviousBuffer; @@ -1184,7 +1184,7 @@ namespace OpticalFlow pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = AccumulatePS; RenderTarget0 = RenderAccumulation; ClearRenderTargets = FALSE; @@ -1196,7 +1196,7 @@ namespace OpticalFlow pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = DatamoshPS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; @@ -1207,7 +1207,7 @@ namespace OpticalFlow pass { - VertexShader = PostProcessVS; + VertexShader = Basic_VS; PixelShader = Copy0PS; RenderTarget = RenderFeedback; #if BUFFER_COLOR_BIT_DEPTH == 8 diff --git a/shaders/kMirror.fx b/shaders/kMirror.fx index 15dac46..a77e894 100644 --- a/shaders/kMirror.fx +++ b/shaders/kMirror.fx @@ -37,11 +37,11 @@ uniform float _Roll < uniform bool _Symmetry < > = true; -texture2D RenderColor : COLOR; +texture2D Render_Color : COLOR; -sampler2D SampleColor +sampler2D Sample_Color { - Texture = RenderColor; + Texture = Render_Color; MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; @@ -52,19 +52,19 @@ 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 MirrorPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Mirror_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { // Convert to polar coordinates - float2 Polar = TexCoord * 2.0 - 1.0; + float2 Polar = Coord * 2.0 - 1.0; float Phi = atan2(Polar.y, Polar.x); float Radius = length(Polar); @@ -75,20 +75,20 @@ void MirrorPS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, Phi += _Roll - _Offset; // Convert back to the texture coordinate. - float2 PhiSinCos; sincos(Phi, PhiSinCos.x, PhiSinCos.y); - TexCoord = (PhiSinCos.yx * Radius) * 0.5 + 0.5; + float2 Phi_Sin_Cos; sincos(Phi, Phi_Sin_Cos.x, Phi_Sin_Cos.y); + Coord = (Phi_Sin_Cos.yx * Radius) * 0.5 + 0.5; // Reflection at the border of the screen. - TexCoord = max(min(TexCoord, 2.0 - TexCoord), -TexCoord); - OutputColor0 = tex2D(SampleColor, TexCoord); + Coord = max(min(Coord, 2.0 - Coord), -Coord); + Output_Color_0 = tex2D(Sample_Color, Coord); } technique KinoMirror { pass { - VertexShader = PostProcessVS; - PixelShader = MirrorPS; + VertexShader = Basic_VS; + PixelShader = Mirror_PS; #if BUFFER_COLOR_BIT_DEPTH == 8 SRGBWriteEnable = TRUE; #endif diff --git a/shaders/kVignette.fx b/shaders/kVignette.fx index 449cc41..ae00b42 100644 --- a/shaders/kVignette.fx +++ b/shaders/kVignette.fx @@ -31,30 +31,30 @@ uniform float _Falloff < // 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 VignettePS(in float4 Position : SV_Position, in float2 TexCoord : TEXCOORD0, out float4 OutputColor0 : SV_Target0) +void Vignette_PS(in float4 Position : SV_POSITION, in float2 Coord : TEXCOORD0, out float4 Output_Color_0 : SV_TARGET0) { - const float AspectRatio = BUFFER_WIDTH / BUFFER_HEIGHT; - float2 Coord = (TexCoord * 2.0 - 1.0) * AspectRatio; + const float Aspect_Ratio = BUFFER_WIDTH / BUFFER_HEIGHT; + float2 Coord = (Coord * 2.0 - 1.0) * Aspect_Ratio; float Radius = length(Coord) * _Falloff; - float Radius2_1 = mad(Radius, Radius, 1.0); - OutputColor0 = rcp(Radius2_1 * Radius2_1); + float Radius_2_1 = mad(Radius, Radius, 1.0); + Output_Color_0 = rcp(Radius_2_1 * Radius_2_1); } technique KinoVignette { pass { - VertexShader = PostProcessVS; - PixelShader = VignettePS; + VertexShader = Basic_VS; + PixelShader = Vignette_PS; // Multiplication blend mode BlendEnable = TRUE; BlendOp = ADD;