I am rendering a simple flat plane + texture to use as the floor for a game. I'm rendering it using a custom effect I've written.

The problem I have is that the ground in the distance gets a bit distorted and shakey when the camera moves forwards and backwards.

If I render the same model + texture using the BasicEffect instead of a custom shader it appears smooth and works correctly.

Here's the XNA code setting up the custom effect:

Matrix worldMatrix = Matrix.CreateScale(0.2f);
_floorEffect.CurrentTechnique = _floorEffect.Techniques["Textured"];
_floorEffect.Parameters["ViewProjection"].SetValue(camera.view * camera.projection);


foreach (EffectPass pass in _floorEffect.CurrentTechnique.Passes)
     device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount);

Here's the shader code:

float4x4 World;
float4x4 ViewProjection;
Texture diffuseTexture;

sampler TextureSampler = sampler_state { texture = <diffuseTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = wrap; AddressV = wrap;};

struct TexturedVertexToPixel
    float4 position : POSITION0;
    float2 textureCoords : TEXCOORD0;

TexturedVertexToPixel TextureVertextShader(float4 inPos : POSITION, float2 inTextureCoords : TEXCOORD0)
    TexturedVertexToPixel output;
    float4x4 preWorldViewProjection = mul (World, ViewProjection);
    output.position = mul(inPos, preWorldViewProjection);    
    output.textureCoords = inTextureCoords;

    return output;

float4 TexturePixelShader(TexturedVertexToPixel input) : COLOR0
    return tex2D(TextureSampler, input.textureCoords);

technique Textured
    pass Pass1
        VertexShader = compile vs_2_0 TextureVertextShader();
        PixelShader = compile ps_2_0 TexturePixelShader();

Videos to demonstrate what I mean:

Using the BasicEffect http://www.youtube.com/watch?v=matmrIZH-pU
Using the Custom Shader http://www.youtube.com/watch?v=Fu9P4D-UCTc (see it clearest in 1080p full screen)

Notice the difference when looking at the ground in the distance.


I managed to fix the issue by enabling the generation of MipMaps for the texture used by the model. This is done within visual studio by finding the texture in the content project right clicking going to properties and then expanding "Content Processors" and enabling the option "Generate MipMaps"

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.