Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: About Textured Smooth Terrain Surfaces...

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Turkey
    Posts
    3

    About Textured Smooth Terrain Surfaces...

    Hi Everyone,

    I am trying to get a good looking textured smooth terrain surface on my Opengl application. I applied triangle_strip,texture-mapping and normals to the terrain but it looks like this,
    http://picasaweb.google.com/muratgozu/OpenglIssues# (non-smooth)

    How can I get a smooth textured terrain surface like this,
    http://picasaweb.google.com/muratgozu/OpenglIssues# (smooth)?

    I am using 257x257 Height-map for the terrain heights and 128x128 rock BMP for texture mapping. I am using a scale factor 200 to enlarge the terrain. But my terrain looks like crisp shape and you can see the rectangle areas. What should I do to get a smooth surface?

    Thanks
    Murat Gozu
    Murat Gozu

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2008
    Location
    france
    Posts
    26

    Re: About Textured Smooth Terrain Surfaces...

    Your lighting model is not precise enough. OpenGL simply requires vertex normals to make smooth lighting transitions.

    First, you'll have to compute each face' normal. Let's assume you have a triangle ABC. Chosse two sides : AB and BC. Take their product ( can't remember the english term right now, but it's not the dot product, it's the other one ), and you'll get a vector that is perpendicular to both of them : the normal of the triangle. Renormalize it.

    Then you need vertex normals. It doesn't really makes sense mathematically, but think of it as the interpolation of the faces normals.
    For each vertex, just take the average of the normals of every face to which the vertex belongs. You can now destroy faces normals and use your vertex normals using glNormal or by binding it to your VBO.

  3. #3
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: About Textured Smooth Terrain Surfaces...

    Take their product ( can't remember the english term right now, but it's not the dot product, it's the other one )
    It is "cross product".

  4. #4
    Intern Contributor
    Join Date
    May 2008
    Posts
    71

    Re: About Textured Smooth Terrain Surfaces...

    hey, are you definiing the nature of the terrain manually by vertices? I want to learn how to make terrain like you have. How is it done? Do we need a game engine ?

  5. #5
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: About Textured Smooth Terrain Surfaces...

    your texture coordinates look wrong.
    also looks like flat shading is used.
    for fixed function pipeline:
    glShadeMode(GL_SMOOTH); // activate linear interpolation across triangle vertices

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: About Textured Smooth Terrain Surfaces...

    baconbeastnz > Like redbarm said, the terrain is built from a height map which is no more than a gray scale texture. To create the terrain, you just need to create a grid, generate texture coordinates for each vertex and fetch texture color at these coordinates. This would give you the vertex elevation.

    _NK47 > this is clearly a normal problem. glShadeModel(GL_SMOOTH); would just enables color interpolation in a triangle, which is the default state.

  7. #7
    Intern Contributor
    Join Date
    May 2008
    Posts
    71

    Re: About Textured Smooth Terrain Surfaces...

    ok I see I see. So in creating a massive world like in WoW. Would the tools developer make a program which allows a 'level creator' to make the terrain entirely from a GUI?

    And the complexity behind the program which generates the terrain, would just be using heightmaps?

  8. #8
    Advanced Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: About Textured Smooth Terrain Surfaces...

    @redbarm
    just for checking maybe glEnable(GL_NORMALIZE) would help.
    better to generate normals on your own though.

    @baconbeastnz
    not all terrains are generated from heightmaps. those are all static as long as the image is static.
    you can use also diamond-square alogrithm to produce slightly random ones or just load a model file.

  9. #9
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: About Textured Smooth Terrain Surfaces...

    And no, the complexity of terrain rendering is not reduced to heightmaps. A basic terrain can be generated from this kind of map but generally, there are behind, many complex algorithms to manage for example level of detail (LOD), texture mapping like megatexturing and others.

    Taking, the WoW 3D engine as an example, you can see that terrain geometry in the background is moving (morphing) because the engine adapts the geometry complexity related to the distance from the viewer.
    More general information here.

  10. #10
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,262

    Re: About Textured Smooth Terrain Surfaces...

    About the terrain morphing, read from page 51 of
    http://s08.idav.ucdavis.edu/olick-cu...m-in-games.pdf
    it's very interesting, and I guess not too hard to make with terrains. (but for generic meshes it can be hell, I guess)

    Ah, and about recomputing normals, I guess this will be mathematically OK:
    Code :
    #define NUM_VERTS 4225
    #define NUM_TRIANGLES 3000
    vec3 vertices[NUM_VERTS]; // initialized with your mesh data
    int triangles[NUM_TRIANGLES*3]; // initialized with your mesh data, indices into vertices[]
     
    vec3 normals[NUM_VERTS];  // we will be computing this
    int  numTrisPerNormal[NUM_VERTS];
     
    void ComputeNormals(){
    	int i;
    	for(i=0;i<NUM_VERTS;i++){
    		normals[i] = vec3(0,0,0);
    		numTrisPerNormal[i]=0;
    	}
    	for(i=0;i<NUM_TRIANGLES;i++){
    		int index0 = triangles[i*3+0];
    		int index1 = triangles[i*3+1];
    		int index2 = triangles[i*3+2];
    		vec3 v0 = vertices[index0];
    		vec3 v1 = vertices[index1];
    		vec3 v2 = vertices[index2];
     
    		vec3 edge1 = v0 - v1;
    		vec3 edge2 = v2 - v1; // or is it = v1-v2
     
    		vec3 norm = cross(edge1,edge2);
    		norm.normalize();
    		normals[i]+=norm;
    	}
    	for(i=0;i<NUM_VERTS;i++){
    		int num = numTrisPerNormal[i];
    		if(num){
    			normals[i] /= num;
    			normals[i].normalize();
    		}else{
    			normals[i] = vec3 (0,1,0); // just in case
    		}
    	}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •