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


    #define MARKINGS

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

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

DepthStencilState ZWriteOff
DepthWriteMask = ZERO;

technique10 T0
pass P0
   SetVertexShader(CompileShader(vs_4_0, VS()));
   SetPixelShader(CompileShader(ps_4_0, PS()));
    #if defined(MARKINGS) || defined(RUNWAY)


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.

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

  1. 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.


  2. matgg says:

    Thankyou so MUCH!!! This is amazing!! Congratulations! I was thinking to fix this I had to install the sdk and do weird stuff with that for each airport I visit, but now I can enjoy dx10 more!! Well done, and like Jean Paul, I am excited to see what happens next! 😀

  3. TomazDrnovsek says:

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

  4. Hamza Nadda says:

    I still don’t understand how I can get it to work. I’ve tried inserting the text but nothing work. Maybe I inserted it in the wrong section? Or perhaps I missed an important step. Is there any way you can help me out? Please send me an E-Mail @ Hamzayahoo@hotmail.com

    • stevefsx says:

      Hi hamza,

      Did you sort this out? Rather than editting the shader I suggest you download all the patches from avsim library – there is a link on menu. It has a basic installer.

      • Hamza Nadda says:

        Hey Steve,

        I completely forgot I had a post here XD. Yes I did manage to sort it out. Silly me, I forgot to delete the Shaders folder, (I think I missed that part when I was reading the blog here but I found out that I had to remove the Shader folder from the Avsim Forum). Thanks man for this wonderful fix! I was hesitant to use FSX with DX10 because of these painful fixes but you did the impossible and fixed it! Congrats man! I really appreciate the work you have done to fix this issue for the Flight Simulation Community!

  5. 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! 🙂

  6. 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 !!!!!!!!!

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

  8. 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!

  9. Wade says:

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

  10. 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 =)

  11. 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!

  12. 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?

  13. stevefsx says:

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s