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

3D Terrain?! How?!

Started by alex_r Nov 2, 2004 at 4:00 PM 16 replies 3.3k views
Original Post
alex_r
alex_r
AHOY! I have a question, how can I create a good 3D terrain system, and how can I create, or apply, the mixed texture? I like to develop a terrain like Torque... but... I don't know how begin, there any tutorial or article about it?
ehmdjii
ehmdjii
lots of articles about terrain:

http://www.gamedev.net/reference/list.asp?categoryid=45#88
alex_r
alex_r
...sorry... I forgot these articles :-/

The topic update:
I just need to know how create the mixed texture...
How can I do this?
skow
skow
I think you need to slow down. Read up on multi-texturing and blending.
ehmdjii
ehmdjii
here is a tutorial for you:

http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg4.htm
celestialVoid
celestialVoid
Quote:
Original post by alex_r
I just need to know how create the mixed texture...
How can I do this?


There are more methods to do it. For example,Texture Splatting.
More: Terrain texturing

You could also use a shader. Here is a brief example I wrote (Cg shader):
////////////////////// Vertex Program //////////////////////struct VP_OUTstr{	float4 position  : POSITION;	float2 texcoord0 : TEXCOORD0;	float2 texcoord1 : TEXCOORD1;	float2 texcoord2 : TEXCOORD2; };VP_OUTstr vp_main (uniform float4x4   modelviewmatrix, 		float4 pos : POSITION,		float2 texcoord0 : TEXCOORD0,		float2 texcoord1 : TEXCOORD1,		float2 texcross	: TEXCOORD2){	VP_OUTstr OUT;	OUT.texcoord0 = texcoord0;	OUT.texcoord1 = texcoord1;	OUT.texcoord2 = texcross;		OUT.position = mul (modelviewmatrix, pos);		return OUT;}//////////////////////// Fragment Program ////////////////////////struct FP_OUTstr{	float4 color : COLOR;};FP_OUTstr fp_main (uniform sampler2D tex0,		uniform sampler2D tex1,		float2 texcoord0 : TEXCOORD0,		float2 texcoord1 : TEXCOORD1,		float2 texcross  : TEXCOORD2){	FP_OUTstr OUT;		float4 color0 = tex2D (tex0, texcoord0);	float4 color1 = tex2D (tex1, texcoord1);	OUT.color = lerp (color0, color1, texcross);	return OUT;}


This shader works per-vertex, but it shouldn't be to hard to extend it to per-fragment level using control maps (you have an image where different color means different texture - you then texture the terrain based on this image).
Above code demonstrates that with two textures, which are then interpolated.
'tex0' and 'tex1' are textures to be interpolated.
'texcoord0', 'texcoord1' are coordinates of these two textures.
'texcross' is an array which holds how much these two texture will be interpolated, and where on the surface.
For example, if you had 6x4 vertices surface, you would apply one texture to the left side of it like this:

float texture_cross [] = { 1.0f,1.0f, 1.0f,1.0f, 0.0f,0.0f,
0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f,

1.0f,1.0f, 1.0f,1.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f,

1.0f,1.0f, 1.0f,1.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f,

1.0f,1.0f, 1.0f,1.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f, 0.0f,0.0f,
};

Each pair of elements in this arrays represents one vertex. You can now think of the surface like:
1 1 0 0 0 0
1 1 0 0 0 0
1 1 0 0 0 0
1 1 0 0 0 0

where 1 is the first texture, and 0 is the second. In the end, you get something like this:


If you need more details, just ask.
alex_r
alex_r
Thanks Wingman, it is easy to do... :D

I have a idea how can I develop my terrain system...

first is a height map, to develop the texture, I think it:

1 = Grass texture
2 = Dust texture
3 = Rock texture
4 = Water texture

in terrain file I place the texture info like this:

411111141
112222442
122114411
123214111
111111111

with this info I create a big texture for the terrain with the mix...
Like this, the first water texture (1,1), I mix with the grass texture (1,2; 2,2; 2,1)...

Is like a layer picture, the first layer is the height value, the second is the texture, 3 is the models ( tree, plants... )...

Thanks everyone for the help :D
alex_r
alex_r
AHOY AGAIN!

Here is my first terrain editor test... This is just a height map, now I'm testing how can I "paint" the texture and modele the terrain.

http://sites.vortexentertainment.com/alex_r/terraintest.jpg


Thx...
Ademan555
Ademan555
Well... out of curiosity, is anyone in here using brute force terrain? if not, what LOD algo are you using?

thanks
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
alex_r
alex_r
Quote:
Original post by Ademan555
Well... out of curiosity, is anyone in here using brute force terrain? if not, what LOD algo are you using?

thanks
-Dan


There no lod and frustum yet... Now I just working in the paint system...

Now the terrain have dynamic shadow, with the Matthew Strahan shadow system (http://www.gamedev.net/reference/articles/article2125.asp)
Here is the final result with shadow, PLEASE!!! IGNORE THE TEXTURE :D hehehehehe

http://sites.vortexentertainment.com/alex_r/terrainshadow.jpg

To create the mountain I get the distance from the center to the border from the circle (red circle), every point inside this circle can be changed... :)
I think I can use the same to create the textures. I got one cool sample from Delphi3D (http://www.delphi3d.net/articles/viewarticle.php?article=terraintex.htm), I think to use the same system too. I just need to understand to "port" to C++ :-/
ade-the-heat
ade-the-heat
I understand how you get the vertices in the shadow - but what do you color the vertex by ? eg do you color the vertex black if in the shadow and then modulate it with the grass texture color ?


cheers
alex_r
alex_r
I set the vertex color, like it: glColor3f(0.5f, 0.5f, 0.5f);
PsyVision
PsyVision
Ademan,

I use a quadtree for my terrain and then frustum cull the quads and then occlusion cull from the list of ones in the frustum, each quad is rendered using VBO's.

This is the result:

http://www.psyvision.co.uk/graphics.JPG
http://www.psyvision.co.uk/screen.jpg
PsYvIsIoN
alex_r
alex_r
Very good PsyVision!!!

I need to read more about quads and VBOs, you know any good article about it?

...I don't know anything about it... but, pelase, don't tell it to anyone... :p hehehe
zedzeek
zedzeek
Quote:
Original post by Ademan555
Well... out of curiosity, is anyone in here using brute force terrain? if not, what LOD algo are you using?

thanks
-Dan


in the method in the screenshot below, im going (1 dimensional explanation)

4 patches of say 8meter's wide == LOD 0
4 patches of say 16meter's wide == LOD 1
4 patches of say 32meter's wide == LOD 2
etc
i draw everything with quad's but on the borders between the patches, i split the lower res quad into 3 triangles (so i dont get cracks)
alex_r
alex_r
Quote:
Original post by Anonymous Poster
alex_r,

How do you draw those circles on the terrain (the red and yellow circles). I'm assuming this is a cursor for your to use as a painting tool on your terrain, how do you do that?

Thanks!


void MapEditorDrawCursor(){	int X = 0;	float x = 0;	float z = 0;	V_Graphic.v_Begin_Poly(VG_LINE_STRIP);	V_Graphic.v_SetColor3(1.0f, 0.0f, 0.0f);	for( X = 0; X <= 360; X+= 45 )	{		x = float(16 * cos(deg2rad(0+X)));		z = float(16 * sin(deg2rad(0+X)));		V_Graphic.v_DrawVertex( x+MouseCursorX, Height(x+MouseCursorX, z+MouseCursorY ), z+MouseCursorY );	}	V_Graphic.v_SetColor3(1.0f, 1.0f, 0.0f);	for( X = 0; X <= 360; X+= 45 )	{		x = float(32 * cos(deg2rad(0+X)));		z = float(32 * sin(deg2rad(0+X)));		V_Graphic.v_DrawVertex( x+MouseCursorX, Height(x+MouseCursorX, z+MouseCursorY ), z+MouseCursorY );	}	V_Graphic.v_End_Poly();}


zedzeek, how you calcule the distance?
alex_r
alex_r
zedzeek, is like this:
Dist = sqrt((double)(val[0]*val[0] + val[1]*val[1] + val[2]*val[2]));

Topic Locked

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

Sign in to reply to this topic.