本文整理汇总了C#中Generator.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Generator.GetValue方法的具体用法?C# Generator.GetValue怎么用?C# Generator.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Generator
的用法示例。
在下文中一共展示了Generator.GetValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BumpMap
///<summary>
/// Creates a texture to use as a bump map, taking height settings as input.
///</summary>
///<param name="length">Texture length.</param>
///<param name="height">Texture height</param>
///<param name="settings">heightmap source</param>
///<returns></returns>
public static Texture BumpMap(int width, int height, Generator noise)
{
var res = new Texture2D(width, height, TextureFormat.RGB24, false);
for (int mip = 0; mip < res.mipmapCount; mip++)
{
Color[] cols = new Color[width * height];
for (int ii = 0; ii < width; ii++)
{
for (int jj = 0; jj < height; jj++)
{
var left = noise.GetValue((ii - 0.5f) / width, (float)jj / height, 0);
var right = noise.GetValue((ii + 0.5f) / width, (float)jj / height, 0);
var down = noise.GetValue((float)ii / width, (jj - 0.5f) / height, 0);
var up = noise.GetValue((float)ii / width, (jj + 0.5f) / height, 0);
Vector3 normal = new Vector3(right - left, up - down, 1).normalized;
cols[ii + jj * width] = new Color(normal.x, normal.y, normal.z);
}
}
res.SetPixels(cols, mip);
width >>= 1;
height >>= 1;
}
res.Apply(false);
return res;
}
示例2: MonochromeTexture
///<summary>
/// Creates a monochrome texture.
///</summary>
///<param name="width">Texture width.</param>
///<param name="height">Texture height</param>
///<param name="noise">Noise source</param>
///<returns></returns>
public static Texture MonochromeTexture (int width, int height, Generator noise)
{
return Make (width, height, (x, y) =>
{
var v = noise.GetValue (x, y, 0) * 0.5f + 0.5f;
return new Color (v, v, v, 1);
}, TextureFormat.RGB24);
}
示例3: RampTexture
///<summary>
/// Creates a texture using ramp of colors. Noise value (clamped to [-1,1]) is mapped to one-dimensional ramp texture to obtain final color.
/// As there are no 1-dimensional textures in Unity, Texture2D is used, that is sampled along its top line.
///</summary>
///<param name="width">Texture width.</param>
///<param name="height">Texture height</param>
///<param name="noise">Noise source</param>
///<param name="ramp">Ramp texture</param>
///<returns></returns>
public static Texture RampTexture (int width, int height, Generator noise, Texture2D ramp)
{
Color[] rampCols = ramp.GetPixels (0, 0, ramp.width, 1);
return Make (width, height, (x, y) =>
{
var v = noise.GetValue (x, y, 0) * 0.5f + 0.5f;
return rampCols [(int)(Mathf.Clamp01 (v) * (ramp.width - 1))];
}, TextureFormat.RGB24);
}
示例4: AlphaTexture
///<summary>
/// Creates a texture with only alpha channel.
///</summary>
///<param name="width">Texture width.</param>
///<param name="height">Texture height</param>
///<param name="noise">Noise source</param>
///<returns></returns>
public static Texture AlphaTexture (int width, int height, Generator noise)
{
return Make (width, height, (x,y) => new Color (0, 0, 0, noise.GetValue (x, y, 0) * 0.5f + 0.5f), TextureFormat.Alpha8);
}