Sign in to follow this  
mwadelin

D3D10 Jagged text, how do I enable filtering?

Recommended Posts

Hi,

I'm have a bit of a problem with jagged text in my app. How do I resolve this? I guess its a texture filtering issue but how do I enable it ?

Heres an image of the issue:[img]http://i186.photobucket.com/albums/x187/mwadelin/jaggedText.png[/img]

The text is being drawn to an texture and I then use a shader to read the texture and draw it to that floating plane. I've recently converted to D3D10 from 9 and I'm unsure how to get it working.

The sampler in the shader is already set like so:

[code]
sampler AnisoSampler
{
MipFilter = ANISOTROPIC;
MinFilter = ANISOTROPIC;
MagFilter = ANISOTROPIC;
AddressU = CLAMP; // do not repeat over the surface
AddressV = CLAMP;
MaxAnisotropy = 16;
};
[/code]

Any help guys? Thanks
Mike

But still its making no difference

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1307663650' post='4821532']
Do you have mipmaps generated for that texture?
[/quote]

Probably not, Do I do that at the point of creating the texture or render target view?

Share this post


Link to post
Share on other sites
When you create the texture, use D3D10_RESOURCE_MISC_GENERATE_MIPS as the the MiscFlags parameter of the D3D10_TEXTURE2D_DESC you use when creating the texture. Make sure you also create the texture with the appropriate number of mip levels (if you pass 0 for MipLevels, it will create a full mip chain). Then after you've rendered the text to the render target, call ID3D10Device::GenerateMips and pass the SRV of the render target texture and it will generate the full mip chain from the top level mip.

Share this post


Link to post
Share on other sites
I'm not sure about D3D10, but under D3D9 ANISOTROPIC isn't always a valid value for mag and mip filters even on cards that support it for the min filter. It might be worth trying linear filtering instead.

Share this post


Link to post
Share on other sites
I tried what you said MJP and it didn't work. This is my code:
[code]

D3D10_TEXTURE2D_DESC desc;
ZeroMemory( &desc, sizeof(desc) );
desc.Width = m_PixelWidth;
desc.Height = m_BodyPixelY;
desc.MipLevels = 5;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Usage = D3D10_USAGE_DEFAULT;
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS;

// Create texture
m_Device->CreateTexture2D( &desc, NULL, &m_BodyTexture);

// render target stuff
D3D10_RENDER_TARGET_VIEW_DESC rtDesc;
rtDesc.Format = desc.Format;
rtDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
rtDesc.Texture2D.MipSlice = 0;

// Create RTV
m_Device->CreateRenderTargetView( m_BodyTexture, &rtDesc, &m_BodyRTV );

D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = desc.Format;
srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
srvDesc.Texture2D.MipLevels = 5;
srvDesc.Texture2D.MostDetailedMip = 0;
// Create SRV
m_Device->CreateShaderResourceView(
m_BodyTexture,
&srvDesc,
&m_pBodySRV);

m_Device->GenerateMips(m_pBodySRV);
[/code]

Its not doing anything to the texture, any ideas?
Do I have to set a sampler state for the device because I remember with the fixed function pipeline in d3d9 you had an option to enable filtering.
Cheers
Mike

Share this post


Link to post
Share on other sites
[quote name='TiagoCosta' timestamp='1307922471' post='4822548']
You are using the GenerateMips() right after you create the render target and shader resource, but you should call it after you render the text to the render target...
[/quote]

I thought that might be the problem so I already tried it and it made no difference :(

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1307999457' post='4822928']
Have you used PIX to verify that the mips are being generated, and that they look correct?
[/quote]

I would do but my crashes in PIX for some reason; I looked at the log and couldn't see anything error message that would suggest why. Although I found it strange that right at the start there were some D3D9 related messages seeing as I'm using D3D10. [img]http://public.gamedev.net/public/style_emoticons/default/huh.gif[/img]

Could the filtering problem be a sampler state thing? I'm new to D3D10 and it seems that states play a big part and so far I don't have any sampler state code apart from what you see in the .fx file?

Share this post


Link to post
Share on other sites
Ok I've got it working now. Not entirely sure what I did but I have been messing with samplerstates within the FX framework and it seems to work using this:
[code]

shared SamplerState g_samLinearClamp
{
Filter = ANISOTROPIC;
AddressU = CLAMP;
AddressV = CLAMP;
};
[/code]


I don't know much about MIP mapping but I found once I got the samplerstate working the text looked a bit blurred. I was using MipLevels = 5 and GenerateMips after rendering the text to it. So I put the levels back to 1 and removed the Call the GenerateMips which made it look a lot crisper but not jagged and pixelated like before. Was I using the MIPs correctly or can someone explain to me why it made it look blurred?

Thanks Guys
Mike

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