#include "config.h"
using namespace irr::core;
-static video::SMaterial baseMaterial() {
+static video::SMaterial baseMaterial()
+{
video::SMaterial mat;
mat.Lighting = false;
-#if ENABLE_GLES
+#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
mat.ZBuffer = video::ECFN_DISABLED;
+ mat.ZWriteEnable = video::EZW_OFF;
#else
+ mat.ZWriteEnable = false;
mat.ZBuffer = video::ECFN_NEVER;
#endif
- mat.ZWriteEnable = false;
mat.AntiAliasing = 0;
mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
return mat;
};
-Sky::Sky(s32 id, ITextureSource *tsrc) :
+Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
RenderingEngine::get_scene_manager(), id)
{
m_box.MaxEdge.set(0, 0, 0);
m_box.MinEdge.set(0, 0, 0);
+ m_enable_shaders = g_settings->getBool("enable_shaders");
+
// Create materials
m_materials[0] = baseMaterial();
- m_materials[0].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ m_materials[0].MaterialType = ssrc->getShaderInfo(ssrc->getShader("stars_shader", TILE_MATERIAL_ALPHA)).material;
m_materials[0].Lighting = true;
m_materials[0].ColorMaterial = video::ECM_NONE;
const f32 t = 1.0f;
const f32 o = 0.0f;
- static const u16 indices[4] = {0, 1, 2, 3};
+ static const u16 indices[6] = {0, 1, 2, 0, 2, 3};
video::S3DVertex vertices[4];
driver->setMaterial(m_materials[1]);
vertex.Pos.rotateXZBy(180);
}
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
// Switch from -Z (south) to +Z (north)
vertex.Pos.rotateXZBy(-180);
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
// Switch from -Z (south) to -X (west)
vertex.Pos.rotateXZBy(-90);
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
// Draw sun
// Switch from -Z (south) to +Z (north)
vertex.Pos.rotateXZBy(-180);
}
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
// Draw bottom far cloudy fog thing in front of sun, moon and stars
vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 1, 0, c, o, t);
vertices[2] = video::S3DVertex( 1, -1.0, 1, 0, 1, 0, c, o, o);
vertices[3] = video::S3DVertex(-1, -1.0, 1, 0, 1, 0, c, t, o);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
}
* wicked_time_of_day: current time of day, to know where should be the sun in the sky
*/
{
- static const u16 indices[4] = {0, 1, 2, 3};
+ static const u16 indices[] = {0, 1, 2, 0, 2, 3};
std::array<video::S3DVertex, 4> vertices;
if (!m_sun_texture) {
driver->setMaterial(m_materials[1]);
for (int i = 0; i < 4; i++) {
draw_sky_body(vertices, -sunsizes[i], sunsizes[i], colors[i]);
place_sky_body(vertices, 90, wicked_time_of_day * 360 - 90);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
} else {
driver->setMaterial(m_materials[3]);
c = video::SColor(255, 255, 255, 255);
draw_sky_body(vertices, -d, d, c);
place_sky_body(vertices, 90, wicked_time_of_day * 360 - 90);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
}
* the sky
*/
{
- static const u16 indices[4] = {0, 1, 2, 3};
+ static const u16 indices[] = {0, 1, 2, 0, 2, 3};
std::array<video::S3DVertex, 4> vertices;
if (!m_moon_texture) {
driver->setMaterial(m_materials[1]);
for (int i = 0; i < 4; i++) {
draw_sky_body(vertices, moonsizes_1[i], moonsizes_2[i], colors[i]);
place_sky_body(vertices, -90, wicked_time_of_day * 360 - 90);
- driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
+ driver->drawIndexedTriangleList(&vertices[0], 4, indices, 2);
}
} else {
driver->setMaterial(m_materials[4]);
float tod = wicked_time_of_day < 0.5f ? wicked_time_of_day : (1.0f - wicked_time_of_day);
float starbrightness = (0.25f - fabsf(tod)) * 20.0f;
- int alpha = clamp<int>(starbrightness * m_star_params.starcolor.getAlpha(), 0, 255);
- if (!alpha) // Stars are only drawn when not fully transparent
+ m_star_color = m_star_params.starcolor;
+ m_star_color.a *= clamp(starbrightness, 0.0f, 1.0f);
+ if (m_star_color.a <= 0.0f) // Stars are only drawn when not fully transparent
return;
-
- m_materials[0].DiffuseColor = video::SColor(alpha, 0, 0, 0);
- m_materials[0].EmissiveColor = m_star_params.starcolor;
+ m_materials[0].DiffuseColor = m_materials[0].EmissiveColor = m_star_color.toSColor();
auto sky_rotation = core::matrix4().setRotationAxisRadians(2.0f * M_PI * (wicked_time_of_day - 0.25f), v3f(0.0f, 0.0f, 1.0f));
auto world_matrix = driver->getTransform(video::ETS_WORLD);
driver->setTransform(video::ETS_WORLD, world_matrix * sky_rotation);
}
}
-void Sky::updateStars() {
+void Sky::updateStars()
+{
m_stars.reset(new scene::SMeshBuffer());
// Stupid IrrLicht doesn’t allow non-indexed rendering, and indexed quad
// rendering is slow due to lack of hardware support. So as indices are
m_stars->Vertices.reallocate(4 * m_star_params.count);
m_stars->Indices.reallocate(6 * m_star_params.count);
+ video::SColor fallback_color = m_star_params.starcolor; // used on GLES 2 “without shaders”
PcgRandom rgen(m_seed);
float d = (0.006 / 2) * m_star_params.scale;
for (u16 i = 0; i < m_star_params.count; i++) {
a.rotateVect(p1);
a.rotateVect(p2);
a.rotateVect(p3);
- m_stars->Vertices.push_back(video::S3DVertex(p, {}, {}, {}));
- m_stars->Vertices.push_back(video::S3DVertex(p1, {}, {}, {}));
- m_stars->Vertices.push_back(video::S3DVertex(p2, {}, {}, {}));
- m_stars->Vertices.push_back(video::S3DVertex(p3, {}, {}, {}));
+ m_stars->Vertices.push_back(video::S3DVertex(p, {}, fallback_color, {}));
+ m_stars->Vertices.push_back(video::S3DVertex(p1, {}, fallback_color, {}));
+ m_stars->Vertices.push_back(video::S3DVertex(p2, {}, fallback_color, {}));
+ m_stars->Vertices.push_back(video::S3DVertex(p3, {}, fallback_color, {}));
}
for (u16 i = 0; i < m_star_params.count; i++) {
m_stars->Indices.push_back(i * 4 + 0);