1
\$\begingroup\$

Here's a youtube video of my problem.

https://youtu.be/1zB4q9_sNQI

Look at how the hideous cube kinda slides into the terrain and rotates weirdly with the world and from above its vanished into the terrain. None of the other models (not instanced) have that problem.

I'm having trouble getting hardware instancing to work as I need it to. For some reason my instanced models appear to vanish from above.

I thought I was doing something wrong with the instance transforms (which maybe I am). So i ripped out all but the scale and translation for those... same problem.

I thought it might be a depth problem so I just set the depth at 0 and STILL i have the same problem.

I made the simplest model I could with 1 bone and 1 texture. Same problem.

Maybe i'm missing something obvious.

Here's the vertex shader:

VertexShaderOutput VertexShaderCommon(VertexShaderInput input, float4x4 instanceTransform)
{
    VertexShaderOutput output;

    // Apply the world and camera matrices to compute the output position.
    float4 worldPosition = mul(input.Position, instanceTransform);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    // Compute lighting, using a simple Lambert model.
    float3 worldNormal = mul(input.Normal, instanceTransform);

    float diffuseAmount = max(-dot(worldNormal, LightDirection), 0);

    float3 lightingResult = saturate(diffuseAmount * DiffuseLight + AmbientLight);

    output.Color = float4(lightingResult, 1);

    // Copy across the input texture coordinate.
    output.TextureCoordinate = input.TextureCoordinate;

    return output;
}

Please help. I've been stuck on this for a day or two now annoyingly.

If you need an more code you might think relevant let me know.

Thanks in advance!

\$\endgroup\$
0
\$\begingroup\$

It was something stupid in the end. In between drawing my non-instanced models and instanced models I had some effects and other stuff rendered, one of which changed the projection matrix. Therefore the Instanced geometry was being rendered with a different projection. One of the guys on GameDev spotted it.

\$\endgroup\$

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.