XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

TerrainProcessor VegetationProcesor SkinningSample

Last post 24/07/2009 11:32 by Ga. 5 replies.
  • 17/07/2009 12:08
    • (0)
    • premium membership
    • Posts 12

    TerrainProcessor VegetationProcesor SkinningSample

    I have merged the terrainprocessor and vegetationprocessor and now have grass and trees on my heightmap terrain generated from a bitmap.

    I also have several dudes (dude.fx) walking across the terrain.

    My problem is the dude now appears odd. I can see through bits of him.

    When I had the dudes walking across my terrain all was fine. I added spritebatch and he went see through again. I fixed this by looking in other posts.

     

    ScreenManager.GraphicsDevice.RenderState.DepthBufferEnable = true;  
    ScreenManager.GraphicsDevice.RenderState.AlphaBlendEnable = false;  
    ScreenManager.GraphicsDevice.RenderState.AlphaTestEnable = false;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap; 

    Now I have billboards on my terrain he's gone odd again.


    This is the code I have now

    ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);  
    ScreenManager.GraphicsDevice.RenderState.DepthBufferEnable = true;  
    ScreenManager.GraphicsDevice.RenderState.AlphaBlendEnable = false;  
    ScreenManager.GraphicsDevice.RenderState.AlphaTestEnable = false;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;  
     
    DrawTerrain(gameTime);  
     
    ScreenManager.GraphicsDevice.RenderState.DepthBufferEnable = true;  
    ScreenManager.GraphicsDevice.RenderState.AlphaBlendEnable = false;  
    ScreenManager.GraphicsDevice.RenderState.AlphaTestEnable = false;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;  
     
    dudeHorde.Draw(viewMatrix, projectionMatrix); 

    The DrawTerrain method is taken from the billboard example and dudeHorde.draw is very simple.

    If I don't draw the terrain the dudes draw fine.

    If I add spritebatch back the dudes draw fine.

    If I draw the dudes first and then the terrain they are still weird and also behind the terrain

    Obviously the billboards are messing things up. Can anyone please help?

     

  • 17/07/2009 13:40 In reply to

    Re: TerrainProcessor VegetationProcesor SkinningSample

    Take a look at the help documentation that came with the billboard sample. It sets a bunch of renderstates related to alphablending to get around having to depth sort the billboards.

    If you look at the technique definitions in the Billboard.fx file you should be able to see which renderstates are being set and then reset any that seem related to your issue manually (as your are already doing with other states) after drawing the terrain.
    www.dadoogames.com
    Curling 2010 - in playtest soon, this month or next, this year for sure (maybe)
  • 17/07/2009 15:12 In reply to
    • (0)
    • premium membership
    • Posts 12

    Re: TerrainProcessor VegetationProcesor SkinningSample

    TA LA!

    I debugged and looked at renderstate before the call to drawTerrain and afterwards. I noted the following had changed. I put in the code and my dude looks as mean as ever!

    ScreenManager.GraphicsDevice.RenderState.DepthBufferEnable = true;  
    ScreenManager.GraphicsDevice.RenderState.AlphaFunction = CompareFunction.Greater;  
    ScreenManager.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;  
    ScreenManager.GraphicsDevice.RenderState.DepthBufferEnable = true;  
    ScreenManager.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;  
    ScreenManager.GraphicsDevice.RenderState.ReferenceAlpha = 0;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;  
    ScreenManager.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;  
     
  • 24/07/2009 10:45 In reply to
    • (0)
    • premium membership
    • Posts 12

    Re: TerrainProcessor VegetationProcesor SkinningSample

    I am still having problems with this.

    If my billboard contains pixels that are solid they appear correctly. They will obscure any models further away.

    If the billboard contains pixels that have a degree of transparency they appear behind the model. The model obscures the pixels even though they should be in front.

    Has anyone managed to place a model on the Billboard sample and got the semi-transparent pixels to render properly??
  • 24/07/2009 10:53 In reply to

    Re: TerrainProcessor VegetationProcesor SkinningSample

    Answer
    Reply Quote
    Are you drawing your billboards last? You likely should be based on the way the transparency part of the sample works.

    If you read the documentation that came with the sample you'll see that for any pixels with greater than 95% transparency depth sorting is thrown out the window to get around the requirement to have to manually depth sort your billboards. You really should read the documentation for this one, it explains everything very well - specifically why it chooses to take the approach that is causing you problems.

    If you find that you need better depth sorting than the sample provides you will need to manually work out the order in which to draw your billboards based on depth from your camera, which is not an easy issue. See here for a good explanation of the issues involved.
    www.dadoogames.com
    Curling 2010 - in playtest soon, this month or next, this year for sure (maybe)
  • 24/07/2009 11:32 In reply to
    • (0)
    • premium membership
    • Posts 12

    Re: TerrainProcessor VegetationProcesor SkinningSample

    Thanks for the reply. I will mark it as the answer.

    If anyone else is using the billboard sample and wants to use semi-transparent billboards and use models at the same time I would advise them to steer clear of this sample.

    It's only good for billboards that are opaque.

    I wanted to use billboard fog randomly placed on my terrain. And have my model walk through the fog. It seems this is not possible without sorting.

    Thanks for the help dadoo!
Page 1 of 1 (6 items) Previous Next