- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
看来在unity3d中制作地形的方法有多了一种,那就是直接用一段程序来生成地形,这个好像很方便,不过本机测试时,导入作者提供的资源包,却没成功,不知是什么原因。有兴趣的朋友可以试试!
So I’ve been working on a simple procedural terrain script in the Unity engine. It currently defines a 2D array of floats, then assigns random values within a certain range. I then call a function that adds rows and collumns between the existing data points, generating midpoints. These midpoints are then given a new value based on the average of the two points on either side with an added noise value.
wp-image-21" />
The next step was to procedurally texture the terrain. I wanted something that would blend textures smoothly, so the grass would become less dense as it progressed up the mountains. I accomplished this by writing my own shader. It currently takes two textures, and combines them based on the alpha values in a blend-map computed based on the altitude of the terrain.
The shader uses a single pass to combine all of the textures together and applies the final texture to the terrain.
wp-image-17" />
The shader also uses lightmaps combined with built in pixel and vertex lights in order to add pre-computed shadows that can also be tinted using ambient light and point lights. The lightmaps are made using a raycast system, where a cast vector is specified, and is projected in a number of itterations along the surface of the terrain. This then writes to the texture on the UV coordinate that is mapped to the hit location. This way, any point that the ray does not hit has a default color value ( Black ), and wherever a ray collides, the value is set to white. This allows simple shadow computation based the slope of the mountain. The lightmap is then blurred to remove any sharp edges. This produces a simple black and white texture that can be multiplied over any other base texture to create shadows.
aligncenter" />
This system allows the user to create a random terrain of a specified size and resolution, with an adjustable lightmap accuracy, and tiling textures that are still shadowed correctly.
示例资源包下载地址:
http://www.dbank.com/download.action?t=40&k=MTgxODczMzM=&pcode=LCwxMzkyNTEsMTM5MjUx&rnd=4
由 u8 发表 |
|