Welcome, Guest.
Username: Password: Remember me

TOPIC: Displaying a texture on one part of the screen

Displaying a texture on one part of the screen 1 month 4 weeks ago #1

  • moriz1
  • moriz1's Avatar
  • Offline
  • Posts: 72
  • Thank you received: 31
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?
The administrator has disabled public write access.

Displaying a texture on one part of the screen 1 month 4 weeks ago #2

  • crosire
  • crosire's Avatar
  • Online
  • Posts: 3003
  • Thank you received: 1758
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).
Cheers, crosire =)
Last Edit: 1 month 4 weeks ago by crosire.
The administrator has disabled public write access.
The following user(s) said Thank You: moriz1

Displaying a texture on one part of the screen 1 month 3 weeks ago #3

  • Fu-Bama
  • Fu-Bama's Avatar
  • Offline
  • Posts: 66
  • Thank you received: 64
You can also change texture sampler settings:
sampler CursorSampler
{
	Texture = CursorTex;
	AddressU = BORDER;
	AddressV = BORDER;
};
If you want to buy me a coffee, www.paypal.me/fubax :)
The administrator has disabled public write access.