FSX Flashing Textures Part 5 Conclusions and a Fix?

The conclusion from looking at how DX9 and DX10 draw the same runway is that there is a very very simple bug in the DX10 implementation.

DX9 draws the airport ground as a series of flat layers that go on top of each other.   The  result for each pixel is therfore either the top layer or a blend of the top layer and lower layers.  As drawing flat layers in this way is very simple it doesn’t need to use the “depth buffer”.

DX10 draws the airport in exactly the same way except that when it  comes to drawing the taxiways it uses a default setting which records the depth of all the taxiway pixels in the depth buffer.   This is like a high water mark.

This mistake means that when subsequent layers are drawn which are essentially at the same distance from the camera the depth buffer is checked and if by an accident of rounding and interpolation one of the pixels in the upper layer is calculated to be fractionally further away than the taxiway pixel then it is “Z rejected” and the taxiway shows through.

Although I cannot change the code – I can detect when the shader associated with the runway is used and amend the state not to use the Z buffer in a C++ DX10 wrapper.

Wondering if there was a better way to implement this than a wrapper library, I googled to see if there was a way to do this from the shader itself. One of the first hits that I found was a discussion on FSX Rain Voids and DX10 where Christian Buchner explained how to update the depth stencil from a shader!

This means that it it is possible to change the state and avoid using the Z buffer only by changing a shader.

A long trial and error search (hours) was needed to find the right set of macros for the compilation of the relevant general10.fx shader.

The revised fix is then to change general10.fx as follows inserting the blue text

#if defined(VT_VERTEX) && defined(SHD_VERTICAL_NORMAL) && defined(SHD_BASE) && defined(SHD_ENV) && defined(SHD_PRECIP_BLEND)
    #define AIRPORT_SHADER

#endif

#if defined(AIRPORT_SHADER) && defined(SHD_BLENDENVBYINVBASEALPHA) && defined(SHD_FINAL_ALPHA_BLEND)
    #define MARKINGS
#endif

 #if defined(AIRPORT_SHADER) && defined(SHD_DETAIL) && defined(SHD_BUMP)
   #define RUNWAY
#endif

 #if defined(MARKINGS) || defined(RUNWAY)

DepthStencilState ZWriteOff
{
DepthWriteMask = ZERO;
};
#endif

technique10 T0
{
pass P0
{
   SetVertexShader(CompileShader(vs_4_0, VS()));
   SetGeometryShader(NULL);
   SetPixelShader(CompileShader(ps_4_0, PS()));
    #if defined(MARKINGS) || defined(RUNWAY)
    SetDepthStencilState(ZWriteOff,0);
    #endif
}

}

And surprisingly perhaps it does seem to work!

Here is a frame analysis after compiling the new shader – there is no flashing and there is now a state of Write Mask Zero for the taxiways which is presumably inherited from the technique in some way.

Its important to note  that there could be another (important) drawcall that uses the same shader options. The fact I haven’t seen one doesn’t mean it doesn’t exist. On a positive note both shaders define the NORMAL as VERTICAL so I think it could only be an issue with flat surfaces.

About stevefsx

I don't use FSX that much. But I am very annoyed when it doesn't work properly!
This entry was posted in DX10, Runways. Bookmark the permalink.

16 Responses to FSX Flashing Textures Part 5 Conclusions and a Fix?

  1. stevefsx says:

    I would need the code to do that!! So no.

  2. stevefsx says:

    You have 3 options

    1) Find a tool that lets you take ownership of the file

    2) Buy the commercial fixer which handles this

    3) Copy the fsx directory and subdirectories elsewhere then set the environment variable FSXDIR to point to the copied location and run the setup.bat. When its done copy the modified shader sources back to the real fsx system.

    • Dan Nunes says:

      Third option worked for me. Now I can finally enjoy FSX as expected! Thanks again, Steve! May I ask, have you ever thought about porting FSX to DirectX 11, like P3D?

  3. Dan Nunes says:

    Hey Steve! First of all, thank you very much for your dedication for the FSX improvement after all these years! I’m trying to install your patch, however I’m getting the same old problem where when I try to run the .bat file, I get the error “general10.fx has readonly attribute set”. I would like to know if there’s a way to manually copy the code into general10.fx file, which I know can be edited via notepad. Thanks for your attention!

  4. sairod says:

    Bumped, Thanks for the help. Fixed mine. Took me a while to understand it though and a few reads… since one of the places i got this from said to copy it at the end… then i read and after breaking my head i noticed the blue lines were to be copied before and after the black lines on the code which are the ending lines. dunno if i explained myself… but =D what matters is that it worked wooooooot . Thanks again!! owe you a beer =)

  5. Wade says:

    Thank You for fixing the problem! It worked for me.

  6. Flo says:

    Just installed your fix into my FSX. Me and my eyes say a big thank you for the effort you put in resolving MS’s bugs!

  7. Someone should be paying you for the DX10 FSX work you are doing… seriously it is most appreciated by me 🙂

  8. rui says:

    Steve, silly question here…I am using DX10, and have frames of 100 if I let FSX doing what he wants, so, yes, I have a fluid simulation, my fear ( and question is) if I try this fix, for flickering runways and taxiways, do you think somehow I will loose this fluidity and go back to some stuttering instead!?
    I have tried your lights fix, and its a treat, again, thank you very much !!!!!!!!!
    later,
    rui

    • stevefsx says:

      There is no reason for the fixes to impact performance.

      However it would be prudent to take a backup copy of the shaders before installing

  9. Adi says:

    Absolutely beautiful solution! It’s now march 2013 and I wanted to try FSX after getting annoyed with it the first time in 2012. I’ve now decided to stick to it and fix the problems and guess what? It was flickering all over the place. I swear I went through a lot of pages to find this page which has the best and most proper solution! Microsoft just totally screwed the shader file, tossed it immature to the users. Thank god someone figured out the root cause! Now, I can finally relax and enjoy the sim with sweet fx and no flickering! 🙂

  10. TomazDrnovsek says:

    Because of you I started using DX10 and I love it! I have the smoothest experience in FSX ever. Thank you!

  11. Jean-Paul says:

    Steve, just a big THANK YOU ! The flickering taxiway issue has been bugging FSX users for ages. Looking forward to whatever you will discover next.

    • stevefsx says:

      Thanks Jean-Paul, I do appreciate your comment.

      I think on the French speaking forum you mentioned that your saw some flashing roof textures at dusk.
      Can you describe where exactly? – I can certainly take a look. I have tried a few flights over London at dusk and haven’t really seen anything yet. I did think that the River Thames flashed once at one point though.

      Steve

Comments are closed.