www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: draga on December 15, 2009, 04:18:27 pm

Title: terrain detail
Post by: draga on December 15, 2009, 04:18:27 pm
Hello,

I'm wondering how Technopolies reached out that terrain texture detail.
At me, the Terrain is very pixeled...(at texture resoltution of 2048x2048)..

How can I get a nice detailed terrain??
Is there some tricks?

Title: Re: terrain detail
Post by: EgonOlsen on December 15, 2009, 08:57:52 pm
I think techno created those textures at startup IIRC, but i've no idea of the logic on which this was based. Maybe rolz can answer this directly, if you manage to contact him in some way.
Title: Re: terrain detail
Post by: draga on December 15, 2009, 09:01:31 pm
ok, thanks..I'll try to go in contact with him.
Title: Re: terrain detail
Post by: EgonOlsen on December 15, 2009, 09:04:34 pm
Another option would be to use some detail textures. Or are you already doing this?
Title: Re: terrain detail
Post by: draga on December 15, 2009, 09:29:24 pm
you mean, another texture in blending mode over a terrain and uv repeat it??
I already have used that technique.

I have recognized that new game have a comlex ground texturing with probably normal mapping.
I'am wondering how they can get the ground texture so high detailed...
Because the texture size of 4096*4096 pixel of a terrain plane is very pixeled (seeable artefacts)
Do they use megaTexture's ??
Title: Re: terrain detail
Post by: Grandmaster B on December 16, 2009, 12:49:40 pm
Probably the game uses multiple meshes for the terrain. Think of a tile based map in 3D. Each tile type/image has its own mesh. The fading effect are tiles that have zero alpha at the borders.

Look at this screenshot: *Removed*
There you can see the "tiles" and the faded borders.
Title: Re: terrain detail
Post by: EgonOlsen on December 16, 2009, 06:10:55 pm
As far as i remember, those blendings were baked into the textures. Techno ran a texture creation process when started for the first time that created them.
Title: Re: terrain detail
Post by: draga on December 16, 2009, 06:59:07 pm
@Grandmaster B
And who forms the terrain??
You mean that (tile) meshes lie on the terrain and also have the form of the terrain part?


@EgonOlsen
But than the texture size must be huge? or the terrain was cuted thus several textures can work to reach the detail?!
Title: Re: terrain detail
Post by: Grandmaster B on December 16, 2009, 07:16:48 pm
Yes, sort of. Do a search on "Multilayer Terrain".
Title: Re: terrain detail
Post by: EgonOlsen on December 16, 2009, 08:17:25 pm
@EgonOlsen
But than the texture size must be huge? or the terrain was cuted thus several textures can work to reach the detail?!
It used several small textures. Too bad that it isn't available anymore...
Title: Re: terrain detail
Post by: draga on December 16, 2009, 09:01:06 pm
Should I code an editor?
or is there other ways with Maya or other 3d modeling tool?
Title: Re: terrain detail
Post by: Grandmaster B on December 16, 2009, 09:34:35 pm
I wrote a fancy editor but first i used stencil maps to build the meshes. However, there are several methods, some are shader driven using only one mesh others draw the terrain several times. I was developing with a AMD K2 350MHz and a TNT2 so i had to optimize a lot, drawing the mesh more than once was not possible so i had to cut out invisible parts of the layers/meshes.

Multilayer terrain only means that you usually draw the terrain several times or in layers instead of stretching or tiling one texture over the whole mesh. You can use stencils, alphas, shaders or meshes to render the layers. This really depends on what you try to do.

You may also take a look at Megatexturing and you will probably need quadtree culling.

If you need a editor depends mostly on how many terrains, levels, worlds you want to create, you hopefully do not try to make a MMORPG so i guess you dont need a editor.

Here is a image of my multi-layer terrain and world editor, was probably a waste of time (except for learning purpose):
http://www.pasteall.org/pic/543

Edit: Here is also a video of the "game"...:
http://www.youtube.com/watch?v=Xe0DCrOG0WQ
Title: Re: terrain detail
Post by: draga on December 17, 2009, 09:43:03 am
wow, man that looks great ;)
Works the editor and game with jpct?
Title: Re: terrain detail
Post by: Grandmaster B on December 17, 2009, 01:15:39 pm
Thanks :)
This is made in C/C++ and OpenGL but it can definately be developed with Java+jPCT. Do you know "Tribal Trouble" its also developed in Java.
Title: Re: terrain detail
Post by: raft on December 18, 2009, 04:03:56 am
yeap, it definetely looks great ;D
are there any LoD, adding/removing meshes or similar things there ? or does it simply render such a big scene ?

btw, "Tribal Trouble" is great. they generate their terrains procedurally on the fly

r a f t
Title: Re: terrain detail
Post by: Grandmaster B on December 18, 2009, 10:53:54 am
No there was no LOD, the terrain layer meshes were used for blending the borders by using the alpha color of the outer vertices, invisible polygons on a layer were removed for the layer mesh. So there were several unique independent meshes that made the whole terrain. If you use a texture for blending the layers and a single terrain mesh, LOD should be doable like in a normal terrain.

Here is the basic layout for multilayer terrain with a shader (LOD-able, fast on decent Hardware):

- Lets say you have a single terrain mesh, and you have 3 layer textures you want to blend into the terrain.
- You also have one blending texture with RGB channels. The R part is for blending layer 1, B is for 2, and C is for 3.
- The blending texture must be UV mapped / stretched to the whole terrain. The layer textures use this UV coordinates but multiply/scale it in the shader to tile more than once.
- Assign the textures to the texture channels of the hardware, both the layer and the blending textures. This takes 4 texture channels in this example.
- Now use a shader to blend the layer textures. This is realy simple shader that just combines the layer textures based on the blending texture and scale the UV for the layer textures.

I haven't used that myself tho.
Title: Re: terrain detail
Post by: EgonOlsen on December 19, 2009, 10:21:12 pm
Nice idea. The shader shouldn't be too hard to write, but how do you create the blending texture? Do current 3d editors have support for this?
Title: Re: terrain detail
Post by: Grandmaster B on December 20, 2009, 05:12:36 pm
The blending texture must be created with a painting program i guess. Blender supports stencil textures to "paint" terrain in realtime but only one channel (one blending-texture per layer), not the packed R-G-B style described below. Its also possible to auto-generate a blending texture based on the slope/normal and height of the terrain.
Title: Re: terrain detail
Post by: EgonOlsen on December 20, 2009, 11:12:29 pm
Inspired by this thread, i've played a little with the vertex alpha method (i.e. no shaders). I had to add two methods to actually assign them and fix one bug on the way. Next i'm going to add trees. This is how it looks now:

High noon at the lake:
(http://www.jpct.net/img/high_noon.jpg)

Sun down:
(http://www.jpct.net/img/sundown.jpg)
Title: Re: terrain detail
Post by: Grandmaster B on December 21, 2009, 12:06:03 am
 :o
Wow, already looks amazing!! Do you have a game idea in mind or are you just playing?
Title: Re: terrain detail
Post by: enbe11_3 on December 21, 2009, 04:06:26 am
awesome graphics!!! are you going to post the source code? ;)
Title: Re: terrain detail
Post by: JavaMan on December 21, 2009, 03:09:21 pm
wow, that's beautiful. I love the water.
Title: Re: terrain detail
Post by: EgonOlsen on December 21, 2009, 11:30:47 pm
Some trees are in. Approx. 1300 of them (with 690 vertices each) are in the view. They really hurt performance even on my Radeon 5870... ;D I'm still not sure why...however, it's still "playable".

To the questions: No, i don't want to make a game of it. It's just for fun and maybe as an additional test bed for the engine. I may post the sources later, but they are really hacky. It's all in one class. The water is pretty simple: Just two textured layers that move up and down while rotating slightly. Looks pretty good considering that it doesn't use any pixel shaders at all.

(http://www.jpct.net/img/trees1.jpg)

(http://www.jpct.net/img/trees2.jpg)
Title: Re: terrain detail
Post by: AW999 on December 22, 2009, 12:01:56 pm
Wow.  What method are you using to generate the terrain, and how far does it extend in any given direction?
Title: Re: terrain detail
Post by: EgonOlsen on December 22, 2009, 02:47:19 pm
It's an OBJ-file created with Treegen. You can see maybe 30% of its width in the screen shot, so it's not very large. Terragen can't export anything larger ATM.
Title: Re: terrain detail
Post by: AW999 on December 22, 2009, 09:43:16 pm
Could you put an applet version of it online so we can see it, or a downloadable jar file ?
(I mean so we can see it in action....)
Title: Re: terrain detail
Post by: EgonOlsen on December 23, 2009, 07:27:26 am
I will do later. Currently, i'm still optimizing some parts of jPCT for it. It's a pretty good test case... ;D
Title: Re: terrain detail
Post by: AW999 on December 28, 2009, 10:45:51 pm
I will do later. Currently, i'm still optimizing some parts of jPCT for it. It's a pretty good test case... ;D

  When are you going to put it online (via an applet or whatnot) so we can see it ?   :)
Title: Re: terrain detail
Post by: EgonOlsen on December 28, 2009, 11:33:12 pm
I hope to manage that within a week. I'm a bit short on time right now and i'm still optimizing jPCT for this usage. I've already increased performance of that test case by 50%, so it should be worth the wait.
Title: Re: terrain detail
Post by: AW999 on January 04, 2010, 07:52:34 pm
I hope to manage that within a week. I'm a bit short on time right now and i'm still optimizing jPCT for this usage. I've already increased performance of that test case by 50%, so it should be worth the wait.

  Is it done yet ?
Title: Re: terrain detail
Post by: EgonOlsen on January 04, 2010, 08:01:37 pm
Almost. I'll upload a zipped version today, if i find the time.
Title: Re: terrain detail
Post by: AW999 on January 04, 2010, 09:34:07 pm
BTW, how did you make the sky in that program?  Are there any articles on creating a good sky?
Title: Re: terrain detail
Post by: EgonOlsen on January 04, 2010, 09:59:01 pm
The sky is a shameless rip from raft's work on Aptal Karga...didn't i gave credit before? I guess, i've forgotten...shame on me... :-[

However, here's the file: http://www.jpct.net/download/misc/terrain.zip (http://www.jpct.net/download/misc/terrain.zip)

As said, it's pretty hacky. Especially processing of the trees and generating the terrain texturing could be improved. Sources are included, i've put everything into one, uncommented (almost) file. It needs the jpct.jar that's included to run, it won't run with 1.19, because it uses some stuff that i've added for 1.20.

There are some keys:

1+2 : Move the sun. The lens flare doesn't take the mountains into account for performance reasons.
t: toggle trees (on by default)
d: toggle detail mapping (off by default)
CRSR+PGUP+PGDOWN: move
ESC: Exit

FPS will be printed to the console each second.

Edit: Performance on my main machine (Core2 Quad@3.2Ghz, Windows Vista Ultimate 32bit, 4GB, Ati Radeon HD 5870 - 1GB, Java6.something) at the starting position without moving the mouse.

With trees: 83fps (was 55 before optimizing...)
W/o trees: 1200fps

Edit2: Performance on my test machine with Intel onboard graphics (Core2 Duo@2.2Ghz, Windows XP, 2GB, Intel 945G, Java6.something):

With trees: 10fps
W/o trees: 31fps




Title: Re: terrain detail
Post by: AW999 on January 05, 2010, 12:35:26 pm
However, here's the file: http://www.jpct.net/download/misc/terrain.zip (http://www.jpct.net/download/misc/terrain.zip)

 Wow. Even on my machine, it runs with a framerate in the 20s or 30s, sometimes 40s or higher.
 Since you provided the sourcecode, I assume we can freely adapt it for our own projects?
Title: Re: terrain detail
Post by: EgonOlsen on January 05, 2010, 09:19:13 pm
Wow. Even on my machine, it runs with a framerate in the 20s or 30s, sometimes 40s or higher.
 Since you provided the sourcecode, I assume we can freely adapt it for our own projects?
Sure. The usual "do whatever you like with it"-license that i'm using for all of my sources applies here too. Just keep in mind, that the whole thing is just written to make it work. There have to be many many ways to do things better than i did in this demo.
Title: Re: terrain detail
Post by: EgonOlsen on January 06, 2010, 06:12:16 pm
BTW: If you have at least a dual core, it can be worth it to set Config.useMultipleThreads in the constructor of Terrain to true. If the graphics card can handle it, the demo scales pretty well (115 fps compared to the 83 of the single threaded renderer).
Title: Re: terrain detail
Post by: EgonOlsen on December 07, 2011, 11:51:58 pm
Resurrected the old terrain stuff to play around with the shader based splatting method mentioned earlier.

See how the path winds through the mellow hills and the lovely meadows? Looks like Skyrim, doesn't it? Well, maybe not... ;)

(http://jpct.de/jpctnet/img/splatting.jpg)

BTW: The benefit of doing it this way is, that you can actually "paint" the splatting into a texture instead of relying on the height and some dubious alpha values.

Edit: Changed picture to one with better lighting.
Title: Re: terrain detail
Post by: Hrolf on December 09, 2011, 05:32:47 am
Oo! Pretty! I wonder if shaders could also be used to fake up some sort of shadows?
Title: Re: terrain detail
Post by: EgonOlsen on December 09, 2011, 07:55:32 pm
I tried this by modifying the blend texture (i.e. the one that tells the shader which texture to use where) when planting the trees by placing a dark spot below each tree. It worked so far, but i forgot that i'm not rendering trees in the distance, so there were no trees but the dark spots remained, which made the terrain look like some kind of acne in the distance.