public float TextureFactor(float h1, float h2, int num_textures)
{
float percent;
float inc = 255 / (float)num_textures;
percent = (inc - Math.Abs(h1 - h2)) / inc;
if (percent < 0.0f)
percent = 0.0f;
else if (percent > 1.0f)
percent = 1.0f;
return percent;
}
public void GenerateTexture()
{
int i;
int x, y;
int num_textures = 4;
float[] tex_fact = new float[num_textures];
Color[] OldC = new Color[num_textures];;
Bitmap[] tex = new Bitmap[4];
tex[0] = new Bitmap(f.s_appPath + "/Data/Textures/sand.bmp");
tex[1] = new Bitmap(f.s_appPath + "/Data/Textures/grass.bmp");
tex[2] = new Bitmap(f.s_appPath + "/Data/Textures/rock.bmp");
tex[3] = new Bitmap(f.s_appPath + "/Data/Textures/snow.bmp");
bmp_heightmap = new Bitmap(i_size, i_size);
float[] region = new float[num_textures];
int region_size = 255 / num_textures;
for (i = 0; i < num_textures; i++)
{
region = 0;
}
for (i = 0; i < num_textures; i++)
{
if (i == 0)
region += region_size;
else
{
region += region + region_size;
}
}
for (y = 0; y < i_size; y++)
{
for (x = 0; x < i_size; x++)
{
float h = GetHeightAtPoint(x, y);
float r = 0;
float g = 0;
float b = 0;
// read colors from all tiles
for (i = 0; i < num_textures; i++)
{
tex_fact<span style="font-weight:bold;"> = TextureFactor(region<span style="font-weight:bold;">, h, num_textures);
OldC<span style="font-weight:bold;"> = tex<span style="font-weight:bold;">.GetPixel(x, y);
r += tex_fact<span style="font-weight:bold;"> * OldC<span style="font-weight:bold;">.R;
g += tex_fact<span style="font-weight:bold;"> * OldC<span style="font-weight:bold;">.G;
b += tex_fact<span style="font-weight:bold;"> * OldC<span style="font-weight:bold;">.B;
}
bmp_heightmap.SetPixel(x, y, Color.FromArgb((int)r, (int)g, (int)b));
}
}
ConvertBitmapToTexture(bmp_heightmap, out i_texturemap);
bmp_heightmap.Save("GeneratedTexture.bmp", ImageFormat.Bmp);
}
</pre>
I'm using visual c# 2008 by the way.
So that's what i'm working with and it's really annoying me.
Thanks,
Scott
Terrain Texture Generation - lowest regions are black
Hi,
I've been tampering with generating textures for my terrain from it's heightmap following the guide over on flipcode (Terrain Texture Generation. It's working the way it's supposed to from what I've gotten out of the site. However I dont like how the lowest regions (where the heightmap is black) turns out black as well on the generated texture.
Examples
(btw, whats a good site to just host pictures for scenarios like this?)
assuming it works the way it's supposed to, couldn't you just change the TextureFactor function a bit, so instead of setting the minimum value to 0.0f you set it to a threshold? Like this:
It can probably be done in a niftier way, but hey, I'm new at this.
#define min_lim 0.1fpublic float TextureFactor(float h1, float h2, int num_textures){ float percent; float inc = 255 / (float)num_textures; percent = (inc - Math.Abs(h1 - h2)) / inc; if (percent < min_lim) percent = min_lim; else if (percent > 1.0f) percent = 1.0f; return percent;}
It can probably be done in a niftier way, but hey, I'm new at this.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement