- Home /
Earth Day/Night cycle texture
Semi-solution found, please see second answer
I have a plane with an Earth texture and bumpmap and would like to add a day/night cycle to the scene. The problem is that only half the world would be in darkness at once, but I have no idea how I could do this. I do have the 'night Earth' texture but need a way to mask it so only some of it shows (like below).
Any ideas?
Answer by doublemax · Oct 11, 2016 at 02:44 PM
Create a material with the earth texture. Set the second texture as "Detail Albedo" in the same material. You can animate it by changing the texture offset over time.
using UnityEngine;
public class RotateTextureOffset : MonoBehaviour
{
private Renderer rend;
public float scrollSpeed = 0.1f;
void Start () {
rend = GetComponent<Renderer>();
}
void Update() {
float offset = Time.time * scrollSpeed;
rend.material.SetTextureOffset("_DetailAlbedoMap", new Vector2(0, offset));
}
}
BTW: For a more realistic effect, you'd need something like this:
http://www.uni.edu/morgans/astro/course/Notes/section1/geochrone2.gif
Problem is this is the result (imagine it was going across the x axis too, I just haven't changed it) -
http://im.ezgif.com/tmp/ezgif-1829365490.gif
It's still a block image with sharp ends and affecting large areas at once. It's also partially showing through to the daytime texture. Is there such a thing as a 'transparency mask' as I think that would work pretty much like you have done?
Answer by pottyscotty · Oct 11, 2016 at 11:04 PM
I have semi-found a solution, however still require help to get it to look alright.
I have made sure there is no Ambient Occlusion or Skybox and then added the 'Night Earth' texture as an emission map. I have also made a new directional light with a cookie that fades out either end (I'll improve on the size and sharpness once I get this working).
Now, when the light is not hitting areas, they clearly show the 'Night Earth' texture. When light is on areas, it shows the 'Day Earth' texture. This works perfectly for me if it wasn't for one problem - the emission map bleeds through even when light is hitting it. As you can see from the pictures, the lights from things like street lamps can still be seen during the day.
Yes, turning down the emission value kind of works (though you can still see lights pretty clearly), but it makes the places that are in night time barely visible. Seems no matter how much you juggle lighting, emission, colour values etc there's a problem. Any ideas as to what I can do to get it looking good? Last resort is I'll just have to ditch the day/night cycle or have the whole world turn dark at once.
I reckon I'd be looking at doing it all in a custom shader, making the emission value some function of the night-darkening value, with a threshold on the latter below which there's no emission. Sorry I'm not a shader expert though, I tend to hack them till they look right and I'd have to research the emission stuff myself.
Years after getting Unity I've still not done much with it, just played around a bit so I've got no idea on the shader front either. I would think with a custom one it'd be possible though as all the required features seems to be there, just needs putting in order.
Your answer
Follow this Question
Related Questions
Blended skybox shader is messing with my lens flare 0 Answers
Billboarded Trees not lit? 1 Answer
Realtime daylight cycle? 1 Answer
Sun(light) rotation is not working 1 Answer
Using adaptive tonemapping along with day-night cycle 0 Answers