This page details how to set up a custom shader for visualisation. This can be used in the to unpack or decode complex formats, or simply apply a custom complex transformation to the image beyond the default controls.
Introduction The basic process of setting up the custom shader involves writing a .hlsl file that will be compiled and used by RenderDoc. There are several special global variables that can be specified and will be filled in with values by RenderDoc. Your pixel shader defines an operation that transforms the raw value from the input texture into a value that will then be displayed by the texture viewer. The usual texture viewer controls for range adaption and channels will still be available on the resulting texture. Multisampled textures will be resolved before being passed to your function. Depth and stencil textures will be bound separately and passed as multisampled resources. To set up your shader, it's recommended that you use the UI defined in the documentation for the , but you can manually create a .hlsl file in %APPDATA%\RenderDoc\. The file must contain an hlsl function main() that returns float4, and uses any of the below inputs. These shaders are loaded when RenderDoc loads a logfile, and RenderDoc watches for any changes to the files (either externally or in the shader editor in RenderDoc) and automatically reloads them.
Predefined inputs There are several pre-defined inputs that can either be taken as parameters to the shader entry point, or defined as global variables with a particular name that will then be filled in. There are also definitions for the different type of input textures. Type and capitalisation is important for these variables, so ensure you use the right declaration! Input Explanation UV co-ordinates float4 main(float4 pos : SV_Position, float4 uv : TEXCOORD0) : SV_Target0 { return 1; } This input is defined as two parameters to the shader entry point. The first defines the usual SV_Position system semantic, and the first two components of the second TEXCOORD0 parameter gives UV co-ordinates from 0 to 1 in each dimension over the size of the texture (or texture slice). You must bind these parameters like this in this order to ensure the linkage with the vertex shader matches. Texture dimensions uint4 RENDERDOC_TexDim; This variable will be filled out with the following values: .x = Width .y = Height (if 2D or 3D) .z = Depth if 3D or array size if an array .w = Number of mip levels Selected Mip level uint RENDERDOC_SelectedMip; This variable will be filled out with the selected mip level in the UI. Current texture type uint RENDERDOC_TextureType; This variable will be set to a given integer value, depending on the type of the current texture being displayed. This can be used to sample from the correct resource. 1D texture 2D texture 3D texture Depth Depth + Stencil Depth (Multisampled) Depth + Stencil (Multisampled) Samplers SamplerState pointSampler : register(s0); SamplerState linearSampler : register(s1); These samplers are provided to allow you to sample from the resource as opposed to doing straight loads. They are bound by slot and not by variable name - so this means you can name them as you wish but you must specify the register binding explicitly. Resources Texture1DArray<float4> texDisplayTex1DArray : register(t1); Texture2DArray<float4> texDisplayTex2DArray : register(t2); Texture3D<float4> texDisplayTex3D : register(t3); Texture2DArray<float2> texDisplayTexDepthArray : register(t4); Texture2DArray<uint2> texDisplayTexStencilArray : register(t5); Texture2DMSArray<float2> texDisplayTexDepthMSArray : register(t6); Texture2DMSArray<uint2> texDisplayTexStencilMSArray : register(t7); Texture2DArray<float4> texDisplayTexCubeArray : register(t8); Texture1DArray<uint4> texDisplayUIntTex1DArray : register(t11); Texture2DArray<uint4> texDisplayUIntTex2DArray : register(t12); Texture3D<uint4> texDisplayUIntTex3D : register(t13); Texture1DArray<int4> texDisplayIntTex1DArray : register(t21); Texture2DArray<int4> texDisplayIntTex2DArray : register(t22); Texture3D<int4> texDisplayIntTex3D : register(t23); These resources are bound sparsely with the appropriate type for the current texture. With a couple of exceptions there will only be one texture bound at any one time. When a cubemap texture is bound, it is bound both to the 2D Array as well as the Cube Array. If a depth-stencil texture has both components, the relevant depth and stencil resources will both be bound at once. To determine which resource to sample from you can use the RENDERDOC_TexType variable above. Usually the float textures are used, but for unsigned and signed integer formats, the relevant integer resources are used. As with the samplers, these textures are bound by slot and not by name, so while you are free to name the variables as you wish, you must bind them explicitly to the slots listed here.