# Color Level Based Moon Phase

**URL:** <https://forums.unrealengine.com/t/color-level-based-moon-phase/127770>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [June 20, 2019, 8:56am UTC](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770 "2019-06-20T08:56:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ichinose](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ichinose/32/561593_2.png) [@Ichinose](https://forums.unrealengine.com/u/Ichinose)\
**Post date:** [June 20, 2019, 8:56am UTC](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770/1 "2019-06-20T08:56:13Z")

</div>

# UPDATE: I have since used better setup for this. [See post below.](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770/4)

* * *

After a little bit of bathroom brainstorming, I got this eureka solution for moon phase, with rather realistic moon curves. No circular overlay on the moon texture, so you can do better looking waxing crescent or gibbous shapes.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/9/6/f96ce103bf20eac26b930544eb0c828c4b658fb0.jpeg "Color Level Based Moon Phase in UE4") ](https://www.youtube.com/watch?v=1uDwpiNEYxI)

 ![T_SpherePhase.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/f/6f28387cc509fa1c2525e782a125f9c83fee87c9.png)  
The general idea is using color level manipulation to “swipe” the revealed mask along a gradient pattern. But since we’re looking for more believable phase, you can’t just use generic linear gradient spanning from 0 to 1 and call it a phase. The gradient map is linear vertically, but we need to add spherical curve to the gradient map, so that we can get that realistic phase. My preferred method is splitting a circle into two arc, each for white and black side respectively, and then blend them to make the gradient map. Or just grab this very gradient map I made with that method in CorelDRAW.

Okay, we get this curved gradient map, now what?

First order of business, how can we use this gradient map for Unreal to “swipe” along the 1 value? The answer is simple: Color Level. You can put following gradient map into GIMP or Photoshop, and play around with Level tool to get that moon phase curves.

After you get the general idea of how this Color Level strat works, time to put this thing into Unreal and make that curved swiping look.

 ![Capture.JPG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/6/165f67fd5e2372da109c25c17fb443bfb0a430ae.jpeg)

_What is going on here?_

We make a float variable that we can manipulate from instanced material, ranging from 0 to 1. We can utilize this exposed scalar parameter to get the moon phase working in-game.

Then, we put that value to an **If** node, so we can do the second half of the phase without putting another gradient map. The **If** node goes like this: If the phase is \< 50%, we use the inverted gradient map where the 1.0 value starts from the right arc, doing the first half of the phase; if the phase is 50%, we simply reveal the entire moon; if the phase is \> 50%, we use the gradient map as is where the 1.0 value starts from the left arc, doing the second half of the phase.

After the **If** node’s out of the way, we feed the result to **3PointLevels** function node’s **Texture (S)** input pin. For the **New Black Value (S)**, **New Middle Value (S)**, and the **New White Value (S)**, I found that those -5, 5, 1 constants gives me the desired result, but feel free to experiment with different constant values.

Now, for the **Middle Point (S)**, this input pin is where we do the whole “swiping” along phase thing. Bring the **Phase** scalar parameter we just made, multiply it by 4, then subtract it by 2, and make it an absolute value. The reason I do that equation is that value between 0.0 to 2.0 is where the moon phase is visible. Anything below 0.0 or above 2.0 will bring the entire map to black. The equation also creates linear curve for the value; where the middle point value is 0.0 for 0% and 100% phase, and 1.0 for 50% phase.

You can put **Clamp** node after **3PointLevels** for safety measures.

And that’s the whole function to make curved moon phase. Note that I use UI material domain in the screenshot - it’s just for testing purposes, because UI material domain have faster shader compiling time.

_Where can I go from this function?_

You can just put the whole function into your skybox material, and adding a **MF\_SkyboxImage** material function for the gradient map’s UV, and you can multiply it with your moon texture in your sky material. Although I have yet to find the best practice for this without masking out the texture details entirely.

You can also put a function in your skysphere BP to update the **Phase** scalar parameter we exposed earlier, and cycle through 0.0 to 1.0 in 30 in-game days, to create more depth to your day/night cycle.

You can also improve the function, the color level values, and/or the gradient map to get even better looking moon phase!

---

<div class="post-metadata">

**Author:** ![Ichinose](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ichinose/32/561593_2.png) [@Ichinose](https://forums.unrealengine.com/u/Ichinose)\
**Post date:** [June 20, 2019, 3:55pm UTC](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770/2 "2019-06-20T15:55:29Z")

</div>

So I made some tweaking here and there, including using the gradient map as Linear Color with sRGB disabled, fixing the implementation in an actual skysphere, and hooking the Phase parameter with the sky BP and match the current in-game date, and I was able to pull off the desired result. The skysphere was taken from DotCam’s Ocean Project which includes a skysphere with scrolling cloud, moon but it’s phase.

 ![HighresScreenshot00037.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/a/ca7ba032753612a8122adf8d2972e4237e9c2992.jpeg)

---

<div class="post-metadata">

**Author:** ![iiMStevo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@iiMStevo](https://forums.unrealengine.com/u/iiMStevo)\
**Post date:** [April 21, 2022, 7:20pm UTC](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770/3 "2022-04-21T19:20:34Z")

</div>

I’ve tried to follow this in UE5, and I’m a bit lost with how you’ve done this. I don’t have the same nodes available to me as you do.

---

<div class="post-metadata">

**Author:** ![Ichinose](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ichinose/32/561593_2.png) [@Ichinose](https://forums.unrealengine.com/u/Ichinose)\
**Post date:** [February 1, 2023, 5:37am UTC](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770/4 "2023-02-01T05:37:50Z")

</div>

I have since made my own sky system from scratch and subsequently remade the material with better nodes:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/9/f/c9f277a7be02b32e05575bed815147e5bc6c969d.png)

I replaced the old 3 Point Level function with smoothstep nodes, and put in additional parameters, but other than that it’s the same technique as the initial post.

In the new sky system that I made, I opted to use a plane following the moon directional light and apply the material on that plane. This is done as I’m not using sky sphere, rather letting Sky Atmosphere doing its thing.

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/f/e/3fe397c2a9dd0900e37d185b88309636b067f35c.jpeg)

---

<div class="post-metadata">

**Author:** ![el.vuk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@el.vuk](https://forums.unrealengine.com/u/el.vuk)\
**Post date:** [March 10, 2023, 10:31pm UTC](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770/5 "2023-03-10T22:31:08Z")

</div>

Hi Ichinose! Thank you very much for sharing your work.  
Can you please tell me what are those 2 blue MoonPhase nodes

 ![d2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/8/7b867e5faa4906820b81d1dff9964889380bb7ab.png)

---

<div class="post-metadata">

**Author:** ![SAPER1985](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SAPER1985](https://forums.unrealengine.com/u/SAPER1985)\
**Post date:** [April 6, 2026, 3:42am UTC](https://forums.unrealengine.com/t/color-level-based-moon-phase/127770/6 "2026-04-06T03:42:29Z")

</div>

![изображение](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/4/2/6429186a4f2241ce05af5d125e17db2c2a61a5fb.png)

For anyone else who has such a question.
