• Advertisement
Sign in to follow this  

Model rendering issue

This topic is 1650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by Headkaze

Share this post


Link to post
Share on other sites
Advertisement

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

 

Do you set the variable diffuse to anything?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Problem solved. I had to turn off alpha blending before rendering the render target quad.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement