OpenGL 3D Game Tutorial 28: Day/Night

preview_player
Показать описание
LWJGL tutorial series on how to create a 3D Java game with OpenGL!

More skybox work this week, as we implement a day/night cycle.

Skybox Night Textures:

Day/Night System Example Code:

End of video music- Kai Engel, "Waking Stars":
Рекомендации по теме
Комментарии
Автор

Nice tutorial as always.. :)
I've come up with following day/night cycle code:

int texture1 = texture;
int texture2 = nightTexture;
float blendFactor = * 0.02f + 1;

if(blendFactor < 0) blendFactor = 0;
 
(after that the gl functions)

i've made the formula myself, just trying out with the program GeoGebra where you can see the graphs of formulas.. :) so my day part would start fading in at 6 a.m. (all over the day) and at 20 pm it would be again 100% night.. ^^

Of course you can alter the code, the lower the "0.02" is, the longer is the day part, the "13" stands for the hour with 100% day.. ^^ and the two lines after that make sure that the lowest value would be 0 (the flipped parabola goes under zero)

rcookie
Автор

This stuff is actually so interesting I love it

OCoptimusconvoy
Автор

For anybody wondering a good way to change the fog color, I've found that having a separate variable to 'time' called 'fogTime', which progresses slower * 10), and '%=240' instead of 24000... and then (using the initial fog color in the tutorial):

if(MasterRenderer.red < 0.5404f){
MasterRenderer.red = MasterRenderer.red + ((0.5404f / 3000.0f) * (fogTime - 50));
}
if(MasterRenderer.green < 0.62f){
MasterRenderer.green = MasterRenderer.green + ((0.62f / 3000.0f) * (fogTime - 50));
}
if(MasterRenderer.blue < 0.69f){
MasterRenderer.blue = MasterRenderer.blue + ((0.69f / 3000.0f) * (fogTime - 50));
}

and just the opposite transitioning to night, testing if > 0 and then fogTime - 210 instead of 50, or whatever matches the system you have.

somethingtojenga
Автор

Whaaaat :o
You accelarated the coding footage and did post commentary? I honestly tried to keep up with your coding speed while rushing through this inanely well made tutorial series.
My fingers hurt now :D

Keep being as awesome!

supperEisMan
Автор

If anyone is having problem with all the screen being fogged when using a cube model!
You need to do this in the vert shader:
vTextureCoords = position * 1000.f; // Scale up the texture coords
to make the fog works because the model is not going to be 500 SIZE like in the code

kafkaphoenix
Автор

Thank you for this share.

The way you descripe how stuff works is pretty nice.

Keep up the good work.

Myrinia
Автор

Looks really funking cool bra. I like the night and stars.

eagletonedward
Автор

If I may make a suggestion, it could be cool to have like a challenge at the end of each of these videos. At the end of each video, you could ask "How would you do this?" and you could pick the best one on the next video. Not only would people be challenged to think more about their learning, they might end up even writing some of your tutorial for you! For example, many times, you say something along the lines of, "I'm not going to cover that in the video, you should be able to implement that."  (For example, multiple terrains on the video about terrains, or multiple lights on the video about lights, first person camera on the video about third person, etc.)

chrismailloux
Автор

Edit: That looks pretty darn good for such a simple addition! Very much looking forward to the next few tutorials!

Darn my interwebs won't let me watch the video!! D:

ExemptAK
Автор

Another great tutorial. My original goal was being able to place a character in a 3d world so your tutorials far exceed that. I have a C++ implementation for normal mapping, going to try writing for java in this rendering engine. Thanks TM

gilleyman
Автор

I absolutely love your work. It great to learn and follow your every code. Please continue the series. I love it!
Josh - From Australia

Gards
Автор

Still waiting for those collision and multiplayer tutorials ;)

Hopsonn
Автор

I believe you can achieve the same exact transition from day to night sky with essentially one function call like so:

blendFactor = (float) ((float)

keeping constant:
texture1 = nightTextureID;
texture2 = dayTextureID;

and adding a variable

float delay;
delay = 100;// this is a good transition speed.

What's nice about this is that it's also easy to implement in the MainGameLoop to modulate the sun's intensity, synchronized with the skybox's cubemap texture blend intensity.

ryklin
Автор

Would love to see text rendering tutorial next! Also great video as always!

Volken
Автор

Yesterday I was like damn... no more stuff and then you upload overnight ;D
BTW, on the topic of terrain generation, I managed to make a system where the terrain is randomly generated. I could send you some code if you would be interested implementing it in your game, it is based of the system you use currently so it wouldn't be too hard. For anyone wondering, it uses Perlin Noise!

TheKidReturnsGaming
Автор

Great as usual. :)

Mini non-related to the video rant: I hate YouTube getting longer ads. I like to support people I watch on YouTube by watching ads/letting them play, but when they are nearly 4 minutes long it gets hard. :'(

ShaneRob
Автор

Yet another helpful tutorial! Next week, if I might make a suggestion, can you start some simple lens flares?

Connorbub
Автор

I'll be waiting for particles tutorial.

HobokerDev
Автор

I'm able to place objects into the 3D world by using a ray picking method. Can't wait for rendering text

eagletonedward
Автор

Please do collision before Multiplayer. Multiplayer is easy, collision is hard.

JoeHOT