Sign in to follow this  
DJTN

Brick Texture Artifacts When Camera is Moving

Recommended Posts

I think my issue is related to mipmaps and my understanding of texture loading and filtering in my pixel shader / DirectX.

The D3DXCreateTextureFromFile method automatically creates mipmaps (11 of them) and sets the filtering.

In my shader I’ve set the texture filtering to:

MinFilter = Anisotropic;
MagFilter = Linear;
MipFilter = Linear;


With these settings everything looks fine until the camera moves. I get artifacts where the grout is (around the bricks). At some distances it looks like a pattern of sorts. Kind of like horizontal lines in a recorded video of a TV screen.

With the filtering in the shader turned off I get the same artifacts but much more sever. Even if I use the D3DXCreateTextureFromFileEx function and manually set the filtering, the issue remains.

Does the filtering in the D3DXCreateTextureFromFile change the appearance of the mipmaped textures that are stored in memory or does it filter them in real-time through the hardware, ignoring my shader’s mipfilter setting?

How many mipmap levels should I have? (performance vs. quality)

Should I even use mipmaps?


To add insult to injury, last week I had an issue with ghosting due to poor refresh rates on my monitors. I’ve ordered new ones but they won’t be here for a couple of weeks. Could my issue be related to ghosting? I’m leaning towards it not being a ghosting issue because the patterns change depending on the distance from the object- Hence why I’m going down the mipmap path looking for the bug. But I could be wrong.

Share this post


Link to post
Share on other sites
Hi,

can you post a screenshot?

In general mipmaps are beneficial for image quality (reduces aliasing) and performance (smaller textures are better for caches).

Anisotropic filtering should give less blurred results over bilinear/trilinear filtering.

Have you verified your MaxAnisotropy value? If it is set to 1, your texture filtering won't look better than tri/bilinear filtering.

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172264(v=vs.85).aspx"]http://msdn.microsof...4(v=vs.85).aspx[/url] check here how to set the maximum anisotropy value under d3d9.

Also, I suggest creating mipmaps offline. NVidia for example has a tools for creating dds files with mipmaps. It shortens the load times significantly.

Cheers! Edited by kauna

Share this post


Link to post
Share on other sites
Thanks for the replies.

I’ve tried every available combination of min, mag and mip filtering and still have the issue.

The Max Anisotropy is 16, (the max available on this machine’s card). I’ve tried it set at 1 -16, with no difference in the results.


The D3D9 Texture interface shows the following properties:

Level Count: 10
Auto Gen Filter Type: Linear
LOD (level of detail): 0

In this particular application I cannot create the mipmaps myself due to its functionality.


I’ve attached a small video showing the issue.

Share this post


Link to post
Share on other sites
As far as I know, anisotropic filtering doesn't change the quality of the image when the triangle is seen from perpendicular angles as we see in your filterissue video.

The [color=#000000][font=Consolas, Courier, monospace][size=3]D3DXCreateTextureFromFile creates mipmaps at the load time. If you don't create/load the mipmaps, the shader can't use any other mip level than the biggest, which means practically that no mip mapping will be applied. So, for mipmapping to work, the texture needs mipmaps and the sampler needs to be set to use them.[/size][/font][/color]

[color=#000000][font=Consolas, Courier, monospace][size=3]Otherwise it is a bit difficult to tell from the video what is going. Can you provide the texture itself? [/size][/font][/color]

[color=#000000][font=Consolas, Courier, monospace][size=3]Why can't you create the mipmaps yourself? If you are able to use [/size][/font][/color][color=#000000][font=Consolas, Courier, monospace][size=3]D3DXCreateTextureFromFile function, you may load .dds files which can contain the mipmaps and you don't need to create them in the application.[/size][/font][/color]

[color=#000000][font=Consolas, Courier, monospace][size=3]Best regards![/size][/font][/color]

Share this post


Link to post
Share on other sites
Thanks Kauna. This particular application allows the end user to load textures they’ve created. There are size restrictions and I could (in code) create images of different sizes in the background for the mipmaps but I’ve been avoiding that as the D3DXCreateTextureFromFile creates them automatically.

The Texture in the video is a simple 512 X 512 brick texture applied to a cube mesh, nothing special. The createtexturefromfile was used so the mipmaps were created automatically.

[quote name='kauna' timestamp='1337965937' post='4943286']
So, for mipmapping to work, the texture needs mipmaps and the sampler needs to be set to use them.
[/quote]

Other than setting the min, mag and mip filter, what else is needed to setup a shader for mipmaps?

Also, in the D3DXCreateTextureFromFileEx function you can set 2 filters, one for the texture and one for the mipmaps. I’m not clear on how these work. Do they override the shader’s sampler filters? I noticed you can have multiple filters applied, is there a standard that works well in most situations?

[quote name='kauna' timestamp='1337965937' post='4943286']
As far as I know, anisotropic filtering doesn't change the quality of the image when the triangle is seen from perpendicular angles as we see in your filterissue video.
[/quote]

Does this mean I have to change the filters depending on the camera angle? It seems as though this could become a huge performance issue with the multiple state changes.

I noticed better results when I set the texture filter to BOX and the mipmap filter to DITHER in the D3DXCreateTextureFromFileEx function. Maybe I need to apply more than one filter. If I set these to none I can see the mipmaps being appled as the camera moves closer but no filtering is being applied, even thoguh I have the mipmap filter in the shader’s sampler set to Linear. I also noticed the scaling being off but this could be a side-effect of the omission of filters.


Thanks again for your help Kauna… Edited by DJTN

Share this post


Link to post
Share on other sites
[quote name='DJTN' timestamp='1337969422' post='4943300']
Other than setting the min, mag and mip filter, what else is needed to setup a shader for mipmaps?

Also, in the D3DXCreateTextureFromFileEx function you can set 2 filters, one for the texture and one for the mipmaps. I’m not clear on how these work. Do they override the shader’s sampler filters? I noticed you can have multiple filters applied, is there a standard that works well in most situations?
[/quote]

Setting min, mag and mip filter is what you need to make shader / sampler to use mipmaps. Of course the texture needs to have mipmaps too.

Filtering options in D3DXCreateTextureFromFile(Ex) affects the image in the load time. These filtering options don't have much to do with the shader/sampler filtering options. Ie. if the function creates mipmaps, different kind of filtering can be applied to this mipmap generation. Also, if the image is rescaled when loading, a filter can be applied. For example if the image size on disk isn't power of 2, the image could be scaled to the nearest power of 2 size.

[quote name='DJTN' timestamp='1337969422' post='4943300']
Does this mean I have to change the filters depending on the camera angle? It seems as though this could become a huge performance issue with the multiple state changes.
[/quote]

Definetely no, my point is that anisotropic filtering doesn't affect the particular case you present. Otherwise it has better image quality than other filtering methods.

Cheers!

Share this post


Link to post
Share on other sites
I've attached another video displaying my issue. I've scaled the texture by 5 (wrapped) so you can see it better. It's a rather large file so I'll need to delete it later.

Share this post


Link to post
Share on other sites
I've noticed when the mesh is rotated clockwise the artifacts disappear. It’s only when the grout of the brick texture is lined vertical and horizontal that the artifacts appear. Maybe this IS a ghosting issue.


Can anyone else see the artifacts in the video?

Share this post


Link to post
Share on other sites
[quote name='3DModelerMan' timestamp='1338041500' post='4943484']
It definitely looks like a mip mapping error. I would try mip maps generated offline. If you disable mip mapping does it still look that way? I wouldn't suggest disabling it and being done, but as a test you should see what it does.
[/quote]


I disabled mipmapping and the artifacts are more sever.

I've tried creating my own, changing the level of detail, and changing the filter combinations to every conceivable sequence in the texture creation as well as the shaders sampler.

I'm at a loss here... Edited by DJTN

Share this post


Link to post
Share on other sites
When I change the color of the mortar of the brick texture to a color other than white (grey for example), the issue disappears. I'm now starting to think this is a limitation of DX and something I cannot fix. This would explain why so many games using muted colors or colors close in range.

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