Jump to content

Coherent perlin noise on a sphere


Padman
 Share

Recommended Posts

Hi,

I'm doing a planet generator for my game. But I've some problems with the c++ libnoise.

I successfully generated a quadtree (maybe with a bad algo... ^^') and successfully transformed it into a sphere according to this great blog.

 

But now, I want to apply a perlin noise using the c++ libnoise library. But the render is not really good... But I think I'm in the right way. My problem is about the noise coherence between each faces of my cube. The faces are not joined. Here is a screenshot.

 

 

I do this following code to generate one face of my cube :

//generating the front face...
Surface* frontFace = model->AddSurface();
for(int i = 0 ; i<numSquare ; i++)
{
 for(int j = 0 ; j<numSquare ; j++)
 {
	 float x = -1+i*segment;
	 float y = -1+j*segment;
	 float z = -1;
	 float dx = (x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0))) * Radius; //transform into sphere
	 float dy = (y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0))) * Radius;
	 float dz = (z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0))) * Radius;
	 float ndz = dz + perlinModule.GetValue(dx,dy,dz);//generate noise
	 int v0 = frontFace->AddVertex(dx,dy,ndz);
	 x = -1+(i*segment)+segment;
	 y = -1+j*segment;
	 z = -1;
	 dx = (x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0))) * Radius;
	 dy = (y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0))) * Radius;
	 dz = (z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0))) * Radius;
	 ndz = dz + perlinModule.GetValue(dx,dy,dz);
	 int v1 = frontFace->AddVertex(dx,dy,ndz);
	 x = -1+(i*segment)+segment;
	 y = -1+(j*segment)+segment;
	 z = -1;
	 dx = (x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0))) * Radius;
	 dy = (y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0))) * Radius;
	 dz = (z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0))) * Radius;
	 ndz = dz + perlinModule.GetValue(dx,dy,dz);
	 int v2 = frontFace->AddVertex(dx,dy,ndz);
	 x = -1+i*segment;
	 y = -1+(j*segment)+segment;
	 z = -1;
	 dx = (x * sqrtf(1.0 - (y*y/2.0) - (z*z/2.0) + (y*y*z*z/3.0))) * Radius;
	 dy = (y * sqrtf(1.0 - (z*z/2.0) - (x*x/2.0) + (z*z*x*x/3.0))) * Radius;
	 dz = (z * sqrtf(1.0 - (x*x/2.0) - (y*y/2.0) + (x*x*y*y/3.0))) * Radius;
	 ndz = dz + perlinModule.GetValue(dx,dy,dz);
	 int v3 = frontFace->AddVertex(dx,dy,ndz);
	 frontFace->AddTriangle(v2,v1,v0);
	 frontFace->AddTriangle(v0,v3,v2);
 }
}

 

I don't know how to solve this. I didn't find good explanations on the web. I'm not really good in maths but I've some logic ideas (I think ...), it's a miracle if this code works xD. Maybe it's my cube generation algorythm which is bad...

I understood that some others use a lerp function to join "smoothly" each faces, but I don't know how I can apply this to my code. ^^' If someone can help it would be great.

Thx !

 

PS: I'm french so really sorry for my english

Link to comment
Share on other sites

Thanks for your help. But I aldready know that ^^'. Sorry if I don't explain correctly my problem. My problem is to apply a perlin noise on my sphere. I don't know how to generate a coherent noised sphere. In my screenshot, all my cube faces are separated. I don't know how to join them "smoothly".

Link to comment
Share on other sites

It seems that your problem is that you have double verticies along your edges ( zooming in this also seems to cause gaps ) you should either merge them or store them and look it up.

 

But I think It may just be easier to take a different approach all together to creating the sphere

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Thank you for your help Guppy. You're right, I have double vertices on my edges because of my bad quadtree generator algorythm ^^. So I recoded it and now I can have a perfect noised sphere. Thank you all for your help. Now ... I have to apply textures on my planet according to the height of my vertices... It's time to work hard (and first read some docs). ^^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...