Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix normals map of the Moon, increase its resolution and implement shadows #2781

Merged
merged 1 commit into from
Oct 28, 2022

Conversation

10110111
Copy link
Contributor

@10110111 10110111 commented Oct 27, 2022

This is an improvement on #2780, which was rejected basically due to the lack of shadows, which the bump mapping technique can't provide.

In this commit, in addition to fixing the normals map, a new kind of texture is added: horizon map. This texture contains elevation of the horizon in four directions: North, East, South, West. These elevations take terrain (mountains, craters etc.) surrounding each point of the map into account.
These data are used in the fragment shader to determine whether the Sun is visible or is hidden behind the terrain.

Even if we later decide that we want a geometric model of the Moon to make non-circularity of its rim visible during solar eclipses, this horizon map will still be useful, because it'll save us from the shadow mapping step, which itself has lots of pitfalls fixing which would likely reduce performance.

The data for the normals and horizon maps were generated using the elevation data in the CGI Moon Kit.
The generation was done using map-bumper with the following commands:

heightmap2normalmap 1727.4 0.5e-3 ~/Downloads/ldem_16_uint.tif moon_normals.png 1024 256
heightmap2horizonmap 1727.4 0.5e-3 ~/Downloads/ldem_16_uint.tif moon_horizon.png 1024

Moon radius is taken here as 1727.4 instead of 1737.4 to take into account that the uint16 version has a global shift of values by 10 km. Normal map was generated with 256-fold supersampling.

Screenshots

View from the Earth

Old:

from-earth-0ld

New:

2now

For comparison see the previous attempt that lacked shadows (the screenshot here).

A real-life photo at the same location, date and time is below. Although it's blurry, you can see some craters being shaded both in the new screenshot above and in this photo.

photo

View from "Earth Observer" (to look at a pole)

Old:

screenshot-1k-0ld

New:

eo-2now

For comparison see the previous attempt that lacked shadows (the screenshot here).

@github-actions
Copy link

Great PR! Please pay attention to the following items before merging:

Files matching src/**/*.cpp:

  • Are possibly unused includes removed?

This is an automatically generated QA checklist based on modified files

@10110111 10110111 force-pushed the moon-bumps-and-shadows branch from 0d1c262 to 26c570c Compare October 27, 2022 18:33
@gzotti
Copy link
Member

gzotti commented Oct 27, 2022

Much better! @Atque, do you have comparisons? Now we'd need real comparison pictures! I try to find something with a date.

@Atque
Copy link
Contributor

Atque commented Oct 27, 2022

Indeed much better!

Much better! @Atque, do you have comparisons? Now we'd need real comparison pictures! I try to find something with a date.

Sadly, no new photos. Here are two that I know the date and location of. The first was taken at 2020-02-12 23:11 UTC+1, and the second at 2020-03-05 17:54 UTC+1, both from 58,3 N, 11,4 E. I took them using a 300 mm lens of cheap quality.

IMG_0951

IMG_1005

@gzotti
Copy link
Member

gzotti commented Oct 27, 2022

This was a Saturn occultation, observed in Vienna Observatory with a historical Zeiss telescope.
stellarium-048
_MG_0150_with_insert_800_50kB

@gzotti
Copy link
Member

gzotti commented Oct 27, 2022

This was a great year for occultations... This was through thin clouds, else also good. Same instrument.
stellarium-049
2007-06-18-17-51-40_Venusbedeckung

@Atque
Copy link
Contributor

Atque commented Oct 27, 2022

Seems like it matches reality pretty good. I can recommend this website for validation too:
https://svs.gsfc.nasa.gov/4955

Keep in mind to use geocentric point of view.

@gzotti
Copy link
Member

gzotti commented Oct 27, 2022

OK, I think this is good. What we need now may be some more finetuning (again) for the Lunar brightness. This is not easy and not part of this PR.

@10110111 10110111 force-pushed the moon-bumps-and-shadows branch from 26c570c to 532050f Compare October 27, 2022 19:48
@10110111 10110111 marked this pull request as ready for review October 27, 2022 19:49
@10110111
Copy link
Contributor Author

I can recommend this website for validation too: https://svs.gsfc.nasa.gov/4955

But do note that its images are simulated, not the ground truth.

@Atque
Copy link
Contributor

Atque commented Oct 27, 2022

I can recommend this website for validation too: https://svs.gsfc.nasa.gov/4955

But do note that its images are simulated, not the ground truth.

True, but I would trust NASA on this. I haven't compared the details though.

…adows

With the old normal map, near the poles we had dark-shaded parts of
craters that should actually be brighter — as if the Sun is not where it
is, and this behavior inconsistently depended on longitude... The new
texture added in this commit fixes behavior of shadows.

Now the resolution of the normal map is the half that of the reflectance
texture, 2048×1024. Further increase leads to excessive noise due to
lack of proper mip mapping (and its non-triviality for normal maps), so
this looks like a good compromise between the shapes of the craters and
background noise.

Additionally, a new kind of texture is added: horizon map. This texture
contains elevation of the horizon in four directions: North, East, South, West.
These elevations take terrain (mountains, craters etc.) surrounding each
point of the map into account.
These data are used in the fragment shader to determine whether the Sun is
visible or is hidden behind the terrain.

The data for the normals and horizon maps were generated using the
elevation data in the
[CGI Moon Kit](https://svs.gsfc.nasa.gov/cgi-bin/details.cgi?aid=4720).
The generation was done using
[map-bumper](https://github.com/10110111/map-bumper) with the following
commands:

heightmap2normalmap 1727.4 0.5e-3 ~/Downloads/ldem_16_uint.tif moon_normals.png 1024 256
heightmap2horizonmap 1727.4 0.5e-3 ~/Downloads/ldem_16_uint.tif moon_horizon.png 1024

Moon radius is taken here as 1727.4 instead of 1737.4 to take into
account that the uint16 version has a global shift of values by 10 km.
Normal map was generated with 256-fold supersampling.
@10110111 10110111 force-pushed the moon-bumps-and-shadows branch from 532050f to 70b2055 Compare October 27, 2022 20:01
@gzotti
Copy link
Member

gzotti commented Oct 27, 2022

Just to be sure: The shader has nothing critical for weak systems, right? I see another sampler2D, but I am not aware of limitations.

@10110111
Copy link
Contributor Author

The shader has nothing critical for weak systems, right?

The shader doesn't. Or shouldn't :) But note that we have two textures now, with total size 9.3× old single texture. In other words, if the original texture took 1.5 MiB of VRAM, these two will take together 14 MiB.

@gzotti
Copy link
Member

gzotti commented Oct 27, 2022

Uh, right. While this should still not pose a problem for PCs, this may be the end of Raspi3 support. Or we can finally provide a guideline to downsample all textures. May be in another PR, I will likely have no dev time for about two weeks now.

Copy link
Member

@gzotti gzotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good now, thank you!

@alex-w alex-w added this to the 1.1 milestone Oct 28, 2022
@alex-w alex-w merged commit 5b93488 into Stellarium:master Oct 28, 2022
@10110111 10110111 deleted the moon-bumps-and-shadows branch October 28, 2022 15:08
@alex-w alex-w added the state: published The fix has been published for testing in weekly binary package label Oct 29, 2022
@github-actions
Copy link

Hello @10110111!

Please check the fresh version (development snapshot) of Stellarium:
https://github.com/Stellarium/stellarium-data/releases/tag/weekly-snapshot

@alex-w alex-w removed the state: published The fix has been published for testing in weekly binary package label Oct 31, 2022
@github-actions
Copy link

Hello @10110111!

Please check the latest stable version of Stellarium:
https://github.com/Stellarium/stellarium/releases/latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants