[XNA]绘制一个简单的透明平面

时间:2014-07-24 18:01:59

标签: xna alpha plane

我正在使用XNA并遇到问题。 一个基本问题,但是argh! 我想绘制一个海洋,BASIC海洋,只是一架飞机,蓝色和透明。 只是一架飞机。 我尝试使用Vertex,模型和纹理。 alpha通道如何在XNA中工作? StencilState,DepthBuffer,什么都行不通。 你能解释一下怎么做吗?    使用VertexPositionColor吗? 对不起,但我找了很久。

class Ocean
{
    Effect shader0;

    public Vector3 Position;
    GraphicsDevice Graphics;
    Camera camera;
    Model Mesh;


    Texture2D waterTexture;
    Rectangle screen;
    Texture2D test;



    public Ocean(Vector3 pos, int size, GraphicsDevice gra, Camera cam, ContentManager content)
    {

        Graphics = gra;
        shader0 = content.Load<Effect>("Ocean");
        //shader0 = new BasicEffect(this.Graphics);
        waterTexture = content.Load<Texture2D>("Images/shaderUnderwater");


        screen = new Rectangle(0, 0, this.Graphics.Viewport.Width, this.Graphics.Viewport.Height);
        Position = pos;


        Mesh = content.Load<Model>("Models/ocean");

        camera = cam;

        foreach (ModelMesh mesh in this.Mesh.Meshes)
        {
            foreach (ModelMeshPart part in mesh.MeshParts)
            {
                part.Effect = shader0;
            }

        }
    }




    bool underWater;
    Vector3 lightDirection = new Vector3(-1.0f, -1.0f, -1.0f);
    public void Draw(SpriteBatch spriteBatch, Player player)
    {

        Matrix world = Matrix.CreateScale(100f) * Matrix.CreateRotationX(MathHelper.ToRadians(-90f)) * Matrix.CreateTranslation(Position);

        //this.shader0.EnableDefaultLighting();
        this.shader0.Parameters["World"].SetValue(world);
        this.shader0.Parameters["View"].SetValue(player.Camera.View);
        this.shader0.Parameters["Projection"].SetValue(player.Camera.Projection);


       // Dessin du model
        foreach (ModelMesh mesh in this.Mesh.Meshes)
        {
            foreach (Effect effect in mesh.Effects)
            {


                effect.CurrentTechnique = effect.Techniques["Textured"];
                effect.Parameters["DiffuseColor"].SetValue(new Vector4(1f, 0.2f, 0.2f, 1f) ); // a reddish light
                effect.Parameters["DiffuseLightDirection"].SetValue(new Vector3(1, 0, 0) );  // coming along the x-axis
                effect.Parameters["SpecularColor"].SetValue(new Vector4(0, 1, 0 ,1f) ); // with green highlights




                effect.Parameters["World"].SetValue(world);
                effect.Parameters["View"].SetValue(player.Camera.View);
                effect.Parameters["Projection"].SetValue(player.Camera.Projection);

            }
            mesh.Draw();
        }
        this.Graphics.BlendState = BlendState.Opaque;



        //Effet 
        if (camera.Position.Y < Position.Y)
            spriteBatch.Draw(this.waterTexture, this.screen, Color.White);

    }

    public void Update(GameTime gameTime)
    {

    }


    void onWater()
    {
        underWater = true;
    }

}

}

1 个答案:

答案 0 :(得分:0)

如果使用BasicEffect渲染海洋,则BasicEffect具有Alpha属性,这会影响透明度。请看这里:http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.basiceffect.alpha.aspx

您可以使用BasicEffect以您用于渲染模型的任何方式创建透明度。