Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (522) Games in Android Showcase (127) games submitted by our members Games in WIP (589) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 LWJGL/OpenGL Spherical Terrain Generation  (Read 3252 times) 0 Members and 1 Guest are viewing this topic.
Alan

Senior Newbie

 « Posted 2012-11-27 07:25:34 »

I'm trying to do spherical terrain generation in real-time, with multiple LODs. Have any of you tried this? Any recommendations? Useful resources? Also yes it's intended to be used as a planet, shaders for atmospheric effects/solar flares, etc, all will be done too. If you can help me anywhere, thanks!
RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

 « Reply #1 - Posted 2012-11-27 09:14:41 »

Well, i want to do the same, but im focussing on the terrain first.
I fould some code to draw an sphere with quads so i guess im going from there, maybe it can help you to:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33 `    public static void drawSphere(float basex, float basey, float r, int lats, int longs) {       int i, j;       float lat0, lat1, z0, z1, zr0, zr1, lng, x, y, prevlat;       float xc = 1f / lats;       float yc = 1f / longs;              for(i = 0; i <= lats; i++) {           prevlat = i - 1;           lat0 = (pi * (-0.5f + prevlat / lats));           z0  = SimpleMath.sin(lat0);           zr0 =  SimpleMath.cos(lat0);               lat1 = (pi * (-0.5f + (float) i / lats));           z1 = SimpleMath.sin(lat1);           zr1 = SimpleMath.cos(lat1);               GL11.glBegin(GL11.GL_QUAD_STRIP);           for(j = 0; j <= longs; j++) {               lng = (float)pi2 * (float) (j - 1) / longs;               x = SimpleMath.cos(lng)*r;               y = SimpleMath.sin(lng)*r;                 GL11.glTexCoord2f(xc*j, yc*prevlat);               GL11.glNormal3f(basex + x * zr0, basey + y * zr0, r * z0);               GL11.glVertex3f(basex + x * zr0, basey + y * zr0, r * z0);                              GL11.glTexCoord2f(xc*j, yc*i);               GL11.glNormal3f(basex + x * zr1, basey + y * zr1, r * z1);               GL11.glVertex3f(basex + x * zr1, basey + y * zr1, r * z1);           }           GL11.glEnd();       }   }`

I guess the only thing to do is determine the size of an quad and create an chunk with multiple vertrices instead of an quad.
also the chunk needs to follow an small curve, so it maps smoothly over an sphere.
Alan

Senior Newbie

 « Reply #2 - Posted 2012-11-27 09:49:19 »

Hmm, the poles are still a problem, have you seen any reasonable fixes for this?
RobinB

JGO Ninja

Medals: 44
Projects: 1
Exp: 3 years

Spacegame in progress

 « Reply #3 - Posted 2012-11-27 10:06:13 »

I guess im just going to use smaller chunks as it gets nearer to the poles, like with textures around an sphere.
With the code i posted im going to check the size of an quad and use these dimensions to determine the chunk size used.
The only problem would be the rotation in all directions, and determining what chunks to generate / draw.
Alan

Senior Newbie

 « Reply #4 - Posted 2012-11-27 10:45:08 »

I've got a concept in mind, but I'm pretty busy these next few days and may not be able to get anything significant done. I'll try to keep this thread updated, maybe it'll help you as well.
Roquen
 « Reply #5 - Posted 2012-11-27 10:56:15 »

Sampling a 3D noise function on the surface of the sphere in the same way you'd sample a 2D noise function on a plane to create a "flat" terrain.
Danny02
 « Reply #6 - Posted 2012-11-27 14:24:08 »

to make the problem with the poles smaller, you can do the following:

- create a highly tessellated convex polyhedron (i.e. http://en.wikipedia.org/wiki/Platonic_solid), like a cube (should be the easiest one)
- normalize all the vertices
- profit!
Alan

Senior Newbie

 « Reply #7 - Posted 2012-11-28 03:32:42 »

I've managed to generate a dodecahedron (12 sided using pentagons), but I'm trying to calculate it's center position (centroid) of each face. I'm slowly melting my face trying to find a proper formula to do this with. Any ways I can do this?
Roquen
 « Reply #8 - Posted 2012-11-28 06:30:25 »

search: "sphere tessellation algorithm".

Don't solved problems that have already been solved 100 billion times.
Alan

Senior Newbie

 « Reply #9 - Posted 2012-11-28 08:40:23 »

search: "sphere tessellation algorithm".

Don't solved problems that have already been solved 100 billion times.

I completely blanked on that word, tessellation, thanks for the tip!
Roquen
 « Reply #10 - Posted 2012-11-28 10:51:28 »

It's probably worth noting that if you're using shaders then you can side-step the problem of tessellation since a sphere is a simple implicit surface.
delt0r

JGO Knight

Medals: 27
Exp: 18 years

Computers can do that?

 « Reply #11 - Posted 2012-11-30 13:41:27 »

implicit surfaces don't play nice with shaders.... Or am i missing something?

I have no special talents. I am only passionately curious.--Albert Einstein
Roquen
 « Reply #12 - Posted 2012-11-30 14:24:00 »

Classically if you want to render a sphere you tessellate the whole thing.  With basic shaders you could simply have the geometry of half a sphere and have it always facing the camera, so pretty much only the edges need to be highly tessellated and very little toward the center.  Assuming the sphere isn't going to intersect with anything else, I'm not thinking of any big reason why you couldn't just render a quad (well, really a pair of tris) sprite...but I don't recall what the impact on current-ish hardware is for discard.  (was a killer for hierarchical depth-buffers at one point)

I've never played around with "real" implicit surfaces on the GPU, but I get the impression that demoscene kids are doing it.
delt0r

JGO Knight

Medals: 27
Exp: 18 years

Computers can do that?

 « Reply #13 - Posted 2012-11-30 14:45:04 »

Sure you could do it. As long as you don't do anything else or if they are really small. Its just like raytracing... not the best match to the hardware/pipeline. Geometry shaders could of course tessellate for you which doesn't require anything to be implicit.

I have no special talents. I am only passionately curious.--Albert Einstein

Junior Devvie

 « Reply #14 - Posted 2012-11-30 20:20:11 »

It depends on how you plan to build and interact with the planet.
• If you only see the planet from a distance, you can use 3D noise to create a sprite of the planet from any angle.
• If the density of a vertices doesn't significantly matter or you need "grid" coordinates, you can distort a cube to a sphere and get planet data from a texture. (You can make planets without visual artifacts, but if you need the grid, it will still be slightly warped.)
• If the planets are manually designed, just create multiple LOD levels.
• If you need relatively uniformly distributed vertices, then you can start with an icosahedron and subdivide in the same method as geodesic domes are created.

Performance wise, the cube based method is the most flexible. LOD algorithms relevant to height maps can be applied to it, too, since it's essentially just 6 side by side.
Danny02
 « Reply #15 - Posted 2012-11-30 20:57:01 »

not the best match to the hardware/pipeline. Geometry shaders could of course tessellate for you which doesn't require anything to be implicit.

creating spheres with simple quads(with shader discard) is easy and should perform quite well. I read a paper about a PS3(?) billiard game some time ago which did exactly that.
Their point was that with this technique a lot more nice effects where possible(cause of the pathtracing), also AA on spheres is a problem which can be solved much better by doing it like this.
Roquen
 « Reply #16 - Posted 2012-12-01 08:37:41 »

Not that I'm suggesting one to do this, but it seems like the work in the fragment shader is about the same if you're using real geometry vs. some flat imposter.  Using a quad will result in something like 22% discard rate...but increasing the sides (even by a small amount) will radically drop this.
Danny02
 « Reply #17 - Posted 2012-12-01 08:46:12 »

this would be of course a nice optimization for imposters
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 trollwarrior1 (24 views) 2014-11-22 12:13:56 xFryIx (69 views) 2014-11-13 12:34:49 digdugdiggy (48 views) 2014-11-12 21:11:50 digdugdiggy (42 views) 2014-11-12 21:10:15 digdugdiggy (36 views) 2014-11-12 21:09:33 kovacsa (60 views) 2014-11-07 19:57:14 TehJavaDev (64 views) 2014-11-03 22:04:50 BurntPizza (62 views) 2014-11-03 18:54:52 moogie (77 views) 2014-11-03 06:22:04 CopyableCougar4 (77 views) 2014-11-01 23:36:41
 theagentd 29x basil_ 27x BurntPizza 23x Riven 19x Spasi 18x princec 17x HeroesGraveDev 16x KevinWorkman 13x SHC 11x kpars 11x Grunnt 10x Nate 9x kevglass 9x Longarmx 9x pitbuller 9x gouessej 9x
 Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org