Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075929 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:00:59 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Terrain rendering methods
Pages: [1]
Print
Author Topic: Terrain rendering methods  (Read 377 times)
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« on: December 27, 2012, 07:36:32 AM »

Hi.

I am here, because I couldn't find clear answers for my questions.

Namely, I'd like to know what, or rather how, can I render a terrain.
What I have (for now) is simply loading up an .obj + applying my texture to it.

Now, this is some kind of method, but the textures are really low-resolution when you come near the ground with the camera.

How should I do it instead? So that the textures are tiled with me still being able to describe which vertices should have which textures applied? (Or something like that)


Basically, I want to be able to display terrain with multiple textures (up to 4) and smooth transitions between them..


Examples I'd like to achieve:

Mount&Blade (I need to know how do the do such terrain, with patches and stuffs) -




Obviously gothic II

http://piclair.com/data/j2x1l.jpg



I know it's kinda chaotic, but I cannot explain better  Epileptic
Now what I ask you for is ways of rendering such terrain, possibly with OpenGL background.
Logged

Nothing to do here
Polly
Level 4
****


View Profile
« Reply #1 on: December 27, 2012, 08:02:46 AM »

How should I do it instead? So that the textures are tiled with me still being able to describe which vertices should have which textures applied? (Or something like that)

Yes, something like that Smiley A common technique for texturing terrain is using weight ( or color, or custom ) attributes for each vertex to determine which textures are used and at what opacity ( the actual rendering of this is done using a shader these days ). This can also be combined with procedural techniques such as using the height coordinates to determine part of the texture selecting.

Are you building your own terrain editor? Or are you using a 3D application such as Softimage / Maya / Blender?
Logged
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #2 on: December 27, 2012, 08:58:33 AM »

I can use both blender and/or 3ds max to make such terrain, but I am not sure how.

I don't know how would this have to look on the technical side. Send attribute for each vertice texture weight (vec4 for four textures here, right?), send 4 textures as sampler2D (I don't really know how can I send more than one texture - never tried that) and then do something like that?:

Code:
vec4 firstColor = texture2D(firstTexture,someUV)*textureWeight[0];
vec4 secondColor = texture2D(secondTexture,someUV)*textureWeight[1];
vec4 thirdColor = texture2D(thirdTexture,someUV)*textureWeight[2];
vec4 fourthColor = texture2D(fourthTexture,someUV)*textureWeight[3];
gl_FragColor = firstColor*secondColor*thirdColor*fourthColor;

Ugh. Also, terrain would have to be exported as .obj, or something?
Logged

Nothing to do here
nospoon
Level 1
*


View Profile Email
« Reply #3 on: December 27, 2012, 10:41:28 AM »

You can use texture masking.

So, you have a texture (RGBA), each channel = diffrent texture type.
So, for example a red channel = grass texture.

Then in the shader you sample the mask texture, with a texture atlas.
Like :

Code:
//pseudocode
vec4 mask = texture2D(maskTex,coords);
vec4 grass = texture2D(grassTex,coords * vec2(100.0));
grass.alpha = mask.r;
vec4 dirt  = texture2D(dirtTex,coords * vec2(100.0));
dirt.alpha = mask.b;
/// add other textures (up to 4 supported)
out = mix_colors(grass,dirt,...);

This way you can easily edit how the terrain will be textured, using any image editor.
This method supports only 4 diffrent texture types, but it shouldnt be a problem to support more.
I multiply the tex coords * 100.0 for the terrain textures - this way the textures are tiled, so they kinda look like they have high resolution.
Logged
kamac
Level 10
*****


Notorious posts editor


View Profile Email
« Reply #4 on: December 27, 2012, 10:53:04 AM »

You can use texture masking.

So, you have a texture (RGBA), each channel = diffrent texture type.
So, for example a red channel = grass texture.

Then in the shader you sample the mask texture, with a texture atlas.
Like :

Code:
//pseudocode
vec4 mask = texture2D(maskTex,coords);
vec4 grass = texture2D(grassTex,coords * vec2(100.0));
grass.alpha = mask.r;
vec4 dirt  = texture2D(dirtTex,coords * vec2(100.0));
dirt.alpha = mask.b;
/// add other textures (up to 4 supported)
out = mix_colors(grass,dirt,...);

This way you can easily edit how the terrain will be textured, using any image editor.
This method supports only 4 diffrent texture types, but it shouldnt be a problem to support more.
I multiply the tex coords * 100.0 for the terrain textures - this way the textures are tiled, so they kinda look like they have high resolution.

I only don't understand what are you using vec4 mask for and why multiplying UV coords by 100.0, 100.0 makes them tiled  Concerned
Logged

Nothing to do here
nospoon
Level 1
*


View Profile Email
« Reply #5 on: December 27, 2012, 11:05:25 AM »

Okay, so :
#1 why *100 makes textures tiled :
I assumed, that the terrains texture coordinates are from (0,0) to (1,1). (for the mask texture to work properly)
If texture coordinates are > 1.0 then the image gets tiled.
So if we are processing the texture at (0.5,0.5) * 100 - it will get tiled, this is just how shaders work.

#2 the maskTex is just an image.
vec4 mask is a "pixel" on the maskTex that's currently being processed by the shader.
vec4 is formatted like (red green blue alpha)
So - I assumed, that the red value is a value for grass texture.
So I take the red component (mask.r), and it's my "alpha" for the terrain grass texture.
I do the same for diffrent textures. (so mask.b is an alpha for dirt etc)

Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic