C# 瓦列集发生器

C# 瓦列集发生器,c#,image-processing,xna,drawing,tiles,C#,Image Processing,Xna,Drawing,Tiles,我一直在尝试创建一个tileset生成器(将两个图像混合在一起),但我一直无法确定需要哪种方法才能使一个纹理/图像与主纹理/图像重叠,或者在特定点以某种方式淡出-或者这是不能(或不应该)自动完成的事情 随着绿色图像淡出,蓝色图像应淡入绿色图像的顶部,以实现平滑过渡。如果我已经有两张图片了,我该怎么做 现在,我只能剪掉蓝色的部分。所以左边唯一的部分是绿色,当我尝试添加一个覆盖层时,它只是很难看,我认为alpha级别应该增加(蓝色应该越蓝,越靠近右下角) 你知道我应该看什么吗 我当前的方法:但目前

我一直在尝试创建一个tileset生成器(将两个图像混合在一起),但我一直无法确定需要哪种方法才能使一个纹理/图像与主纹理/图像重叠,或者在特定点以某种方式淡出-或者这是不能(或不应该)自动完成的事情

随着绿色图像淡出,蓝色图像应淡入绿色图像的顶部,以实现平滑过渡。如果我已经有两张图片了,我该怎么做

现在,我只能剪掉蓝色的部分。所以左边唯一的部分是绿色,当我尝试添加一个覆盖层时,它只是很难看,我认为alpha级别应该增加(蓝色应该越蓝,越靠近右下角)

你知道我应该看什么吗

我当前的方法:但目前,这只适用于一个角点,但应适用于“所有”角点;不知道是什么引起的


我会尝试将草和雪纹理混合在一起作为3D基本体。这样,您就不需要为纹理和淡入方向的每个组合生成单独的位图。为了演示,您可以将以下代码片段粘贴到Visual Studio中默认XNA项目的
Draw
方法中:

GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.BlendState = BlendState.NonPremultiplied;
effect.TextureEnabled = true;
effect.VertexColorEnabled = true;
effect.World = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, 0))
    * Matrix.CreateScale(300)
    * Matrix.CreateTranslation(-Vector3.UnitZ);
effect.Projection = Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 1, 10000);
effect.View = Matrix.CreateLookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY);

var grassVertices = new[]
{
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 1f), Vector2.Zero),
    new VertexPositionColorTexture(Vector3.UnitY, new Color(1f, 1f, 1f, 1f), Vector2.UnitY),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 1f), Vector2.One),
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 1f), Vector2.Zero),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 1f), Vector2.One),
    new VertexPositionColorTexture(Vector3.UnitX, new Color(1f, 1f, 1f, 0f), Vector2.UnitX),
};
effect.Texture = grassTexture;
effect.Techniques[0].Passes[0].Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, grassVertices, 0, 2);

var snowVertices = new[]
{
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 0f), Vector2.Zero),
    new VertexPositionColorTexture(Vector3.UnitY, new Color(1f, 1f, 1f, 0f), Vector2.UnitY),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 0f), Vector2.One),
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 0f), Vector2.Zero),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 0f), Vector2.One),
    new VertexPositionColorTexture(Vector3.UnitX, new Color(1f, 1f, 1f, 1f), Vector2.UnitX),
};
effect.Texture = snowTexture;
effect.Techniques[0].Passes[0].Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, snowVertices, 0, 2);
下面是
LoadContent
方法初始化资源所需的内容:

grassTexture = Content.Load<Texture2D>("grass");
snowTexture = Content.Load<Texture2D>("snow");
effect = new BasicEffect(GraphicsDevice);
grassTexture=Content.Load(“草”);
snowTexture=Content.Load(“雪”);
效果=新的基本效果(图形设备);

要在其他方向创建平铺淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入。对于直接向右、向左、向上或向下的淡入淡出,您需要使用四个三角形而不是两个三角形。

我会尝试将草和雪纹理混合在一起作为3D基本体。这样,您就不需要为纹理和淡入方向的每个组合生成单独的位图。为了演示,您可以将以下代码片段粘贴到Visual Studio中默认XNA项目的
Draw
方法中:

GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.BlendState = BlendState.NonPremultiplied;
effect.TextureEnabled = true;
effect.VertexColorEnabled = true;
effect.World = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, 0))
    * Matrix.CreateScale(300)
    * Matrix.CreateTranslation(-Vector3.UnitZ);
effect.Projection = Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 1, 10000);
effect.View = Matrix.CreateLookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY);

var grassVertices = new[]
{
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 1f), Vector2.Zero),
    new VertexPositionColorTexture(Vector3.UnitY, new Color(1f, 1f, 1f, 1f), Vector2.UnitY),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 1f), Vector2.One),
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 1f), Vector2.Zero),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 1f), Vector2.One),
    new VertexPositionColorTexture(Vector3.UnitX, new Color(1f, 1f, 1f, 0f), Vector2.UnitX),
};
effect.Texture = grassTexture;
effect.Techniques[0].Passes[0].Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, grassVertices, 0, 2);

var snowVertices = new[]
{
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 0f), Vector2.Zero),
    new VertexPositionColorTexture(Vector3.UnitY, new Color(1f, 1f, 1f, 0f), Vector2.UnitY),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 0f), Vector2.One),
    new VertexPositionColorTexture(Vector3.Zero, new Color(1f, 1f, 1f, 0f), Vector2.Zero),
    new VertexPositionColorTexture(new Vector3(1, 1, 0), new Color(1f, 1f, 1f, 0f), Vector2.One),
    new VertexPositionColorTexture(Vector3.UnitX, new Color(1f, 1f, 1f, 1f), Vector2.UnitX),
};
effect.Texture = snowTexture;
effect.Techniques[0].Passes[0].Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, snowVertices, 0, 2);
下面是
LoadContent
方法初始化资源所需的内容:

grassTexture = Content.Load<Texture2D>("grass");
snowTexture = Content.Load<Texture2D>("snow");
effect = new BasicEffect(GraphicsDevice);
grassTexture=Content.Load(“草”);
snowTexture=Content.Load(“雪”);
效果=新的基本效果(图形设备);

要在其他方向创建平铺淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入淡入。对于直接向右、向左、向上或向下的淡入淡出,您需要使用四个三角形,而不是两个。

希望这适用于更高级的图像,如真实纹理。您能发布一张您希望看到的图像以及实际发生的情况,以及代码吗?整个图像上的主图像,覆盖层慢慢地向右下角淡入。或者类似于在两个平铺之间进行转换的操作。您可以使用
SetPixel
执行此操作,但如果您有很多调用,则速度会非常慢。我认为这应该通过alpha遮罩来完成,虽然我不确定。如何在不使用着色器的情况下预先对图像进行alpha遮罩?仅用于Tileset生成器。希望这能与更高级的图像(如真实纹理)一起使用。请发布一张您希望看到的图像,以及实际发生的情况,以及代码。整个图像上的主图像,覆盖层慢慢向右下角淡入。或者类似于在两个平铺之间进行转换的操作。您可以使用
SetPixel
执行此操作,但如果您有很多调用,则速度会非常慢。我认为这应该通过alpha遮罩来完成,虽然我不确定。如何在不使用着色器的情况下预先对图像进行alpha遮罩?仅用于Tileset生成器。