Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
Sorry for my shitty Paint skills by the way. The picture is not supposed to represent anything, although I must admit it looks a bit like a man. –  Mathias Lykkegaard Lorenzen Sep 29 '11 at 10:43
    
Not sure what you're after.. just scale the UV coordinates by the amount you need? –  Jari Komppa Sep 29 '11 at 11:20
    
That sounds like an awesome idea Jari. Provide me with an HLSL code example, and I'll mark it as answer. –  Mathias Lykkegaard Lorenzen Sep 29 '11 at 11:49
    
I'll let someone else type it in. I'm more on the glsl side myself =) –  Jari Komppa Sep 29 '11 at 12:56
add comment

1 Answer

up vote 3 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.