Is it posible to create a cubemap on-the-fly ?

Hi all

Is it posible to create a cubemap on-the-fly when, for example, Start() function of a script is called ?

Imagine that you know the colors of the pixels the cubemap will contain, we only need a cubemap to store and use them. How can i generate a cubemap to fill pixels with my colors ?

Thanks a lot for your time :)

Yes, pretty much like any texture. There is Cubemap class, and it has functions to set a bunch of pixels (SetPixels) as well as changing individual pixels (SetPixel).

My Unite 2007 talk project has a helper that creates Cubemap from code and fills it with a "lighting function". Then at runtime the cubemap is used for lighting, instead of actual lights.

If you want to create a cubemap and render into it (e.g. for realtime environment reflections), use Camera.RenderToCubemap function.

I remember of a "cubemap on-the-fly" example in the Sewer Control Room project. You can download it here:

http://unity3d.com/support/resources/example-projects/sewercontrolroom

Yes it is possible, and Unity provides a built-in function to do so which is part of the Camera class:

Read more about it on the Camera.RenderToCubemap manual page.

I thought this function was a Pro-only feature, but it's not marked as such in the documentation. This could be an error with the documentation - please add a comment and let us know if it works in the free edition!

Hi all

I have a good news and bad news.

Good one is for creating a cubemap is simple as hell, you only need to do something like this:

	Cubemap cm = new Cubemap(2, TextureFormat.ARGB32, false);
	cm.name = "Prueba_CubeMap";
	cm.filterMode = FilterMode.Bilinear;

	//cm.SetPixel(CubemapFace.NegativeY, 1, 1, Color.red);

	for (int i = 0; i < 2; i++)
	{
		for (int n = 0; n < 2; n++)
		{
			cm.SetPixel(CubemapFace.NegativeX, i, n, Color.red);
		}
	}

	for (int i = 0; i < 2; i++)
	{
		for (int n = 0; n < 2; n++)
		{
			cm.SetPixel(CubemapFace.NegativeY, i, n, Color.red);
		}
	}

	for (int i = 0; i < 2; i++)
	{
		for (int n = 0; n < 2; n++)
		{
			cm.SetPixel(CubemapFace.NegativeZ, i, n, Color.red);
		}
	}

	for (int i = 0; i < 2; i++)
	{
		for (int n = 0; n < 2; n++)
		{
			cm.SetPixel(CubemapFace.PositiveX, i, n, Color.red);
		}
	}

	for (int i = 0; i < 2; i++)
	{
		for (int n = 0; n < 2; n++)
		{
			cm.SetPixel(CubemapFace.PositiveY, i, n, Color.red);
		}
	}

	for (int i = 0; i < 2; i++)
	{
		for (int n = 0; n < 2; n++)
		{
			cm.SetPixel(CubemapFace.PositiveZ, i, n, Color.red);
		}
	}

	cm.Apply();

	this.light.cookie = cm;

The bad one is cookie cubemap only uses alpha channel to play with intensity of the light. No color is involved on this.

Why Unity3D doesnt use color of cookies cubemap to multyply point lights color ? Without this feature, making a stained glass tamp turns from a simple thing to pain thing.

Thanks for your time