Help with creating alpha map for terrain texture splat

Started by
3 comments, last by dpadam450 11 years, 10 months ago
Hey guys, I'm making a Terrain world editor tool. The tool can raise/lower vertices, place objects, etc. I want to implement texture splatting, so an alphamap texture is created and RGBA channels will corespond with 4 different tiled texutres (grass,dirt,snow,sand).

I understand how to write the shader code for the texture splat rendering, what I don't know how to do, is create an image and dynamically change that images's data. I want the user to click on the terrain, and for me to change that assoiated pixel(s) in the image. WHen everything is said and done, I want to be able to export that image into my game.

So my questions are:

Should I send some float array (of weighted values) to the shader?
Or should I manipulate textures and send that to the shader?
And How do you know what pixel to change coresponding on the intersection point on the terrain?

The ultimate goal is for the user to be able and paint roads, or snow, etc. Also, I don't know if it matters, but a TGA image file would be best.

If anyone has any advice, it would be much appreciated.

Thank you.
Advertisement
Perhaps someone can tell me if i'm in the right direction

Lets say my terrain is 100 units long
and I have a 512 x 512 image I want to make an alpha map.

Lets say the user clicks on spot (x,z) = (25,50).

Then I take the percentage of the distance so x is 1/4 of the way across the terrain, and z is 1/2 of the way across the terrain.

So I want to edit the pixel at (128, 256) in the texture image. Since that is the spot 1/4 across and 1/2 down?

If this is the correct way in thinking, i could then set pixels around that one depending on my brush size. (and run a box filter on them)?

If this is correct, I guess I need some help accessing a texture and changing the pixel data. If I know the rect (1 pixel) I want to edit.
I'm pretty sure in the past I just re-uploaded a texture every time the mouse was down to do a paint. What would be best is to paint to texture/FBO. say your map is 2048x2048. Set the viewport to 2048, find the pixel location as you stated above, and actually just paint to the FBO with a 2D brush texture. Then immediately use that texture on the terrain. This will keep the texture on the GPU at all times and be really fast.

To get the users spot try gluUnproject() and just how u have, draw your brush texture into the FBO texture at that location.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

I'm not sure if I understand everything your saying. I might be wrong, but are you talking about just having one texture and painting right onto it using other textures? This sounds like a foreign concept for me, so I am sorry. I'm assuming you are telling me to not use an alpha blend map + 4 textures to do my terrain tiling?
To modify the alpha map though, keep it on the gpu, and when you want to modify it, attach it to an FBO and just draw brushes into it, unbind it from the FBO, and then use that texture for your shader. Repeat for every time the user wants to paint the terrain.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement