3
\$\begingroup\$

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:

Small 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:

enter image description here

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?

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

1 Answer 1

3
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .