I am programming the editor for a RTS game and I have created the following: enter image description here

I am trying to modify the terrain so that it is not completely grassy. I am intending to add functionality so that I can create paths while playing the game. I already have created a blendmap that someone here recommended for me, but that does not allow the user to edit the texture while using the app, but only after drawing an image and saving it to the game folder. I fiddled with the shaders a bit, but I was only able to add a square that is able to move, but it does not leave a path behind it. Here is an example of what I am working towards. I have not been able to find any resources that really shows what I need.

Here is a snippet of the code:

if(((tiledCoords.x - mouseTexCoords.x) < 4) && ((tiledCoords.x - mouseTexCoords.x) > 0))
if(((tiledCoords.y - mouseTexCoords.y) < 4) && ((tiledCoords.y - mouseTexCoords.y) > 0))
blendMapColor.g = 1;
//rTextureColor = texture(rTexture, tiledCoords) * 1;


With these if statements, it checks to see if the mouse is over a certain area within a few units, and if it is, it changes the terrain texture to a sand texture. However, it is unsuccessful in being able to create paths, but rather, a mere square that can move around the landscape.

Thank you all in advance!

  • 1
    \$\begingroup\$ How did you create the "moving square"? This might be a good starting point. \$\endgroup\$
    – tkausl
    Jul 27, 2022 at 1:02
  • \$\begingroup\$ I created it by setting each point on the terrain to have a red value of 1 that is within a certain range. However, the other points maintain their color, and thawt is what is causing this problem... \$\endgroup\$ Jul 27, 2022 at 7:17
  • \$\begingroup\$ The key term you want to search for here is "Render Target" - you want to render your path-drawing cursor into a texture, instead of rendering to the screen, accumulating its influence this frame with all the previous marks you laid down in previous frames. Then you switch back to rendering to the screen, using your modified texture as a blend map. \$\endgroup\$
    – DMGregory
    Jul 27, 2022 at 10:51

1 Answer 1


How I see it in my head:

You have the tiles, each tile has at least one type of terrain texture at each moment (stone, grass, snow etc.) or some value that represent type of terrain on its tiles. From now you can draw each tile separately sampling terrain texture appropriate for the type of terrain in current tile.

Blending two different type of terrain

Let's go farther and allow one tile to have, let's say, an array of terrain types in it. For example one tile has terrain = [grass, stone], another terrain = [grass]. Base on that you can sample and blend between all terrain texture you tile has for smooth looking.

Cursor moving

When you move cursor and know the chosen type of terrain (e.x grass), you detect if cursor is over a curtain tile, then changes tile terrain type to grass or, if you support blending, you can add to terrain type array of tile the grass type, so hovered tile now has [snow, grass]. You can decide to add or remove a curtain type of terrain from tile based on what type of terrain it surrounded (what type of terrain surrounded tiles have). It's done in game/engine code. I don't how exactly you draw terrain, but you can send all terrain types as one array to opengl buffer and access it by index in shader, index = index of your tile. Or you can draw tile one by one time setting type for each tile to shader each time it's about to draw.

Modifying texture

You don't need this, usually you have a concrete set of textures you use in game. And then, in fragment shader, you work with them. You can use multiple of textures and blend between them in shader. And in your game code using opengl you set exact texture you want your fragment shader to use. For now I would recommend to send all your terrain textures to shader (it actually can be a one atlas) and by type in tiles decide for texture or textures to use to get a result color(sampling).

I hope I got you thinking.

  • \$\begingroup\$ This is not exactly how I draw my terrain... though this is a good idea... I draw the landscape as a whole and then on top of that I put the texture down. \$\endgroup\$ Jul 27, 2022 at 18:44
  • \$\begingroup\$ Your idea requires the creation of terrain patches which, at the end of the day, would be easier to texture, but at the same time, it would require much more computing power, I have found. You see, I used to program my terrain engines using patches, but when all the patches would be rendering, it would lead to a heavy decrease in framerate, and with this being a Real Time Strategy game, framerate is something that is almost completely necessary. \$\endgroup\$ Jul 27, 2022 at 18:46
  • \$\begingroup\$ Ok, I got it. What about continue drawing as you do, but still have information about terrain type for each patch (it's just one integer or even less - short). And the patch is just a smallest size of square you want to apply a terrain texture on. So in the shader you just need to understand the index of current drawable part of terrain (square, patch) and take appropriate type from array of terrain types by index. At the same time @DmGregory solution also great. U can maintain a one big texture of the terrain in video memory, change in one pass(using as render target), apply in result pass \$\endgroup\$
    – justix
    Jul 28, 2022 at 6:12
  • \$\begingroup\$ Hmmm... is there a way that I could get the texture as it is shown in the Fragment Shader and then just set THAT texture to the texture that I have on my terrain? \$\endgroup\$ Jul 29, 2022 at 6:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .