Model rendering issue

Started by
4 comments, last by Headkaze 10 years, 9 months ago

I'm having a problem rendering an X model. When I use the DirectX ModelView app it renders the model correctly.

I have tried various different lighting but no matter how I rotate the model the edges are always black when they should be green.

I'm wondering if it's my vertex format which is:


VertexFormat.Position | VertexFormat.Normal | VertexFormat.Texture1

I've attached the X model to this post along with screenshots showing ModelView's rendering and my own engine rendering.

Any ideas what it could be?

EDIT: I tried adding VertexFormat.Diffuse but no difference.

Advertisement

Can you show us your shader, because it's quite hard to determine your shader.

Do you set the variable diffuse to anything?

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

I'm using Direct X 9 with the fixed pipeline (sorry should have mentioned that).

Here are the main render states:

device.SetRenderState(RenderState.ZEnable, true);
device.SetRenderState(RenderState.ZWriteEnable, true);
device.SetRenderState(RenderState.FillMode, FillMode.Solid);
device.SetRenderState(RenderState.FogEnable, false);
device.SetRenderState(RenderState.AlphaTestEnable, false);
device.SetRenderState(RenderState.NormalizeNormals, true);
device.SetRenderState(RenderState.Lighting, true);
device.SetRenderState(RenderState.SpecularEnable, false);
device.SetRenderState(RenderState.CullMode, Cull.Counterclockwise);

Lighting:

Light light = new Light();
light.Type = LightType.Point;
light.Diffuse = new Color4(1, 1, 1);
light.Ambient = new Color4(1, 1, 1);
light.Specular = new Color4(1, 1, 1);
light.Position = new Vector3(0, 0, -2);
light.Attenuation0 = 0;
light.Attenuation1 = 0.75f;
light.Attenuation2 = 0;
light.Range = 100;
device.SetLight(0, light);
device.EnableLight(0, true);

If I use the following blend states the sides turn white. The sides don't have a texture.

device.SetRenderState(RenderState.AlphaBlendEnable, true);
device.SetRenderState(RenderState.SourceBlend, Blend.SourceColor);
device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);

device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
device.SetTextureStageState(0, TextureStage.ColorArg1, TextureArgument.Texture);
device.SetTextureStageState(0, TextureStage.ColorArg2, TextureArgument.Diffuse);

device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Disable);
device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture);
device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse);

And the rendering

for (int i = 0; i < m_materials.Length; i++)
{
    device.Material = m_materials[i];

    device.SetTexture(0, m_textures[i]);

    m_mesh.DrawSubset(i);
}

I'm coming to the conclusion it has something to do with my blend states.

If I change my rendering code to the following the green is rendered correctly:

for (int i = 0; i < m_materials.Length; i++)
{
    m_materials[i].Diffuse = new Color4(1.0f, m_materials[i].Diffuse.Red, m_materials[i].Diffuse.Green, m_materials[i].Diffuse.Blue);
 
    device.Material = m_materials[i];
 
    device.SetTexture(0, m_textures[i]);
 
    m_mesh.DrawSubset(i);
}
Why does setting the diffuse's alpha to 1.0f (original was 0.0025f) render it correctly? Both DirectX's ModelView and XAnimator render it correctly without this line.

I have tried so many different settings including trying to copy the render states directly from XAnimator but to no avail. I'm sure it's something simple.
Okay I have since discovered that it's caused by rendering to a render target (I need to do this for pixel shader effects).

Can anyone explain why rendering to a render target messes with the alpha value of a diffuse material?
Problem solved. I had to turn off alpha blending before rendering the render target quad.

This topic is closed to new replies.

Advertisement