Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Model rendering issue

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 Headkaze   Members   

607
Like
0Likes
Like

Posted 11 July 2013 - 03:03 AM

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.

Attached Thumbnails

  • Model_Mine.png
  • Model_ModelView.png

Attached Files


Edited by Headkaze, 11 July 2013 - 03:49 AM.


#2 Migi0027 (肉コーダ)   Members   

4565
Like
0Likes
Like

Posted 11 July 2013 - 09:56 AM

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/


#3 Headkaze   Members   

607
Like
0Likes
Like

Posted 11 July 2013 - 03:42 PM

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.



#4 Headkaze   Members   

607
Like
0Likes
Like

Posted 15 July 2013 - 06:06 PM

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.

#5 Headkaze   Members   

607
Like
0Likes
Like

Posted 15 July 2013 - 09:08 PM

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?

#6 Headkaze   Members   

607
Like
0Likes
Like

Posted 15 July 2013 - 09:30 PM

Problem solved. I had to turn off alpha blending before rendering the render target quad.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.