Jump to content
  • Advertisement
Sign in to follow this  
UnIXbLueStar

OpenGL Crazy terrain texturing technique

This topic is 3548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, this is what i've figured out for my project and i want to share this. First, my primary language isn't english. Info : -I am using a 1024x1024 texture atlas which contains many 64x64 textures. -Each line correspond to a type of terrain (sand, grass, rock...). -Each type of terrain has 16 variation since 16 64x64 textures can fit on a line. -The terrain is a heightmap. -For each tile and for each texture unit, a number is indicating which texture to use in the atlas. The technique i will explain permit you to use 4 Unit of texture. I think this is perfect for a map editor. I assume you are using VBO's and that your ColorPointer isn't already used. First, we make a color matrix for each vertex (a matrix as big as your heightmap) and we pass it to glColorPointer when rendering the terrain. To blend texture together, we will use a shader that take the fragment's R, G, B and A color as the Texture unit 0 intensity, Texture unit 1 intensity etc... Since opengl can blend vertex colors on the polygon, it makes this technic very easy to smooth textures. uniform sampler2D unit1; uniform sampler2D unit2; uniform sampler2D unit3; uniform sampler2D unit4; ... texel1 = texture2D(unit1,gl_TexCoord[0].st); texel2 = texture2D(unit2,gl_TexCoord[1].st); texel3 = texture2D(unit3,gl_TexCoord[2].st); texel4 = texture2D(unit4,gl_TexCoord[3].st); float totalColor = gl_Color.r+gl_Color.g+gl_Color.b+gl_Color.a; texel1=vec4(mix(vec3(0.0, 0.0, 0.0), texel1.rgb, gl_Color.r/totalColor), texel1.a); texel2=vec4(mix(vec3(0.0, 0.0, 0.0), texel2.rgb, gl_Color.g/totalColor), texel2.a); texel3=vec4(mix(vec3(0.0, 0.0, 0.0), texel3.rgb, gl_Color.b/totalColor), texel3.a); texel4=vec4(mix(vec3(0.0, 0.0, 0.0), texel4.rgb, gl_Color.a/totalColor), texel4.a); ... ct = texel1.rgb+texel2.rgb+texel3.rgb+texel4.rgb; ... im not a shader master so sorry for the spaghetti code. Using this technic, you can texture your terrain like if every unit of texture was a layer in photoshop. Here's an example : It's moving from sand(near water) to grass. http://img152.imageshack.us/img152/3462/ionix3ps6.jpg (sorry for bad texture tiling) Does this technic already exist?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by UnIXbLueStar
Does this technic already exist?

Yes, that's standard layer blending with per-vertex weights. Commonly, people use a separate texture for the layer weights instead of doing it per-vertex. This gives you higher resolution control over the process.

The technique is called texture splatting. It can be extended to use as many layers as you need, possibly by doing multiple passes if you exceed the available number of texture image units.

Share this post


Link to post
Share on other sites
This technique is called "texture splatting".

One thing I would suggest is that you introduce some noise in your blend function so that you don't just get a perfectly smooth transition from grass to sand.

I'm planning to use a similar technique in my terrain engine. Another thing which I've been thinking about is including an alpha channel in my base textures to help control the blending. So if you've got a "pebble" texture, for example, you can use the alpha channel to make the top of the pebbles dissappear more slowly than the bottom of the pebbles, for example. It's hard to explain without a screenshot, but at the moment this idea is still just in my head [smile]

It's also a bit hard to see what's going on in your screenshot with all the blooming going on :-)

Edit: oops, beaten to the punch!

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
This technique is called "texture splatting".

One thing I would suggest is that you introduce some noise in your blend function so that you don't just get a perfectly smooth transition from grass to sand.

I'm planning to use a similar technique in my terrain engine. Another thing which I've been thinking about is including an alpha channel in my base textures to help control the blending. So if you've got a "pebble" texture, for example, you can use the alpha channel to make the top of the pebbles dissappear more slowly than the bottom of the pebbles, for example. It's hard to explain without a screenshot, but at the moment this idea is still just in my head [smile]

It's also a bit hard to see what's going on in your screenshot with all the blooming going on :-)


well in the screenshot theres 3 unit used for texturing and 1 for bump mapping. Its the same normal map for the whole terrain coz i havent worked on different terrain type in the atlas for now plus my map editor interface isnt done which make tests harders.

Share this post


Link to post
Share on other sites
Depending on your GPU you may want to think about a different method than all those mix commands for blending your textures.. They can be painfully slow.

Adding the textures and then dividing the result by the number of textures is one possible method.

Alternatively layering your textures in 3D batches and using the z index as the blend control is another method.

In my experimentation with texture splatting on various GPUs those two gave me better results.

For more realistic effects you can also pair your texture tiles with bump map versions of the same textures and it's then fairly easy to do the maths in the vertex shader for Tangent and Binormal to give some real meatiness to the texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by scratt
Depending on your GPU you may want to think about a different method than all those mix commands for blending your textures.. They can be painfully slow.

Adding the textures and then dividing the result by the number of textures is one possible method.

Alternatively layering your textures in 3D batches and using the z index as the blend control is another method.

In my experimentation with texture splatting on various GPUs those two gave me better results.


still running at 150 fps on a 8800 gts with a mix of terrain + water in screen.
i cant add everything and divide after though cause that would kill the concept of texture unit intensity.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!