render texture smaller then screen

Started by
4 comments, last by hdxpete 10 years, 11 months ago

currently using direct x 11

i'm trying to generate a render texture smaller then the screen size, and then stretch it across the entire screen.

my problem is that the texture is only taking up the equivalent amount of space on the screen.

I.E. is i make my render texture 1/2 the width, height of the screen, then when i render it to the screen it will appear in 1/4 the screen.

my pixel/vertex shader are in screen coordinates.

does anyone have a clue what might be going on? or an example for making render textures smaller then the screen? my render texture works perfectly if the render texture size is the same as the screen size.

thanks

Advertisement
You got plenty of possibilities:
  • Use the transformation matrices. Though it's 2D the same logic applies, i.e. use the so-called world transformation to position and scale your quad.
  • Set up a vertex buffer covering the whole screen (clip space from -1 to 1 for both x and y, z = 0, w = 1) and just pass them through in the vertex shader
  • For a fullscreen quad you don't even need transformations or vertex buffers at all. You can setup a vertex shader which generates the position/texcoords automatically, see below.


void FullScreenTriangleFromIndex(uint index, out float4 position, out float2 tex)
{    
    tex = float2((index << 1) & 2, index & 2);
    position = float4(tex * float2(2,-2) + float2(-1,1), 1, 1);    
}

// Call with Draw(3,0)
void FullScreenTrianglePositionOnlyVS(uint id : SV_VertexID,
    out float4 position: SV_Position)
{
    float2 tex;
    FullScreenTriangleFromIndex(id, position, tex);
}

void FullScreenTrianglePositionTexVS(uint id : SV_VertexID,
    out float4 position: SV_Position,
    out float2 tex: TEXCOORD)
{    
    FullScreenTriangleFromIndex(id, position, tex);
}

static uint fsqids[] = {0,1,2,1,3,2};
void FullScreenQuadFromIndex(uint index, out float4 position, out float2 tex)
{    
    uint id = fsqids[index];
    tex = float2(id & 1, (id >> 1) & 1);
    position = float4(tex * float2(2,-2) + float2(-1,1), 1, 1);    
}

// Call with Draw(6,0)
void FullScreenQuadPositionOnlyVS(uint id : SV_VertexID,
    out float4 position: SV_Position)    
{    
    float2 tex;
    FullScreenQuadFromIndex(id, position, tex);
}

void FullScreenQuadPositionTexVS(uint id : SV_VertexID,
    out float4 position: SV_Position,
    out float2 tex)
{    
    FullScreenTriangleFromIndex(id, position, tex);
}

i'm doing the second option. and what i find is that if the render texture is not the same size as the display size then it takes up the equilivent space.

so

displaywidth = texturewidth

displayheight = textureheight * 2

then my texture will appear across the entire screen but will take up 1/2 the height.

appreciate the help.

Are you setting your viewport correctly when drawing the full screen quad / rendering to render target etc?

Cheers!

that is interesting... i do set the viewport but i don't set the viewport when i change render textures... i had not thought of that.

i'll have to look more into that after the long japanese weekend. thank you Kauna.

Kauna,

Sorry for the delayed response (Japanese holiday and all...) thanks for the assist, got my project perfect now.

This topic is closed to new replies.

Advertisement