PDA

View Full Version : Code: Skybox/-dome



Michael Hartlef
30-09-2008, 11:37
Hi folks,

as the races are mostly outside I would like to have some generic functions that deal with managing a skydome or skybox. Visually I think a skydome could look better but we have to see how the performance will be . Please try to use the entity functionalities of TBGL as this is the fastest way and I'm positive that out game will use these extensively. Maybe your routines will make it into TBGL as an official command set. If you could provide the media for around 4 skys, then that would be awesome too. Please don't use 3rd party stuff only if you are allowed to.

Thanks
Michael

Petr Schreiber
30-09-2008, 18:13
Hi Mike,

making good sky is one of the things I did some research on ... but did not come with anything spectacular yet.

Here just to sum my thoughts:
Skybox
+ Can look very good
+ Cheap on performance
- It can look "too good" and not fit with the rest of scene
- Static clouds ... this simply does not happen in reality

Animated skydome
+ Adds more life to the scene
+ Can be usually parametrized
- Is usually more expensive
- It is easy to do "something blurry animated on the sky", like Quake 3 does for example, but it does not look good
- I personaly do not like procedural stuff, I can smell perlin noise from big distance :) - it is used tooo often

I was thinking of some particle chunks ( clouds ) shifted on the sky - but I am not sure how cheap would be that, and it would probably require long view distance to look natural.

Maybe some hybrid approach could take place as well.

Just thinking out loud,
Petr

Lionheart008
30-09-2008, 19:01
hi michael, hi petr, don't know if it helps;)

but...

- perhaps it's possible to create a cube or a sphere and texture it 'inside' with a sky bmp where the whole game is included? when scenes are changing, the sky will follow it;)

- what about procedurale textures and animate it?

best regards, lionheart

Petr Schreiber
30-09-2008, 19:11
Hi Frank,

it is not problem to do attached skybox, see example from here (http://community.thinbasic.com/index.php?topic=1380.msg9713#msg9713) ( walking on isle and shooting mad guy in baloon :); W,S,A,D to move, mouse to look, click to shoot ).

The problem is that it is too static, it needs high res texture...
If you look at the water, it is done via very cheap trick to look animated. Maybe something similar could be used for sky, not sure.

Did you played IL2-Sturmovik? They have very nice sky - with realistic fake volumetric clouds, looks natural.


Petr

Michael Hartlef
30-09-2008, 21:35
Petr, as we have a fast action game here where you won't have time to pay attention to the sky, things like moving clouds and stuff like that is to much I think. For our game I envisision some nice skys. Sunny, cloudy, rainy, Night. Nothing spectacular.

Petr Schreiber
30-09-2008, 22:07
You are right :),

that is quite logical. So maybe even static skybox would be ok then?
Only problem with skyboxes is they need different texture handling to avoid seams.
I could do it as single TBGL command, taking as input 5 or 6 textures ( front, back, left, right, top [, down ] ).


Petr

Michael Hartlef
01-10-2008, 06:20
Sounds good to me.

Michael Hartlef
10-10-2008, 23:07
Is someone working on this and if yes, when do you think it will be done?

kryton9
12-10-2008, 04:44
Mike, Petr and I have made several skybox examples, some posted and others that never made it to the forums.
So it already works, or are you talking about a single command to handle making a skybox?

Michael Hartlef
12-10-2008, 09:47
Yes Kent, I talk about a few commands/functions that will let you setup a skybox easily. Just include an include file, or USES a module and then you have a few command calls to use a skybox. Maybe you can wrap your code into a nice include file and make the render routine independant from over stuff.

kryton9
12-10-2008, 23:37
Mike, would lens flare be something you would like to see as an option for skybox?

I think commands could be made by Petr for tbgl, will wait to see what he says.

Michael Hartlef
12-10-2008, 23:39
Kent, Petr can't do everything.

If the fucntionset can be implemented into TBGL, then he will do it later on.

Yes, lensflare support would be great but for our game not important.

ISAWHIM
16-10-2008, 14:43
Kent, I found the GL commands to change perspective, which may come in handy for the sky-box... Sure came in handy for my sandbox! (Gonna nick-name it the litter-box soon... it is full of...)

Not sure if we need both of these or just one... I sort-of hacked it together.

Add these under the (Uses "TBGL")

#INCLUDE "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#INCLUDE "%APP_INCLUDEPATH%\thinbasic_glu.inc"

Now, after the loop-draw commands...

TBGL_ClearFrame ' -- Old Code, erase drawing/screen

glMatrixMode(%GL_PROJECTION) ' -- Get matrix view-port stack/buffer
glLoadIdentity ' -- Load matrix view-port stack/buffer
' Warning, this is sensitive to camera position and focal point! (Sniper-view zoom is about 20 view-angle)
' Perspective(view-angle, screen-ratio, near-view, distance-view)
gluPerspective(60,1.3333,0.2,1000) ' -- Set matrix view-port perspective-deform changes

TBGL_SceneRender(%sScene) ' -- Old code, redraw view-port stack/buffer
TBGL_DrawFrame ' -- Old code, display view-port drawing/screen

Petr Schreiber
16-10-2008, 16:25
Hi Jason,

yes, you can do it this way, TBGL can be combined with OpenGL.
Default TBGL FOV is 45.
The only problem will occur when you will try to render fonts created from textures, they currently require 45 FOV.

TBGL Field Of View management is on the TODO list, Mike already suggested it.


Petr

ISAWHIM
16-10-2008, 22:31
In the "Core", there is only one location for fonts, in the "%sINFO" render area. (Suggested)... Rendered data would be on a 3D page (Flat surface) or in a view-port. I can't imagine a need for 3D sprite letters within the race-game or the sky-box... so we should be safe there. (I imagine the GUI would be an overlay to the game-scene.)

Petr Schreiber
16-10-2008, 22:39
Ok then,

I just wanted to let you know there is such a "danger".
Mikes GUI routines use the second type of font, which is FOV resistant :)


Petr

kryton9
17-10-2008, 04:53
Kent, I found the GL commands to change perspective, which may come in handy for the sky-box... Sure came in handy for my sandbox! (Gonna nick-name it the litter-box soon... it is full of...


Never thought about perspective for skybox. Thanks Jason will play with it sometime soon.

kryton9
17-10-2008, 08:15
Here is a test of a skybox.

The 512 x 512 texture size looks too pixelated if you ask me. I will try 1024x1024 this weekend.
I also am relearning terragen and set the camera too high, but I thought I might as well post this.

I threw in a quick dummy wall. The bottom of the wall because of my bad camera setting is way off. But the top of the city wall seemed to be about where I imagined from reading the design document. Let me know if you think it is too high or not. Thanks.

The next skybox I do I will add a little bit higher mountains too and at 1024 x 1024.

Escape to exit, move mouse to look around.

Petr Schreiber
17-10-2008, 09:21
Hi Kent,

thanks for your demo.
Your rotations were too fast on my PC! I guess this is because you have that monster 3D card which makes the mouse delta very tiny.

For mouse input I recommend using TBEM event, to get mouse delta at constant 1/40 time interval for example. This is only way to avoid problems on high end cards.

The problem is mouse delta is always integer, mouse coordinate cannot be returned as decimal number. That brings some imprecision in the end.


Petr

Michael Hartlef
17-10-2008, 10:28
Ok then,

I just wanted to let you know there is such a "danger".
Mikes GUI routines use the second type of font, which is FOV resistant :)


Petr


No problem Petr. I guess I will stop working on this function set too if other people have different plans. More time to concentrate on my new stuff. ;D

ISAWHIM
17-10-2008, 10:45
The only thing I have issues with is the wall inside the skybox.

If you imagine a floor under you, and it slides away from your camera, it slides closer to the skybox wall. (Giving the illusion that the wall is moving closer to you, as you travel backwards.)

On the opposite end... If you approach the end of the city, where the wall should be... it seems to run away from you. (The wall, not the city.)

We do have one thing to our advantage. In a race game, the camera does not usually look up and down, so we can use a 4-wall object, as opposed to making a floor and ceiling. (The wall should actually slide-up and down, depending on game-camera height, to give the illusion of perspective. The motion should be a percentage of the height-value, which will determine where our eyes think the horizon actually rests.)

I would also go on to suggest that the horizon be made to look more realistic, without using a real life panoramic image, by fading to white where the land meets the sky. As hills/mountains roll-off into the distance, they loose vibrancy as there is more atmosphere between our eyes and the distant land. Grassy hills go from bright green under our feet, to dark green at the tops of the curves in the near-distance, while they get more washed-out to grey/white/green, with each hill-roll. (The grey-wash is on a curve, not linear. So you would have 1 pixel of white on the horizon, than 2 pixels on the next layer that are grey/green/mint, than 4 darker, 8, 16, 32, 64... and that is where the near-distant graphics would begin to change. 64-256 would be about normal for color.)

Same with the sky... directly above you, looking up, it is bright blue. In the distance, at the horizon, it is pure white... (At noon). At night white would be reversed to black for both the sky and ground. That white would be a color of the sun-set/rise.

We can actually simulate that "Color" by making the sky and land full color, but use an alpha-horizon of pure white which matches the contour of the land-graphic-levels and solid-fade sky-line... then colorize the alpha image as white, orange, grey, mint, red, yellow... to match the sun-level.

Takes a little bit of graphical know-how to pull that off... but with a "Rendered" scene as your images, it is not that difficult to separate the required images.

1. Make a full 3D scene...
- Setup normal lighting (Sun light and Ambient)
- Sky is solid blue (Sky color), add clouds if desired.
- Land is full-color, generic tiles work fine, but grass green, mountain tan, snow-capped... etc...
- Create FOG levels so distant land, about 1/2 mile is crystal clear, but it fills to pure white before your land runs out.
- Now turn off the fog... you need a shot without it.

Get a full panoramic rendering of this scene.

- Now... Turn on the fog on, you will need it for this shot.
- Turn off the Sun light, and keep the ambient light, to light the fog.
- Dump all image-maps, and turn the sky and land pure black, with the fog still pure white.

You now have an alpha-mask view of the fog-element.

Get a full panoramic rendering of this scene.

If you overlay this image as an alpha... onto your full-color image... you have the fog which matches all the contours of the land.

You can adjust the blend-level to make it less dramatic. But when it goes to a night scene, black should be black, so alpha would have to be 100%. Whatever color you colorize the alpha, should be the color-blend on the land. (You can make white alpha (100% MOD) less blended, but you can't make a grey alpha (50% MOD) get darker. EG, if the alpha is originally 50% translucent, to change the land to grey, not pure white... that will give you land at night that is half-bright, or dark 50% when the horizon should be dark 100%.)

(Actually, the LAND and SKY and CLOUDS all would have separate alphas, as the sun hits them at separate times depending on sun-rise/set/overcast. But that is way above us. We can do the other things!)

Here is a link to a sample "Fogged-out" atmosphere horizon. (GL fog is not an option, it gets too thick too fast. Like within feet.)
http://chris-a-dilla.com/Assignment1/chinoH.html

Here is a good example of sky... Going from dark-navy blue above, to white on the horizon... (At noon, above sky does not get that dark, and turns to Lt-blue/cyan.
http://flickr.com/photos/smartvital/339817243/in/photostream/

I attached a hand-drawn sample of an ALPHA from FOG, imposed on a non-fogged rendering...
Top Left: Normal "Toon" style depth-shadow render (What GL makes)
Top Right: Same 3D scene, but with all black-objects, and full-white-fog (Saved as alpha)
Bottom Left: Overlay of alpha colored white @ 50% translucent.
Bottom Right: Same overlay colored black @ 50% translucent, but at night, so 3D is darker ambient.

Darker ambient is the same as coloring the object that the image is imposed onto, 128,128,128 as opposed to 255,255,255

Again, only because using a real life panoramic image, or a half/half real/rendered looks unnatural to the game.

I also wanted to say... the skybox does not need to be that large. 2000 x 2000... The purpose of a skybox is to use a smaller box which is less processor/code demanding. (Again, I realize this is only a sample.)

Great work. Should fit-in nicely with the core-code too.

kryton9
17-10-2008, 19:39
Jason, I can add haze and control mnay aspects with terragen.

I will make quite a few without any walls this weekend. Then we can pick which are ok.

What size do yu want the skybox? It is only 6 quads, so no problem for the video cards to handle.I think we can make it any size then without overhead on the gpu.

I will make it so the bottom is at 0 y when in our game.
the box will be centered at 0,0 for the x z dimensions.

how high should i place the camera when rendering? I am thinking 2 meters.

kryton9
19-10-2008, 11:42
Here are 5 skyboxes, 1 for each city.
I guess modelers can try the different ones with their city models to see which works best.

Press 1,2,3,4 or 5 to go between the different skyboxes.
PageUp and PageDown control the mouse speed: PageUp faster, PageDown slower.
Escape to exit.

West being 270, the Sun is at 225 and 60 Altitude in all skyboxes.

Updated Oct. 19, 2008: You might need to clear your browser cache prior to downloading.
SkyBox5 (http://www.kryton9.com/web/posts/programs/SkyBox5.rar)

Petr Schreiber
19-10-2008, 12:01
Hi Kent,

good job, I like the 4 especially.

Did you know :D that using
TBGL_ClearFrame(%TBGL_CLEAR_depth) instead of
TBGL_ClearFrame can give poor mortals like me extra 25 to 30% of performance boost?

As skybox covers whole screen, you don't need to clear color, as pixels will get overwriten anyway.
Low end cards suffering from low fillrate appreciate such a tweaks, this trick is used in lot of games.


Petr

kryton9
19-10-2008, 22:42
Thanks Petr, did not know, will make the change and update the download. Thanks.

Petr Schreiber
19-10-2008, 23:42
I will add this information to help file,

it is really useful trick.


Petr