Distorted texture after lost/reset device

Hi,

I'm drawing a textured mesh using DrawIndexedPrimitive, using an effect interface.
After a windowed/full screen toggle the texture appears distorted.
Interestingly when I draw another mesh in wireframe mode in the same render call
the problem doesn't occur.

Can somebody help

Nico


Answer this question

Distorted texture after lost/reset device

  • lastan06

    Nice suggestions, thanks!

    The multiplication of the tex coords with 2 just uniformly scales the texture, there is
    no clamping. The texture is just repeated.

  • Ted Sung

    Oh and I guess the D3DTEXTUREADDRESS you need to specify when you use fixed function vertex processing Because with DX I only used shaders so far.

    I load the texture with

    D3DXCreateTextureFromFile( pd3dDevice,
                                                         m_strTextureFilename,
                                                        &m_pColorTexture);

    And I set it with

    m_pEffect->SetTexture( m_hColorTexture,
    m_pColorTexture) ;

  • mikul

    I just dumped the tex coords before rendering the mesh with the undistorted texture and
    than before rendering the distorted version. They are identical.
    But interesting is the result of your second suggestion: to use the tex coords as color
    values in the pixel shader reveals that the tex coords in the undistorted render call arriving in the shader are different from the ones in the distorted call!
    Basically U and V seemed to be swapped with some kind of scaling.

    I will try to figure out the reason for that...    nasty thing ;-)

  • FredSaw

    It seems the DrawSubset function sets some state. That would explaine the strange behaviour.
    But I don't know exactly what it does/sets that makes the texture appear correctly after the device was reset.

  • GinkZ182

    Thanks for your answer. The texture is loaded in the managed pool, so it hasn't to
    be recreated on reset device as far as I know. Also before I used the DrawIndexedPrimitive function (drawing the mesh as a tri strip) I used mesh->DrawSubset(..), without any problems.


  • Huwwuh

    Fascinating, I've seen lots of odd things come out of directx but that one is so uniform in its oddness. Usually its a horrible mess.

    My impression from the picture is some kind of uniform uv coordinate mangling. Looks like the whole texture gets squashed into that lower right hand side and it mirrored in the one dimension and them clamped in the other direction. What D3DTEXTUREADDRESS do you use when you draw that object (and what happens if you change them) Are you using any texture transform states anywhere

    One question we haven't asked - is this all fixed function or do we need to worry about any shader parameters you may have set. (though I still have no clue why drawing another mesh would fix this).

    Sorry for more questions... this one has me quite confused. Maybe someone else has seen a drawing anomoly like that.

    If you don't want to publish the project to the whole world I am fascinated enough to spend a few minutes taking a look if you want to email me.



  • Don Farrey

    Sorry, my question is not answered yet, so I unmarked it as answered.
    maybe my "thanks for the answer" indicated that it was answered sufficiently. :)

  • mike Delaney

    Hi ZMan, I could sent you the whole project, but it is quite big and you will not get it running if you don't have the August 05 DX SDK version  on your machine because I did some changes in the dxutgui.h and dxutgui.cpp.
    Also I use a SM 3 Shader. But I could remove that quickly, if necessary.

    To your question: I'm using a simple shader for drawing the object, you can have a look in the effect file here.

    The (basic) render code you can find here.

  • Keith Brown

    Depending on where you load the textures to, you need to release them and recreate them. Make sure that you are properly handling them. Look at the Samples in the DirectX SDK install directory and also under lost devices in the documentation. It explains clearly how you must handle a lost device and how to reset it.

    I hope this helps.
    Take care.


  • Ultrageek

    I'm pretty sure DrawSubset doesn't change any state - there would be a lot of bad side effects if it did.

    Looks like you might have to post your project somewhere and hope its small enough or someone has time to look through it. If you have a really small repro project you can post a link to that would be good.

    Or maybe you can post some screenshots of the non distorted and distorted images so we can see the effect you are seeing.

    As for performance of MDX - the MS line is still that is 95%+ of native DX, however there are no official perf numbers I've seen. This is the same claim I have always heard and I've not seen or heard any general cases (I'm sure if you look hard enough there are specific APIs that are not 95% as fast) that dipute this. As I've often said in the forums you will likely hit perf problems becuase of your algorithms (e.g. smart culling or collions detection) or bad use of the directX api in general (e.g. making too many draw calls) long before you hit the MDX/native DX perf threshold.



  • jetter

    I'm guessing that you are not resetting a renderstate after the device is reset then Do you set some renderstates globally after the intial device creation that do not get set after the device reset Maybe when you draw your wireframe the code that sets renderstates is run

  • B1u3dr4g0n

    Oh no, I just wrote a lot and when previewing it got somehow deleted :(    

    ;-) Anyway, so shortly: it seems to have something to do with rendering the first object as a tri strip. When I render it also using the meshs DrawSubset() function, like I do with the second object, no texture distortion occurs.
    There seem to be no state changes I overlooked.

    @ZMan: Btw: is managed DirectX comparable in performance with unmanaged DX now Yes, I know there is some performance difference, but how big is it I haven't found a clear answer about that yet.

  • Syntosys

    Man I feel your pain, nothing looks out the ordinary to me which probably means I'm missing the same thing as you...

    The only odd thing I see is the *2 in your pixel shader which depending on your tex coords could take some of them >1.0 which would possibly cause clamping. What happens without the *2

    Couple of things I would do to help me debug at this stage.

    1. Write a routine to dump the u,v coordinates to the debug window. Use that to dump them before the reset and after. It doesn't make sense to think they are changing since drawing the other mesh 'fixes' the problem but it would make me feel comfortable that it wasn't something obvious. Copy the text to a file and windiff them

    2. Modify your pixel shader to assign the color based on the uv coordinate i.e. take the actual texture out of the equation. just set r=u, g=0 and b=v. You should see your mesh in a nice set of red/blue/purple shades. Then compare the before and after reset images. If they are the same then you know your texture coordinates and calculations in the pixel shader are OK and we can start looking at the texture itself.



  • Chris_e_m

    Undistorted Tex Screenshot
    Distorted Tex Screenshot

    The project is quite big and I use my own classes wrapped around the DX callback framework.
    So it's a little difficult to post it here. But if I don't find the bug soon I will probably try to post parts of it.

    About managed DX: sounds quite promising what you say. I love C#, so maybe I will soon try some MDX project...

  • Distorted texture after lost/reset device