Skip to content

Reflect sun and moon using actual textures or generated moon phase.#17066

Open
sofar wants to merge 1 commit intoluanti-org:masterfrom
sofar:sofar/sun_moon_reflection
Open

Reflect sun and moon using actual textures or generated moon phase.#17066
sofar wants to merge 1 commit intoluanti-org:masterfrom
sofar:sofar/sun_moon_reflection

Conversation

@sofar
Copy link
Copy Markdown
Contributor

@sofar sofar commented Mar 27, 2026

This patch replaces the "placeholder" sun reflection in water. For this to work, you must have waving water enabled. Previously this only worked when shadows were enabled, but, with this change, it no longer depends on shadows being enabled or not.

The sun/moon reflection uses the actual texture that the game uses. I've used Mineclonia to test it and tweak sizes (they're a tiny tiny bit larger in the reflection but I think it's reasonable, because smaller looks weird really quick) and test that the actual reflections are correct (this part took quite a while).

Mineclonia relies on the generated sun texture (a bunch of squares stacked on top of each other) so this has been tested with both variants - texture and generated sun/moon.

A bunch of new shader stuff is needed to make this work, this patch pulls all of those changes in. The noise functions previously only in the shadow ifdefs are now also needed outside of it.

@sofar
Copy link
Copy Markdown
Contributor Author

sofar commented Mar 27, 2026

Example of moon reflection:

screenshot_20260326_194458

(Note: not default water waving settings so you can see the proper mirroring of the moon texture).

@sofar sofar force-pushed the sofar/sun_moon_reflection branch 3 times, most recently from 10ca98d to 3cedbbc Compare March 27, 2026 04:39
@sofar
Copy link
Copy Markdown
Contributor Author

sofar commented Mar 27, 2026

Daytime/dawn screenshot:

screenshot_20260326_214728

@sofar
Copy link
Copy Markdown
Contributor Author

sofar commented Mar 27, 2026

Example showing shadows cutting into the reflection:

screenshot_20260326_215059

@SkyBuilder1717
Copy link
Copy Markdown
Contributor

screenshot_20260328_073247 That's actually so cool! 😭😭

@Xeno333
Copy link
Copy Markdown
Contributor

Xeno333 commented Mar 28, 2026

That's really nice, I hope we can get this merged.

@lhofhansl lhofhansl self-requested a review March 28, 2026 16:03
This patch replaces the "placeholder" sun reflection in water. For this
to work, you must have waving water enabled. Previously this only
worked when shadows were enabled, but, with this change, it no longer
depends on shadows being enabled or not.

The sun/moon reflection uses the actual texture that the game uses. I've
used Mineclonia to test it and tweak sizes (they're a tiny tiny bit
larger in the reflection but I think it's reasonable, because smaller
looks weird really quick) and test that the actual reflections are
correct (this part took quite a while).

Mineclonia relies on the generated sun texture (a bunch of squares
stacked on top of each other) so this has been tested with both variants
- texture and generated sun/moon.

A bunch of new shader stuff is needed to make this work, this patch
pulls all of those changes in. The noise functions previously only
in the shadow ifdefs are now also needed outside of it.

The specular dot that was previously used is now gone. The only times
when it now could be used is when the sun or moon is actively hidden or
there is a loading issue, or at the wicked time boundary. We avoid
any weird visual in all those conditions by just not having it anymore.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sofar sofar force-pushed the sofar/sun_moon_reflection branch from 3cedbbc to 00833fa Compare March 28, 2026 17:33
float fresnel_factor = computeFresnelFactor(fNormal, viewVec);

// Derive nighttime from dayLight brightness
float dayBrightness = dot(dayLight, vec3(0.2125, 0.7154, 0.0721));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for extracting most of it into functions.

I am still a bit unclear why this (non-shadow) branch is any different than the shadow branch.

For example if we check for caves here, shouldn't we in the other branch as well? It seems to me that the code should be identical.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll do another pass over this. I noticed it too and you're right, I don't think it needs to be that different to begin with. It probably stems from me starting with a group of things that were unrelated before I made the change independent of shadows being enabled.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for looking.
(And sorry for the tone of the first comment - about the code duplication, wasn't meant to sound snarky, but it did.)

@Zughy Zughy added @ Client / Audiovisuals Feature ✨ PRs that add or enhance a feature Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it labels Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@ Client / Audiovisuals Feature ✨ PRs that add or enhance a feature Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants