project-navigation
Personal tools

Author Topic: Improved 3D Geoscape Rendering [was: Nightime city lights in 3D geoscape]  (Read 71298 times)

Offline arisian

  • Rookie
  • ***
  • Posts: 91
    • View Profile
So, the 2D geoscape has these nice lights that show up on the "night" portion of the globe.  They're nice for several reasons, ranging from "it's pretty" to "it improves immersion" to "it marks the population centers" to "it helps you figure out where stuff is in the dark" (helping to counteract the issues with low ambient lighting).

The method used for the 2D geoscape isn't directly applicable to the 3D version, but I took a look at it this afternoon and it's fairly straightforward to render the lights as emissive sources, which makes them glow nicely at night.  The only trouble with this is that they don't "turn off" during the day, though they're a lot less obvious during the day because of the lower contrast with the background.

I've attached a diff (based on the current trunk; it's the output of `svn diff` run in src/client/ ) of the simple changes I made; I make no claim that my little hack is the best way to implement this feature, but it was the quickest way for me to get nightlights.  I've also attached the image that I used as an emissive light texture; it's basically just a thresholded version of the standard nightime geoscape texture.

If someone who's actually familiar with the overall code structure wants to add this feature properly (eg. as an option in the menu, or as a selectable "overlay" like the nation borders or radar overlays, etc.) feel free to use it; if the devs don't think this feature is something they want, that's fine too, I'll just keep it around for my personal use.
« Last Edit: March 23, 2010, 08:41:35 pm by Mattn »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Nightime city lights in 3D geoscape
« Reply #1 on: March 18, 2010, 08:20:22 am »
applied this patch to trunk - thanks. if you know opengl and have the time and the interest... we are searching for new coders and could really need some opengl coders, too.

Offline MCR

  • PHALANX veteran
  • ******
  • Posts: 1244
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #2 on: March 18, 2010, 09:11:49 am »
Great idea, arisian & thanx 4 helping here also. 8)

Had the same idea already written down on paper (I love glowing lights  ;)), but no knowledge about implementing it  ;)
Great to see improvements happening on the geoscape also...

My feature requests regarding graphical upgrades to the geoscape would be also this:

- We could add a normalmap to the geoscape also to enhance visual quality. The engine seems to be very capable of great bump-mapping, so this should not be a big problem, but for me it is  ;). Mattn, any ideas !?

- This idea is actually stolen from here: http://colabti.org/irclogger/irclogger_log/ufoai?date=2010-03-16
Look @ 15:05. (The discussion starts 14:42.)
So it is basically the idea of reflecting the season-change onto the globe  8)
I think this is a great idea & would enhance immersion into the game for the player big time !!!

We do not need to use 12 different pictures for each month, but could blend 4 pictures, although I do not know if this would be a technical problem when we have to blend day/night & seasons & add a bumpmap to all of this.
Mattn, I think your technical expertise is needed once again here  ;)
« Last Edit: March 19, 2010, 08:13:53 am by MCR »

Offline arisian

  • Rookie
  • ***
  • Posts: 91
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #3 on: March 18, 2010, 07:15:55 pm »
Actually, this the first time I'd done any openGL coding (I'm a fairly experienced C/C++ coder, and I've done a decent amount of graphics work, just not with openGL).  That's why it took me all afternoon; I was learning the relevant parts of openGL as I went :)

I'd also like to state again that the patch I posted is a somewhat brittle way of implementing the feature, and has the downside of making the cities look white-ish during the day (ie. everyone keeps their lights on 24/7).

Anyway, I've certainly got interest; I like the ideas behind ufoai a lot.  Time, on the other hand, is not something I'm exactly swimming in.  I might be able to do small things from time to time, but I'm just not in a place where I can claim I'll be reliable in doing things in a timely fashion.

The other trouble is that the things that I'd most like to fix/improve about the current development version are things which would require re-writing substantial portions of the codebase (for example, .50 caliber sniper rounds bouncing off rice paper dividers, or allowing missions to be fought in pseudo-realtime a la the UFO:After* games as well as the turn-based mode.  I love turn-based, but it makes thing so darned *slow*, especially given the frequency of terror missions.  I find myself using the "auto-resolve" frequently just because I'm sick of trying to balance good tactics with the desire to explore the map and find the enemy before my hair turns gray).

That said, I may have time to occasionally implement some small feature or other; do you use any formal feature/bug tracking system that I could look at to see what things are awaiting implementation/fixing, or should I just use the wiki? Nevermind, I found the sourceforge tracking systems, though things there seem more like random feature requests than an ordered list of things that need doing.

Also, what's the best way of submitting changes?  I'm currently using SVN anonymously, so I assume I can't do commits that way, and posting patches in the forums seems sub-optimal if I'm going to do this more than once.
« Last Edit: March 18, 2010, 07:29:46 pm by arisian »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Nightime city lights in 3D geoscape
« Reply #4 on: March 18, 2010, 08:42:08 pm »
either use our patch tracker https://sourceforge.net/tracker/?atid=805244&group_id=157793&func=browse or submit one more patch that fits the coding guidelines and i can grant you write access to the svn

about the feature tracker: i know, it's that everyone is posting his ideas, but we have way too little heads and helping hands to implement them. there will be a roadmap after 2.3 is released. but it's not yet carved into stone.

i know the time issue myself, too and i think everyone who is no student anymore knows it, too - but for me ufoai is my obsession ;)

it would be quite cool to welcome you in our team - we could need every helping hand.
« Last Edit: March 18, 2010, 08:45:29 pm by Mattn »

Offline arisian

  • Rookie
  • ***
  • Posts: 91
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #5 on: March 19, 2010, 01:32:54 am »
Hmm, looks like my previous patch didn't follow all the guidelines; I hadn't read them because I wasn't really expecting it to get put into trunk without revision.  It won't be hard to fix though (mostly things like tabs vs. spaces, comment style); I'll try to post a better version tomorrow.

Offline MCR

  • PHALANX veteran
  • ******
  • Posts: 1244
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #6 on: March 19, 2010, 08:19:54 am »
 8) to see you motivated  ;D
& sorry for misspelling your name in my last post (I've corrected it).
I think there is a lot of stuff which could have been done, but cannot by me, because of my lacking programming-skills.
So I try to improve this project on other fronts  ;), but it is really great to see another programmer here.


Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Nightime city lights in 3D geoscape
« Reply #7 on: March 19, 2010, 01:17:35 pm »
Hmm, looks like my previous patch didn't follow all the guidelines; I hadn't read them because I wasn't really expecting it to get put into trunk without revision.  It won't be hard to fix though (mostly things like tabs vs. spaces, comment style); I'll try to post a better version tomorrow.

you don't have to - as your patch is already in the svn... ;)

Offline MCR

  • PHALANX veteran
  • ******
  • Posts: 1244
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #8 on: March 21, 2010, 06:42:37 pm »
I like the lights  ;D

Offline arisian

  • Rookie
  • ***
  • Posts: 91
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #9 on: March 23, 2010, 03:08:00 pm »
I decided that if I'm actually going to be the one to implement this feature, I want to do it right, rather than just the proof-of-concept I posted before, so this is a new, vastly improved version.

Now the city lights only show up where it's actually nighttime, and are prettier to boot.  Also, I've implemented bump-mapping and specularity-mapping and texture-blending as well.  This means that the 3D geoscape now has topographic rendering with lightsource-dependent shadows, and sunlight reflects off the water.  It also means that the visuals now correctly represent seasonal changes with smooth, seamless changes over the course of the year.

These new rendering features are all handled by a GSLS shader program, but the older rendering methods all still work the way they always did (ie. there's no change to the way that nation overlays and the like appear).  There is also a new option in the "options->game" menu that lets you switch between the new globe renderer and the old one (though you need to restart the program after switching the option before it will take effect).

This is particularly important because the new version has higher requirements than the old one.  If your graphics card doesn't have the features required, it will automatically fall back on the old rendering system, but I think that any reasonably modern graphics card should work (if anyone has issues, please let me know).  It also requires more system memory, especially if you use the high-res textures.

Speaking of textures, I've been using higher resolution images for the globe surface, which look much crisper and prettier when you zoom all the way in.  The disadvantage is that they are, well, bigger.  This means that they take longer to load into memory, and they take up more memory once loaded.  It takes several extra seconds on my system to bring up the geoscape, with an additional ~3 second pause near the beginning of a new month while it loads the texture for that month.

That said, I can't upload the high res images here because they're ~25Mb a piece, and there are 12 of them.  I have therefore uploaded lower resolution versions so people can actually see the system working, but I really think the high-res versions are prettier; I just don't know what the best way to distribute them is.

The current season system consists of one texture image per month; the images I'm using come from NASA's Blue Marble project (as did the images I started with when making the bump map, city lights, and gloss textures, though those required some modification).  The system blends two textures, one associated with the beginning of the month, and the other associated with the end of the month (ie. the beginning of the following month).  The two textures are combined according to how far through the month it is, so things change slowly and smoothly.  If you want to see it in action, I recommend modifying the campaign.ufo to set the "minimum happiness" to something negative; otherwise, you'll generally loose after just a few months if you don't do anything but watch the globe spin, and you really need to speed things up to the fastest speed and watch for a few months to get the full effect :)

I've attached a diff relative to the current svn, along with a zipfile that contains the new images needed (extremely low-res versions only, I'm afraid, since the forum only  accepts up to 1Mb of attachments; if someone wants to give me svn access so I can upload the high-res versions, my sourceforge username is "arisian"...;)).

Please let me know what you think, or any issues you might have, especially if you experience anything that looks "wrong;" I've only been able to test this on my own system.  It looks very pretty for me, but I'm not 100% confident that it will look the same on other brands of graphics cards (my current one is an nvidia geforce 9800gt).

Offline Kildor

  • Project Artist
  • Captain
  • ***
  • Posts: 757
  • Project mapper and some other stuff`er
    • View Profile
    • http://ufoai.nx0.ru
Re: Nightime city lights in 3D geoscape
« Reply #10 on: March 23, 2010, 03:48:40 pm »
I can`t compile the game with your patch, since I get this errors:
Code: [Select]
\src\client\renderer\r_program.c||In function 'R_LoadShader':|
\src\client\renderer\r_program.c|349|warning: passing argument 3 of 'qglShaderSource' from incompatible pointer type|
\src\client\renderer\r_sphere.c||In function 'R_InitBumpmap':|
\src\client\renderer\r_sphere.c|213|error: 'uint' undeclared (first use in this function)|
\src\client\renderer\r_sphere.c|213|error: (Each undeclared identifier is reported only once|
\src\client\renderer\r_sphere.c|213|error: for each function it appears in.)|
\src\client\renderer\r_sphere.c|213|error: expected ';' before 'max_instructions'|
\src\client\renderer\r_sphere.c|217|error: expected ';' before 'res'|
\src\client\renderer\r_sphere.c|223|error: 'max_instructions' undeclared (first use in this function)|
\src\client\renderer\r_sphere.c|226|error: 'max_indirections' undeclared (first use in this function)|
\src\client\renderer\r_sphere.c|233|error: 'res' undeclared (first use in this function)|
\src\client\renderer\r_sphere.c||In function 'R_SphereRender':|
\src\client\renderer\r_sphere.c|316|warning: implicit declaration of function 'glActiveTexture'|
\src\client\renderer\r_sphere.c|353|warning: implicit declaration of function 'glClientActiveTexture'|
||=== Build finished: 8 errors, 3 warnings ===|

But I like the idea, it will be excellent addition to the game.

Offline BTAxis

  • Administrator
  • PHALANX Commander
  • *******
  • Posts: 2607
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #11 on: March 23, 2010, 03:58:15 pm »
The one thing that the seaons system as presented here is lacking is additional terrain maps that correspond with the seasonal textures. The current terrain map is base/pics/geoscape/map_earth_terrain.tga. Its legend can be found here. More terrain maps will have to be created before the seasonal changes are committed.

Offline Kildor

  • Project Artist
  • Captain
  • ***
  • Posts: 757
  • Project mapper and some other stuff`er
    • View Profile
    • http://ufoai.nx0.ru
Re: Nightime city lights in 3D geoscape
« Reply #12 on: March 23, 2010, 04:00:37 pm »
I think, we no need in smouth change of terrain map, 12 discret maps will be enought, will not?

Offline arisian

  • Rookie
  • ***
  • Posts: 91
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #13 on: March 23, 2010, 04:01:14 pm »
Hmm, looks like you're using a different build environment; are you building on Windows by any chance?  I run Linux, so I appreciate feedback from those on other platforms.  In any case, try this version; hopefully it will be more friendly with non-gcc compilers (the only difference is using slightly longer forms of names in a few places).

Offline BTAxis

  • Administrator
  • PHALANX Commander
  • *******
  • Posts: 2607
    • View Profile
Re: Nightime city lights in 3D geoscape
« Reply #14 on: March 23, 2010, 04:01:46 pm »
I think, we no need in smouth change of terrain map, 12 discret maps will be enought, will not?

Yes.