### Define ReShade Technique with Pass Settings Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md This example demonstrates how to define a ReShade technique with a tooltip and configure a pass with primitive topology, vertex count, shaders, render targets, and blending options. ```hlsl technique Example < ui_tooltip = "This is an example!"; > { pass p0 { // The primitive topology rendered in the draw call. // Available values: // POINTLIST, LINELIST, LINESTRIP, TRIANGLELIST, TRIANGLESTRIP PrimitiveTopology = TRIANGLELIST; // or PrimitiveType // The number of vertices ReShade generates for the draw call. // This has different effects on the rendered primitives based on the primitive topology. // A triangle list needs 3 separate vertices for every triangle for example, a strip on the other hand reuses the last 2, so only 1 is needed for every additional triangle. VertexCount = 3; // The following two accept function names declared above which are used as entry points for the shader. // Please note that all parameters must have an associated semantic so the runtime can match them between shader stages. VertexShader = ExampleVS; PixelShader = ExamplePS0; // The number of thread groups to dispatch when a compute shader is used. DispatchSizeX = 1; DispatchSizeY = 1; DispatchSizeZ = 1; // Compute shaders are specified with the number of threads per thread group in brackets. // The following for example will create groups of 64x1x1 threads: ComputeShader = ExampleCS0<64,1,1>; // RenderTarget0 to RenderTarget7 allow to set one or more render targets for rendering to textures. // Set them to a texture name declared above in order to write the color output (SV_Target0 to RenderTarget0, SV_Target1 to RenderTarget1, ...) to this texture in this pass. // The output semantics SV_Target and SV_Target0 as well as COLOR and COLOR0 are all aliases. Similarly COLOR1 to 7 are also aliases for SV_Target1 to 7. // If multiple render targets are used, the dimensions of them has to match each other. // If no render targets are set here, RenderTarget0 points to the backbuffer. // Be aware that you can only read **OR** write a texture at the same time, so do not sample from it while it is still bound as render target here. // RenderTarget and RenderTarget0 are aliases. RenderTarget = texTarget; // Set to true to clear all bound render targets to zero before rendering. ClearRenderTargets = false; // Set to false to disable automatic rebuilding of the mipmap chain of all render targets and/or storage objects. // This is useful when using a compute shader that writes to specific mipmap levels, rather than relying on the automatic generation. // Note that the texture must have MipLevels set to a number higher than 1 for this to work. GenerateMipMaps = true; // A mask applied to the color output before it is written to the render target. RenderTargetWriteMask = 0xF; // or ColorWriteEnable // Enable or disable gamma correction applied to the output. SRGBWriteEnable = false; // BlendEnable0 to BlendEnable7 allow to enable or disable color and alpha blending for the respective render target. // Don't forget to also set "ClearRenderTargets" to "false" if you want to blend with existing data in a render target. // BlendEnable and BlendEnable0 are aliases, BlendEnable = false; // The operator used for color and alpha blending. // To set these individually for each render target, append the render target index to the pass state name, e.g. BlendOp3 for the fourth render target (zero-based index 3). // Available values: // ADD, SUBTRACT, REVSUBTRACT, MIN, MAX BlendOp = ADD; BlendOpAlpha = ADD; // The data source and optional pre-blend operation used for blending. // To set these individually for each render target, append the render target index to the pass state name, e.g. SrcBlend3 for the fourth render target (zero-based index 3). // Available values: // ZERO, ONE, // SRCCOLOR, SRCALPHA, INVSRCCOLOR, INVSRCALPHA // DESTCOLOR, DESTALPHA, INVDESTCOLOR, INVDESTALPHA SrcBlend = ONE; SrcBlendAlpha = ONE; DestBlend = ZERO; DestBlendAlpha = ZERO; // Enable or disable the stencil test. // The depth and stencil buffers are cleared before rendering each pass in a technique. StencilEnable = false; } } ``` -------------------------------- ### UIMask.fx Mask Creation Workflow Source: https://context7.com/crosire/reshade-shaders/llms.txt This section provides a step-by-step workflow for creating a custom mask texture for the UIMask shader. It guides users through taking a screenshot, painting the mask in an image editor, applying a blur, and saving the texture with the correct filename. ```plaintext Mask creation workflow: 1. Screenshot your game with HUD visible. 2. In GIMP/Photoshop: new layer over screenshot, paint WHITE where HUD is, BLACK elsewhere. 3. Gaussian blur the mask layer for soft edges. 4. Save as "MyHUDMask.png" in your ReShade Textures folder. 5. Set UIMASK_TEXTURE = "MyHUDMask.png" in preprocessor definitions. ``` -------------------------------- ### Vertex Shader for Fullscreen Triangle Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Generates a simple fullscreen triangle using ReShade's provided vertices. This is a common setup for post-processing effects. ```hlsl [shader("vertex")] void ExampleVS(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 = float4(texcoord * float2(2, -2) + float2(-1, 1), 0, 1); } ``` -------------------------------- ### Core ReShade.fxh Header and Basic Effect Source: https://context7.com/crosire/reshade-shaders/llms.txt Includes the foundational ReShade.fxh header for accessing global textures and screen metrics. Demonstrates how to sample the back-buffer and linearized depth, applying a simple channel swap effect based on depth. Requires ReShade 3.0+. ```hlsl // Correct depth for a game that stores a reversed, non-logarithmic depth buffer #define RESHADE_DEPTH_INPUT_IS_REVERSED 1 #define RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN 0 #define RESHADE_DEPTH_INPUT_IS_LOGARITHMIC 0 #define RESHADE_DEPTH_LINEARIZATION_FAR_PLANE 1000.0 #include "ReShade.fxh" // Access screen metrics // BUFFER_PIXEL_SIZE = float2(1/width, 1/height) // BUFFER_SCREEN_SIZE = float2(width, height) // BUFFER_ASPECT_RATIO = width / height // ReShade::PixelSize, ReShade::ScreenSize, ReShade::AspectRatio (static consts) // Sample the back-buffer float4 PS_MyEffect(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target { float4 color = tex2D(ReShade::BackBuffer, uv); // Get linearized depth [0..1] where 0=near, 1=far float depth = ReShade::GetLinearizedDepth(uv); // Only apply effect to geometry closer than half the far plane if (depth < 0.5) color.rgb = color.gbr; // swap channels as a demo return color; } technique MyEffect { pass { VertexShader = PostProcessVS; // provided by ReShade.fxh PixelShader = PS_MyEffect; } } ``` -------------------------------- ### Define Combo UI Element Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Template Use this to create a dropdown menu for user selection in ReShade. Ensure ui_items are null-terminated strings. ```hlsl uniform int combo < ui_type = "combo"; ui_label = "combo"; ui_tooltip = "Choose one"; //ui_category = ""; ui_items = "Option 1\0" "Option 2\0" "Option 3\0"; > = 0; ``` -------------------------------- ### Getting Texture Dimensions in ReShade FX Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Retrieve the dimensions (width, height, depth) of a texture for a specific mipmap level. Use `tex1Dsize`, `tex2Dsize`, or `tex3Dsize` accordingly. `storage` types are also supported for size retrieval. ```hlsl int tex1Dsize(sampler1D s) int tex1Dsize(sampler1D s, int lod) int tex1Dsize(storage1D s) int2 tex2Dsize(sampler2D s) int2 tex2Dsize(sampler2D s, int lod) int2 tex2Dsize(storage2D s) int3 tex3Dsize(sampler3D s) int3 tex3Dsize(sampler3D s, int lod) int3 tex3Dsize(storage3D s) ``` -------------------------------- ### Uniform and Constant Declarations Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Demonstrates how to declare uniform variables with initializers and static constants. Uniforms can be set at runtime, while constants are fixed values. It is recommended to use constants for non-changing or non-user-configurable values. ```hlsl // Initializers are used to specify the default value (zero is used if not specified). uniform float4 UniformSingleValue = float4(0.0f, 0.0f, 0.0f, 0.0f); // It is recommended to use constants instead of uniforms if the value is not changing or user-configurable. static const float4 ConstantSingleValue = float4(0.0f, 0.0f, 0.0f, 0.0f); ``` -------------------------------- ### Implement Photoshop-Compatible Blending Modes in HLSL Source: https://context7.com/crosire/reshade-shaders/llms.txt Uses the ComHeaders::Blending::Blend dispatcher to apply one of 30+ Photoshop-style blending modes. Requires Blending.fxh and ReShade.fxh includes. ```hlsl #include "Blending.fxh" #include "ReShade.fxh" // Declare a UI combo populated with all 30+ blending modes (default: Normal = 0) BLENDING_COMBO(_BlendMode, "Blend Mode", "Photoshop-style blending.", "Options", false, 0, 0) uniform float fBlendAlpha < __UNIFORM_SLIDER_FLOAT1 ui_label = "Blend Alpha"; ui_min = 0.0; ui_max = 1.0; > = 1.0; // Overlay texture to blend on top of the back-buffer texture texLayer < source = "overlay.png"; > { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; }; sampler sampLayer { Texture = texLayer; }; float4 PS_BlendLayer(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target { float4 base = tex2D(ReShade::BackBuffer, uv); float4 layer = tex2D(sampLayer, uv); // ComHeaders::Blending::Blend(mode, base_rgb, layer_rgb, alpha) → float3 base.rgb = ComHeaders::Blending::Blend(_BlendMode, base.rgb, layer.rgb, fBlendAlpha * layer.a); return base; } technique BlendLayer { pass { VertexShader = PostProcessVS; PixelShader = PS_BlendLayer; } } // Direct function calls without the dispatcher: // float3 r = ComHeaders::Blending::Overlay(base.rgb, layer.rgb); // float3 r = ComHeaders::Blending::Screen(base.rgb, layer.rgb); // float3 r = ComHeaders::Blending::Luminosity(base.rgb, layer.rgb); ``` -------------------------------- ### Version-Compatible UI Annotation Macros (ReShadeUI.fxh) Source: https://context7.com/crosire/reshade-shaders/llms.txt Provides preprocessor macros for emitting correct ui_type annotations, abstracting breaking changes between ReShade versions. Macros follow the pattern __UNIFORM__ and are used inline as annotation bodies. ```hlsl #include "ReShadeUI.fxh" // Slider for a float — resolves to ui_type = "slider" on ReShade >= 4.0.1, // ui_type = "drag" on older versions uniform float fStrength < __UNIFORM_SLIDER_FLOAT1 ui_label = "Effect Strength"; ui_tooltip = "Controls the intensity of the post-processing effect."; ui_min = 0.0; ui_max = 1.0; > = 0.5; // Drag widget for an integer uniform int iSamples < __UNIFORM_DRAG_INT1 ui_label = "Sample Count"; ui_min = 1; ui_max = 16; > = 4; // Color picker (resolves to ui_type = "color") uniform float3 fTint < __UNIFORM_COLOR_FLOAT3 ui_label = "Tint Color"; > = float3(1.0, 1.0, 1.0); // SUPPORTED_VERSION macro for conditional feature gating #if SUPPORTED_VERSION(4,3,0) // Use list widget only on ReShade 4.3+ uniform int iMode < ui_type = "list"; ui_items = "Mode A\0Mode B\0Mode C\0"; > = 0; #endif ``` -------------------------------- ### Uniform Annotations for Runtime Values Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Use annotations like `source` to request special runtime values such as frametime, frame count, date, timers, mouse input, buffer readiness, overlay status, and screenshot status. Some annotations support additional parameters for configuration. ```hlsl uniform float frametime < source = "frametime"; >; ``` ```hlsl uniform int framecount < source = "framecount"; >; ``` ```hlsl uniform float4 date < source = "date"; >; ``` ```hlsl uniform float timer < source = "timer"; >; ``` ```hlsl uniform float2 pingpong < source = "pingpong"; min = 0; max = 10; step = 2; smoothing = 0.0; >; ``` ```hlsl uniform int random_value < source = "random"; min = 0; max = 10; >; ``` ```hlsl uniform bool space_bar_down < source = "key"; keycode = 0x20; mode = ""; >; ``` ```hlsl uniform bool left_mouse_button_down < source = "mousebutton"; keycode = 0; mode = ""; >; ``` ```hlsl uniform float2 mouse_point < source = "mousepoint"; >; ``` ```hlsl uniform float2 mouse_delta < source = "mousedelta"; >; ``` ```hlsl uniform float2 mouse_value < source = "mousewheel"; min = 0.0; max = 10.0; > = 1.0; ``` ```hlsl uniform bool has_depth < source = "bufready_depth"; >; ``` ```hlsl uniform bool overlay_open < source = "overlay_open"; >; ``` ```hlsl uniform int active_variable < source = "overlay_active"; >; ``` ```hlsl uniform int hovered_variable < source = "overlay_hovered"; >; ``` ```hlsl uniform bool screenshot < source = "screenshot"; >; ``` -------------------------------- ### DisplayDepth.fx Configuration and Usage Source: https://context7.com/crosire/reshade-shaders/llms.txt This HLSL code provides configuration options and usage notes for the DisplayDepth shader, which visualizes the depth buffer and/or screen-space normal map for calibration purposes. It explains preprocessor definitions and overlay controls for live preview adjustments. ```hlsl // Enable technique "DisplayDepth" in ReShade to enter calibration mode. // Present type combo: // 0 = Depth map only // 1 = Normal map only // 2 = Side-by-side (left = normals, right = depth) [default] // "Show live preview" — override global preprocessor settings for immediate feedback. // Preview sub-settings (only active when live preview is on): // Upside Down — mirrors RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN // Reversed — mirrors RESHADE_DEPTH_INPUT_IS_REVERSED // Logarithmic — mirrors RESHADE_DEPTH_INPUT_IS_LOGARITHMIC // Scale — mirrors RESHADE_DEPTH_INPUT_X/Y_SCALE // Offset — mirrors RESHADE_DEPTH_INPUT_X/Y_PIXEL_OFFSET // Far Plane — mirrors RESHADE_DEPTH_LINEARIZATION_FAR_PLANE // Multiplier — mirrors RESHADE_DEPTH_MULTIPLIER // Correct depth reading: normals appear smooth/bluish-green, depth shows // near objects dark and far objects bright. // Once calibrated, copy the values to "Edit global preprocessor definitions" // in the ReShade Settings tab, then disable DisplayDepth. ``` -------------------------------- ### Daltonize.fx Pixel Shader Pipeline Source: https://context7.com/crosire/reshade-shaders/llms.txt Outlines the steps involved in the Daltonize shader: color space conversion, deficiency simulation, LMS to RGB conversion, error calculation, error redistribution, and final output correction. This process aims to make colors visible to color-blind individuals. ```hlsl // Pixel shader pipeline (from Daltonize.fx): // 1. RGB → LMS color space via fixed matrix // 2. Simulate deficiency: zero out / remap the affected LMS channel // 3. LMS → RGB // 4. Compute error = original_rgb - simulated_rgb // 5. Redistribute error.r into error.g and error.b weighted channels // 6. Output = original_rgb + correction ``` -------------------------------- ### Configure Deband.fx Parameters Source: https://context7.com/crosire/reshade-shaders/llms.txt Exposes various parameters for banding analysis, removal, and debugging. Adjust thresholds, range, and iterations to fine-tune debanding quality. Depth-gating can be enabled to confine debanding to specific depth ranges. ```hlsl // Banding analysis (category "Banding analysis"): // enable_weber = true — enable Weber ratio detection // enable_sdeviation = true — enable standard deviation detection // enable_depthbuffer= false — gate analysis on depth // t1 = 0.007 — std-dev threshold (lower = more aggressive) // t2 = 0.04 — Weber threshold // banding_depth = 1.0 — depth threshold (1.0 = process entire scene) // Banding removal (category "Banding detection & removal"): // range = 24.0 — sampling radius in pixels // iterations = 1 — passes (1–4; more = better quality, slower) // Debug (category "Debug"): // debug_output = 0 — 0=None, 1=Blurred image, 2=Banding map // Usage: enable the "Deband" technique in ReShade. // Typical sky-banding fix: // enable_depthbuffer = true // banding_depth = 0.98 (only process very distant pixels) // range = 24 // iterations = 2 ``` -------------------------------- ### One-Liner Uniform & Technique Macros (Macros.fxh) Source: https://context7.com/crosire/reshade-shaders/llms.txt Provides compact single-line macros for declaring common uniform widget types, textures, samplers, and techniques. Categorized variants are prefixed with CAT_. All macros expand to standard ReShade FX uniform declarations. ```hlsl #include "Macros.fxh" // Boolean checkbox UI_BOOL(bEnable, "Enable Effect", "Turns the effect on or off.", true) // Integer slider (name, label, tooltip, min, max, default) UI_INT_S(iRadius, "Blur Radius", "Kernel radius in pixels.", 1, 16, 4) // Float drag inside a named category CAT_FLOAT_D(fGamma, "Color Grading", "Gamma", "Adjusts gamma.", 0.5, 2.5, 1.0) // Float2 slider UI_FLOAT2_S(fOffset, "UV Offset", "UV shift.", 0.0, 1.0, 0.0, 0.0) // RGB color picker UI_COLOR(fHighlightColor, "Highlight Color", "Color for highlights.", 1.0, 0.9, 0.5) // Combo box (integer with named items) UI_COMBO(iBlendMode, "Blend Mode", "Select blend operation.", 0, 2, 0, "Normal\0Additive\0Multiply\0") // Texture + sampler convenience macros TEXTURE(texOverlay, "overlay.png") // BUFFER_WIDTH x BUFFER_HEIGHT, RGBA8 TEXTURE_FULL(texLUT, "lut.png", 1024, 32, RGBA8) // explicit dimensions/format SAMPLER(sampOverlay, texOverlay) // default filtering SAMPLER_UV(sampBorder, texOverlay, BORDER) // explicit address mode // Technique with two passes TECHNIQUE(MyFX, PASS(0, PostProcessVS, PS_MyFX_Pass0) PASS_RT(1, PostProcessVS, PS_MyFX_Pass1, texIntermediate) ) ``` -------------------------------- ### UIMask.fx Technique Ordering and Overlay Controls Source: https://context7.com/crosire/reshade-shaders/llms.txt This HLSL code details the required technique ordering for UIMask.fx in the ReShade home tab and describes the overlay controls for mask intensity and display. It also lists the toggleable channels for multi-channel mode. ```hlsl // --- Technique ordering in the ReShade home tab --- // [UIMask_Top] ← must be FIRST in the pipeline (captures clean frame) // ... your color grading, bloom, etc. effects ... // [UIMask_Bottom] ← must be LAST (restores HUD regions) // Overlay controls: // Mask Intensity [0–1] — how strongly HUD is protected (1.0 = full protection) // Display Mask — shows the raw mask texture for debugging // Multi-channel mode only: // Toggle Red Channel — enable/disable HUD mask stored in R channel // Toggle Green Channel — enable/disable inventory mask in G channel // Toggle Blue Channel — enable/disable menu mask in B channel ``` -------------------------------- ### Render On-Screen Text and Numbers with DrawText.fxh in HLSL Source: https://context7.com/crosire/reshade-shaders/llms.txt Renders ASCII text and floating-point numbers using glyphs from FontAtlas.png. Supports drawing strings, formatted floats with decimal precision, and calculating multi-line offsets. Requires DrawText.fxh and ReShade.fxh. ```hlsl #include "DrawText.fxh" #include "ReShade.fxh" uniform float fMonitoredValue < source = "frametime"; >; // built-in frametime source float4 PS_HUD(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target { float4 color = tex2D(ReShade::BackBuffer, uv); float overlay = 0.0; // --- Line 0: static label "FPS:" at pixel (10, 10), size 20px --- int label[4] = { __F, __P, __S, __Colon }; DrawText_String(float2(10.0, 10.0), 20, 1.0, uv, label, 4, overlay); // --- Line 0 continued: numeric frametime value, 2 decimal places --- // DrawText_Shift moves right by 4 characters (int2(4,0)) at the same size/ratio float2 numPos = DrawText_Shift(float2(10.0, 10.0), int2(4, 0), 20, 1.0); DrawText_Digit(numPos, 20, 1.0, uv, 2, fMonitoredValue, overlay); // --- Line 1: "RESHADE" label one line below --- int title[7] = { __R, __E, __S, __H, __A, __D, __E }; float2 line1 = DrawText_Shift(float2(10.0, 10.0), int2(0, 1), 20, 1.0); DrawText_String(line1, 20, 1.0, uv, title, 7, overlay); // Composite: white text on top of scene color.rgb = lerp(color.rgb, 1.0, overlay); return color; } technique HUDOverlay { pass { VertexShader = PostProcessVS; PixelShader = PS_HUD; } } ``` -------------------------------- ### Namespace Usage for Code Organization Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Illustrates how to use namespaces to group functions and variables, preventing name collisions. The '::' operator is used to access members within nested namespaces. ```hlsl namespace MyNamespace { namespace MyNestedNamespace { void DoNothing() { } } void DoNothing() { MyNestedNamespace::DoNothing(); } } ``` -------------------------------- ### Basic Pixel Shader Implementation Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Template A fundamental pixel shader that samples the backbuffer color and returns it after saturation. This serves as a base for applying post-processing effects. ```hlsl float3 TemplatePS(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target { // Sample the color from the framebuffer float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb; // Do stuff to it // Return the result return saturate(color); } ``` -------------------------------- ### Configure Stencil Buffer Operations Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Set masks, function, reference value, and operations for stencil testing. Available values are listed in comments. ```reshade-shaders // The masks applied before reading from/writing to the stencil. // Available values: // 0-255 StencilReadMask = 0xFF; // or StencilMask StencilWriteMask = 0xFF; // The function used for stencil testing. // Available values: // NEVER, ALWAYS // EQUAL, NEQUAL or NOTEQUAL // LESS, GREATER, LEQUAL or LESSEQUAL, GEQUAL or GREATEREQUAL StencilFunc = ALWAYS; // The reference value used with the stencil function. StencilRef = 0; // The operation to perform on the stencil buffer when the // stencil test passed/failed or stencil passed but depth test // failed. // Available values: // KEEP, ZERO, REPLACE, INCR, INCRSAT, DECR, DECRSAT, INVERT StencilPassOp = KEEP; // or StencilPass StencilFailOp = KEEP; // or StencilFail StencilDepthFailOp = KEEP; // or StencilZFail ``` -------------------------------- ### Configure Sampler Objects in ReShade FX Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Samplers define how textures are read and how out-of-bounds coordinates are handled. Configure texture, addressing modes, filtering, LOD, and SRGB conversion. ```hlsl sampler2D samplerColor { // The texture to be used for sampling. Texture = texColorBuffer; // The method used for resolving texture coordinates which are out of bounds. // Available values: CLAMP, MIRROR, WRAP or REPEAT, BORDER AddressU = CLAMP; AddressV = CLAMP; AddressW = CLAMP; // The magnification, minification and mipmap filtering types. // Available values: POINT, LINEAR, ANISOTROPIC MagFilter = LINEAR; MinFilter = LINEAR; MipFilter = LINEAR; // The maximum mipmap levels accessible. MinLOD = 0.0f; MaxLOD = 1000.0f; // An offset applied to the calculated mipmap level (default: 0). MipLODBias = 0.0f; // Enable or disable converting to linear colors when sampling from the // texture. SRGBTexture = false; // Unspecified properties are set to the defaults shown here. }; sampler2D samplerDepth { Texture = texDepthBuffer; }; sampler2D samplerTarget { Texture = texTarget; }; ``` -------------------------------- ### LUT.fx Pixel Shader Core Logic Source: https://context7.com/crosire/reshade-shaders/llms.txt Reference implementation showing how the LUT shader maps input colors to the LUT texture, interpolates values, and applies color grading based on chroma and luma amounts. The output color is adjusted based on hue/saturation and brightness grading. ```hlsl float4 color = tex2D(ReShade::BackBuffer, texcoord); float3 lutcoord = /* map color.rgb → tiled UV */; float3 lutcolor = /* bilinear interpolation across tile boundary */; color.xyz = lerp(normalize(color.xyz), normalize(lutcolor.xyz), fLUT_AmountChroma) * lerp(length(color.xyz), length(lutcolor.xyz), fLUT_AmountLuma); ``` -------------------------------- ### Dot Product for Vector Multiplication Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Tips,-Tricks-and-Optimizations Demonstrates using the dot product for efficient vector multiplication and summation, which can compile to single-cycle instructions like DP4. ```hlsl dot(float4(a, b, c, d), float4(a, b, c, d)) == a*a + b*b + c*c + d*d // ASM for this is DP4 ``` -------------------------------- ### Faster Smoothstep Approximation Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Tips,-Tricks-and-Optimizations Provides a faster, in-line approximation of the smoothstep function for values within the 0 to 1 range. This avoids a function call overhead. ```hlsl x = x * x * (3.0 - 2.0 * x) // faster smoothstep(0.0, 1.0, x) alternative //Only works in the 0 to 1 range though. ``` -------------------------------- ### Fullscreen Triangle Vertex Shader (PostProcessVS) Source: https://context7.com/crosire/reshade-shaders/llms.txt Generates a single fullscreen triangle using SV_VertexID. All effect passes in this repository use it. It outputs SV_Position in clip space and TEXCOORD UV in [0,1]². ```hlsl #include "ReShade.fxh" // PostProcessVS signature (defined in ReShade.fxh): // void PostProcessVS(in uint id : SV_VertexID, // out float4 position : SV_Position, // out float2 texcoord : TEXCOORD) float4 PS_Passthrough(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target { return tex2D(ReShade::BackBuffer, uv); // identity pass } technique Passthrough { pass { VertexShader = PostProcessVS; // no vertex buffer needed PixelShader = PS_Passthrough; } } ``` -------------------------------- ### Dot Product with Common Multiplier Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Tips,-Tricks-and-Optimizations Shows how a dot product with a constant vector (e.g., all 1.0s) can be used for summing components, potentially optimizing to single-cycle instructions. ```hlsl dot(float4(a, b, c, d), float4(1.0, 1.0, 1.0, 1.0)) ``` -------------------------------- ### Load Texture from File Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Declare and load a 2D texture from an image file. ReShade supports various image formats including BMP, PNG, JPG, TGA, DDS, and Cube LUTs. ```c texture2D imageTex < source = "path/to/image.bmp"; > { ... }; ``` -------------------------------- ### Define ReShade Technique Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Template Sets up a rendering technique that uses a post-processing vertex shader and the defined pixel shader. This is the core of applying the shader's effect. ```hlsl technique Template { pass { VertexShader = PostProcessVS; // in ReShade.fxh PixelShader = TemplatePS; } } ``` -------------------------------- ### Define Color Picker UI Element Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Template Implement a color picker for users to select colors within the ReShade UI. ```hlsl uniform float3 color_option < ui_type = "color"; ui_label = "Color"; > = float3(1.00, 0.50, 0.00); ``` -------------------------------- ### Define Boolean Toggle UI Element Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Template Create a simple on/off toggle switch for user control in ReShade. ```hlsl uniform bool Boolean < ui_label = "Boolean"; ui_tooltip = "On/Off"; > = false; ``` -------------------------------- ### Mathematical Identities for Shader Optimization Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Tips,-Tricks-and-Optimizations A collection of mathematical identities that can be used to simplify expressions and potentially reduce shader instruction count by leveraging dot products and other efficient operations. ```hlsl pow(a+b, 2.0) == (a+b) * (a+b) == a*a + 2.0*a*b + b*b == a*a + a*b + a*b + b*b == dot(float4(a, a, a, b), float4(a, b, b, b)) ``` ```hlsl pow(a-b, 2.0) == (a-b) * (a-b) == a*a – 2.0*a*b + b*b == a*a - a*b - a*b + b*b == dot(float4(a,-a,-a, b), float4(a, b, b, b)) ``` ```hlsl pow(a+b, 2.0) + pow(a-b, 2.0) == (a+b) * (a+b) + (a-b) * (a-b) == 2.0 * (a*a + b*b) == dot(float4(a, a, b, b), float4(a, a, b, b)) ``` ```hlsl pow(a+b, 2.0) - pow(a-b, 2.0) = (a+b) * (a+b) - (a-b) * (a-b) == (a * b) * 4.0 == dot(float4(a, a, a, a), float4(b, b, b, b)) ``` ```hlsl (a+b) * (a–b) == a*a – b*b = dot(float2(a, -b), float2(a, b)) ``` ```hlsl (x+a) * (x+b) == x*x + x*(a+b) + a*b == x*x + x*a + x*b + a*b == dot(float4(x, x, x, a), float4(x, a, b, b)) ``` ```hlsl pow(a, 3.0) + pow(b, 3.0) == (a*a*a) + (b*b*b) == dot(float3(a, -a, b), float3(a, b, b)) * (a + b) ``` ```hlsl pow(a, 3.0) - pow(b, 3.0) == (a*a*a) - (b*b*b) == dot(float3(a, a, b), float3(a, b, b)) * (a - b) ``` ```hlsl pow(x, 1.5) == (x * x) * rsqrt(x) // because rsqrt(x) == pow(x,-0.5). //BTW `sqrt(x) == pow(x,0.5)` but using a `sqrt` would be slower than using a `rsqrt` // this is because rsqrt is so commonly used it has its own instruction ``` ```hlsl exp(a) * exp(b) == exp(a + b) ``` ```hlsl pow(pow(a, b), c) == pow(a, b * c) ``` ```hlsl a / pow(b, c) == a * pow(b, -c) ``` ```hlsl log(a) + log(b) == log(a*b) ``` ```hlsl log(a/b) == log(a) - log(b) ``` ```hlsl log(pow(a, b)) == b * log(a) ``` ```hlsl log(sqrt(a)) == log(a) * 0.5 ``` ```hlsl cross(a, cross(b, c)) == b * dot(a, c) - c * dot(a, b) ``` -------------------------------- ### Texture Sampling Functions in ReShade FX Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Use these functions to sample textures in ReShade FX. They support different dimensions (1D, 2D, 3D) and can optionally take an offset. Ensure the sampler type matches the texture dimension. ```hlsl T tex1D(sampler1D s, float coords) Tex1D(sampler1D s, float coords, int offset) Tex2D(sampler2D s, float2 coords) Tex2D(sampler2D s, float2 coords, int2 offset) Tex3D(sampler3D s, float3 coords) Tex3D(sampler3D s, float3 coords, int3 offset) ``` -------------------------------- ### Texture Size and Store Functions Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Functions to retrieve texture dimensions and store values into textures. ```APIDOC ## Texture Size and Store ### `tex1Dsize`, `tex2Dsize`, `tex3Dsize` **Description**: Gets the texture dimensions of the specified mipmap level. **Signatures**: - `int tex1Dsize(sampler1D s)` - `int tex1Dsize(sampler1D s, int lod)` - `int tex1Dsize(storage1D s)` - `int2 tex2Dsize(sampler2D s)` - `int2 tex2Dsize(sampler2D s, int lod)` - `int2 tex2Dsize(storage2D s)` - `int3 tex3Dsize(sampler3D s)` - `int3 tex3Dsize(sampler3D s, int lod)` - `int3 tex3Dsize(storage3D s)` ### `tex1Dstore`, `tex2Dstore`, `tex3Dstore` **Description**: Stores a value into the texture. **Signatures**: - `void tex1Dstore(storage1D s, int coords, T value)` - `void tex2Dstore(storage2D s, int2 coords, T value)` - `void tex3Dstore(storage2D s, int3 coords, T value) ``` -------------------------------- ### Texture Fetch and Gather Functions Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Functions for directly fetching texel values and gathering neighboring pixel components. ```APIDOC ## Texture Fetch and Gather ### `tex1Dfetch`, `tex2Dfetch`, `tex3Dfetch` **Description**: Fetches a value from the texture directly without any sampling. **Signatures**: - `T tex1Dfetch(sampler1D s, int coords)` - `T tex1Dfetch(sampler1D s, int coords, int lod)` - `T tex1Dfetch(storage1D s, int coords)` - `T tex2Dfetch(sampler2D s, int2 coords)` - `T tex2Dfetch(sampler2D s, int2 coords, int lod)` - `T tex2Dfetch(storage2D s, int2 coords)` - `T tex3Dfetch(sampler3D s, int3 coords)` - `T tex3Dfetch(sampler3D s, int3 coords, int lod)` - `T tex3Dfetch(storage3D s, int3 coords)` ### `tex2DgatherR`, `tex2DgatherG`, `tex2DgatherB`, `tex2DgatherA` **Description**: Gathers the specified component of the four neighboring pixels and returns the result. **Signatures**: - `float4 tex2DgatherR(sampler2D s, float2 coords)` - `float4 tex2DgatherR(sampler2D s, float2 coords, int2 offset)` - `float4 tex2DgatherG(sampler2D s, float2 coords)` - `float4 tex2DgatherG(sampler2D s, float2 coords, int2 offset)` - `float4 tex2DgatherB(sampler2D s, float2 coords)` - `float4 tex2DgatherB(sampler2D s, float2 coords, int2 offset)` - `float4 tex2DgatherA(sampler2D s, float2 coords)` - `float4 tex2DgatherA(sampler2D s, float2 coords, int2 offset)` **Note**: `tex2DgatherR` is equivalent to `texture2D.GatherRed`. ``` -------------------------------- ### UIMask.fx Preprocessor Configuration Source: https://context7.com/crosire/reshade-shaders/llms.txt This HLSL code outlines the preprocessor configuration for the UIMask shader, which preserves the game's HUD from post-processing effects. It specifies texture names and multi-channel mode settings, intended to be set in ReShade's global preprocessor definitions. ```hlsl // --- Preprocessor configuration (set in ReShade "Edit global preprocessor definitions") --- // UIMASK_TEXTURE = "MyHUDMask.png" // mask image name in Textures folder (default: UIMask.png) // UIMASK_MULTICHANNEL = 1 // 0 = grayscale mask (R only), 1 = RGB multi-channel ``` -------------------------------- ### Define Slider UI Element Source: https://github.com/crosire/reshade-shaders/wiki/Shader-Template Use this to create a slider for adjusting float values within a specified range in ReShade. ```hlsl uniform float Slider < ui_type = "slider"; ui_label = "slider"; ui_tooltip = "Slide"; ui_min = 0.0; ui_max = 1.0; ui_step = 0.1; > = 0.5; ``` -------------------------------- ### Define a Preprocessor Macro Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Define a preprocessor macro that ReShade will not display in its UI. This is useful for internal constants or flags. ```c #ifndef MY_PREPROCESSOR_DEFINE #define MY_PREPROCESSOR_DEFINE 0 #endif ``` -------------------------------- ### Configure LUT Texture and Size in LUT.fx Source: https://context7.com/crosire/reshade-shaders/llms.txt Override default texture name, tile size, and tile count for the LUT shader using preprocessor definitions. Ensure the texture path and dimensions match the defined tile size and count. ```hlsl #define fLUT_TextureName "my_cinematic_lut.png" #define fLUT_TileSizeXY 64 // 64x64 tiles #define fLUT_TileAmount 64 // 64 tiles → 4096x64 texture ``` -------------------------------- ### Fetching Texture Values Directly in ReShade FX Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Fetch texture values directly without sampling, useful for accessing specific texels. Supports 1D, 2D, and 3D textures and can specify a mipmap level. Use `storage` types for write operations. ```hlsl T tex1Dfetch(sampler1D s, int coords) Tex1Dfetch(sampler1D s, int coords, int lod) Tex1Dfetch(storage1D s, int coords) Tex2Dfetch(sampler2D s, int2 coords) Tex2Dfetch(sampler2D s, int2 coords, int lod) Tex2Dfetch(storage2D s, int2 coords) Tex3Dfetch(sampler3D s, int3 coords) Tex3Dfetch(sampler3D s, int3 coords, int lod) Tex3Dfetch(storage3D s, int3 coords) ``` -------------------------------- ### Texture Sampling Functions Source: https://github.com/crosire/reshade-shaders/blob/slim/REFERENCE.md Functions for sampling textures at different levels of detail and with gradient information. ```APIDOC ## Texture Sampling ### `tex1D`, `tex2D`, `tex3D` **Description**: Samples a texture. **Signatures**: - `T tex1D(sampler1D s, float coords)` - `T tex1D(sampler1D s, float coords, int offset)` - `T tex2D(sampler2D s, float2 coords)` - `T tex2D(sampler2D s, float2 coords, int2 offset)` - `T tex3D(sampler3D s, float3 coords)` - `T tex3D(sampler3D s, float3 coords, int3 offset)` ### `tex1Dlod`, `tex2Dlod`, `tex3Dlod` **Description**: Samples a texture on a specific mipmap level. **Signatures**: - `T tex1Dlod(sampler1D s, float4 coords)` - `T tex1Dlod(sampler1D s, float4 coords, int offset)` - `T tex2Dlod(sampler2D s, float4 coords)` - `T tex2Dlod(sampler2D s, float4 coords, int2 offset)` - `T tex3Dlod(sampler3D s, float4 coords)` - `T tex3Dlod(sampler3D s, float4 coords, int3 offset)` **Note**: Accepted coordinates are in the form `float4(x, y, 0, lod)`. ### `tex1Dgrad`, `tex2Dgrad`, `tex3Dgrad` **Description**: Samples a texture using a gradient to influence the sample location calculation. **Signatures**: - `T tex1Dgrad(sampler1D s, float coords, float ddx, float ddy)` - `T tex1Dgrad(sampler1D s, float coords, float ddx, float ddy, int offset)` - `T tex2Dgrad(sampler2D s, float2 coords, float2 ddx, float2 ddy)` - `T tex2Dgrad(sampler2D s, float2 coords, float2 ddx, float2 ddy, int2 offset)` - `T tex3Dgrad(sampler3D s, float3 coords, float3 ddx, float3 ddy)` - `T tex3Dgrad(sampler3D s, float3 coords, float3 ddx, float3 ddy, int3 offset)` ```