Sunmoon_BIT/XNA 3.1

XNA 객체 투명하게만들기

와앙노 2010. 6. 10. 22:29

 

코드내에 Draw(GameTime gameTime)

 

//아마도 렌더스테이트에다가 알파값을 사용하겠다고 선언하는 같아요.

GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;
GraphicsDevice.RenderState.AlphaBlendEnable = true;
GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;

//그리고 Model Drawing 부분에서도 알파값을 1.0f 완전 불투명   0.0f 완전 투명이라 했을때 중간 값을 넣으시면

그만큼 충분한 투명값을 얻을 있습니다.

 

Matrix[] transforms = new Matrix[darwin.model.Bones.Count];
darwin.model.CopyAbsoluteBoneTransformsTo(transforms);

foreach (ModelMesh mesh in darwin.model.Meshes)
{
         foreach (BasicEffect effect in mesh.Effects)
         {
                     effect.EnableDefaultLighting();
                     effect.Alpha = alpha;//
부분처럼 써주시면 됩니다. 알파값을 설정해주시면 돼요ㅎ 현재 알파변수는 0.3f입니다
                     effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(darwin.rotation) * Matrix.CreateTranslation(darwin.position);
                     effect.View = arcCamera.View;
                     effect.Projection = arcCamera.Projection;
         }
         mesh.Draw();

}

 

이렇게 하시면 결과물로 투명한 유리인 아래 사진 같은 결과를 얻을 있습니다.

 

 

[출처] XNA에서 오브젝트 투명하게 띄우기(유리) (XNA | Game Studio Express) |작성자 부퍼엉