Need Help with UIMask and KeyToggle

More
2 months 2 weeks ago - 2 months 2 weeks ago #1 by Isaac92
Need Help with UIMask and KeyToggle was created by Isaac92
Hello guys,

I'm trying to make the UIMask to display an additional overlay or sort of icon-image when pressing the ToggleKeys (Virtual KeyCodes are 0x71, 0x72).
The UIMask with it's channel masking is working fine and I edited the UiMask.png so it only masks certain areas (R,G,B) when I open some menus by pressing the KeyCodes and it worked too.

PROBLEM:  Whenever I switch .ini presets the UImask tends to enable masked areas without pressing a key and since my shaders are subtle and mild it is hard to distinguish whether the masked areas are on or not. I sometimes switch ini presets during gaming depending on scenes.

GOAL: I want to add a small icon overlay for each KeyCode (0x71, 0x72, 0x73) whenever I press these KeyCodes so I can always see what area is masked and what's not. How do I do that?

I'm new to this reshade stuff and I tried to copy paste some codes I found on the internet and other shaders.fx into Uimask.fx, but I failed miserably.
I appreciate every help!
/*
    Simple UIMask shader by luluco250    
    Copyright (c) 2017 Lucas Melo

//#region Preprocessor

#include "ReShade.fxh"
#include "ReShadeUI.fxh"

#ifndef UIMASK_MULTICHANNEL
    #define UIMASK_MULTICHANNEL 0
#endif

#ifndef UIMASK_TOGGLEKEY_RED
    #define UIMASK_TOGGLEKEY_RED 0x67 //Numpad 7
#endif

#ifndef UIMASK_TOGGLEKEY_GREEN
    #define UIMASK_TOGGLEKEY_GREEN 0x68 //Numpad 8
#endif

#ifndef UIMASK_TOGGLEKEY_BLUE
    #define UIMASK_TOGGLEKEY_BLUE 0x69 //Numpad 9
#endif

#if !UIMASK_MULTICHANNEL
    #define TEXFORMAT R8
#else
    #define TEXFORMAT RGBA8
#endif

//#endregion

namespace UIMask
{

//#region Uniforms

uniform int _Help
<
    ui_label = " ";
    ui_text =
        "For more detailed instructions, see the text at the top of this "
        "effect's shader file (UIMask.fx).\n"
        "\n"
        "Available preprocessor definitions:\n"
        "  UIMASK_MULTICHANNEL:\n"
        "    If set to 1, each of the RGB color channels in the texture is "
        "treated as a separate mask.\n"
        "  UIMASK_TOGGLEKEY_RED:\n"
        "    Defines the key for using the mask in the red channel, the "
        "default is Numpad 7.\n"
        "  UIMASK_TOGGLEKEY_GREEN:\n"
        "    Defines the key for using the mask in the green channel, the "
        "default is Numpad 8.\n"
        "  UIMASK_TOGGLEKEY_BLUE:\n"
        "    Defines the key for using the mask in the blue channel, the "
        "default is Numpad 9.\n"
        "\n"
        "Google \"virtual key codes\" for the values of each keyboard key.\n"
        "\n"
        "How to create a mask:\n"
        "\n"
        "1. Take a screenshot with the game's UI appearing.\n"
        "2. Open the screenshot in an image editor, GIMP or Photoshop are "
        "recommended.\n"
        "3. Create a new layer over the screenshot layer, fill it with black.\n"
        "4. Reduce the layer opacity so you can see the screenshot layer "
        "below.\n"
        "5. Cover the UI with white to mask it from effects. The stronger the "
        "mask white color, the more opaque the mask will be.\n"
        "6. Set the mask layer opacity back to 100%.\n"
        "7. Save the image in one of your texture folders, named "
        "\"UIMask.png\".\n"
        ;
    ui_category = "Help";
    ui_category_closed = true;
    ui_type = "radio";
>;

uniform float fMask_Intensity
<
    __UNIFORM_SLIDER_FLOAT1

    ui_label = "Mask Intensity";
    ui_tooltip =
        "How much to mask effects from affecting the original image.\n"
        "\nDefault: 1.0";
    ui_min = 0.0;
    ui_max = 1.0;
    ui_step = 0.001;
> = 1.0;

uniform bool bDisplayMask <
    ui_label = "Display Mask";
    ui_tooltip =
        "Display the mask texture.\n"
        "Useful for testing multiple channels or simply the mask itself.\n"
        "\nDefault: Off";
> = false;

#if UIMASK_MULTICHANNEL

uniform bool ToggleRed
<
    source = "key";
    keycode = UIMASK_TOGGLEKEY_RED;
    toggle = true;
>;

uniform bool ToggleGreen
<
    source = "key";
    keycode = UIMASK_TOGGLEKEY_GREEN;
    toggle = true;
>;

uniform bool ToggleBlue
<
    source = "key";
    keycode = UIMASK_TOGGLEKEY_BLUE;
    toggle = true;
>;

#endif

//#endregion

//#region Textures

texture BackupTex
{
    Width = BUFFER_WIDTH;
    Height = BUFFER_HEIGHT;
};
sampler Backup
{
    Texture = BackupTex;
};

texture MaskTex <source="UIMask.png";>
{
    Width = BUFFER_WIDTH;
    Height = BUFFER_HEIGHT;
    Format = TEXFORMAT;
};
sampler Mask
{
    Texture = MaskTex;
};

//#endregion

//#region Shaders

float4 BackupPS(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target {
    return tex2D(ReShade::BackBuffer, uv);
}

float4 MainPS(float4 pos : SV_Position, float2 uv : TEXCOORD) : SV_Target {
    float4 color = tex2D(ReShade::BackBuffer, uv);
    float4 backup = tex2D(Backup, uv);

    #if !UIMASK_MULTICHANNEL
        float mask = tex2D(Mask, uv).r;
    #else
        float3 mask_rgb = tex2D(Mask, uv).rgb;

        // This just works, it basically adds masking with each channel that has
        // been toggled. 'ToggleRed' is inverted so it defaults to 'true' upon
        // start.
        float mask = saturate(
            1.0 - dot(1.0 - mask_rgb,
                float3(!ToggleRed, ToggleGreen, ToggleBlue)));
    #endif

    color = lerp(color, backup, mask * fMask_Intensity);
    color = bDisplayMask ? mask : color;

    return color;
}

//#endregion

//#region Techniques

technique UIMask_Top
<
    ui_tooltip = "Place this *above* the effects to be masked.";
>
{
    pass
    {
        VertexShader = PostProcessVS;
        PixelShader = BackupPS;
        RenderTarget = BackupTex;
    }
}

technique UIMask_Bottom
<
    ui_tooltip =
        "Place this *below* the effects to be masked.\n"
        "If you want to add a toggle key for the effect, set it to this one.";
>
{
    pass
    {
        VertexShader = PostProcessVS;
        PixelShader = MainPS;
    }
}

//#endregion

} // Namespace.
Last edit: 2 months 2 weeks ago by Isaac92.

Please Log in or Create an account to join the conversation.