Allegro.cc - Online Community

Allegro.cc Forums » The Depot » OpenGL Fractal noise terrain program with animated water

This thread is locked; no one can reply to it. rss feed Print
OpenGL Fractal noise terrain program with animated water
altalena
Member #13,639
October 2011
avatar

{"name":"607510","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/4\/24b94302ee436254f49316090add167b.png","w":2560,"h":1440,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/4\/24b94302ee436254f49316090add167b"}607510
{"name":"607511","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/3\/d399be5c19768861836068c939ed34f1.png","w":2560,"h":1440,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/3\/d399be5c19768861836068c939ed34f1"}607511
{"name":"607512","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/e\/8edac0351f8cfd7df523b05b464c2f12.png","w":2560,"h":1440,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/e\/8edac0351f8cfd7df523b05b464c2f12"}607512
{"name":"607513","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/c\/ec7852f3fcf997a6837f4b50494d413c.png","w":2560,"h":1440,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/c\/ec7852f3fcf997a6837f4b50494d413c"}607513

Here's the program I've coded. It's got water that moves up and down, with animated textures, and terrain colours that approach a light grey colour as elevation increases. I still have to improve the code to use multiple levels of detail alongside the wrapping toroidal terrain buffer, and put some actual gameplay in it, including in the water areas.

edit: I added source and binary-only archive.

...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270

ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3

Edgar Reynaldo
Member #8,592
May 2007
avatar

Arthur Kalliokoski
Second in Command
February 2005
avatar

You could use a 3D texture that had greys for bare mountain rock above the timberline, and whitish for above the snowline. Since the 3D texture has an entire 2D texture for each height, it wouldn't appear to repeat or tile unless the width and breadth was really small, and the mountains appeared at regular intervals, no matter how far the terrain went. And you're not using lighting that makes the polygons facing the sun brighter?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

altalena
Member #13,639
October 2011
avatar

Just to confirm, it actually worked for Edgar and Arthur? Did the binary run and/or the code compile? The font has to be in the same directory as the executable. The program tries to use the maximum resolution available to the monitor(native resolution for LCD panels). It calculates number of pixels for each video mode and selects the one with the most. Also there's a 'compatibility mode' for CRT monitors with 800x600 resolution.

Shading based on the z-value was the first version of the program. This version uses perlin noise both to generate the heights of the terrain vertices, and the colours of the terrain and water. The height of the terrain vertices does however affect the colour of the terrain, it's used to change the perlin noise to a light grey colour.

As for shading the terrain based on sunlight, I haven't figured out how to make a day-night cycle, but I'd like to put one in, and have volumetric 4d perlin clouds. I have to make the blue sky blend to a sunset and then to the starry sky. This would allow for sun shadows on terrain. Right now, it's just a planet with no sun, drifting through space by itself and heated by a nuclear reaction at the planet's core.

Arthur, regarding 3d textures, do you mean something like how Minecraft had grass textures, but they were different colours instead of all being the same? I think I'd like to texture the polygons, but I want to use point filtering like the Mass Effect 1, or like Half-life 1 in software mode. Maybe I'll just use a level of detail system and sub-divide each pair of isosceles right triangles into a number of sub-triangles, depending on how far they are from the camera. I want it to run just as well on 3840x2160 as on a 800x600 monitor - yeah it's poorly optimized and probably CPU bound.

Sorry if that's too much text. The biggest attachment I uploaded has a video of the game.

Edit: I fixed font and crosshairs scaling. Circle-strafing makes the crosshairs more accurate, I don't know if I should change this.

...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270

ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3

LennyLen
Member #5,313
December 2004
avatar

altalena said:

Just to confirm, it actually worked for Edgar and Arthur? Did the binary run and/or the code compile?

Your provided binaries work perfectly for me. I was also able to build from source, and the resulting program runs, but doesn't seem to be working correctly. For an instant, I get a landscape, then the screen goes black and the only thing visible is the text. Pressing ESC brings up the menu, and when I choose Quit, I get a flash of landscape again as the program exits.

Compiled with gcc 4.7.0

altalena
Member #13,639
October 2011
avatar

I compile it with Code::Blocks and MinGW following the tutorial on the Allegro wiki. At least the binary works.
I'm using allegro 5.0.8.
Here's a new version with distance fog (sort of). I also fixed diagonal movement to make speedruns less complicated. Next up: Making detail textures by subdividing the terrain squares by powers of 4.

...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270

ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3

Arthur Kalliokoski
Second in Command
February 2005
avatar

altalena said:

Did the binary run and/or the code compile?

I didn't notice the link until I saw that a half hour ago. I'm not on windows ATM, but the code compiled and ran, it seemed very laggy, and when I moved forward far enough I found myself below ground level.

By 3D texture, I meant this.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

altalena
Member #13,639
October 2011
avatar

It's laggy because the animated water is resource intensive and the program is not well optimized. I use perlin noise a in it, and although the algorithm I use is probably the fastest one, I use it a lot.

I think when I figure out a day-night cycle I'll use 3d textures for clouds and fog.

I'm running this on a 2600k at 4.1 GHz. I'm getting 12.7 frames per second.

Movement is currently in 'noclip' mode, but I've got a system ready to go from my old program to let the player walk on the terrain. I'll have to modify it to smoothly transition to swimming on the surface, and (similar to noclip mode) swimming underwater.

edit: new version with width 80 instead of 128, now it runs at a smooth 30 fps. I've disabled vsync and set my FPS variable to 60 and 120, but I can't get it to run any faster than 30fps. (Maybe it's my NVidia card.) It did, however, make the waves move faster, as my physics, like in Dark Souls, is tied to FPS.

edit2: finished detail textures

edit3: interpolated large-scale textures, detail textures are still blocky the way i like them - maybe I'll figure out how to alpha-blend even the detail textures with a smaller-scale open-GL repeating procedural noise texture. next: fractal vegetation that fades out 'Shadow of Chernobyl' style, smooth LOD transitions, walking physics, and some basic projectile(and jumping) physics.

...At the briefest instant following creation all the matter of the universe was concentrated in a very small place, no larger than a grain of mustard. The matter at this time was very thin, so intangible, that it did not have real substance. It did have, however, a potential to gain substance and form and to become tangible matter. From the initial concentration of this intangible substance in its minute location, the substance expanded, expanding the universe as it did so. As the expansion progressed, a change in the substance occurred. This initially thin noncorporeal substance took on the tangible aspects of matter as we know it. From this initial act of creation, from this ethereally thin pseudosubstance, everything that has existed, or will ever exist, was, is, and will be formed. - the RaMBaN, 1194 - 1270

ג וּשְׁאַבְתֶּם-מַיִם, בְּשָׂשׂוֹן, מִמַּעַיְנֵי, הַיְשׁוּעָה. - Yeshayahu 12:3

Go to: