Page 1 of 3
Volumetric coloring of fog, based on sun / moon & horizon color

Posted:
Wed Jun 26, 2013 14:30
by MirceaKitsune
Before anyone gets upset, I'm not blindly suggesting copying things from Minecraft to Minetest. This is a feature which highly enhances immersion and environment, and regardless that I noticed it in MC or any other project that's the only reason I'm suggesting it for. On topic:
Like Minetest, Minecraft has fog covering the draw distance limit. Unlike Minetest however, it has a fantastic addition: Fog color is radially influenced by the sun and moon. In any direction you look, the fog is colored the same as the horizon, and brighter around the sun and moon. This is a huge visual enhancement, and makes the environment look a lot more beautiful and real. I'd love to see Minetest get this too.
Here's how Minetest's and fog and sky look like at sunset... very dull and simple:

Now here's what Minecraft does instead:



Again, this is not saying "copy everything Minecraft has". But I think no one can deny the sky + fog setup in MC is a ton more colorful, vivid and realistic, nor that it's something we want too. Some of it is just better sky coloring, but I think most of the beauty is due to the selective fog color.
Does Irrlicht support coloring distance fog in a volumetric manner? Can Minetest's architecture allow this so far?

Posted:
Wed Jun 26, 2013 14:46
by PilzAdam
Currently Minetests fog uses the color of the sky, so its exactly the color of the horizon.

Posted:
Wed Jun 26, 2013 14:46
by Inocudom
That would be a very good thing to add to Minetest. Are you able to code it?

Posted:
Wed Jun 26, 2013 15:10
by Sokomine
Sunset/sunrise really seems much more impressive in Minecraft. If it could be improved in Minetest, that would be great. There where some screenshots with a real sky as background at night, but I was told that that worked only in very old versions. Perhaps that could be made to work again as well?

Posted:
Wed Jun 26, 2013 15:14
by PilzAdam
RealBadAngel was working on a skydome, so we probably have to wait for him to finish it.

Posted:
Wed Jun 26, 2013 17:31
by MirceaKitsune
PilzAdam wrote:Currently Minetests fog uses the color of the sky, so its exactly the color of the horizon.
Yes it does. But the fog has the same color everywhere. The magic Minecraft does is that if you look at the sun during sunset / sunrise, fog is orange. If you look behind however (where the moon is rising), fog is blue. Fog needs to be red at sunset / sunrise in front of the sun, and more white in front of the moon when it sets / rises, otherwise horizon color.
PilzAdam wrote:RealBadAngel was working on a skydome, so we probably have to wait for him to finish it.
Like I told RBA, I don't agree with the skydome concept. If I remember right, the sky dome is an inside-out mesh attached to the player. Although I appreciate all of his works, that's something I'd be scared to see upstream. As a mod it's ok if anyone wants it.
Only way I'd agree with it is if the sky dome can be generated dynamically in the code and customizable (no mesh files). Also if it has unlimited distance like most cubemap / spheremap skies, instead of being a huge floating half-sphere that follows the player around. Personally, I'd like to see abilities to texture the sun, moon, and horizon at sunset... I find the current sky system itself good.

Posted:
Wed Jun 26, 2013 17:47
by PilzAdam
From what I read in the code so far its only possible to set one color for the fog, I might be wrong, though.

Posted:
Wed Jun 26, 2013 17:53
by MirceaKitsune
PilzAdam wrote:From what I read in the code so far its only possible to set one color for the fog, I might be wrong, though.
Minetest doesn't have any of this yet, so it depends on what Irrlicht allows whether or not it can be added easily. At worst though it should be possible to do it with shaders... but I'm not sure even about that to what extent it would work.

Posted:
Wed Jun 26, 2013 19:14
by BlockMen
MirceaKitsune wrote:Before anyone gets upset, I'm not blindly suggesting copying things from Minecraft to Minetest.
There are still alot good things we can take from MC, so nothing to get upset.
And a really good suggestion. It looks great at MC.
PilzAdam wrote:From what I read in the code so far its only possible to set one color for the fog, I might be wrong, though.
Then it may not be too hard to change the fog color at sunrise/sunset and moon. That would be a great improvement IMO

Posted:
Wed Jun 26, 2013 19:44
by PilzAdam
BlockMen wrote:PilzAdam wrote:From what I read in the code so far its only possible to set one color for the fog, I might be wrong, though.
Then it may not be too hard to change the fog color at sunrise/sunset and moon. That would be a great improvement IMO
The fog color already changes on sunset/sunrise, the problem is to change only the part that is in the direction of the sun/moon.

Posted:
Wed Jun 26, 2013 20:25
by Inocudom
What all is RealBadAngel working on? If any of you are able to, you could assist him.

Posted:
Thu Jun 27, 2013 23:01
by MirceaKitsune
Brought this up on IRC. PilzAdam suggested a simpler technique, which although of less quality would be easy to do: Instead of setting a different fog color in each direction, we could change fog color dynamically based on where the player is looking.
So if the sun is setting and the moon is rising; When the player looks into the sun, fog is a bright orange. When the player is looking into the moon, fog is a brighter pale blue. When looking at neither, fog is the horizon color (same as currently). Of course colors gradually fade in between.
This should be very simple to do, but yields one issue: What if a client's FOV is so big (for some reason) that it covers 90* of the sky? One would notice that fog is the same everywhere and only changes based on where you're looking. Still, I assume it should look good enough.
If anyone can point out where fog color is set in the Minetest code, I might give this a try myself. As long as I'm able to read daytime and player view angles within that function, and detect how close the crosshair is to the sun and moon.

Posted:
Thu Jun 27, 2013 23:57
by PilzAdam
MirceaKitsune wrote:Brought this up on IRC. PilzAdam suggested a simpler technique, which although of less quality would be easy to do: Instead of setting a different fog color in each direction, we could change fog color dynamically based on where the player is looking.
No, I did not. It was celeron55.

Posted:
Fri Jun 28, 2013 09:56
by MirceaKitsune
PilzAdam wrote:No, I did not. It was celeron55.
My mistake. Anyway the idea sounds good, at least until someone can figure position coloring for fog later on.

Posted:
Fri Jun 28, 2013 17:24
by MirceaKitsune
I've started working on this today. Found a way to read the player's Pitch and Yaw from sky.cpp, and SunColor + MoonColor are already existent in Sky::Render where this code fits like a glove. Only thing left to do are the maths, which replace horizon + fog color with sun / moon color gradually, the more you look into the sun or moon.
The formula I'm aiming at is: If sun or moon aren't in your view, you see the normal fog color. The more the sun or moon is visible, the more fog color changes to reflect that. When you look straight into the moon or sun, fog color becomes its color.
Normally this should look great nice, and also yield in a simple "god rays" effect. But I'm not sure how the extreme yellow fits against the blue sky still. Here is a screenshot from a test, which always sets horizon to sun color. Tell me what you think and if it seems acceptable. There aren't many alternatives to the screenshot below however, though I can make the horizon a bit darker and see how that goes.


Posted:
Fri Jun 28, 2013 19:26
by paramat
Weird, unnatural and i like it.

Posted:
Fri Jun 28, 2013 20:05
by Jordach
MirceaKitsune wrote:
Lookin' good! But, you need to make this a gradient.
EDIT: It's piss yellow.

Posted:
Fri Jun 28, 2013 21:25
by BlockMen
MirceaKitsune wrote:
It goes definitively in the right direction. Keep on good work!

Posted:
Fri Jun 28, 2013 23:46
by MirceaKitsune
Glad you like :) I'm onto finishing it, but right now am stuck at one big problem. If someone can name a solution it would be very appreciated.
I must use the pitch and yaw of the local player to determine if they're looking into the sun. To get this done properly, I work with angles. First I convert the sun position: 0* at midnight, 90* at sunrise, 180* at midday, 270* at sunset. Then I convert the player's pitch and yaw to match the same angle mapping, so when you look as high as the sun you automatically have the same converted yaw as the converted time of day. By subtracting yaw angle from sun angle I obtain the angular difference between the player's crosshair and the sun, then of course I can use pitch to obtain distance laterally as well. It sounds like it should all work... but here is the problem:
The player might be looking up or down either toward where the sun rises or where it sets. If we blindly account yaw, we'll see the sun effect in both directions at the same time. Therefore we need to tell if the player is looking forward or backward. So I convert yaw to use a 360* approach... which means 0* when looking down, 90* when looking straight forward, 180* when looking up into the sky, 270* when looking straight backward (matching the angles I described for the sun earlier). If pitch is between 0 and 180 yaw is calculated from looking into the ground (0*) to looking into the sky (180*), whereas if pitch is between 180 and 360 yaw is calculated from looking into the sky (180*) to looking into the ground (360*). It partly fixes the issue and the sun is theoretically tracked at any time of day... but here's the remaining problem:
The moment pitch exits the 0* to 180* range, converted yaw snaps to a different angle. If the player is looking straight up as he turns around, there's no problem and yaw transition is smooth. But if they're looking at the horizon while the pitch range changes, 90 becomes 270 when the pitch range changes, and so on. There's no way to get rid of this snapping if I am to track the player's pitch all across the sky.
So how can I follow the yaw from one end to the other (sunrise to sunset) by having the same amount of yaw be 90* at one and 270* at other, without the value suddenly snapping when I go from 0 - 180 pitch to 180 - 360 pitch? This is a bit complicated to explain so it's ok if many don't understand what I'm talking about. If anyone does and has a solution however, please let me know. I'll likely finish tomorrow if this is solved.

Posted:
Sat Jun 29, 2013 13:57
by MirceaKitsune
Got a lot further with the code today. You can ignore my last post, since I decided to go for another approach: Instead of tracking the crosshair - sun distance, I track the crosshair's distance from the sunset and sunrise locations and apply a -90 to 90 degree scale. This is both simpler and more correct since it's the least extreme way of changing between colors.
So far I got a glimpse of how this will look like. I'm applying sun color at sunrise, moon color at sunset, and horrizon color at any of the two in-betweens. Next comes the maths to filter and reverse them based on time of day, and only during the time when the sun and moon are transitioning. I can say the colors and transition look pretty beautiful, especially compared to how it did before with one fog color.

Posted:
Sat Jun 29, 2013 22:24
by MirceaKitsune
Finished working on the code for today. At this moment it's almost entirely ready... I'm only finishing optimizations to the formula and tweaks to the colors themselves. The sun and moon are combined all the way from 0 to 180 pitch, so the transitions are as smooth and unnoticeable as possible... which I think is what Minecraft does as well to achieve this. Will likely post the code and screenshots tomorrow when it's ready.

Posted:
Sat Jun 29, 2013 22:32
by Inocudom
Very good work, MirceaKitsune. This feature is a step in the right direction for giving life to Minetest.

Posted:
Sun Jun 30, 2013 00:15
by Jordach
Taoki (MK) wrote:Will likely post the code and screenshots tomorrow when it's ready.
It's now tomorrow. Can we have screenshots?

Posted:
Sun Jun 30, 2013 04:01
by ashenk69
Jordach wrote:It's now tomorrow. Can we have screenshots?
Patience is a virtue

Posted:
Sun Jun 30, 2013 08:56
by Jordach
ashenk69 wrote:Jordach wrote:It's now tomorrow. Can we have screenshots?
Patience is a virtue
I was having a joke.

Posted:
Sun Jun 30, 2013 09:13
by MirceaKitsune
Jordach wrote:Taoki (MK) wrote:Will likely post the code and screenshots tomorrow when it's ready.
It's now tomorrow. Can we have screenshots?
For me, tomorrow just started now. So expect more within the next hours :)

Posted:
Sun Jun 30, 2013 09:15
by Jordach
MirceaKitsune wrote:Jordach wrote:Taoki (MK) wrote:Will likely post the code and screenshots tomorrow when it's ready.
It's now tomorrow. Can we have screenshots?
For me, tomorrow just started now. So expect more within the next hours :)
I was using timezones here as the hinge for the joke.

Posted:
Sun Jun 30, 2013 09:42
by Thermal_Shock
Thanks for tackling this MirceaKitsune. Sometimes I find myself stopping and just watching the sunsets in Minecraft because they look so good. I think it would be a very immersive feature for Minetest.

Posted:
Sun Jun 30, 2013 17:56
by MirceaKitsune

Posted:
Sun Jun 30, 2013 18:00
by Jordach
Taoki wrote:PICS
It's a bit toooo sharp. But it looks good. The intensity of fog is way way way way way way way way too powerful.