Draw all horizons and sky base, in front of stars (#7932)

Move star draw to before sun glow texture draw and before sun draw,
not currently essential but the logical order. Will be necessary if
a 'no far ground' option is added, to draw stars behind the sun.
master
Paramat 2018-12-06 03:56:35 +00:00 committed by GitHub
parent 56f22bfa5c
commit 08884d258b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 102 additions and 98 deletions

View File

@ -228,7 +228,7 @@ void Sky::render()
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
// Draw far cloudy fog thing
// Draw far cloudy fog thing at and below all horizons
for (u32 j = 0; j < 4; j++) {
video::SColor c = cloudyfogcolor;
vertices[0] = video::S3DVertex(-1, -1.0, -1, 0, 0, 1, c, t, t);
@ -252,22 +252,96 @@ void Sky::render()
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
// Draw bottom far cloudy fog thing
video::SColor c = cloudyfogcolor;
vertices[0] = video::S3DVertex(-1, -1.0, -1, 0, 1, 0, c, t, t);
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);
// If sun, moon and stars are (temporarily) disabled, abort here
if (!m_bodies_visible)
return;
driver->setMaterial(m_materials[2]);
// Draw stars before sun and moon to be behind them
do {
driver->setMaterial(m_materials[1]);
// Tune values so that stars first appear just after the sun
// disappears over the horizon, and disappear just before the sun
// appears over the horizon.
// Also tune so that stars are at full brightness from time 20000 to
// time 4000.
float starbrightness = MYMAX(0, MYMIN(1,
(0.25 - fabs(wicked_time_of_day < 0.5 ?
wicked_time_of_day : (1.0 - wicked_time_of_day))) * 20));
float f = starbrightness;
float d = 0.007 / 2;
video::SColor starcolor(255, f * 90, f * 90, f * 90);
// Stars are only drawn when brighter than skycolor
if (starcolor.getBlue() < m_skycolor.getBlue())
break;
#ifdef __ANDROID__
u16 indices[SKY_STAR_COUNT * 3];
video::S3DVertex vertices[SKY_STAR_COUNT * 3];
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
indices[i * 3 + 0] = i * 3 + 0;
indices[i * 3 + 1] = i * 3 + 1;
indices[i * 3 + 2] = i * 3 + 2;
v3f r = m_stars[i];
core::CMatrix4<f32> a;
a.buildRotateFromTo(v3f(0, 1, 0), r);
v3f p = v3f(-d, 1, -d);
v3f p1 = v3f(d, 1, 0);
v3f p2 = v3f(-d, 1, d);
a.rotateVect(p);
a.rotateVect(p1);
a.rotateVect(p2);
p.rotateXYBy(wicked_time_of_day * 360 - 90);
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
vertices[i * 3 + 0].Pos = p;
vertices[i * 3 + 0].Color = starcolor;
vertices[i * 3 + 1].Pos = p1;
vertices[i * 3 + 1].Color = starcolor;
vertices[i * 3 + 2].Pos = p2;
vertices[i * 3 + 2].Color = starcolor;
}
driver->drawIndexedTriangleList(vertices, SKY_STAR_COUNT * 3,
indices, SKY_STAR_COUNT);
#else
u16 indices[SKY_STAR_COUNT * 4];
video::S3DVertex vertices[SKY_STAR_COUNT * 4];
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
indices[i * 4 + 0] = i * 4 + 0;
indices[i * 4 + 1] = i * 4 + 1;
indices[i * 4 + 2] = i * 4 + 2;
indices[i * 4 + 3] = i * 4 + 3;
v3f r = m_stars[i];
core::CMatrix4<f32> a;
a.buildRotateFromTo(v3f(0, 1, 0), r);
v3f p = v3f(-d, 1, -d);
v3f p1 = v3f( d, 1, -d);
v3f p2 = v3f( d, 1, d);
v3f p3 = v3f(-d, 1, d);
a.rotateVect(p);
a.rotateVect(p1);
a.rotateVect(p2);
a.rotateVect(p3);
p.rotateXYBy(wicked_time_of_day * 360 - 90);
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
p3.rotateXYBy(wicked_time_of_day * 360 - 90);
vertices[i * 4 + 0].Pos = p;
vertices[i * 4 + 0].Color = starcolor;
vertices[i * 4 + 1].Pos = p1;
vertices[i * 4 + 1].Color = starcolor;
vertices[i * 4 + 2].Pos = p2;
vertices[i * 4 + 2].Color = starcolor;
vertices[i * 4 + 3].Pos = p3;
vertices[i * 4 + 3].Color = starcolor;
}
driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT * 4,
indices, SKY_STAR_COUNT, video::EVT_STANDARD,
scene::EPT_QUADS, video::EIT_16BIT);
#endif
} while(false);
// Draw sunrise/sunset horizon glow texture (textures/base/pack/sunrisebg.png)
{
driver->setMaterial(m_materials[2]);
float mid1 = 0.25;
float mid = wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1);
float a_ = 1.0f - std::fabs(wicked_time_of_day - mid) * 35.0f;
@ -366,89 +440,6 @@ void Sky::render()
}
}
// Draw stars before moon to be behind the moon
do {
driver->setMaterial(m_materials[1]);
// Tune values so that stars first appear just after the sun
// disappears over the horizon, and disappear just before the sun
// appears over the horizon.
// Also tune so that stars are at full brightness from time 20000 to
// time 4000.
float starbrightness = MYMAX(0, MYMIN(1,
(0.25 - fabs(wicked_time_of_day < 0.5 ?
wicked_time_of_day : (1.0 - wicked_time_of_day))) * 20));
float f = starbrightness;
float d = 0.007 / 2;
video::SColor starcolor(255, f * 90, f * 90, f * 90);
// Stars are only drawn when brighter than skycolor
if (starcolor.getBlue() < m_skycolor.getBlue())
break;
#ifdef __ANDROID__
u16 indices[SKY_STAR_COUNT * 3];
video::S3DVertex vertices[SKY_STAR_COUNT * 3];
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
indices[i * 3 + 0] = i * 3 + 0;
indices[i * 3 + 1] = i * 3 + 1;
indices[i * 3 + 2] = i * 3 + 2;
v3f r = m_stars[i];
core::CMatrix4<f32> a;
a.buildRotateFromTo(v3f(0, 1, 0), r);
v3f p = v3f(-d, 1, -d);
v3f p1 = v3f(d, 1, 0);
v3f p2 = v3f(-d, 1, d);
a.rotateVect(p);
a.rotateVect(p1);
a.rotateVect(p2);
p.rotateXYBy(wicked_time_of_day * 360 - 90);
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
vertices[i * 3 + 0].Pos = p;
vertices[i * 3 + 0].Color = starcolor;
vertices[i * 3 + 1].Pos = p1;
vertices[i * 3 + 1].Color = starcolor;
vertices[i * 3 + 2].Pos = p2;
vertices[i * 3 + 2].Color = starcolor;
}
driver->drawIndexedTriangleList(vertices, SKY_STAR_COUNT * 3,
indices, SKY_STAR_COUNT);
#else
u16 indices[SKY_STAR_COUNT * 4];
video::S3DVertex vertices[SKY_STAR_COUNT * 4];
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
indices[i * 4 + 0] = i * 4 + 0;
indices[i * 4 + 1] = i * 4 + 1;
indices[i * 4 + 2] = i * 4 + 2;
indices[i * 4 + 3] = i * 4 + 3;
v3f r = m_stars[i];
core::CMatrix4<f32> a;
a.buildRotateFromTo(v3f(0, 1, 0), r);
v3f p = v3f(-d, 1, -d);
v3f p1 = v3f( d, 1, -d);
v3f p2 = v3f( d, 1, d);
v3f p3 = v3f(-d, 1, d);
a.rotateVect(p);
a.rotateVect(p1);
a.rotateVect(p2);
a.rotateVect(p3);
p.rotateXYBy(wicked_time_of_day * 360 - 90);
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
p3.rotateXYBy(wicked_time_of_day * 360 - 90);
vertices[i * 4 + 0].Pos = p;
vertices[i * 4 + 0].Color = starcolor;
vertices[i * 4 + 1].Pos = p1;
vertices[i * 4 + 1].Color = starcolor;
vertices[i * 4 + 2].Pos = p2;
vertices[i * 4 + 2].Color = starcolor;
vertices[i * 4 + 3].Pos = p3;
vertices[i * 4 + 3].Color = starcolor;
}
driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT * 4,
indices, SKY_STAR_COUNT, video::EVT_STANDARD,
scene::EPT_QUADS, video::EIT_16BIT);
#endif
} while(false);
// Draw moon
if (wicked_time_of_day < 0.3 || wicked_time_of_day > 0.7) {
if (!m_moon_texture) {
@ -525,27 +516,40 @@ void Sky::render()
}
}
// Draw far cloudy fog thing below East and West horizons.
// These act as horizons that the sun and moon rise and set over.
// Draw far cloudy fog thing below all horizons in front of sun, moon
// and stars.
driver->setMaterial(m_materials[1]);
for (u32 j = 0; j < 2; j++) {
for (u32 j = 0; j < 4; j++) {
video::SColor c = cloudyfogcolor;
vertices[0] = video::S3DVertex(-1, -1.0, -1, 0, 0, 1, c, t, t);
vertices[1] = video::S3DVertex( 1, -1.0, -1, 0, 0, 1, c, o, t);
vertices[2] = video::S3DVertex( 1, -0.02, -1, 0, 0, 1, c, o, o);
vertices[3] = video::S3DVertex(-1, -0.02, -1, 0, 0, 1, c, t, o);
for (video::S3DVertex &vertex : vertices) {
//if (wicked_time_of_day < 0.5)
if (j == 0)
// Don't switch
{}
else if (j == 1)
// Switch from -Z (south) to +X (east)
vertex.Pos.rotateXZBy(90);
else
else if (j == 2)
// Switch from -Z (south) to -X (west)
vertex.Pos.rotateXZBy(-90);
else
// Switch from -Z (south) to +Z (north)
vertex.Pos.rotateXZBy(-180);
}
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
}
// Draw bottom far cloudy fog thing in front of sun, moon and stars
video::SColor c = cloudyfogcolor;
vertices[0] = video::S3DVertex(-1, -1.0, -1, 0, 1, 0, c, t, t);
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);
}
}