Skip to main content
GameDev.net gamedev.net
🔒 Locked

Down smapling a texture

Started by ZappBranigan Feb 27, 2007 at 11:13 AM 0 replies 600+ views
Original Post
ZappBranigan
ZappBranigan
Howdy, Just a quick question that I would appreciate some help with. I'm trying to downsample my texture to implement some post process effects like blur, bloom etc using DirectX and HLSL. All is good regarding getting the texture but when I attempt to downsample it it never seems to downsample correctly. I am currently getting the top left quarter of my old texture (down sampling to a quarter size) in the new texture instead of the entire texture squashed into the new texture as expected. I am new to HLSL so it be something I am doing there but I have checked a good number of downsampling examples that appear to be doing more or less the same thing. My DirectX part looks like this


   // pixel size to convert to texel space
   float pixelSizeX = -1.0f / (SCREEN_WIDTH / 2.0f);
   float pixelSizeY = 1.0f / (SCREEN_HEIGHT/ 2.0f);

    IDirect3DSurface9* downSizeSurface;
    downSize->GetSurfaceLevel(0, &downSizeSurface);
    Device->SetRenderTarget(0, downSizeSurface);
    
    Device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0 );

    effect->SetTechnique("downSize");

    effect->SetTexture("DownMap",postProc);
    effect->SetVector("pixelSize", &D3DXVECTOR4(pixelSizeX, pixelSizeY, 1.0f, 1.0f));

    //render
    int numPass;
    effect->Begin((UINT*)&numPass,0);
    for(int i = 0; i < numPass; i++)
    {
	effect->BeginPass(i);
	Device->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
	Device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, quad, sizeof(planeVertex));
	effect->EndPass();
    }
    effect->End();

The relevant part of my fx file then looks like this (Wolfgang Engels implementation in Programming and Pixel Shaders)


...
texture2D DownMap;
...
sampler DownMapSampler = sampler_state
{
   Texture = <DownMap>;
   MinFilter = LINEAR;
   MagFilter = LINEAR;
   MipFilter = LINEAR;
   AddressU  = Clamp;
   AddressV  = Clamp;
};

...
VS_OutScale VSdownsize(float4 Pos : POSITION, float2 Tex : TEXCOORD0)
{
    VS_OutScale Out = (VS_OutScale)0;        
    Out.Pos.xy = Pos.xy + pixelSize.xy;
    Out.Pos.z = 0.5f;
    Out.Pos.w = 1.0f;
	
    Out.Tex = float2(0.5f, -0.5f) * Pos.xy + 0.5f.xx;	
	
    return Out;
}

float4 PSdownsize( float2 Tex :TEXCOORD0): COLOR				
{
    return tex2D(DownMapSampler, Tex);
}

...

technique downSize
{
    pass p0
    {
        VertexShader = compile vs_1_1 VSdownsize();
        PixelShader  = compile ps_2_0 PSdownsize();
        
        Zenable = false;
    }
};

Thanks in advance

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.