2012-03-16 15:34:30 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2012-03-16 15:34:30 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2012-03-16 15:34:30 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2012-03-16 15:34:30 +01:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2022-01-22 13:37:26 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-28 21:25:13 +01:00
|
|
|
#include "irrlichttypes_extrabloated.h"
|
2012-03-16 15:34:30 +01:00
|
|
|
#include <ISceneNode.h>
|
2019-07-30 20:25:47 +02:00
|
|
|
#include <array>
|
2014-04-27 16:09:21 +02:00
|
|
|
#include "camera.h"
|
2020-11-22 14:29:31 +01:00
|
|
|
#include "irr_ptr.h"
|
2020-11-22 16:25:41 +01:00
|
|
|
#include "shader.h"
|
2019-08-21 22:47:45 +02:00
|
|
|
#include "skyparams.h"
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2019-08-21 22:47:45 +02:00
|
|
|
#define SKY_MATERIAL_COUNT 12
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2015-01-17 20:05:45 +01:00
|
|
|
class ITextureSource;
|
|
|
|
|
2012-03-16 15:34:30 +01:00
|
|
|
// Skybox, rendered with zbuffer turned off, before all other nodes.
|
|
|
|
class Sky : public scene::ISceneNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! constructor
|
2021-04-29 08:51:17 +02:00
|
|
|
Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShaderSource *ssrc);
|
2012-03-16 15:34:30 +01:00
|
|
|
|
|
|
|
virtual void OnRegisterSceneNode();
|
|
|
|
|
|
|
|
//! renders the node.
|
|
|
|
virtual void render();
|
|
|
|
|
2017-04-07 08:50:17 +02:00
|
|
|
virtual const aabb3f &getBoundingBox() const { return m_box; }
|
2012-03-16 15:34:30 +01:00
|
|
|
|
|
|
|
// Used by Irrlicht for optimizing rendering
|
2017-04-07 08:50:17 +02:00
|
|
|
virtual video::SMaterial &getMaterial(u32 i) { return m_materials[i]; }
|
|
|
|
virtual u32 getMaterialCount() const { return SKY_MATERIAL_COUNT; }
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2017-04-07 08:50:17 +02:00
|
|
|
void update(float m_time_of_day, float time_brightness, float direct_brightness,
|
|
|
|
bool sunlight_seen, CameraMode cam_mode, float yaw, float pitch);
|
2017-03-22 21:41:02 +01:00
|
|
|
|
2017-04-07 08:50:17 +02:00
|
|
|
float getBrightness() { return m_brightness; }
|
2013-05-02 22:52:50 +02:00
|
|
|
|
2024-01-23 22:33:33 +01:00
|
|
|
video::SColor getBgColor() const
|
2017-03-22 21:41:02 +01:00
|
|
|
{
|
2013-05-02 22:52:50 +02:00
|
|
|
return m_visible ? m_bgcolor : m_fallback_bg_color;
|
|
|
|
}
|
2017-03-22 21:41:02 +01:00
|
|
|
|
2024-01-23 22:33:33 +01:00
|
|
|
video::SColor getSkyColor() const
|
2017-03-22 21:41:02 +01:00
|
|
|
{
|
2013-05-02 22:52:50 +02:00
|
|
|
return m_visible ? m_skycolor : m_fallback_bg_color;
|
|
|
|
}
|
2017-03-22 21:41:02 +01:00
|
|
|
|
2019-08-21 22:47:45 +02:00
|
|
|
void setSunVisible(bool sun_visible) { m_sun_params.visible = sun_visible; }
|
2022-03-26 16:58:26 +01:00
|
|
|
bool getSunVisible() const { return m_sun_params.visible; }
|
2021-04-05 13:38:31 +02:00
|
|
|
void setSunTexture(const std::string &sun_texture,
|
|
|
|
const std::string &sun_tonemap, ITextureSource *tsrc);
|
2019-08-21 22:47:45 +02:00
|
|
|
void setSunScale(f32 sun_scale) { m_sun_params.scale = sun_scale; }
|
|
|
|
void setSunriseVisible(bool glow_visible) { m_sun_params.sunrise_visible = glow_visible; }
|
2021-04-05 13:38:31 +02:00
|
|
|
void setSunriseTexture(const std::string &sunglow_texture, ITextureSource* tsrc);
|
2022-08-17 16:30:05 +02:00
|
|
|
v3f getSunDirection();
|
2019-08-21 22:47:45 +02:00
|
|
|
|
|
|
|
void setMoonVisible(bool moon_visible) { m_moon_params.visible = moon_visible; }
|
2022-03-26 16:58:26 +01:00
|
|
|
bool getMoonVisible() const { return m_moon_params.visible; }
|
2021-04-05 13:38:31 +02:00
|
|
|
void setMoonTexture(const std::string &moon_texture,
|
|
|
|
const std::string &moon_tonemap, ITextureSource *tsrc);
|
2019-08-21 22:47:45 +02:00
|
|
|
void setMoonScale(f32 moon_scale) { m_moon_params.scale = moon_scale; }
|
2022-08-17 16:30:05 +02:00
|
|
|
v3f getMoonDirection();
|
2019-08-21 22:47:45 +02:00
|
|
|
|
|
|
|
void setStarsVisible(bool stars_visible) { m_star_params.visible = stars_visible; }
|
2022-01-22 13:37:26 +01:00
|
|
|
void setStarCount(u16 star_count);
|
2019-08-21 22:47:45 +02:00
|
|
|
void setStarColor(video::SColor star_color) { m_star_params.starcolor = star_color; }
|
2020-11-22 14:29:31 +01:00
|
|
|
void setStarScale(f32 star_scale) { m_star_params.scale = star_scale; updateStars(); }
|
2022-07-02 20:57:48 +02:00
|
|
|
void setStarDayOpacity(f32 day_opacity) { m_star_params.day_opacity = day_opacity; }
|
2019-08-21 22:47:45 +02:00
|
|
|
|
2017-05-07 18:41:47 +02:00
|
|
|
bool getCloudsVisible() const { return m_clouds_visible && m_clouds_enabled; }
|
|
|
|
const video::SColorf &getCloudColor() const { return m_cloudcolor_f; }
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2017-04-07 08:50:17 +02:00
|
|
|
void setVisible(bool visible) { m_visible = visible; }
|
2024-01-23 22:33:33 +01:00
|
|
|
|
2017-04-28 04:06:49 +02:00
|
|
|
// Set only from set_sky API
|
|
|
|
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
|
2021-04-05 13:38:31 +02:00
|
|
|
void setFallbackBgColor(video::SColor fallback_bg_color)
|
2017-04-07 08:50:17 +02:00
|
|
|
{
|
2013-05-02 22:52:50 +02:00
|
|
|
m_fallback_bg_color = fallback_bg_color;
|
|
|
|
}
|
2023-02-26 01:08:33 +01:00
|
|
|
void setBodyOrbitTilt(float body_orbit_tilt)
|
|
|
|
{
|
2023-03-24 12:34:21 +01:00
|
|
|
if (body_orbit_tilt != SkyboxParams::INVALID_SKYBOX_TILT)
|
|
|
|
m_sky_params.body_orbit_tilt = rangelim(body_orbit_tilt, -90.f, 90.f);
|
2023-02-26 01:08:33 +01:00
|
|
|
}
|
2021-04-05 13:38:31 +02:00
|
|
|
void overrideColors(video::SColor bgcolor, video::SColor skycolor)
|
2017-05-07 18:41:47 +02:00
|
|
|
{
|
|
|
|
m_bgcolor = bgcolor;
|
|
|
|
m_skycolor = skycolor;
|
|
|
|
}
|
2020-05-26 17:38:31 +02:00
|
|
|
void setSkyColors(const SkyColor &sky_color);
|
2019-08-21 22:47:45 +02:00
|
|
|
void setHorizonTint(video::SColor sun_tint, video::SColor moon_tint,
|
2021-04-05 13:38:31 +02:00
|
|
|
const std::string &use_sun_tint);
|
2019-08-21 22:47:45 +02:00
|
|
|
void setInClouds(bool clouds) { m_in_clouds = clouds; }
|
|
|
|
void clearSkyboxTextures() { m_sky_params.textures.clear(); }
|
2024-01-23 22:33:33 +01:00
|
|
|
void addTextureToSkybox(const std::string &texture, int material_id,
|
2019-08-21 22:47:45 +02:00
|
|
|
ITextureSource *tsrc);
|
2020-11-22 16:25:41 +01:00
|
|
|
const video::SColorf &getCurrentStarColor() const { return m_star_color; }
|
2024-01-23 22:33:33 +01:00
|
|
|
|
|
|
|
// Note: the Sky class doesn't use these values. It just stores them.
|
2023-07-01 04:11:17 +02:00
|
|
|
void setFogDistance(s16 fog_distance) { m_sky_params.fog_distance = fog_distance; }
|
|
|
|
s16 getFogDistance() const { return m_sky_params.fog_distance; }
|
|
|
|
|
|
|
|
void setFogStart(float fog_start) { m_sky_params.fog_start = fog_start; }
|
|
|
|
float getFogStart() const { return m_sky_params.fog_start; }
|
2020-11-22 16:25:41 +01:00
|
|
|
|
2024-01-23 22:33:33 +01:00
|
|
|
void setFogColor(video::SColor v) { m_sky_params.fog_color = v; }
|
|
|
|
video::SColor getFogColor() const {
|
|
|
|
if (m_sky_params.fog_color.getAlpha() > 0)
|
|
|
|
return m_sky_params.fog_color;
|
|
|
|
return getBgColor();
|
|
|
|
}
|
2023-10-24 02:05:31 +02:00
|
|
|
|
2012-03-16 15:34:30 +01:00
|
|
|
private:
|
2016-02-11 15:21:21 +01:00
|
|
|
aabb3f m_box;
|
2012-03-16 15:34:30 +01:00
|
|
|
video::SMaterial m_materials[SKY_MATERIAL_COUNT];
|
2013-06-30 17:17:14 +02:00
|
|
|
// How much sun & moon transition should affect horizon color
|
|
|
|
float m_horizon_blend()
|
|
|
|
{
|
|
|
|
if (!m_sunlight_seen)
|
|
|
|
return 0;
|
2017-04-07 08:50:17 +02:00
|
|
|
float x = m_time_of_day >= 0.5 ? (1 - m_time_of_day) * 2
|
|
|
|
: m_time_of_day * 2;
|
2014-10-07 09:01:07 +02:00
|
|
|
|
2013-06-30 17:17:14 +02:00
|
|
|
if (x <= 0.3)
|
|
|
|
return 0;
|
|
|
|
if (x <= 0.4) // when the sun and moon are aligned
|
|
|
|
return (x - 0.3) * 10;
|
|
|
|
if (x <= 0.5)
|
|
|
|
return (0.5 - x) * 10;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mix two colors by a given amount
|
2021-04-05 13:38:31 +02:00
|
|
|
static video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor)
|
2013-06-30 17:17:14 +02:00
|
|
|
{
|
|
|
|
video::SColor result = video::SColor(
|
2017-04-07 08:50:17 +02:00
|
|
|
col1.getAlpha() * (1 - factor) + col2.getAlpha() * factor,
|
|
|
|
col1.getRed() * (1 - factor) + col2.getRed() * factor,
|
|
|
|
col1.getGreen() * (1 - factor) + col2.getGreen() * factor,
|
|
|
|
col1.getBlue() * (1 - factor) + col2.getBlue() * factor);
|
2013-06-30 17:17:14 +02:00
|
|
|
return result;
|
|
|
|
}
|
2021-04-05 13:38:31 +02:00
|
|
|
static video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor)
|
2013-06-30 17:17:14 +02:00
|
|
|
{
|
2017-04-07 08:50:17 +02:00
|
|
|
video::SColorf result =
|
|
|
|
video::SColorf(col1.r * (1 - factor) + col2.r * factor,
|
|
|
|
col1.g * (1 - factor) + col2.g * factor,
|
|
|
|
col1.b * (1 - factor) + col2.b * factor,
|
|
|
|
col1.a * (1 - factor) + col2.a * factor);
|
2013-06-30 17:17:14 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-21 11:51:29 +02:00
|
|
|
bool m_visible = true;
|
|
|
|
// Used when m_visible=false
|
|
|
|
video::SColor m_fallback_bg_color = video::SColor(255, 255, 255, 255);
|
2022-01-22 13:37:26 +01:00
|
|
|
bool m_first_update = true; // Set before the sky is updated for the first time
|
2012-03-16 15:34:30 +01:00
|
|
|
float m_time_of_day;
|
|
|
|
float m_time_brightness;
|
|
|
|
bool m_sunlight_seen;
|
2017-06-21 11:51:29 +02:00
|
|
|
float m_brightness = 0.5f;
|
|
|
|
float m_cloud_brightness = 0.5f;
|
2017-05-04 07:52:31 +02:00
|
|
|
bool m_clouds_visible; // Whether clouds are disabled due to player underground
|
2017-06-21 11:51:29 +02:00
|
|
|
bool m_clouds_enabled = true; // Initialised to true, reset only by set_sky API
|
2013-12-15 15:30:02 +01:00
|
|
|
bool m_directional_colored_fog;
|
2019-08-21 22:47:45 +02:00
|
|
|
bool m_in_clouds = true; // Prevent duplicating bools to remember old values
|
2020-11-22 16:25:41 +01:00
|
|
|
bool m_enable_shaders = false;
|
2019-08-21 22:47:45 +02:00
|
|
|
|
2017-06-21 11:51:29 +02:00
|
|
|
video::SColorf m_bgcolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
video::SColorf m_skycolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
video::SColorf m_cloudcolor_bright_f = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
|
2012-03-16 15:34:30 +01:00
|
|
|
video::SColor m_bgcolor;
|
|
|
|
video::SColor m_skycolor;
|
|
|
|
video::SColorf m_cloudcolor_f;
|
2019-08-21 22:47:45 +02:00
|
|
|
|
|
|
|
// pure white: becomes "diffuse light component" for clouds
|
|
|
|
video::SColorf m_cloudcolor_day_f = video::SColorf(1, 1, 1, 1);
|
|
|
|
// dawn-factoring version of pure white (note: R is above 1.0)
|
|
|
|
video::SColorf m_cloudcolor_dawn_f = video::SColorf(
|
|
|
|
255.0f/240.0f,
|
|
|
|
223.0f/240.0f,
|
|
|
|
191.0f/255.0f
|
|
|
|
);
|
|
|
|
|
|
|
|
SkyboxParams m_sky_params;
|
|
|
|
SunParams m_sun_params;
|
|
|
|
MoonParams m_moon_params;
|
|
|
|
StarParams m_star_params;
|
|
|
|
|
|
|
|
bool m_default_tint = true;
|
|
|
|
|
2020-11-22 14:41:36 +01:00
|
|
|
u64 m_seed = 0;
|
2020-11-22 14:29:31 +01:00
|
|
|
irr_ptr<scene::SMeshBuffer> m_stars;
|
2020-11-22 16:25:41 +01:00
|
|
|
video::SColorf m_star_color;
|
2019-08-21 22:47:45 +02:00
|
|
|
|
2017-04-07 08:50:17 +02:00
|
|
|
video::ITexture *m_sun_texture;
|
|
|
|
video::ITexture *m_moon_texture;
|
|
|
|
video::ITexture *m_sun_tonemap;
|
|
|
|
video::ITexture *m_moon_tonemap;
|
2019-08-21 22:47:45 +02:00
|
|
|
|
2020-11-22 14:29:31 +01:00
|
|
|
void updateStars();
|
|
|
|
|
2022-09-06 12:21:55 +02:00
|
|
|
void draw_sun(video::IVideoDriver *driver, const video::SColor &suncolor,
|
2019-08-21 22:47:45 +02:00
|
|
|
const video::SColor &suncolor2, float wicked_time_of_day);
|
2022-09-06 12:21:55 +02:00
|
|
|
void draw_moon(video::IVideoDriver *driver, const video::SColor &mooncolor,
|
2019-08-21 22:47:45 +02:00
|
|
|
const video::SColor &mooncolor2, float wicked_time_of_day);
|
2019-07-30 20:25:47 +02:00
|
|
|
void draw_sky_body(std::array<video::S3DVertex, 4> &vertices,
|
2019-08-21 22:47:45 +02:00
|
|
|
float pos_1, float pos_2, const video::SColor &c);
|
|
|
|
void draw_stars(video::IVideoDriver *driver, float wicked_time_of_day);
|
|
|
|
void place_sky_body(std::array<video::S3DVertex, 4> &vertices,
|
|
|
|
float horizon_position, float day_position);
|
2012-03-16 15:34:30 +01:00
|
|
|
};
|
2021-06-06 18:51:21 +02:00
|
|
|
|
|
|
|
// calculates value for sky body positions for the given observed time of day
|
|
|
|
// this is used to draw both Sun/Moon and shadows
|
|
|
|
float getWickedTimeOfDay(float time_of_day);
|