Advertisement
luluco250

ReShadeFX Quick Rundown

Apr 11th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.60 KB | None | 0 0
  1. //"ReShade.fxh" is a header that defines some common things like the main texture, called "BackBuffer".
  2. //It's also defined with a namespace, so keep that in mind.
  3. #include "ReShade.fxh"
  4. /*
  5.     This is a PixelShader, it returns float4 because we're writing to a float 4D vector: (red, green, blue, alpha).
  6.     "SV_Position", "TEXCOORD" and "SV_Target" are information we get from the GPU, don't really worry about them for now.
  7.     Just know that "TEXCOORD" stores the current coordinate of the fragment we're working on.
  8.     Also, usually "TEXCOORD" is a shortening for "TEXCOORD0", as there can be multiple GPU registers for coordinates.
  9.     Remember that in HLSL/CG and in ReShadeFX the coordinates are normalized (0.0-1.0) as opposed to GLSL.
  10.     The ':' indicates what register we're writing to, in this case it's the screen render target.
  11.     Anything screen-related in DirectX is denoted by 'SV_' if I recall correctly.
  12.     Note that this function could also be a void, using an "out float4 color : SV_Target" as a pointer parameter.
  13.     But I find it simpler to just be a returning function.
  14. */
  15. float4 PS_Example(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target {
  16.     /*
  17.         ReShade::BackBuffer is the main texture of the screen, we can write to and read it freely.
  18.         But normally other textures can only be either writen or read in separate shaders/passes.
  19.         tex2D() reads a texture with the specified coordinate and returns a float4.
  20.         Since we're not interested in the alpha (which could be useful in some cases)
  21.         we specify we only want the RGB components with .rgb. This is also called 'swizzling'.
  22.         Swizzling in shader languages allows us to freely manipulate components of a vector.
  23.         For example, we could switch the order of colors using .bgr.
  24.         .xyzw and .rgba are synonymous, though you cannot use them together.
  25.         I usually only use .rgba when referring to values that I know are regular colors.
  26.         Otherwise I use .xyzw when it's other kind of information, like normals, coordinates etc.
  27.     */
  28.     float3 col = tex2D(ReShade::BackBuffer, uv).rgb;
  29.     return float4(col, 1.0); //We need to return float4, so we append a 1.0 alpha to the float3 color, making it a float4!
  30. }
  31.  
  32. /*
  33.     Techniques are a HLSL/CG standard where we can specify how effects are to be done in our pipeline.
  34.     Although these do not natively exist in GLSL (we have to manually specify in code how to manipulate OpenGL shaders)
  35.     ReShade is capable of making these work with OpenGL out of the box.
  36.     On an side note, you could use a scripting language like Lua together with C++ to manipulate effects like techniques
  37.     in OpenGL, as C++ can be cumbersome and Lua can be modified post program compilation.
  38. */
  39. technique Example {
  40.     //A technique can have many passes, optionally with a name.
  41.     pass {
  42.         /*
  43.             VertexShader and PixelShader allow us to specify what shaders to use.
  44.             This is a simplified version of how you do it in HLSL/CG.
  45.             Also, PostProcessVS is a vertex shader defined in 'ReShade.fxh',
  46.             though for reasons unknown to me it does not follow the namespace rule anymore.
  47.             (it used to in older versions of ReShade, you had to do ReShade::VS_PostProcess)
  48.         */
  49.         VertexShader = PostProcessVS;
  50.         PixelShader = PS_Example;
  51.         /*
  52.             We could define other things here, but doesn't matter now.
  53.             For example, ReShade automatically writes to the backbuffer if no render target is specified.
  54.             The same as:
  55.             RenderTarget = ReShade::BackBufferTex;
  56.             "RenderTarget" can be followed by a number, it defaults to "RenderTarget0" if it's not specified.
  57.             This allows for multiple render target rendering, though all of them must be of the same resolution.
  58.         */
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement