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

API for light intensity and color at night and day #14091

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sfence
Copy link
Contributor

@sfence sfence commented Dec 11, 2023

Add compact, short information about your PR for easier understanding:

  • Allows games to change sun color, intensity, and night's darkness.
  • It changed get_sunlight_color function, so no constants are used for sun color calculation, but configurable parameters.
  • This can be useful with mods that control moon phases and weather. It also can be useful in space games.
  • With this, heavy cloudy nights can be darkness than normal nights, etc.

To do

This PR is Ready for Review.

How to test

Run game devtest and run command set_light_intensity from lighting mod.

Screen.Recording.2024-01-02.at.17.47.51_480.mov

@sfan5 sfan5 changed the title Light intensity and color at night and day API for light intensity and color at night and day Dec 12, 2023
@Zughy Zughy added Feature ✨ PRs that add or enhance a feature Roadmap The change matches an item on the current roadmap labels Dec 12, 2023
@sfence sfence force-pushed the sfence_lightIntensity branch from a0a30f4 to cbcfa1f Compare December 22, 2023 03:21
Copy link
Contributor

@Zughy Zughy left a comment

Choose a reason for hiding this comment

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

only went through the DOCS. It'd be also nice having some pictures or a small video

@sfence sfence force-pushed the sfence_lightIntensity branch from 78d8b63 to ecd7eb7 Compare January 2, 2024 16:59
@sfence
Copy link
Contributor Author

sfence commented Jan 2, 2024

@appgurueu @Zughy Fixes, feedback applied, rebased, and a small video added (to PR itself).

@sfence sfence force-pushed the sfence_lightIntensity branch from 423525e to 1de2312 Compare January 22, 2024 15:38
@sfence sfence force-pushed the sfence_lightIntensity branch from 1de2312 to 5a9c097 Compare February 3, 2024 22:11
@sfence
Copy link
Contributor Author

sfence commented Feb 3, 2024

Rebased, merged to one commit, and cleaned Lua code

@sfence sfence force-pushed the sfence_lightIntensity branch 2 times, most recently from 40144a3 to 4b3ed11 Compare February 23, 2024 18:46
@sfence sfence force-pushed the sfence_lightIntensity branch from 4b3ed11 to 60d1927 Compare March 25, 2024 04:43
@Andrey2470T
Copy link
Contributor

Andrey2470T commented Jun 28, 2024

I've made some testing of this feature. I assume it actually should depend now on #14789 as it repairs generally applying any colorful light values to the common vertex light color and this PR is not an exception also.

At the set single-channel color offsets the devtest player model gets fully dark. It happens on adjusting the red and blue channels:
Снимок экрана от 2024-06-28 19-41-42

The particles are not affected by the sunlight color at all with any combinations of the offsets and coefficients:
Снимок экрана от 2024-06-28 19-49-44

The color of the nodes going with such paramtype2 as colorfacedir (and I'm sure also other its colorized analogues) randomly diverges with the actual set sunlight color. This much possibly happens of that issue (wrong mixing of the different light colors together with the hardware one):
Снимок экрана от 2024-06-28 19-52-07

src/lighting.h Outdated
* sunlight->b = colorOffset_rgb.Z+colorRatioCoef_rgb.Z*daynight_ratio;
*
*/
struct LightIntensity
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be renamed to SkyLight for the same reason mentioned above.

if (lua_istable(L, -1)) {
lua_getfield(L, 3, "color_offset");
if (lua_istable(L, -1)) {
lighting.lightIntensity.colorOffset_rgb.X = getfloatfield_default(L, -1, "r", lighting.lightIntensity.colorOffset_rgb.X);
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a some reference to the structure like LightIntensity &sky_light = lighting.lightIntensity to avoid writing overly long lines. Also, I think it is worth to remove _rgb suffix since it is pretty clear this is RGB format by judging the storing only 3 float values (v3f).

@@ -1815,4 +1815,12 @@ void Client::handleCommand_SetLighting(NetworkPacket *pkt)
}
if (pkt->getRemainingBytes() >= 4)
*pkt >> lighting.volumetric_light_strength;
if (pkt->getRemainingBytes() >= 24) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is worth to change the check for the bytes availability in the packet doing it similar with https://github.com/minetest/minetest/pull/14343/files#diff-592338f1bfb0275512da218625ce67e993b91984c175f70fe376825ab4e0aad2R1804

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the normally used style.
I will change it in the rebase after PR #14343 is merged.

@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/directiontables.h"
#include "client/meshgen/collector.h"
#include "client/renderingengine.h"
#include "client/localplayer.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

why localplayer is included here ? we should not have player inclusion on mapblock_mesh, which is close to render and has nothing to do with player session/object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the light setting is stored in the local player.

@Andrey2470T
Copy link
Contributor

Andrey2470T commented Jun 29, 2024

If the shaders are disabled, the new sunlight color on the mapblocks meshes should be appeared immediately after updating it in LocalPlayer. You could keep some flag signalizing about that somewhere in the ClientMap and then call MapblockMesh->animate() on all visible mapblock meshes. Because currently this circumstance leads to the following artifacts:
Снимок экрана от 2024-06-29 22-34-41

@sfence
Copy link
Contributor Author

sfence commented Jul 1, 2024

At the set single-channel color offsets the devtest player model gets fully dark. It happens on adjusting the red and blue channels:

The particles are not affected by the sunlight color at all with any combinations of the offsets and coefficients:

The color of the nodes going with such paramtype2 as colorfacedir (and I'm sure also other its colorized analogues) randomly diverges with the actual set sunlight color. This much possibly happens of that issue (wrong mixing of the different light colors together with the hardware one):

No affected particles are a bug. I will check it.

When texture without red color is shown as black in the light which does not include the red part, it is not a bug.
You cannot expect that a surface that can reflect only red light, will reflect green or blue light.

This PR should affect only the color of sunlight, not the color of light from artificial light sources.
You cannot expect that the pure red texture will reflect pure green light.

@sfence sfence force-pushed the sfence_lightIntensity branch from 60d1927 to e4c4c8a Compare August 6, 2024 15:13
@sfence sfence force-pushed the sfence_lightIntensity branch from e4c4c8a to b03c4b0 Compare October 2, 2024 14:21
@sfence sfence force-pushed the sfence_lightIntensity branch from 09a54f8 to a4bb71d Compare November 3, 2024 18:55
@sfence
Copy link
Contributor Author

sfence commented Nov 3, 2024

Rebased, sky color is applied also to particles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Client rendering Feature ✨ PRs that add or enhance a feature Roadmap The change matches an item on the current roadmap @ Script API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants