2011-04-29 14:34:26 +02:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-04-29 14:34:26 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 17:26:10 +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
|
2011-04-29 14:34:26 +02: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 17:26:10 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-04-29 14:34:26 +02:00
|
|
|
|
2012-06-05 17:26:10 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-04-29 14:34:26 +02:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-06-26 20:11:17 +02:00
|
|
|
#include "client/renderingengine.h"
|
2011-04-29 14:34:26 +02:00
|
|
|
#include "clouds.h"
|
|
|
|
#include "noise.h"
|
|
|
|
#include "constants.h"
|
|
|
|
#include "debug.h"
|
2011-10-18 12:56:35 +02:00
|
|
|
#include "profiler.h"
|
2011-10-18 22:55:55 +02:00
|
|
|
#include "settings.h"
|
2017-05-07 18:41:47 +02:00
|
|
|
#include <cmath>
|
2011-04-29 14:34:26 +02:00
|
|
|
|
2015-04-01 15:01:28 +02:00
|
|
|
|
|
|
|
// Menu clouds are created later
|
|
|
|
class Clouds;
|
|
|
|
Clouds *g_menuclouds = NULL;
|
2021-05-03 10:27:00 +02:00
|
|
|
scene::ISceneManager *g_menucloudsmgr = NULL;
|
2015-04-01 15:01:28 +02:00
|
|
|
|
2017-05-07 18:41:47 +02:00
|
|
|
// Constant for now
|
|
|
|
static constexpr const float cloud_size = BS * 64.0f;
|
|
|
|
|
2015-07-09 08:23:08 +02:00
|
|
|
static void cloud_3d_setting_changed(const std::string &settingname, void *data)
|
2015-07-09 08:07:59 +02:00
|
|
|
{
|
|
|
|
((Clouds *)data)->readSettings();
|
|
|
|
}
|
|
|
|
|
2017-06-26 20:11:17 +02:00
|
|
|
Clouds::Clouds(scene::ISceneManager* mgr,
|
2011-04-29 14:34:26 +02:00
|
|
|
s32 id,
|
2017-08-04 05:58:10 +02:00
|
|
|
u32 seed
|
2011-04-29 14:34:26 +02:00
|
|
|
):
|
2017-06-26 20:11:17 +02:00
|
|
|
scene::ISceneNode(mgr->getRootSceneNode(), mgr, id),
|
2017-06-16 11:25:52 +02:00
|
|
|
m_seed(seed)
|
2011-04-29 14:34:26 +02:00
|
|
|
{
|
|
|
|
m_material.setFlag(video::EMF_LIGHTING, false);
|
2012-03-16 15:34:30 +01:00
|
|
|
//m_material.setFlag(video::EMF_BACK_FACE_CULLING, false);
|
|
|
|
m_material.setFlag(video::EMF_BACK_FACE_CULLING, true);
|
2011-04-29 14:34:26 +02:00
|
|
|
m_material.setFlag(video::EMF_BILINEAR_FILTER, false);
|
2012-03-16 15:34:30 +01:00
|
|
|
m_material.setFlag(video::EMF_FOG_ENABLE, true);
|
|
|
|
m_material.setFlag(video::EMF_ANTI_ALIASING, true);
|
2011-04-29 14:34:26 +02:00
|
|
|
//m_material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
|
2012-03-16 15:34:30 +01:00
|
|
|
m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
2011-04-29 14:34:26 +02:00
|
|
|
|
2017-08-04 05:58:10 +02:00
|
|
|
m_params.height = 120;
|
2017-03-17 10:39:47 +01:00
|
|
|
m_params.density = 0.4f;
|
|
|
|
m_params.thickness = 16.0f;
|
2017-05-02 02:37:23 +02:00
|
|
|
m_params.color_bright = video::SColor(229, 240, 240, 255);
|
2017-03-17 10:39:47 +01:00
|
|
|
m_params.color_ambient = video::SColor(255, 0, 0, 0);
|
|
|
|
m_params.speed = v2f(0.0f, -2.0f);
|
|
|
|
|
2015-07-09 08:07:59 +02:00
|
|
|
readSettings();
|
|
|
|
g_settings->registerChangedCallback("enable_3d_clouds",
|
|
|
|
&cloud_3d_setting_changed, this);
|
2015-05-04 22:50:04 +02:00
|
|
|
|
2017-03-17 10:39:47 +01:00
|
|
|
updateBox();
|
2011-04-29 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Clouds::~Clouds()
|
|
|
|
{
|
2015-07-09 08:07:59 +02:00
|
|
|
g_settings->deregisterChangedCallback("enable_3d_clouds",
|
|
|
|
&cloud_3d_setting_changed, this);
|
2011-04-29 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clouds::OnRegisterSceneNode()
|
|
|
|
{
|
|
|
|
if(IsVisible)
|
|
|
|
{
|
2012-03-16 15:34:30 +01:00
|
|
|
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
|
|
|
|
//SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID);
|
2011-04-29 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISceneNode::OnRegisterSceneNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clouds::render()
|
|
|
|
{
|
2017-03-17 10:39:47 +01:00
|
|
|
|
|
|
|
if (m_params.density <= 0.0f)
|
|
|
|
return; // no need to do anything
|
|
|
|
|
2011-04-29 14:34:26 +02:00
|
|
|
video::IVideoDriver* driver = SceneManager->getVideoDriver();
|
|
|
|
|
2012-03-16 15:34:30 +01:00
|
|
|
if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
|
|
|
|
//if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
|
2011-04-29 14:34:26 +02:00
|
|
|
return;
|
|
|
|
|
2019-08-13 19:56:55 +02:00
|
|
|
ScopeProfiler sp(g_profiler, "Clouds::render()", SPT_AVG);
|
2017-06-26 20:11:17 +02:00
|
|
|
|
2015-05-04 22:50:04 +02:00
|
|
|
int num_faces_to_draw = m_enable_3d ? 6 : 1;
|
2017-06-26 20:11:17 +02:00
|
|
|
|
2015-05-04 22:50:04 +02:00
|
|
|
m_material.setFlag(video::EMF_BACK_FACE_CULLING, m_enable_3d);
|
2011-10-18 22:55:55 +02:00
|
|
|
|
2011-04-29 14:34:26 +02:00
|
|
|
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
|
|
|
|
driver->setMaterial(m_material);
|
2017-06-26 20:11:17 +02:00
|
|
|
|
2011-04-29 14:34:26 +02:00
|
|
|
/*
|
2015-05-04 19:53:58 +02:00
|
|
|
Clouds move from Z+ towards Z-
|
2011-04-29 14:34:26 +02:00
|
|
|
*/
|
|
|
|
|
2015-05-04 19:53:58 +02:00
|
|
|
const float cloud_full_radius = cloud_size * m_cloud_radius_i;
|
2017-06-26 20:11:17 +02:00
|
|
|
|
2017-05-07 18:41:47 +02:00
|
|
|
v2f camera_pos_2d(m_camera_pos.X, m_camera_pos.Z);
|
2011-04-29 14:34:26 +02:00
|
|
|
// Position of cloud noise origin from the camera
|
2017-05-07 18:41:47 +02:00
|
|
|
v2f cloud_origin_from_camera_f = m_origin - camera_pos_2d;
|
2011-04-29 14:34:26 +02:00
|
|
|
// 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(
|
2017-05-07 18:41:47 +02:00
|
|
|
std::floor(center_of_drawing_in_noise_f.X / cloud_size),
|
|
|
|
std::floor(center_of_drawing_in_noise_f.Y / cloud_size)
|
2011-04-29 14:34:26 +02:00
|
|
|
);
|
2017-05-07 18:41:47 +02:00
|
|
|
|
2011-04-29 14:34:26 +02:00
|
|
|
// 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,
|
|
|
|
center_of_drawing_in_noise_i.Y * cloud_size
|
2017-03-17 10:39:47 +01:00
|
|
|
) + m_origin;
|
2011-04-29 14:34:26 +02:00
|
|
|
|
2012-03-16 15:34:30 +01:00
|
|
|
/*video::SColor c_top(128,b*240,b*240,b*255);
|
|
|
|
video::SColor c_side_1(128,b*230,b*230,b*255);
|
|
|
|
video::SColor c_side_2(128,b*220,b*220,b*245);
|
|
|
|
video::SColor c_bottom(128,b*205,b*205,b*230);*/
|
|
|
|
video::SColorf c_top_f(m_color);
|
|
|
|
video::SColorf c_side_1_f(m_color);
|
|
|
|
video::SColorf c_side_2_f(m_color);
|
|
|
|
video::SColorf c_bottom_f(m_color);
|
|
|
|
c_side_1_f.r *= 0.95;
|
|
|
|
c_side_1_f.g *= 0.95;
|
|
|
|
c_side_1_f.b *= 0.95;
|
|
|
|
c_side_2_f.r *= 0.90;
|
|
|
|
c_side_2_f.g *= 0.90;
|
|
|
|
c_side_2_f.b *= 0.90;
|
|
|
|
c_bottom_f.r *= 0.80;
|
|
|
|
c_bottom_f.g *= 0.80;
|
|
|
|
c_bottom_f.b *= 0.80;
|
|
|
|
video::SColor c_top = c_top_f.toSColor();
|
|
|
|
video::SColor c_side_1 = c_side_1_f.toSColor();
|
|
|
|
video::SColor c_side_2 = c_side_2_f.toSColor();
|
|
|
|
video::SColor c_bottom = c_bottom_f.toSColor();
|
|
|
|
|
|
|
|
// Get fog parameters for setting them back later
|
|
|
|
video::SColor fog_color(0,0,0,0);
|
|
|
|
video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR;
|
|
|
|
f32 fog_start = 0;
|
|
|
|
f32 fog_end = 0;
|
|
|
|
f32 fog_density = 0;
|
|
|
|
bool fog_pixelfog = false;
|
|
|
|
bool fog_rangefog = false;
|
|
|
|
driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density,
|
|
|
|
fog_pixelfog, fog_rangefog);
|
2017-06-26 20:11:17 +02:00
|
|
|
|
2012-03-16 15:34:30 +01:00
|
|
|
// Set our own fog
|
|
|
|
driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5,
|
|
|
|
cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog);
|
|
|
|
|
|
|
|
// Read noise
|
|
|
|
|
2021-04-05 13:38:31 +02:00
|
|
|
std::vector<bool> grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2);
|
2020-11-22 07:13:16 +01:00
|
|
|
std::vector<video::S3DVertex> vertices;
|
|
|
|
vertices.reserve(16 * m_cloud_radius_i * m_cloud_radius_i);
|
2015-03-07 13:23:38 +01:00
|
|
|
|
2015-05-04 19:53:58 +02:00
|
|
|
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;
|
2015-03-07 13:23:38 +01:00
|
|
|
|
2015-05-04 19:53:58 +02:00
|
|
|
for (s16 xi = -m_cloud_radius_i; xi < m_cloud_radius_i; xi++) {
|
2015-03-07 13:23:38 +01:00
|
|
|
u32 i = si + xi;
|
|
|
|
|
2017-05-07 18:41:47 +02:00
|
|
|
grid[i] = gridFilled(
|
2015-03-07 13:23:38 +01:00
|
|
|
xi + center_of_drawing_in_noise_i.X,
|
|
|
|
zi + center_of_drawing_in_noise_i.Y
|
|
|
|
);
|
|
|
|
}
|
2012-03-16 15:34:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius))
|
2014-10-29 06:54:11 +01:00
|
|
|
#define INAREA(x, z, radius) \
|
2012-03-16 15:34:30 +01:00
|
|
|
((x) >= -(radius) && (x) < (radius) && (z) >= -(radius) && (z) < (radius))
|
|
|
|
|
2015-05-04 19:53:58 +02:00
|
|
|
for (s16 zi0= -m_cloud_radius_i; zi0 < m_cloud_radius_i; zi0++)
|
|
|
|
for (s16 xi0= -m_cloud_radius_i; xi0 < m_cloud_radius_i; xi0++)
|
2012-03-16 15:34:30 +01:00
|
|
|
{
|
|
|
|
s16 zi = zi0;
|
|
|
|
s16 xi = xi0;
|
2020-11-22 07:13:16 +01:00
|
|
|
// Draw from back to front for proper transparency
|
2012-03-16 15:34:30 +01:00
|
|
|
if(zi >= 0)
|
2015-05-04 19:53:58 +02:00
|
|
|
zi = m_cloud_radius_i - zi - 1;
|
2012-03-16 15:34:30 +01:00
|
|
|
if(xi >= 0)
|
2015-05-04 19:53:58 +02:00
|
|
|
xi = m_cloud_radius_i - xi - 1;
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2015-05-04 19:53:58 +02:00
|
|
|
u32 i = GETINDEX(xi, zi, m_cloud_radius_i);
|
2012-03-16 15:34:30 +01:00
|
|
|
|
2017-08-17 20:23:54 +02:00
|
|
|
if (!grid[i])
|
2011-04-29 14:34:26 +02:00
|
|
|
continue;
|
|
|
|
|
2012-03-16 15:34:30 +01:00
|
|
|
v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f;
|
2011-07-18 22:50:14 +02:00
|
|
|
|
2012-06-05 17:26:10 +02:00
|
|
|
video::S3DVertex v[4] = {
|
2011-07-19 01:43:30 +02:00
|
|
|
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
|
|
|
|
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
|
|
|
|
video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
|
|
|
|
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
|
2011-04-29 14:34:26 +02:00
|
|
|
};
|
2011-07-18 22:50:14 +02:00
|
|
|
|
2020-11-22 07:13:16 +01:00
|
|
|
const f32 rx = cloud_size / 2.0f;
|
2017-03-17 10:39:47 +01:00
|
|
|
// if clouds are flat, the top layer should be at the given height
|
2020-11-22 07:13:16 +01:00
|
|
|
const f32 ry = m_enable_3d ? m_params.thickness * BS : 0.0f;
|
|
|
|
const f32 rz = cloud_size / 2;
|
2011-07-18 22:50:14 +02:00
|
|
|
|
2011-10-18 22:55:55 +02:00
|
|
|
for(int i=0; i<num_faces_to_draw; i++)
|
2011-07-18 22:50:14 +02:00
|
|
|
{
|
|
|
|
switch(i)
|
|
|
|
{
|
2012-06-05 17:26:10 +02:00
|
|
|
case 0: // top
|
2017-08-20 19:37:29 +02:00
|
|
|
for (video::S3DVertex &vertex : v) {
|
|
|
|
vertex.Normal.set(0,1,0);
|
2012-06-05 17:26:10 +02:00
|
|
|
}
|
|
|
|
v[0].Pos.set(-rx, ry,-rz);
|
|
|
|
v[1].Pos.set(-rx, ry, rz);
|
|
|
|
v[2].Pos.set( rx, ry, rz);
|
|
|
|
v[3].Pos.set( rx, ry,-rz);
|
|
|
|
break;
|
|
|
|
case 1: // back
|
2015-05-04 19:53:58 +02:00
|
|
|
if (INAREA(xi, zi - 1, m_cloud_radius_i)) {
|
|
|
|
u32 j = GETINDEX(xi, zi - 1, m_cloud_radius_i);
|
2012-06-05 17:26:10 +02:00
|
|
|
if(grid[j])
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
for (video::S3DVertex &vertex : v) {
|
|
|
|
vertex.Color = c_side_1;
|
|
|
|
vertex.Normal.set(0,0,-1);
|
2012-06-05 17:26:10 +02:00
|
|
|
}
|
|
|
|
v[0].Pos.set(-rx, ry,-rz);
|
|
|
|
v[1].Pos.set( rx, ry,-rz);
|
2017-03-17 10:39:47 +01:00
|
|
|
v[2].Pos.set( rx, 0,-rz);
|
|
|
|
v[3].Pos.set(-rx, 0,-rz);
|
2012-06-05 17:26:10 +02:00
|
|
|
break;
|
|
|
|
case 2: //right
|
2015-05-04 19:53:58 +02:00
|
|
|
if (INAREA(xi + 1, zi, m_cloud_radius_i)) {
|
|
|
|
u32 j = GETINDEX(xi+1, zi, m_cloud_radius_i);
|
2012-06-05 17:26:10 +02:00
|
|
|
if(grid[j])
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
for (video::S3DVertex &vertex : v) {
|
|
|
|
vertex.Color = c_side_2;
|
|
|
|
vertex.Normal.set(1,0,0);
|
2012-06-05 17:26:10 +02:00
|
|
|
}
|
|
|
|
v[0].Pos.set( rx, ry,-rz);
|
|
|
|
v[1].Pos.set( rx, ry, rz);
|
2017-03-17 10:39:47 +01:00
|
|
|
v[2].Pos.set( rx, 0, rz);
|
|
|
|
v[3].Pos.set( rx, 0,-rz);
|
2012-06-05 17:26:10 +02:00
|
|
|
break;
|
|
|
|
case 3: // front
|
2015-05-04 19:53:58 +02:00
|
|
|
if (INAREA(xi, zi + 1, m_cloud_radius_i)) {
|
|
|
|
u32 j = GETINDEX(xi, zi + 1, m_cloud_radius_i);
|
2012-06-05 17:26:10 +02:00
|
|
|
if(grid[j])
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
for (video::S3DVertex &vertex : v) {
|
|
|
|
vertex.Color = c_side_1;
|
|
|
|
vertex.Normal.set(0,0,-1);
|
2012-06-05 17:26:10 +02:00
|
|
|
}
|
|
|
|
v[0].Pos.set( rx, ry, rz);
|
|
|
|
v[1].Pos.set(-rx, ry, rz);
|
2017-03-17 10:39:47 +01:00
|
|
|
v[2].Pos.set(-rx, 0, rz);
|
|
|
|
v[3].Pos.set( rx, 0, rz);
|
2012-06-05 17:26:10 +02:00
|
|
|
break;
|
|
|
|
case 4: // left
|
2015-05-04 19:53:58 +02:00
|
|
|
if (INAREA(xi-1, zi, m_cloud_radius_i)) {
|
|
|
|
u32 j = GETINDEX(xi-1, zi, m_cloud_radius_i);
|
2012-06-05 17:26:10 +02:00
|
|
|
if(grid[j])
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-20 19:37:29 +02:00
|
|
|
for (video::S3DVertex &vertex : v) {
|
|
|
|
vertex.Color = c_side_2;
|
|
|
|
vertex.Normal.set(-1,0,0);
|
2012-06-05 17:26:10 +02:00
|
|
|
}
|
|
|
|
v[0].Pos.set(-rx, ry, rz);
|
|
|
|
v[1].Pos.set(-rx, ry,-rz);
|
2017-03-17 10:39:47 +01:00
|
|
|
v[2].Pos.set(-rx, 0,-rz);
|
|
|
|
v[3].Pos.set(-rx, 0, rz);
|
2012-06-05 17:26:10 +02:00
|
|
|
break;
|
|
|
|
case 5: // bottom
|
2017-08-20 19:37:29 +02:00
|
|
|
for (video::S3DVertex &vertex : v) {
|
|
|
|
vertex.Color = c_bottom;
|
|
|
|
vertex.Normal.set(0,-1,0);
|
2012-06-05 17:26:10 +02:00
|
|
|
}
|
2017-03-17 10:39:47 +01:00
|
|
|
v[0].Pos.set( rx, 0, rz);
|
|
|
|
v[1].Pos.set(-rx, 0, rz);
|
|
|
|
v[2].Pos.set(-rx, 0,-rz);
|
|
|
|
v[3].Pos.set( rx, 0,-rz);
|
2012-06-05 17:26:10 +02:00
|
|
|
break;
|
2011-07-18 22:50:14 +02:00
|
|
|
}
|
|
|
|
|
2017-03-17 10:39:47 +01:00
|
|
|
v3f pos(p0.X, m_params.height * BS, p0.Y);
|
2014-01-26 11:40:21 +01:00
|
|
|
pos -= intToFloat(m_camera_offset, BS);
|
2011-07-18 22:50:14 +02:00
|
|
|
|
2020-11-22 07:13:16 +01:00
|
|
|
for (video::S3DVertex &vertex : v) {
|
2017-08-20 19:37:29 +02:00
|
|
|
vertex.Pos += pos;
|
2020-11-22 07:13:16 +01:00
|
|
|
vertices.push_back(vertex);
|
|
|
|
}
|
2011-07-18 22:50:14 +02:00
|
|
|
}
|
2011-04-29 14:34:26 +02:00
|
|
|
}
|
2020-11-22 07:13:16 +01:00
|
|
|
int quad_count = vertices.size() / 4;
|
|
|
|
std::vector<u16> indices;
|
|
|
|
indices.reserve(quad_count * 6);
|
|
|
|
for (int k = 0; k < quad_count; k++) {
|
|
|
|
indices.push_back(4 * k + 0);
|
|
|
|
indices.push_back(4 * k + 1);
|
|
|
|
indices.push_back(4 * k + 2);
|
|
|
|
indices.push_back(4 * k + 2);
|
|
|
|
indices.push_back(4 * k + 3);
|
|
|
|
indices.push_back(4 * k + 0);
|
|
|
|
}
|
|
|
|
driver->drawVertexPrimitiveList(vertices.data(), vertices.size(), indices.data(), 2 * quad_count,
|
|
|
|
video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
|
2017-06-26 20:11:17 +02:00
|
|
|
|
2012-03-16 15:34:30 +01:00
|
|
|
// Restore fog settings
|
|
|
|
driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density,
|
|
|
|
fog_pixelfog, fog_rangefog);
|
2011-04-29 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clouds::step(float dtime)
|
|
|
|
{
|
2017-03-17 10:39:47 +01:00
|
|
|
m_origin = m_origin + dtime * BS * m_params.speed;
|
2011-04-29 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-07 18:41:47 +02:00
|
|
|
void Clouds::update(const v3f &camera_p, const video::SColorf &color_diffuse)
|
2011-04-29 14:34:26 +02:00
|
|
|
{
|
2020-11-22 14:43:38 +01:00
|
|
|
video::SColorf ambient(m_params.color_ambient);
|
|
|
|
video::SColorf bright(m_params.color_bright);
|
2011-04-29 14:34:26 +02:00
|
|
|
m_camera_pos = camera_p;
|
2020-11-22 14:43:38 +01:00
|
|
|
m_color.r = core::clamp(color_diffuse.r * bright.r, ambient.r, 1.0f);
|
|
|
|
m_color.g = core::clamp(color_diffuse.g * bright.g, ambient.g, 1.0f);
|
|
|
|
m_color.b = core::clamp(color_diffuse.b * bright.b, ambient.b, 1.0f);
|
|
|
|
m_color.a = bright.a;
|
2017-05-07 18:41:47 +02:00
|
|
|
|
|
|
|
// is the camera inside the cloud mesh?
|
|
|
|
m_camera_inside_cloud = false; // default
|
|
|
|
if (m_enable_3d) {
|
2021-05-25 23:44:41 +02:00
|
|
|
float camera_height = camera_p.Y - BS * m_camera_offset.Y;
|
2017-05-07 18:41:47 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-04-29 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
2015-07-09 08:07:59 +02:00
|
|
|
void Clouds::readSettings()
|
|
|
|
{
|
|
|
|
m_cloud_radius_i = g_settings->getU16("cloud_radius");
|
|
|
|
m_enable_3d = g_settings->getBool("enable_3d_clouds");
|
|
|
|
}
|
2017-05-07 18:41:47 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|