Question

I'm somewhat new to XNA and am creating a 3D game using BEPU physics (this is required for a college course). I'm trying to implement a simple particle system from a particle example from Microsoft. In the particles' Draw() method, the following code is executed:

// Activate the particle effect.
foreach (EffectPass pass in particleEffect.CurrentTechnique.Passes)
{
    pass.Apply();

    //Draw particle primitives
    ...

}

There is one pass in CurrentTechnique.Passes that is titled P0, which corresponds to the following pass in the particle effects FX file:

// Effect technique for drawing particles.
technique Particles
{
    pass P0
    {
        VertexShader = compile vs_2_0 ParticleVertexShader();
        PixelShader = compile ps_2_0 ParticlePixelShader();
    }
}

However, this operation causes the UV map for some of my models to render improperly, and I'm not using any custom shaders aside from the ones I'm using for the particle system. Is it possible to effectively undo the effects of applying this pass in order to draw my other models? I can call GraphicsDevice.Reset() at the start of the game's main Draw() loop, and that fixes the problem, but in fullscreen mode the screen flashes black each time GraphicsDevice.Reset() is called.

Was it helpful?

Solution

You will need to explicitly set the necessary render states to whatever is appropriate for your models. It is uncommon for rendering code (in XNA or otherwise) to "clean up after itself" in the way which you expect; that would be an additional expense that is often unnecessary. Rather, it's usually assumed that if you need the device to be set a certain way before rendering, that'll you do so yourself at the time, and if you don't explicitly set something then you're fine with it being any arbitrary value.

It's hard to know exactly what's wrong when you say that your models "render improperly," but I would recommend that you investigate the following properties on GraphicsDevice:

The MSDN documentation specifies their default values, so you might try explicitly resetting them. It is unlikely that you need to reset all of them; my guess based on what you've written is that SamplerStates is likely the culprit. Learn what each one does and try to understand how it might be influencing what you see.

Definitely don't call GraphicsDevice.Reset(). That's way overkill, and not intended for this purpose.

OTHER TIPS

Cole Campbell's answer to my question can definitely help with solving some shader problems, so be sure to take a look at that if you're having similar issues. I fixed my issue, however, when I found the following Sampler code used in the FX file:

sampler Sampler = sampler_state
{
    Texture = (Texture);    

    ...

    AddressU = Clamp;
    AddressV = Clamp;
};

My model texture was supposed to wrap, but as you can see, the shader was being set to clamp textures (which was the source of my texture distortion). The particle system doesn't really need clamped textures, so I set both values in the above code to Wrap instead of Clamp. This took care of my problem!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top