- Home /
Texture Lighting stops working when I change Bump Map during Runtime
TL;DR; I am changing bump maps and textures for an object during run time. Prior to change the object responds to light. If I only change the texture the object responds to light correctly. If I change the bump map the object lights up as if light is coming from a different angle than the actual source.
=====
I'm making a model of a solar system - a star and planets revolving around it. I want the model to be randomized, so each planet generates a few random textures when it initializes (for land, water, clouds). Objects are using built-in unity shaders - either Legacy Shaders/Transparent/Bumped Diffuse or Legacy Shaders/Bumped Diffuse.
I'm setting things up so that I can add new textures to the lists after installation - so my art assets aren't in a Resources folder. Instead, I use System.IO to load a folder of textures into a List. The lists take a second or two to fully populate, so planets have to wait before displaying a texture. They spend about 2 seconds circling the star as solid colored sphere. During this time the object receives light and shadow correctly.
When the textures update, the planets stop receiving light from the star correctly. They revolve, but so does the lighted area. So rather than the light side always facing the sun, the light side is always at an angle. The angle is always at a 90 degree angle from the actual source of the light.
If I only change the textures of the planet I don't have a problem. If I change the bump maps on the planet I do.
I have also experimented with delaying planet motion before the textures change. The light side of the planet faces the sun, and when the bump map changes the light side of the planet jumps 90 degrees without the source of light changing.
I think there is some step I am skipping after I change the bump map for the objects..?
// Update is called once per frame
void FixedUpdate () {
//get a random texture from tm, but only do so once
if (!landLoaded) {
if (tm.PlanetTexturesReady()){
RandomTexture();
}
}
//spin
land.Rotate (Vector3.down * Time.deltaTime * spinSpeed);
atmo.Rotate (Vector3.up * Time.deltaTime * spinSpeed * atmoSpeed);
//revolve around star. Replace Vector3.zero with the position of the star for the system
transform.RotateAround (Vector3.zero, Vector3.up, Time.deltaTime * rotateSpeed * 5);
}
private void RandomTexture(){
//access renderer components of children
Renderer rLand = land.gameObject.GetComponent<Renderer> ();
Renderer rAtmo = atmo.gameObject.GetComponent<Renderer> ();
Renderer rWater = water.gameObject.GetComponent<Renderer> ();
//change the texture and bump for each component
rLand.material.SetTexture ("_MainTex", tm.RandomLand());
rLand.material.SetTexture ("_BumpMap", tm.RandomLandBump ());
rAtmo.material.SetTexture ("_MainTex", tm.RandomAtmo());
rAtmo.material.SetTexture ("_BumpMap", tm.RandomAtmoBump ());
rWater.material.SetTexture ("_MainTex", tm.RandomWater());
rWater.material.SetTexture ("_BumpMap", tm.RandomWaterBump ());
//don't repeat this step
landLoaded = true;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612073807im_/https://answers.unity.com/themes/thub/images/avi.jpg)