C ++ OpenGL Cube映射Perlin噪声到球体 [英] C++ OpenGL Cube Map Perlin Noise to Sphere

查看:265
本文介绍了C ++ OpenGL Cube映射Perlin噪声到球体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究一些地球行星,主要是为了好玩,希望能够结束一些踢屁股行星。我正在使用已经通过标准化映射到球体的立方体。



地形不是在这张照片中正确纹理。这只是来自Heightmap的渲染。然而,这不是我的问题。当从立方体创建一个球体时,您将留下6个面弯曲成球体的面。因此,我没有可用于在地形周围包裹球形高度图的经度和纬度。目前我正在使用多维数据集映射。但是,这导致了一些问题,如您所见:

—我的问题变得明显。问题是由于球体仍然具有立方体的拓扑结构。我必须为每个脸部生成一个高度图。我目前使用Libnoise作为高度图,这是大问题开始的地方。我可以将它作为球形高度图导出 - 如果我有球体,这将很有用 - 或者我可以使用平面高度贴图,它必须映射到所有6个面。但是,由于映射的工作原理。我可以在中间排列3个面并且无缝,但最后一个高度图不会加入第一个,因为Lib噪声使用边界并创建坐标网格。



<创建球体的方式如下所示:

  for(int i = 0; i< vertices.size(); i ++ )
{

glm :: vec3 oldVec = vertices [i];
glm :: vec3 newVec = glm :: normalize(oldVec);
顶点[i] = newVec * glm :: vec3(500,500,500);
}

背后的推理可以看出 here



然而,球体的结构将使得稍后以Quad-Ttee的形式实现lod更容易。无论如何,我可以用LibNoise生成立方体贴图高度图吗?还是有什么我可以做的,使球体能够使用球体高度图?



我想出了如何使用Sphere Maps进行渲染,但这不是当我开始使用四叉树时会继续工作。然而,它产生了一些不错的结果,例如:



所以,我非常需要知道如何将噪音平铺到立方体贴图中。无论是Libnoise还是顶点着色器。

解决方案

我终于搞定了它的工作方式。为此,我通常在没有立方体贴图或球体贴图的情况下解开立方体。我以立方体贴图的形式应用3D Perlin噪声的高度,但是我没有使用UV坐标,因此我没有将它解开为立方体贴图并不重要。然后我根据顶点的高度应用一个纹理,它似乎产生了很好的结果。也许以后我会遇到问题谁知道。这是我现在得到的照片:



PS:那不是月亮它是太阳。为了测试的目的,它更接近,我目前没有太阳纹理,所以我只使用了旧的灰度高度贴图纹理,这样我就可以更好地看到它。这个星球现在开始看起来很棒。

I'm currently working on some Planet Generation mainly for fun and hoping to end up with some kick ass planets. I'm using a Cube which has been mapped into a sphere by normalization.

The terrain isn't textured properly yet in this picture. This is just the render from the Heightmap. However this is not my problem. When creating a sphere from a cube you are left with 6 faces bent to the shape of a sphere. Therefore, I do not have latitude and longitude that can be used to wrap a spherical heightmap around the terrain. Currently I'm using Cube Mapping. However, this has caused several problems, as you can see: —where my problem becomes obvious. The problem is due to the fact that the sphere still has the topology of a cube. I have to generate a heightmap for each face. I use Libnoise currently for the heightmap and this is where the big problem starts. I can either export it as a spherical heightmap—which would be useful if i had a sphere—or I can use planar heightmaps which must be mapped to all 6 faces. However, due to how the mapping works. I can get 3 faces to line up around the middle and be seamless but the last heightmap won't join to the first as Lib noise uses bounds and creates a grid of coordinates.

The sphere is created like so—

for(int i = 0; i < vertices.size(); i++)
{

    glm::vec3 oldVec = vertices[i];
    glm::vec3 newVec = glm::normalize(oldVec);
    vertices[i] = newVec * glm::vec3(500, 500, 500);
}

The reasoning behind this can be seen here.

However, the structure of the sphere will make it easier to implement lod in the form of a Quad-Ttee later on. Is there anyway I can generate a cube map heightmap with LibNoise? Or is there something I can do to make the sphere be able to use a sphereical heightmap?

I figured out how to make it render using Sphere Maps but this isn't going to work when i come to using a quad tree. However, it produces some nice results like:

So, i pretty much i need to know how to tile noise into a cube map. Either with Libnoise or in the vertex shader.

解决方案

I finally got it working how i intended. To do this i normally unwrapped the cube without a cube map or sphere map. I apply the heights with 3D Perlin noise in the form of a cube map but i'm not using the UV coordinates so it doesn't matter that i haven't unwrapped it as a cube map. I then apply a texture according to the height of the vertex and it seems to produce great results. Maybe i'll have problems later on who knows. Here's a picture of what i got now:

PS: That's not the moon it's the sun. For testing purpose it's closer and i haven't got a sun texture at the moment so i just used an old greyscale heightmap texture so i could see it better. The planet's starting to look great now.

这篇关于C ++ OpenGL Cube映射Perlin噪声到球体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆