Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem when rendering a model of my World - when rendered using BasicEffect, it looks just peachy. Problem is when I render it using deferred rendering. See for yourselves:

what it looks like:

enter image description here

what it should look like:

enter image description here

(Please ignora the cars, they shouldn't be there. Nothing changes when they are removed)

Im using Deferred renderer from


except very simplified, without the custom content processor. Here's the code for the GBuffer shader:

float4x4 World;
float4x4 View;
float4x4 Projection;
float specularIntensity = 0.001f;
float specularPower = 3; 

texture Texture;
sampler diffuseSampler = sampler_state
    Texture = (Texture);
    AddressU = Wrap;
    AddressV = Wrap;

struct VertexShaderInput
    float4 Position : POSITION0;
    float3 Normal : NORMAL0;
    float2 TexCoord : TEXCOORD0;

struct VertexShaderOutput
    float4 Position : POSITION0;
    float2 TexCoord : TEXCOORD0;
    float3 Normal : TEXCOORD1;
    float2 Depth : TEXCOORD2;

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    output.TexCoord = input.TexCoord;                            //pass the texture coordinates further
    output.Normal = mul(input.Normal,World);                   //get normal into world space
    output.Depth.x = output.Position.z;
    output.Depth.y = output.Position.w;
    return output;
struct PixelShaderOutput
    half4 Color : COLOR0;
    half4 Normal : COLOR1;
    half4 Depth : COLOR2;

PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
    PixelShaderOutput output;
    output.Color = tex2D(diffuseSampler, input.TexCoord);            //output Color
    output.Color.a = specularIntensity;                                              //output SpecularIntensity
    output.Normal.rgb = 0.5f * (normalize(input.Normal) + 1.0f);    //transform normal domain
    output.Normal.a = specularPower;                                            //output SpecularPower
    output.Depth = input.Depth.x / input.Depth.y;                           //output Depth
    return output;

technique Technique1
    pass Pass1
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();

And here are the rendering parts in XNA:

public void RednerModel(Model model, Matrix world)
            Matrix[] boneTransforms = new Matrix[model.Bones.Count];

            Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            Game.GraphicsDevice.BlendState = BlendState.Opaque;
            Game.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

            foreach (ModelMesh mesh in model.Meshes)
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    GBufferEffect.Parameters["World"].SetValue(boneTransforms[mesh.ParentBone.Index] * world);
                    RenderMeshpart(mesh, meshPart);

        private void RenderMeshpart(ModelMesh mesh, ModelMeshPart part)
            Game.GraphicsDevice.Indices = part.IndexBuffer;
                                                          0, 0, part.NumVertices,
                                                          part.StartIndex, part.PrimitiveCount);

I import the model using the built in content processor for FBX. The FBX is created in 3DS Max. I don't know the exact details of that export, but if you think it might be relevant, I will get them from my collegue who does them.

What confuses me though is why the BasicEffect approach works... seems the FBX shouldnt be a problem.

Any thoughts? They will be greatly appreciated :)

share|improve this question

closed as off-topic by Josh Petrie Dec 30 '13 at 16:53

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

It might be that some parts of the FBX mesh require a primitive ordering type other than TriangleList, for instance a TriangleStrip that shares adjacent vertices. Other than that, I'd also like to point out that getting effect parameter values on each frame is rather slow and you can run into performance issues when leaving the program running for a while. The custom content processor is made so that you don't need the manual setting of textures, among other things. – ChrisC Nov 21 '11 at 21:50
Nope, that's not it.. I changed it to TriangleStrip but still nothing.. Thx for the optimization tips, I will get to them once I get the rendering working ;) – Tomáš Bezouška Nov 22 '11 at 12:26
Ok, I just read again your post - you say SOME of the meshes require not TriangleList, say a TriangleStrip. But how can I tell which ones? Or How can I change the export to FBX to prevent that? – Tomáš Bezouška Nov 22 '11 at 19:27
If it renders correctly using basiceffect then I don't think it can be a problem with the primitive type. My guess would be something wrong with the vertex shader, but it looks ok :/ – Martin Dec 14 '12 at 18:55
This question appears to be off-topic because it is about debugging your code for you. – Josh Petrie Dec 30 '13 at 16:53