g_menucloudsmgr = RenderingEngine::get_scene_manager()->createNewSceneManager();
if (!g_menuclouds)
g_menuclouds = new Clouds(g_menucloudsmgr, -1, rand(), 100);
- g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
+ g_menuclouds->update(v3f(0, 0, 0), video::SColor(255, 200, 200, 255));
scene::ICameraSceneNode* camera;
camera = g_menucloudsmgr->addCameraSceneNode(0,
v3f(0, 0, 0), v3f(0, 60, 100));
#include "debug.h"
#include "profiler.h"
#include "settings.h"
+#include <cmath>
// Menu clouds are created later
Clouds *g_menuclouds = NULL;
irr::scene::ISceneManager *g_menucloudsmgr = NULL;
+// Constant for now
+static constexpr const float cloud_size = BS * 64.0f;
+
static void cloud_3d_setting_changed(const std::string &settingname, void *data)
{
// TODO: only re-read cloud settings, not height or radius
ISceneNode::OnRegisterSceneNode();
}
-#define MYROUND(x) (x > 0.0 ? (int)x : (int)x - 1)
-
void Clouds::render()
{
Clouds move from Z+ towards Z-
*/
- static const float cloud_size = BS * 64.0f;
-
const float cloud_full_radius = cloud_size * m_cloud_radius_i;
+ v2f camera_pos_2d(m_camera_pos.X, m_camera_pos.Z);
// Position of cloud noise origin from the camera
- v2f cloud_origin_from_camera_f = m_origin - m_camera_pos;
+ v2f cloud_origin_from_camera_f = m_origin - camera_pos_2d;
// The center point of drawing in the noise
v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f;
// The integer center point of drawing in the noise
v2s16 center_of_drawing_in_noise_i(
- MYROUND(center_of_drawing_in_noise_f.X / cloud_size),
- MYROUND(center_of_drawing_in_noise_f.Y / cloud_size)
+ std::floor(center_of_drawing_in_noise_f.X / cloud_size),
+ std::floor(center_of_drawing_in_noise_f.Y / cloud_size)
);
+
// The world position of the integer center point of drawing in the noise
v2f world_center_of_drawing_in_noise_f = v2f(
center_of_drawing_in_noise_i.X * cloud_size,
bool *grid = new bool[m_cloud_radius_i * 2 * m_cloud_radius_i * 2];
- float cloud_size_noise = cloud_size / BS / 200;
for(s16 zi = -m_cloud_radius_i; zi < m_cloud_radius_i; zi++) {
u32 si = (zi + m_cloud_radius_i) * m_cloud_radius_i * 2 + m_cloud_radius_i;
for (s16 xi = -m_cloud_radius_i; xi < m_cloud_radius_i; xi++) {
u32 i = si + xi;
- v2s16 p_in_noise_i(
+ grid[i] = gridFilled(
xi + center_of_drawing_in_noise_i.X,
zi + center_of_drawing_in_noise_i.Y
);
-
- float noise = noise2d_perlin(
- (float)p_in_noise_i.X * cloud_size_noise,
- (float)p_in_noise_i.Y * cloud_size_noise,
- m_seed, 3, 0.5);
- // normalize to 0..1 (given 3 octaves)
- static const float noise_bound = 1.0f + 0.5f + 0.25f;
- float density = noise / noise_bound * 0.5f + 0.5f;
- grid[i] = (density < m_params.density);
}
}
m_origin = m_origin + dtime * BS * m_params.speed;
}
-void Clouds::update(v2f camera_p, video::SColorf color_diffuse)
+void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse)
{
m_camera_pos = camera_p;
m_color.r = MYMIN(MYMAX(color_diffuse.r * m_params.color_bright.getRed(),
m_color.b = MYMIN(MYMAX(color_diffuse.b * m_params.color_bright.getBlue(),
m_params.color_ambient.getBlue()), 255) / 255.0f;
m_color.a = m_params.color_bright.getAlpha() / 255.0f;
+
+ // is the camera inside the cloud mesh?
+ m_camera_inside_cloud = false; // default
+ if (m_enable_3d) {
+ float camera_height = camera_p.Y;
+ if (camera_height >= m_box.MinEdge.Y &&
+ camera_height <= m_box.MaxEdge.Y) {
+ v2f camera_in_noise;
+ camera_in_noise.X = floor((camera_p.X - m_origin.X) / cloud_size + 0.5);
+ camera_in_noise.Y = floor((camera_p.Z - m_origin.Y) / cloud_size + 0.5);
+ bool filled = gridFilled(camera_in_noise.X, camera_in_noise.Y);
+ m_camera_inside_cloud = filled;
+ }
+ }
}
void Clouds::readSettings()
m_cloud_radius_i = g_settings->getU16("cloud_radius");
m_enable_3d = g_settings->getBool("enable_3d_clouds");
}
+
+bool Clouds::gridFilled(int x, int y) const
+{
+ float cloud_size_noise = cloud_size / (BS * 200.f);
+ float noise = noise2d_perlin(
+ (float)x * cloud_size_noise,
+ (float)y * cloud_size_noise,
+ m_seed, 3, 0.5);
+ // normalize to 0..1 (given 3 octaves)
+ static constexpr const float noise_bound = 1.0f + 0.5f + 0.25f;
+ float density = noise / noise_bound * 0.5f + 0.5f;
+ return (density < m_params.density);
+}
void step(float dtime);
- void update(v2f camera_p, video::SColorf color);
+ void update(const v3f &camera_p, const video::SColorf &color);
void updateCameraOffset(v3s16 camera_offset)
{
updateBox();
}
+ bool isCameraInsideCloud() const { return m_camera_inside_cloud; }
+
+ const video::SColor getColor() const { return m_color.toSColor(); }
+
private:
void updateBox()
{
BS * 1000000.0f, height_bs + thickness_bs - BS * m_camera_offset.Y, BS * 1000000.0f);
}
+ bool gridFilled(int x, int y) const;
+
video::SMaterial m_material;
aabb3f m_box;
s16 m_passed_cloud_y;
u16 m_cloud_radius_i;
bool m_enable_3d;
u32 m_seed;
- v2f m_camera_pos;
+ v3f m_camera_pos;
v2f m_origin;
v3s16 m_camera_offset;
video::SColorf m_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
CloudParams m_params;
+ bool m_camera_inside_cloud = false;
};
Update clouds
*/
if (clouds) {
- v3f player_position = player->getPosition();
if (sky->getCloudsVisible()) {
clouds->setVisible(true);
clouds->step(dtime);
- clouds->update(v2f(player_position.X, player_position.Z),
- sky->getCloudColor());
+ // camera->getPosition is not enough for 3rd person views
+ v3f camera_node_position = camera->getCameraNode()->getPosition();
+ v3s16 camera_offset = camera->getOffset();
+ camera_node_position.X = camera_node_position.X + camera_offset.X * BS;
+ camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS;
+ camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS;
+ clouds->update(camera_node_position,
+ sky->getCloudColor());
+ if (clouds->isCameraInsideCloud() && m_cache_enable_fog &&
+ !flags.force_fog_off) {
+ // if inside clouds, and fog enabled, use that as sky
+ // color(s)
+ video::SColor clouds_dark = clouds->getColor()
+ .getInterpolated(video::SColor(255, 0, 0, 0), 0.9);
+ sky->overrideColors(clouds_dark, clouds->getColor());
+ sky->setBodiesVisible(false);
+ runData.fog_range = 20.0f * BS;
+ // do not draw clouds after all
+ clouds->setVisible(false);
+ }
} else {
clouds->setVisible(false);
}
/*
Drawing begins
*/
-
const video::SColor &skycolor = sky->getSkyColor();
TimeTaker tt_draw("mainloop: draw");
void GUIEngine::cloudInit()
{
m_cloud.clouds = new Clouds(m_smgr, -1, rand(), 100);
- m_cloud.clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
+ m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255,200,200,255));
m_cloud.camera = m_smgr->addCameraSceneNode(0,
v3f(0,0,0), v3f(0, 60, 100));
vertices[3] = video::S3DVertex(-1, -1.0, 1, 0, 1, 0, c, t, o);
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ // If sun, moon and stars are (temporarily) disabled, abort here
+ if (!m_bodies_visible)
+ return;
+
driver->setMaterial(m_materials[2]);
// Draw sunrise/sunset horizon glow texture (textures/base/pack/sunrisebg.png)
}
// Draw stars
- driver->setMaterial(m_materials[1]);
do {
+ driver->setMaterial(m_materials[1]);
float starbrightness = MYMAX(0, MYMIN(1,
(0.285 - fabs(wicked_time_of_day < 0.5 ?
wicked_time_of_day : (1.0 - wicked_time_of_day))) * 10));
m_time_of_day = time_of_day;
m_time_brightness = time_brightness;
m_sunlight_seen = sunlight_seen;
+ m_bodies_visible = true;
bool is_dawn = (time_brightness >= 0.20 && time_brightness < 0.35);
return m_visible ? m_skycolor : m_fallback_bg_color;
}
- bool getCloudsVisible() { return m_clouds_visible && m_clouds_enabled; }
- const video::SColorf &getCloudColor() { return m_cloudcolor_f; }
+ bool getCloudsVisible() const { return m_clouds_visible && m_clouds_enabled; }
+ const video::SColorf &getCloudColor() const { return m_cloudcolor_f; }
void setVisible(bool visible) { m_visible = visible; }
// Set only from set_sky API
{
m_fallback_bg_color = fallback_bg_color;
}
+ void overrideColors(const video::SColor &bgcolor, const video::SColor &skycolor)
+ {
+ m_bgcolor = bgcolor;
+ m_skycolor = skycolor;
+ }
+ void setBodiesVisible(bool visible) { m_bodies_visible = visible; }
private:
aabb3f m_box;
bool m_clouds_visible; // Whether clouds are disabled due to player underground
bool m_clouds_enabled = true; // Initialised to true, reset only by set_sky API
bool m_directional_colored_fog;
+ bool m_bodies_visible = true; // sun, moon, stars
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);