- Home /
Dynamic Skybox
Hi,
So I currently have a skybox that gets rendered with six still images. I'd like to continue using this method, but with a little different way of getting the images instead of them being in my project. I'd like to have a website that has a picture constantly being updated. There would have to be six sites for this to transmit into a skybox, though for now being perfect images for a skybox doesn't matter to me, I just want the functionality.
So the code below I used on a plane to pull an image off of a website and apply it to the texture.
// url of image;
var url = "http://ETC";
function Start () {
// Start a download of the given URL
var www : WWW = new WWW (url);
// wait for download to complete
yield www;
// assign texture
renderer.material.mainTexture = www.texture;
}
I'd like to use this same method, but the thing is I don't know how to apply code to the skybox considering these images are being taken directly from project.
Answer by Bunny83 · Jul 18, 2011 at 07:33 PM
When you switch your inspector into Debug mode you can see the texture parameters in list form. They are:
_FrontTex, _BackTex, _LeftTex, _RightTex, _UpTex, _DownTex
There are also _MainTex
and _Tex
but i guess they aren't used.
To set them just use Material.SetTexture.
GetComponent.<Skybox>().material.SetTexture("_FrontTex",www.texture);
edit
You can load one texture at a time and load them one by one, or load them all at once. WWW-calls are asynchron so you can start all 6 downloads at once and wait for them to finish.
private static var skyboxTextures : String[] = ["_FrontTex", "_BackTex", "_LeftTex", "_RightTex", "_UpTex", "_DownTex"];
var url = "http://domain/path/to/skybox/folder/";
function LoadSkybox(skyboxName : String)
{
var www : WWW[] = new WWW[6];
for (var i = 0;i < 6; i++)
{
www[i] = new WWW(url + skyboxName + skyboxTextures[i] + ".png");
}
var mat = GetComponent.<Skybox>().material;
for (i = 0;i < 6; i++)
{
yield www[i]; // wait for all images to finish
mat.SetTexture(skyboxTextures[i],www[i].texture);
}
}
function Start()
{
LoadSkybox("desert");
// Images should be named:
// "desert_FrontTex.png"
// "desert_BackTex.png"
// ...
}
Answer by sistematix · Aug 26, 2014 at 04:23 AM
dont forget to clamp the textures, the famous white lines would appear on your skybox
Your answer
Follow this Question
Related Questions
Camera: Possible to render partial skybox with no background color fill? 0 Answers
Unity 5 procedural skybox with working bottom 1 Answer
How to made a normal skybox with a rectangle part of solid color 0 Answers
function unity_SpecCube0 doesn't work (or problem with skyBox) 1 Answer
What happens if I use the wrong shader for a skybox? 1 Answer