Advertisement

Help scaling render texture to window size

Started by April 07, 2018 06:13 PM
1 comment, last by trojanfoe 6 years, 9 months ago

Hi there, I am rendering my game to render textures but I am having difficulty figuring out how to scale it to fill the window.  The window looks like this:

window.png.3cc62bbccfff3b8a4bc8380c899b763d.png

and the render texture looks like this (it's the window resolution downscaled by 4):

Screenshot_20180407190902766.png.31d19c61d88de10c33fb25a23cf05540.png

(I implemented a screenshot function of the render texture which has proved to be very useful getting this working so far).

My vertex shader is the classic "draw fullscreen triangle without binding a vertex or index buffer" as seen many times on this site:


PS_IN_PosTex main(uint id : SV_VertexID)
{
    PS_IN_PosTex output;
    output.tex = float2((id << 1) & 2, id & 2);
    output.pos = float4(output.tex * float2(2, -2) + float2(-1, 1), 0, 1);
    return output;
}

and the pixel shader is simply:


Texture2D txDiffuse : register(t0);
SamplerState samp : register(s0);

float4 main(PS_IN_PosTex input) : SV_TARGET
{
    return txDiffuse.Sample(samp, input.tex);
}

Can someone please give me a clue as to how to scale this correctly?

Many thanks,

Andy

 

 

Indie Game Dev

OK, fixed it.  Beginners mistake.  I had forgotten to set the viewport of the window before rendering from render texture to window :|

Indie Game Dev

This topic is closed to new replies.

Advertisement