# Increasing resolution of a texture?

I'm doing some experiments on my own to improve my general skills with HLSL and so forth. In other words, I'm not doing any serious game development, but only looking to expand my knowledge within the field.

I'm trying to figure out how I can increase the resolution of a texture, and multiply it X amount of times.

Consider the following low-resolution picture:

A typical scenario for me would be to scale up this picture 3 times in the shader without interpolation, and draw the new result:

I've been experimenting with a shader that transfers the small picture on to a texture as a variable on the shader. I got that far. Now I just need it to take that texture using tex2D or something else, and scale it up.

How would I do that?

• Not sure what you're after.. just scale the UV coordinates by the amount you need? Commented Sep 29, 2011 at 11:20
• That sounds like an awesome idea Jari. Provide me with an HLSL code example, and I'll mark it as answer. Commented Sep 29, 2011 at 11:49
• I'll let someone else type it in. I'm more on the glsl side myself =) Commented Sep 29, 2011 at 12:56

It depends because it's not clear whether you want to scale the texture (which would be scaling the UV coords as @Jari said) or if you want to scale the underlying geometry.

For example, you may want to display a square with a texture, such as sprite rendering, then for scaling the sprite you wouldn't be scaling the texture coordinates but the vertex positions themselves. In this case, transforming the texture coordinates will make your texture wrap or truncate according to the relative mapping to the vertices and won't match the underlying geometry.

Anyway, for transforming the texture coordinates alone you can do it simply by scaling the texture coordinates of the vertices (the UV mapping), like this:

uniform extern float2 gScale;

OutputVS Vertex( float3 posL : POSITION0, float2 tex0 : TEXCOORD0 )
{
OutputVS ovs    = (OutputVS)0;
ovs.tex0.x  = tex0.x*gScale.x;
ovs.tex0.y  = tex0.y*gScale.y;
ovs.posH    = mul( float4( posL, 1.0f ), gWVP );
return ovs;
}


The tex2D comes later with the pixel shader, but by then you already have the scaled coordinates, so you don't need to do anything else other than get the colors as float4 texColor = tex2D(SampS0, tex0).rgba; or something like that.