Jump to content
  • Advertisement
Sign in to follow this  
fervent

[mdx] Semi-transparent shield effect

This topic is 4554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'd like to create a semi-transparent spherical shield effect around one of my models (using managed d3d). I was thinking to accomplish this effect, I'd simply create a spherical shell mesh and set the opacity of the mesh to ~20%. Problem is, I'm not 100% clear on the best way (performance, etc) to set the transparency of a mesh. Here's my Mesh code:
private static Mesh loadMesh(Device d, string file, ref Material[] meshMats, ref Texture[] meshTexts)
{
    ExtendedMaterial[] mtrl;
    Mesh tempMesh = Mesh.FromFile(file, MeshFlags.SystemMemory, d, out mtrl);

    if ((mtrl != null) && (mtrl.Length > 0))
    {
        meshMats = new Material[mtrl.Length];
        meshTexts = new Texture[mtrl.Length];

        for (int i = 0; i < mtrl.Length; i++)
        {
            meshMats = mtrl.Material3D;
            meshMats.Ambient = meshMats.Diffuse;

            if ((mtrl.TextureFilename != null) && (mtrl.TextureFilename != string.Empty))
                meshTexts = TextureLoader.FromFile(d, @"..\..\Models\" + mtrl.TextureFilename);
        }
    }

    return tempMesh;
}

public void Draw()
{
    for (int i = 0; i < materials.Length; i++)
    {
        device.Material = materials;
        device.SetTexture(0, textures);
        mesh.DrawSubset(i);
    }
}


I'd like to modify the loadMesh and Draw method in such a way that I can specify: Draw(.25); to get the mesh to draw with 25% opacity. Any help would be greatly appreciated! Thanks, Dave

Share this post


Link to post
Share on other sites
Advertisement
Performance isn't really going to change one way or the other.

Are you using effects or fixed function?

You want to set up your texturing and blending (or pixel shader) such that your ".25" goes out in the alpha component of the output color. Then you turn on framebuffer blending, with the appropriate blend function (SRCALPHA,INVSRCALPHA if not using pre-multiplied alpha, ONE,INVSRCALPHA if you are).

Remember to draw all transparent objects last, sorted from far to near.

For a pixel shader, it's really easy -- just make your ".25" a parameter to the shader, and move that value into OCOLOR.w.

For a fixed function, you probably want to set the AlphaSrc to the Constant value, and set the constant to contain 0xff000000*alpha (where "alpha" is your floating-point value). Check out the documentation on the texture stage states for more information.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!