Skip to content

Commit ce2d33e

Browse files
random-geeksfan5
authored andcommittedSep 27, 2018
Fix stretched stars bug, change render order
1 parent 4a2a112 commit ce2d33e

File tree

1 file changed

+77
-76
lines changed

1 file changed

+77
-76
lines changed
 

Diff for: ‎src/sky.cpp

+77-76
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,83 @@ void Sky::render()
290290
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
291291
}
292292

293+
// Draw stars
294+
do {
295+
driver->setMaterial(m_materials[1]);
296+
float starbrightness = MYMAX(0, MYMIN(1,
297+
(0.285 - fabs(wicked_time_of_day < 0.5 ?
298+
wicked_time_of_day : (1.0 - wicked_time_of_day))) * 10));
299+
float f = starbrightness;
300+
float d = 0.007/2;
301+
video::SColor starcolor(255, f * 90, f * 90, f * 90);
302+
if (starcolor.getBlue() < m_skycolor.getBlue())
303+
break;
304+
#ifdef __ANDROID__
305+
u16 indices[SKY_STAR_COUNT * 3];
306+
video::S3DVertex vertices[SKY_STAR_COUNT * 3];
307+
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
308+
indices[i * 3 + 0] = i * 3 + 0;
309+
indices[i * 3 + 1] = i * 3 + 1;
310+
indices[i * 3 + 2] = i * 3 + 2;
311+
v3f r = m_stars[i];
312+
core::CMatrix4<f32> a;
313+
a.buildRotateFromTo(v3f(0, 1, 0), r);
314+
v3f p = v3f(-d, 1, -d);
315+
v3f p1 = v3f(d, 1, 0);
316+
v3f p2 = v3f(-d, 1, d);
317+
a.rotateVect(p);
318+
a.rotateVect(p1);
319+
a.rotateVect(p2);
320+
p.rotateXYBy(wicked_time_of_day * 360 - 90);
321+
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
322+
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
323+
vertices[i * 3 + 0].Pos = p;
324+
vertices[i * 3 + 0].Color = starcolor;
325+
vertices[i * 3 + 1].Pos = p1;
326+
vertices[i * 3 + 1].Color = starcolor;
327+
vertices[i * 3 + 2].Pos = p2;
328+
vertices[i * 3 + 2].Color = starcolor;
329+
}
330+
driver->drawIndexedTriangleList(vertices, SKY_STAR_COUNT * 3,
331+
indices, SKY_STAR_COUNT);
332+
#else
333+
u16 indices[SKY_STAR_COUNT * 4];
334+
video::S3DVertex vertices[SKY_STAR_COUNT * 4];
335+
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
336+
indices[i * 4 + 0] = i * 4 + 0;
337+
indices[i * 4 + 1] = i * 4 + 1;
338+
indices[i * 4 + 2] = i * 4 + 2;
339+
indices[i * 4 + 3] = i * 4 + 3;
340+
v3f r = m_stars[i];
341+
core::CMatrix4<f32> a;
342+
a.buildRotateFromTo(v3f(0, 1, 0), r);
343+
v3f p = v3f(-d, 1, -d);
344+
v3f p1 = v3f( d, 1, -d);
345+
v3f p2 = v3f( d, 1, d);
346+
v3f p3 = v3f(-d, 1, d);
347+
a.rotateVect(p);
348+
a.rotateVect(p1);
349+
a.rotateVect(p2);
350+
a.rotateVect(p3);
351+
p.rotateXYBy(wicked_time_of_day * 360 - 90);
352+
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
353+
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
354+
p3.rotateXYBy(wicked_time_of_day * 360 - 90);
355+
vertices[i * 4 + 0].Pos = p;
356+
vertices[i * 4 + 0].Color = starcolor;
357+
vertices[i * 4 + 1].Pos = p1;
358+
vertices[i * 4 + 1].Color = starcolor;
359+
vertices[i * 4 + 2].Pos = p2;
360+
vertices[i * 4 + 2].Color = starcolor;
361+
vertices[i * 4 + 3].Pos = p3;
362+
vertices[i * 4 + 3].Color = starcolor;
363+
}
364+
driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT * 4,
365+
indices, SKY_STAR_COUNT, video::EVT_STANDARD,
366+
scene::EPT_QUADS, video::EIT_16BIT);
367+
#endif
368+
} while(false);
369+
293370
// Draw sun
294371
if (wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85) {
295372
if (!m_sun_texture) {
@@ -442,82 +519,6 @@ void Sky::render()
442519
}
443520
}
444521

445-
// Draw stars
446-
do {
447-
driver->setMaterial(m_materials[1]);
448-
float starbrightness = MYMAX(0, MYMIN(1,
449-
(0.285 - fabs(wicked_time_of_day < 0.5 ?
450-
wicked_time_of_day : (1.0 - wicked_time_of_day))) * 10));
451-
float f = starbrightness;
452-
float d = 0.007;
453-
video::SColor starcolor(255, f * 90, f * 90, f * 90);
454-
if (starcolor.getBlue() < m_skycolor.getBlue())
455-
break;
456-
#ifdef __ANDROID__
457-
u16 indices[SKY_STAR_COUNT * 3];
458-
video::S3DVertex vertices[SKY_STAR_COUNT * 3];
459-
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
460-
indices[i * 3 + 0] = i * 3 + 0;
461-
indices[i * 3 + 1] = i * 3 + 1;
462-
indices[i * 3 + 2] = i * 3 + 2;
463-
v3f p = m_stars[i];
464-
core::CMatrix4<f32> a;
465-
a.buildRotateFromTo(v3f(0, 1, 0), v3f(d, 1 + d, -d / 2));
466-
v3f p1 = p;
467-
a.rotateVect(p1);
468-
a.buildRotateFromTo(v3f(0, 1, 0), v3f(d, 1 - d, d / 2));
469-
v3f p2 = p;
470-
a.rotateVect(p2);
471-
p.rotateXYBy(wicked_time_of_day * 360 - 90);
472-
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
473-
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
474-
vertices[i * 3 + 0].Pos = p;
475-
vertices[i * 3 + 0].Color = starcolor;
476-
vertices[i * 3 + 1].Pos = p1;
477-
vertices[i * 3 + 1].Color = starcolor;
478-
vertices[i * 3 + 2].Pos = p2;
479-
vertices[i * 3 + 2].Color = starcolor;
480-
}
481-
driver->drawIndexedTriangleList(vertices, SKY_STAR_COUNT * 3,
482-
indices, SKY_STAR_COUNT);
483-
#else
484-
u16 indices[SKY_STAR_COUNT * 4];
485-
video::S3DVertex vertices[SKY_STAR_COUNT * 4];
486-
for (u32 i = 0; i < SKY_STAR_COUNT; i++) {
487-
indices[i * 4 + 0] = i * 4 + 0;
488-
indices[i * 4 + 1] = i * 4 + 1;
489-
indices[i * 4 + 2] = i * 4 + 2;
490-
indices[i * 4 + 3] = i * 4 + 3;
491-
v3f p = m_stars[i];
492-
core::CMatrix4<f32> a;
493-
a.buildRotateFromTo(v3f(0, 1, 0), v3f(d, 1 + d / 2, 0));
494-
v3f p1 = p;
495-
a.rotateVect(p1);
496-
a.buildRotateFromTo(v3f(0, 1, 0), v3f(d, 1, d));
497-
v3f p2 = p;
498-
a.rotateVect(p2);
499-
a.buildRotateFromTo(v3f(0, 1, 0), v3f(0, 1 - d / 2, d));
500-
v3f p3 = p;
501-
a.rotateVect(p3);
502-
p.rotateXYBy(wicked_time_of_day * 360 - 90);
503-
p1.rotateXYBy(wicked_time_of_day * 360 - 90);
504-
p2.rotateXYBy(wicked_time_of_day * 360 - 90);
505-
p3.rotateXYBy(wicked_time_of_day * 360 - 90);
506-
vertices[i * 4 + 0].Pos = p;
507-
vertices[i * 4 + 0].Color = starcolor;
508-
vertices[i * 4 + 1].Pos = p1;
509-
vertices[i * 4 + 1].Color = starcolor;
510-
vertices[i * 4 + 2].Pos = p2;
511-
vertices[i * 4 + 2].Color = starcolor;
512-
vertices[i * 4 + 3].Pos = p3;
513-
vertices[i * 4 + 3].Color = starcolor;
514-
}
515-
driver->drawVertexPrimitiveList(vertices, SKY_STAR_COUNT * 4,
516-
indices, SKY_STAR_COUNT, video::EVT_STANDARD,
517-
scene::EPT_QUADS, video::EIT_16BIT);
518-
#endif
519-
} while(false);
520-
521522
// Draw far cloudy fog thing below east and west horizons
522523
for (u32 j = 0; j < 2; j++) {
523524
video::SColor c = cloudyfogcolor;

0 commit comments

Comments
 (0)
Please sign in to comment.