Sign in to follow this  
RogerRZW

About Downsample texture

Recommended Posts

RogerRZW    103
Hi all,

Regarding the downsampling texture, Is it mean that copying a larger texture to a smaller texture?

In my understanding we need do something like below:

1) Render scene to a full-screen sized rendertarget.
2) Downsample it to a smaller texture.
3) Use it for something like blurring.

I wrote a simple example code to verify it, but met some problems. Below is snip code of my example:

[CODE]
m_device->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_diffuse, NULL);
m_device->CreateTexture(m_width*0.5, m_height*0.5, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_DownSampleTexture, NULL);
SetRenderTarget(0, m_depth);
m_effect->SetTechnique("RenderToTexture");
//Draw something
......
//Do downsampling texture
SetRenderTarget(0, m_DownSampleTexture);
PlaneVertex axPlaneVertices[] =
{
{ 0.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f},
{ m_width*0.5, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f},
{ m_width*0.5, m_height*0.5, 0.5f, 1.0f, 1.0f,1.0f},
{ 0.0f, m_height*0.5, 0.5f, 1.0f, 0.0f,1.0f}
};
m_effect->SetTechnique("Downsampling");
m_effect->SetTexture("SrcTex", m_diffuse);
//Render
......
m_device->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
m_device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,axPlaneVertices,sizeof(PlaneVertex));
......
D3DXSaveTextureToFile("Dest.bmp",D3DXIFF_BMP,m_DownSampleTexture,NULL);
[/CODE]


But i think there is something wrong with my code, because I want to save m_DownSampleTexture, nothing is drew on Dest.bmp.

Any help is appreciated

Share this post


Link to post
Share on other sites
RogerRZW    103
Mistake

[CODE]
m_device->CreateTexture(m_width, m_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_diffuse, NULL);
m_device->CreateTexture(m_width*0.5, m_height*0.5, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_DownSampleTexture, NULL);
SetRenderTarget(0, m_diffuse);
[/CODE]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this