Displaying a texture on one part of the screen

  • moriz1
  • Topic Author
More
6 years 1 month ago #1 by moriz1 Displaying a texture on one part of the screen was created 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.

  • crosire
More
6 years 1 month ago - 6 years 1 month ago #2 by crosire Replied by crosire on topic Displaying a texture on one part of the screen
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).
Last edit: 6 years 1 month ago by crosire.
The following user(s) said Thank You: moriz1

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

  • Fu-Bama
More
6 years 1 month ago #3 by Fu-Bama Replied by Fu-Bama on topic Displaying a texture on one part of the screen
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.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.