mirror of https://github.com/minetest/minetest.git
Textureable sun and moon. Use tonemaps to tint both.
This commit is contained in:
parent
382357d61c
commit
fe194e4833
141
src/sky.cpp
141
src/sky.cpp
|
@ -37,14 +37,24 @@ Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id):
|
|||
m_materials[0] = mat;
|
||||
|
||||
m_materials[1] = mat;
|
||||
//m_materials[1].MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
|
||||
m_materials[1].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||
|
||||
m_materials[2] = mat;
|
||||
m_materials[2].setTexture(0, mgr->getVideoDriver()->getTexture(
|
||||
getTexturePath("sunrisebg.png").c_str()));
|
||||
m_materials[2].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||
//m_materials[2].MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
|
||||
|
||||
m_materials[3] = mat;
|
||||
m_materials[3].Lighting = true;
|
||||
m_materials[3].setTexture(0, mgr->getVideoDriver()->getTexture(
|
||||
getTexturePath("sun.png").c_str()));
|
||||
m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||
|
||||
m_materials[4] = mat;
|
||||
m_materials[4].Lighting = true;
|
||||
m_materials[4].setTexture(0, mgr->getVideoDriver()->getTexture(
|
||||
getTexturePath("moon.png").c_str()));
|
||||
m_materials[4].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||
|
||||
for(u32 i=0; i<SKY_STAR_COUNT; i++){
|
||||
m_stars[i] = v3f(
|
||||
|
@ -54,6 +64,10 @@ Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id):
|
|||
);
|
||||
m_stars[i].normalize();
|
||||
}
|
||||
m_sun_tonemap = mgr->getVideoDriver()->getTexture(
|
||||
getTexturePath("sun_tonemap.png").c_str());
|
||||
m_moon_tonemap = mgr->getVideoDriver()->getTexture(
|
||||
getTexturePath("moon_tonemap.png").c_str());
|
||||
}
|
||||
|
||||
void Sky::OnRegisterSceneNode()
|
||||
|
@ -95,19 +109,8 @@ void Sky::render()
|
|||
if(m_sunlight_seen)
|
||||
{
|
||||
float sunsize = 0.07;
|
||||
video::SColorf suncolor_f(1, 1, 0, 1);
|
||||
suncolor_f.r = 1;
|
||||
suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.7+m_time_brightness*(0.5)));
|
||||
suncolor_f.b = MYMAX(0.0, m_brightness*0.95);
|
||||
video::SColorf suncolor2_f(1, 1, 1, 1);
|
||||
suncolor_f.r = 1;
|
||||
suncolor_f.g = MYMAX(0.3, MYMIN(1.0, 0.85+m_time_brightness*(0.5)));
|
||||
suncolor_f.b = MYMAX(0.0, m_brightness);
|
||||
|
||||
float moonsize = 0.04;
|
||||
video::SColorf mooncolor_f(0.50, 0.57, 0.65, 1);
|
||||
video::SColorf mooncolor2_f(0.85, 0.875, 0.9, 1);
|
||||
|
||||
|
||||
float nightlength = 0.415;
|
||||
float wn = nightlength / 2;
|
||||
float wicked_time_of_day = 0;
|
||||
|
@ -120,22 +123,29 @@ void Sky::render()
|
|||
/*std::cerr<<"time_of_day="<<m_time_of_day<<" -> "
|
||||
<<"wicked_time_of_day="<<wicked_time_of_day<<std::endl;*/
|
||||
|
||||
video::SColor suncolor = suncolor_f.toSColor();
|
||||
video::SColor suncolor2 = suncolor2_f.toSColor();
|
||||
video::SColor mooncolor = mooncolor_f.toSColor();
|
||||
video::SColor mooncolor2 = mooncolor2_f.toSColor();
|
||||
|
||||
float offset=(1.0-fabs(sin((m_time_of_day - 0.5)*irr::core::PI)))*511;
|
||||
u8 * texels = (u8 *)m_sun_tonemap->lock();
|
||||
video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
|
||||
video::SColor suncolor (255,texel->getRed(),texel->getGreen(), texel->getBlue());
|
||||
m_sun_tonemap->unlock();
|
||||
m_materials[3].EmissiveColor=suncolor;
|
||||
texels = (u8 *)m_moon_tonemap->lock();
|
||||
texel = (video::SColor *)(texels + (u32)offset * 4);
|
||||
video::SColor mooncolor (255,texel->getRed(),texel->getGreen(), texel->getBlue());
|
||||
m_moon_tonemap->unlock();
|
||||
m_materials[4].EmissiveColor=mooncolor;
|
||||
|
||||
const f32 t = 1.0f;
|
||||
const f32 o = 0.0f;
|
||||
static const u16 indices[4] = {0,1,2,3};
|
||||
video::S3DVertex vertices[4];
|
||||
|
||||
|
||||
driver->setMaterial(m_materials[1]);
|
||||
|
||||
|
||||
//video::SColor cloudyfogcolor(255,255,255,255);
|
||||
video::SColor cloudyfogcolor = m_bgcolor;
|
||||
//video::SColor cloudyfogcolor = m_bgcolor.getInterpolated(m_skycolor, 0.5);
|
||||
|
||||
|
||||
// Draw far cloudy fog thing
|
||||
for(u32 j=0; j<4; j++)
|
||||
{
|
||||
|
@ -209,14 +219,12 @@ void Sky::render()
|
|||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
}
|
||||
|
||||
driver->setMaterial(m_materials[1]);
|
||||
|
||||
// Draw sun
|
||||
driver->setMaterial(m_materials[3]);
|
||||
if(wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85)
|
||||
{
|
||||
float d = sunsize * 1.7;
|
||||
video::SColor c = suncolor;
|
||||
c.setAlpha(0.05*255);
|
||||
video::SColor c(0,0,0,0);
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
|
||||
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
|
||||
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
|
||||
|
@ -227,51 +235,14 @@ void Sky::render()
|
|||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
|
||||
d = sunsize * 1.2;
|
||||
c = suncolor;
|
||||
c.setAlpha(0.15*255);
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
|
||||
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
|
||||
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
|
||||
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
|
||||
for(u32 i=0; i<4; i++){
|
||||
// Switch from -Z (south) to +X (east)
|
||||
vertices[i].Pos.rotateXZBy(90);
|
||||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
|
||||
d = sunsize;
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor, t, t);
|
||||
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor, o, t);
|
||||
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor, o, o);
|
||||
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor, t, o);
|
||||
for(u32 i=0; i<4; i++){
|
||||
// Switch from -Z (south) to +X (east)
|
||||
vertices[i].Pos.rotateXZBy(90);
|
||||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
|
||||
d = sunsize * 0.7;
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, suncolor2, t, t);
|
||||
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, suncolor2, o, t);
|
||||
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, suncolor2, o, o);
|
||||
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, suncolor2, t, o);
|
||||
for(u32 i=0; i<4; i++){
|
||||
// Switch from -Z (south) to +X (east)
|
||||
vertices[i].Pos.rotateXZBy(90);
|
||||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
}
|
||||
// Draw moon
|
||||
driver->setMaterial(m_materials[4]);
|
||||
if(wicked_time_of_day < 0.3 || wicked_time_of_day > 0.7)
|
||||
{
|
||||
float d = moonsize * 1.9;
|
||||
video::SColor c = mooncolor;
|
||||
c.setAlpha(0.05*255);
|
||||
video::SColor c(0,0,0,0);
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
|
||||
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
|
||||
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
|
||||
|
@ -282,45 +253,9 @@ void Sky::render()
|
|||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
|
||||
d = moonsize * 1.3;
|
||||
c = mooncolor;
|
||||
c.setAlpha(0.15*255);
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, c, t, t);
|
||||
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, c, o, t);
|
||||
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, c, o, o);
|
||||
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, c, t, o);
|
||||
for(u32 i=0; i<4; i++){
|
||||
// Switch from -Z (south) to -X (west)
|
||||
vertices[i].Pos.rotateXZBy(-90);
|
||||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
|
||||
d = moonsize;
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor, t, t);
|
||||
vertices[1] = video::S3DVertex( d,-d,-1, 0,0,1, mooncolor, o, t);
|
||||
vertices[2] = video::S3DVertex( d, d,-1, 0,0,1, mooncolor, o, o);
|
||||
vertices[3] = video::S3DVertex(-d, d,-1, 0,0,1, mooncolor, t, o);
|
||||
for(u32 i=0; i<4; i++){
|
||||
// Switch from -Z (south) to -X (west)
|
||||
vertices[i].Pos.rotateXZBy(-90);
|
||||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
|
||||
float d2 = moonsize * 0.6;
|
||||
vertices[0] = video::S3DVertex(-d,-d,-1, 0,0,1, mooncolor2, t, t);
|
||||
vertices[1] = video::S3DVertex( d2,-d,-1, 0,0,1, mooncolor2, o, t);
|
||||
vertices[2] = video::S3DVertex( d2, d2,-1, 0,0,1, mooncolor2, o, o);
|
||||
vertices[3] = video::S3DVertex(-d, d2,-1, 0,0,1, mooncolor2, t, o);
|
||||
for(u32 i=0; i<4; i++){
|
||||
// Switch from -Z (south) to -X (west)
|
||||
vertices[i].Pos.rotateXZBy(-90);
|
||||
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
|
||||
}
|
||||
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
|
||||
}
|
||||
|
||||
driver->setMaterial(m_materials[1]);
|
||||
// Stars
|
||||
do{
|
||||
float starbrightness = MYMAX(0, MYMIN(1,
|
||||
|
|
|
@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#ifndef SKY_HEADER
|
||||
#define SKY_HEADER
|
||||
|
||||
#define SKY_MATERIAL_COUNT 3
|
||||
#define SKY_MATERIAL_COUNT 5
|
||||
#define SKY_STAR_COUNT 200
|
||||
|
||||
// Skybox, rendered with zbuffer turned off, before all other nodes.
|
||||
|
@ -78,6 +78,8 @@ private:
|
|||
v3f m_stars[SKY_STAR_COUNT];
|
||||
u16 m_star_indices[SKY_STAR_COUNT*4];
|
||||
video::S3DVertex m_star_vertices[SKY_STAR_COUNT*4];
|
||||
video::ITexture* m_sun_tonemap;
|
||||
video::ITexture* m_moon_tonemap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 286 B |
Binary file not shown.
After Width: | Height: | Size: 220 B |
Binary file not shown.
After Width: | Height: | Size: 335 B |
Binary file not shown.
After Width: | Height: | Size: 209 B |
Loading…
Reference in New Issue