6

I have an issue with rendering my textures in Silverlight. When I look at it from above everything looks fine:

enter image description here

But if I only change angle of watching it it looks terrible:

enter image description here

I am using very simple pixel shader (hlsl):

float4 main(VsOutput vertex) : COLOR
{
        float4 texColor = tex2D(textureSampler, texCoord);
    return texColor;

}

If I don' t use that pixel shader and load texture via BasicEffect like:

BasicEffect.texture = myTexture

Everything looks fine. Why my pixel shader affects texture so bad?


I expect that it might be somehow connected with mipmapping, but I am not sure - my texture is pretty small so I guess it shouldn' t have such a big effect. Anyway I need some advices :).


bartosz.baczek
  • 399
  • 1
  • 12
  • 6
    I think you need anisotropic texture sampling – Alan Wolfe Sep 10 '15 at 14:01
  • 1
    Please attach your shader completely, it's variable definition I mean, may be you need to define a High precision or mid precision variable instead of lowp – Iman Nia Sep 10 '15 at 14:29
  • 3
    It migh be an issue with the texture filtering you're using. Which filter is it? Point, bilininear, trilinear? Also, make sure you did compute the correct mipmaps for the texture. – glampert Sep 10 '15 at 18:22
  • @AlanWolfe You were right! I will add some proper answer - hope you don' t mind :) Lman I am using floats everywhere, but suggestion above solved the problem anyway. Glampert As I sad I think I don't compute mipmaps at all (I think because it might be done by default somewhere, but I don' t know about it :) I used "LinearWrap" sampler state if that's what you mean – bartosz.baczek Sep 11 '15 at 06:11

1 Answers1

5

So I followed Alan Wolfe suggestion (in comment to my question) And turned out he was right. I was using SamplerState.LinearWrap and that was the issue. When I changed this to AnisotropicWrap it looked much better. Below are some examples of different sampling types and how they affect texture:

graphicsDevice.SamplerStates[0] = SamplerState.PointWrap;

enter image description here

graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

enter image description here

graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicWrap;

enter image description here

David Kuri
  • 2,293
  • 13
  • 32
bartosz.baczek
  • 399
  • 1
  • 12
  • 1
    Glad to help! Anisotropic filtering is more expensive than bilinear. If that becomes a problem for you, you might try a higher resolution texture, or distance field textures since it looks to be just 2 colors. http://blog.demofox.org/2014/06/30/distance-field-textures/ – Alan Wolfe Sep 11 '15 at 14:33