duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

ReShade.fxh (3908B)


      1 #pragma once
      2 
      3 #if !defined(__RESHADE__) || __RESHADE__ < 30000
      4 	#error "ReShade 3.0+ is required to use this header file"
      5 #endif
      6 
      7 #ifndef RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
      8 	#define RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN 0
      9 #endif
     10 #ifndef RESHADE_DEPTH_INPUT_IS_REVERSED
     11 	#define RESHADE_DEPTH_INPUT_IS_REVERSED 1
     12 #endif
     13 #ifndef RESHADE_DEPTH_INPUT_IS_LOGARITHMIC
     14 	#define RESHADE_DEPTH_INPUT_IS_LOGARITHMIC 0
     15 #endif
     16 
     17 #ifndef RESHADE_DEPTH_MULTIPLIER
     18 	#define RESHADE_DEPTH_MULTIPLIER 1
     19 #endif
     20 #ifndef RESHADE_DEPTH_LINEARIZATION_FAR_PLANE
     21 	#define RESHADE_DEPTH_LINEARIZATION_FAR_PLANE 1000.0
     22 #endif
     23 
     24 // Above 1 expands coordinates, below 1 contracts and 1 is equal to no scaling on any axis
     25 #ifndef RESHADE_DEPTH_INPUT_Y_SCALE
     26 	#define RESHADE_DEPTH_INPUT_Y_SCALE 1
     27 #endif
     28 #ifndef RESHADE_DEPTH_INPUT_X_SCALE
     29 	#define RESHADE_DEPTH_INPUT_X_SCALE 1
     30 #endif
     31 // An offset to add to the Y coordinate, (+) = move up, (-) = move down
     32 #ifndef RESHADE_DEPTH_INPUT_Y_OFFSET
     33 	#define RESHADE_DEPTH_INPUT_Y_OFFSET 0
     34 #endif
     35 #ifndef RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET
     36 	#define RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET 0
     37 #endif
     38 // An offset to add to the X coordinate, (+) = move right, (-) = move left
     39 #ifndef RESHADE_DEPTH_INPUT_X_OFFSET
     40 	#define RESHADE_DEPTH_INPUT_X_OFFSET 0
     41 #endif
     42 #ifndef RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET
     43 	#define RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET 0
     44 #endif
     45 
     46 #define BUFFER_PIXEL_SIZE float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT)
     47 #define BUFFER_SCREEN_SIZE float2(BUFFER_WIDTH, BUFFER_HEIGHT)
     48 #define BUFFER_ASPECT_RATIO (BUFFER_WIDTH * BUFFER_RCP_HEIGHT)
     49 
     50 namespace ReShade
     51 {
     52 #if defined(__RESHADE_FXC__)
     53 	float GetAspectRatio() { return BUFFER_WIDTH * BUFFER_RCP_HEIGHT; }
     54 	float2 GetPixelSize() { return float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); }
     55 	float2 GetScreenSize() { return float2(BUFFER_WIDTH, BUFFER_HEIGHT); }
     56 	#define AspectRatio GetAspectRatio()
     57 	#define PixelSize GetPixelSize()
     58 	#define ScreenSize GetScreenSize()
     59 #else
     60 	// These are deprecated and will be removed eventually.
     61 	static const float AspectRatio = BUFFER_WIDTH * BUFFER_RCP_HEIGHT;
     62 	static const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);
     63 	static const float2 ScreenSize = float2(BUFFER_WIDTH, BUFFER_HEIGHT);
     64 #endif
     65 
     66 	// Global textures and samplers
     67 	texture BackBufferTex : COLOR;
     68 	texture DepthBufferTex : DEPTH;
     69 
     70 	sampler BackBuffer { Texture = BackBufferTex; };
     71 	sampler DepthBuffer { Texture = DepthBufferTex; };
     72 
     73 	// Helper functions
     74 	float GetLinearizedDepth(float2 texcoord)
     75 	{
     76 #if RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
     77 		texcoord.y = 1.0 - texcoord.y;
     78 #endif
     79 		texcoord.x /= RESHADE_DEPTH_INPUT_X_SCALE;
     80 		texcoord.y /= RESHADE_DEPTH_INPUT_Y_SCALE;
     81 #if RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET
     82 		texcoord.x -= RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET * BUFFER_RCP_WIDTH;
     83 #else // Do not check RESHADE_DEPTH_INPUT_X_OFFSET, since it may be a decimal number, which the preprocessor cannot handle
     84 		texcoord.x -= RESHADE_DEPTH_INPUT_X_OFFSET / 2.000000001;
     85 #endif
     86 #if RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET
     87 		texcoord.y += RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET * BUFFER_RCP_HEIGHT;
     88 #else
     89 		texcoord.y += RESHADE_DEPTH_INPUT_Y_OFFSET / 2.000000001;
     90 #endif
     91 		float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x * RESHADE_DEPTH_MULTIPLIER;
     92 
     93 #if RESHADE_DEPTH_INPUT_IS_LOGARITHMIC
     94 		const float C = 0.01;
     95 		depth = (exp(depth * log(C + 1.0)) - 1.0) / C;
     96 #endif
     97 #if RESHADE_DEPTH_INPUT_IS_REVERSED
     98 		depth = 1.0 - depth;
     99 #endif
    100 		const float N = 1.0;
    101 		depth /= RESHADE_DEPTH_LINEARIZATION_FAR_PLANE - depth * (RESHADE_DEPTH_LINEARIZATION_FAR_PLANE - N);
    102 
    103 		return depth;
    104 	}
    105 }
    106 
    107 // Vertex shader generating a triangle covering the entire screen
    108 void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
    109 {
    110 	texcoord.x = (id == 2) ? 2.0 : 0.0;
    111 	texcoord.y = (id == 1) ? 2.0 : 0.0;
    112 	position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
    113 }