TextureUtils

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: <csharp> /// TextureUtils 0.1 /// by nihilocrat <nihilocrat@gmail.com> /// /// Some utility functions for procedurally generating or modifying textures at runtime /// Just put this in yo...)
 
m (Text replace - "<csharp>" to "<syntaxhighlight lang="csharp">")
Line 1: Line 1:
<csharp>   
+
<syntaxhighlight lang="csharp">   
 
/// TextureUtils 0.1
 
/// TextureUtils 0.1
 
/// by nihilocrat <nihilocrat@gmail.com>
 
/// by nihilocrat <nihilocrat@gmail.com>

Revision as of 20:44, 10 January 2012

 
/// TextureUtils 0.1
/// by nihilocrat <nihilocrat@gmail.com>
///
/// Some utility functions for procedurally generating or modifying textures at runtime
/// Just put this in your Assets/Plugins directory and call like so in any of your scripts:
/// "TextureUtils.Colorize(myPixels, myColor)"
///
/// licensed under the BSD license : http://creativecommons.org/licenses/BSD/
 
using UnityEngine;
 
public class TextureUtils {
	/// colorize a texture
	public static Color[] Colorize(Color[] pixels, Color tint) {
		for(int i=0; i < pixels.Length; i++) {				
			pixels[i].r = pixels[i].r - (1.0f - tint.r);
			pixels[i].g = pixels[i].g - (1.0f - tint.g);
			pixels[i].b = pixels[i].b - (1.0f - tint.b);
		}
 
		return pixels;
	}
 
	/// mask a texture using a second texture
	public static Color[] Mask(Color[] pixels, Color[] maskPixels) {
		for(int i=0; i < pixels.Length; i++) {
			pixels[i].a = maskPixels[i].a;
			if(pixels[i].a <= 0.0f) {
				pixels[i] = new Color(0,0,0,0);
			}
		}
 
		return pixels;
	}
 
	/// paste one texture on top of another
	public static Color[] Paste(Color[] topPixels, Color[] bottomPixels) {
		for(int i=0; i < bottomPixels.Length; i++) {
			bottomPixels[i] = Color.Lerp(bottomPixels[i], topPixels[i], topPixels[i].a);
		}
 
		return bottomPixels;
	}
}
</csharp>
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox