Displaying a texture on one part of the screen

  • Posts: 85
2 years 1 month ago #1 by moriz1
Is there a way to display a texture only on one part of the screen?

Currently, any non-screen-resolution texture will simply stretch to fit the entire screen. Is there a way to make it so it doesn't do that?

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

  • Posts: 3665
2 years 1 month ago - 2 years 1 month ago #2 by crosire
Sure. Simple:
float4 Main(in float4 vpos : SV_POSITION, in float2 texcoord : TEXCOORD) : SV_TARGET
{
    const float2 overlay_pos = float2(10, 10); // Position in pixels from top left on the screen.
    const float2 overlay_size = float2(200, 200); // Size of the overlay texture in pixels on the screen.

    if (vpos.x > overlay_pos.x && vpos.x < (overlay_pos.x + overlay_size.x) &&
        vpos.y > overlay_pos.y && vpos.y < (overlay_pos.y + overlay_size.y))
    {
        return tex2D(overlay_texture, (vpos.xy - overlay_pos) / overlay_size);
    }
    else
    {
        return tex2D(ReShade::BackBuffer, texcoord);
    }
}
Instead of "vpos", you can also use "texcoord" and do the same in texture coordinate space (between 0 and 1), rather than screen space (between 0 and screen width/height in pixels).
The following user(s) said Thank You: moriz1

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

  • Posts: 156
2 years 3 weeks ago #3 by Fu-Bama
You can also change texture sampler settings:
sampler CursorSampler
{
	Texture = CursorTex;
	AddressU = BORDER;
	AddressV = BORDER;
};

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