XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Translucent shaders

Last post 10/9/2007 4:50 PM by Nick Gravelyn. 3 replies.
  • 10/9/2007 8:49 AM

    Translucent shaders

    Does anyone have a descent translucent shader so I can render a model almost invisible?  I assume shaders are the way to do it?

    Thanks

    3DMUVE LLC - http://www.3dmuve.com

    QUADgnim@3dmuve.com

    Visit my Blog
  • 10/9/2007 9:54 AM In reply to

    Re: Translucent shaders

    Shaders would be the way to do this, yes.  Find any simple shader, and where it outputs color, change the alpha value to something like 0.5, so it's halfway transparent.  Make sure to draw opaque objects first!
  • 10/9/2007 9:56 AM In reply to

    Re: Translucent shaders

    Shaders are one way to do it, but that depends on the total effect you are going for.  If the only change you are interested in is to change the "visibility" of the model then you can use a BasicEffect instead of writing a shader.  Just turn on the Alpha Blending render state on the graphics device and set the alpha value.  For Alpha values 1.0f is fully opaque and 0.0f is invisible - you probably want something closer to zero.

    Example (Modified *very* slighty from the XNA documention on how to draw a model):

     private void DrawModel(Model m, Matrix World)
    {
    Matrix[] transforms = new Matrix[m.Bones.Count];
    m.CopyAbsoluteBoneTransformsTo(transforms);

    foreach (ModelMesh mesh in m.Meshes)
    {

    foreach (BasicEffect effect in mesh.Effects)
    {
    effect.EnableDefaultLighting();
    //you can modify this models effect here
    effect.Alpha = 0.5f;
    //modification done.
    effect.View = m_viewMatrix;
    effect.Projection = m_projectionMatrix;
    effect.World = transforms[mesh.ParentBone.Index] * World;
    }

    mesh.Draw();
    }
    }

    http://shatteredgenious.blogspot.com/
  • 10/9/2007 4:50 PM In reply to

    Re: Translucent shaders

    Both of the above are solutions. If you want to also distort the background, check out the Distortion Sample from this site. It shows how to make a model nearly invisible and distort the stuff behind it.
Page 1 of 1 (4 items) Previous Next