Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LWJGL/OpenGL Spherical Terrain Generation  (Read 2877 times)
0 Members and 1 Guest are viewing this topic.
Offline Alan

Senior Newbie





« Posted 2012-11-27 08: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!
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #1 - Posted 2012-11-27 10: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.
Offline Alan

Senior Newbie





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

Hmm, the poles are still a problem, have you seen any reasonable fixes for this?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #3 - Posted 2012-11-27 11: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.
Offline Alan

Senior Newbie





« Reply #4 - Posted 2012-11-27 11: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.
Online Roquen
« Reply #5 - Posted 2012-11-27 11: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.
Offline Danny02
« Reply #6 - Posted 2012-11-27 15: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 Wink (should be the easiest one)
- normalize all the vertices
- profit!
Offline Alan

Senior Newbie





« Reply #7 - Posted 2012-11-28 04: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?
Online Roquen
« Reply #8 - Posted 2012-11-28 07:30:25 »

search: "sphere tessellation algorithm".

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

Senior Newbie





« Reply #9 - Posted 2012-11-28 09: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!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Roquen
« Reply #10 - Posted 2012-11-28 11: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.
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #11 - Posted 2012-11-30 14: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
Online Roquen
« Reply #12 - Posted 2012-11-30 15: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.
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #13 - Posted 2012-11-30 15: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
Offline Best Username Ever

Junior Member





« Reply #14 - Posted 2012-11-30 21: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.
Offline Danny02
« Reply #15 - Posted 2012-11-30 21: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.
Online Roquen
« Reply #16 - Posted 2012-12-01 09: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.
Offline Danny02
« Reply #17 - Posted 2012-12-01 09: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.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!