Non rectangular GUI Mask / Matte?

I have looked around a bit but can’t find anything definitive on this.

I’m using GUI.DrawTexture along with a GUI Group to move textureA behind textureB so that textureA looks like it’s disappearing. However, textureB has transparency and a curve so using a simple rect from the GUI Group does not achieve the look.

Is there a way to pass in alpha or color information from another texture in order to get a non-rect masking effect?

I saw something about using the Graphics class along with a custom material which I will look into more. I don’t know shader scripting very well so I am hoping there is a more simple approach that I am overlooking.

Thanks!
John

Edit: Adding an image to help clarify my question.
alt text

Tricky :). If the moving part (textureA) has no transparency, you could try using a transparent cutout material. There’s an example of more or less what you’d need to do here, but your alpha channel would look more like this:

alt text

Then, you’d just check the screen y-value of your object and adjust the alpha cutoff accordingly. That’s the easiest way I know of to do it without a bunch of coding and pixel manipulation - hopefully someone else will come along with a more elegant solution :slight_smile:

Or you could cutout the Texture before using it:

	public static Texture2D CircularCutoutTexture(Texture2D texture) {
		if (texture == null) return null;
		Color[] pixels = texture.GetPixels(0);

		// generate cutout
		Texture2D cutout = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);
		int size = (int)Mathf.Sqrt(pixels.Length);
		for (int y = 0; y < size; y++) {
			for (int x = 0; x < size; x++) {
				float dx = x - size/2;
				float dy = y - size/2;
				float d = Mathf.Sqrt(dx * dx + dy * dy) - size/2;
				if (d >= 0) pixels[x + y * size].a = Mathf.Max(1 - d, 0);
			}
		}
		
		cutout.SetPixels(pixels, 0);
		cutout.Apply();
		return cutout;
	}