Jump to content
  • Advertisement
  • entries
    232
  • comments
    1463
  • views
    961355

Terrain texturing

Sign in to follow this  
Ysaneya

296 views

I started to work on the texture synthesis for the terrain chuncks of my planet.

In the past, i have tried many different approaches. Namely:

1. Texture splatting: i've got many texture layers (grass, rock, sand, snow, etc..) and for each vertex of the chunk, i assign some weights to these textures. This work is done on the CPU asynchronously.

2. Unique procedural texture, on the CPU: for each chunk, a unique texture is procedurally generated, by using the heightfield and some noise functions.

The results:

1. Moderately fast, average quality. Dependant on tesselation. Morphing hard to implement since you must morph the weights too.

2. Awfully slow, better quality. Became unusable when you started to zoom on the planet's surface. A few mipmapping problems.

So, for the next (and hopefully last) version of the terrain engine, i'm going to try a different technique: a unique, procedural texture.. but generated on the GPU instead of the CPU. This should solve the performance problem.

At the moment i'm first trying to generate some good normals to, later, do lighting, but also texturing (based on the slope of the terrain, which requires normals).

The input is the heightfield for the terrain patch. It is currently 33 x 33. That's very low resolution. Assuming a 512x512 unique texture to cover this patch, the question is.. how to upsample that heightfield, add some noise (for more details), and generate normals.. all of that... without any artifact ?

I spent hours working on that. Some problems:

- upsampling using bilinear filtering: when differencing the heights for the normals, the derivatives are not continuous -> lots "grid-based" artifacts

- 8-bits heightfield -> normals are of low quality -> lighting is very bad

- so i tried to encode the heights as f32 into an RGBA vector, and to decode it in the pixel shaders. Works better, but still some quality artifacts.

- i switched to floating point textures. Problem: bilinear filtering is not available on them.

- so, i had to implement filtering myself in a pixel shader. I tried to smooth-step the filtering parameters, too. Improved the quality a bit.

- but even after that, artifacts were still visible. So i had to blur the upsampled, filtered heigthfield twice (with a 15x15 kernel size) in a pixel shader. This smoothened the heightfield (hence the normals) by a lot.

- finally, noise is generated by taking N pre-generated 2D Perlin noise textures and adding them together with varying weights. The noise is then added on top of the upsampled, filtered heightfield.

The result is rather nice, and is generated 100% on the GPU (which means real-time):



It's not finished though. I'm concerned about the blurring. It works well here, but when two terrain patches will be adjacent, the pixel shader will not have access to the adjacent texels. This means, an ugly seam might potentially appear. To avoid it, i'd have to not use blurring.. but i have to find a way to avoid artifacts too.
Sign in to follow this  


6 Comments


Recommended Comments

Looking Good [smile]

I'm looking at trying out some new terrain-texturing algorithms in light of my fun with UVAtlas'ing..

I render the texture map by flattening the geometry and rendering to a texture. The interesting part is that i can feed that texture map through a vertex and pixel shader.

I'm wondering if i can get some good results by using that process to generate a slope, normal and heightmap - accurate to per-pixel.

Thought of using a simple render-to-texture approach to generate your data?

Jack

Share this comment


Link to comment
... and in other news, Laz is completely confused, but quite impressed and in awe.

Share this comment


Link to comment
Quote:
I'm wondering if i can get some good results by using that process to generate a slope, normal and heightmap - accurate to per-pixel.

Thought of using a simple render-to-texture approach to generate your data?


I'm a bit confused.. isn't it the same than what i've been showing up here ?

Well okay, there's a difference: i'm not generating the heightfield on the GPU. And i do not want to. But the slope, normals and later texture, are accurately per-pixel generated by ping-ponging between many floating-point render buffers.

Share this comment


Link to comment
Quote:
Original post by Ysaneya
- upsampling using bilinear filtering: when differencing the heights for the normals, the derivatives are not continuous -> lots "grid-based" artifacts


Did you try bicubic interpolation?
At the four boundaries you'd have to store the respective adjacent rows of vertices, too, so that you can calculate some derivative values for the interpolation. So you'd have to store a 35x35 field instead of 33x33 per patch.
But then, you'd be able to generate a smooth interpolated heightfield where also the normals are smooth (that is, continuous but not differentiable... normals would be as if bilinearly interpolated, phong-like). Remember the two example heightmaps I once sent you, one with bilinear and one with bicubic interpolation?

Share this comment


Link to comment
Quote:
I'm a bit confused.. isn't it the same than what i've been showing up here ?

Yeah, maybe I need to pay more attention [oh]

Sorry!
Jack

Share this comment


Link to comment
Lutz: yes, actually i'm using a quintic interpolation now :) It definately improved the normals quality by a lot.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!