Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL terrain

Started by martyj2009 Jan 11, 2014 at 7:02 PM 4 replies 3.3k views
Original Post
martyj2009
martyj2009

I was wondering if I could get some input on managing terrains with OpenGL.

For terrains I'm using a heightmap. I also have a corresponding texture map which designates the textures to use for each vertex.

The texutres are loaded with a GL_TEXTURE_ARRAY_2D accessed by a textureIndex.

This allows me to change the texture at a given point to a path based texture, grass, ect.

I know other people out there use height of a verticie to indicate the texture to use. My problem with this is, how would I ever designate paths in my terrain?

How does everyone else manage terrains?

AbandonedAccount
AbandonedAccount

Are you asking how to store pathing data in a texture? If so, think of the terrain as a grid and each cell of the grid is a pixel of the image. You can then store bools for whether you can go each direction from a given cell (pixel). That's usually not even necessary since there are usually rules (can't climb X elevation change as an example). It is useful in some limited situations though.

Unless you're using path data in a shader, there is very little reason to use a texture though. You'd often duplicate the data anyways since you still need to write code that can path with better knowledge than just neighboring cells unless you don't have AI players and don't allow the user to move to distant points with a single action.

If that's not the answer you're looking for, you might try posting in a more general forum than OpenGL. It sounds like you're asking about pathing, terrain, etc. in general, not anything specific to OpenGL.

empirical2
empirical2

If you are asking what i think you are asking I also use texture arrays but I store selection info in the vertex RGBA components. (up to) 2 textures and a transparency for belding (if req)

L. Spiro
L. Spiro

Automatic selection of textures for grass, rocks, cliff-sides, etc. is one part, but paths need to be manually drawn through the terrain via some kind of editor. Your terrain system needs to support not only automatic texture selection based on height and slope, but also manual texture applications for artists.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
dpadam450
dpadam450

Depends what you mean by "path" is this just where you can walk on the terrain? OR do you mean painting dirt trails and such?

Typically for AI paths, you take the height map and create an array of walkable squares. Each square is walkable if the normal of it is pointing up towards the sky. For instance a 45 degree slope might be your cap:

if (dot_product(Tile.normal, Vec3(0,1,0) < .5) { // terrain tile is tagged as walkable;}

NBA2K, Madden, Maneater, Killing Floor, Sims 
Murdocki
Murdocki

You could have a look at texture splatting.

If you use all four channels of a splat/detail texture you can have four types in a single base texture, resulting in four possible textures. I'm using two splat textures so i can have up to eight different textures applied to the terrain. This is more than enough for a single terrain patch.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.