• Advertisement

Archived

This topic is now archived and is closed to further replies.

terrain texturing

This topic is 5004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello. i''m trying to draw large terrain (1024x1024), i''ve implemented ROAM and it works fine. but results with big texture are very bad, so i have to use texture tiling. can you show me some ways how can i realize that? (i''m looking for pretty fast solution. speed is going down when i bind texture per triangle) thanks a for your time eL

Share this post


Link to post
Share on other sites
Advertisement
You are asking how to tile a texture? This is very simple.
If you are using shaders it''s as simply as multiplying the texture coordinates by the number of times you want it to tile.
If you aren''t using shaders, you can use the texture matrix. Just select the matrix with glMatrixMode(GL_TEXTURE) and do your normal glScaling.

(I think that''s the right call to select the matrix, might be a wrong keyword though)

Share this post


Link to post
Share on other sites
no.

each triangle has index for texture. when i draw whole terrain i have to bind intensively too many textures. i need avoid that, coz it''s slow.

Share this post


Link to post
Share on other sites
The only way to get around that is batching. You shouldn''t have very many textures, and if you want to reduce the number of switches, switch to a texture, draw every patch that has that texture, switch to another texture, draw every path that has that, etc.

Share this post


Link to post
Share on other sites
Hi,

if you have multitexturing available, you can create an alpha-map for each tiling-texture that streches across the entire terrain.
Then you simply modulate the texture with the alpha. This way you render your terrain several times but you can also use linear filtering on the alpha map and get nice looking transitions between different textures.
This would even work without using multitexturing if you have destination-alpha available by using additive blending but it''s probably slow as hell because of the read-modify-write for the blending.

Regards,

Jan

Share this post


Link to post
Share on other sites
jeickmann> sounds like a solution. but i''m not sure if i completely understand. each triangle has two uv - one to tile-texture and second to alpha-map, right? how it''s realized transition triangle then? (has been drawned twice?)

Share this post


Link to post
Share on other sites
Yes, each triangle has two u/v''s (usually you can use texgen for it, which, on modern cards, is probably faster than sending 4 floats per vertex).
For the transition-triangles, you use additive blending:
glBlendFunc(GL_ONE, GL_ONE);

if you want to speed up rendering, you should also add an alpha-test that only allows fragments with alpha>0.0f to pass on to the blending stage. This prevents the black fragments from taking up memory bandwith for the blending.
glAlphaFunc(GL_GREATER, 0.0f);
glEnable(GL_ALPHA_TEST);

Jan

Share this post


Link to post
Share on other sites
i see.
but roam algorithm split far triangles, which uv and texture i have to use then?
or should i look for another terrain visualisation algorithm, which will be better suitable with texturing?

eL

Share this post


Link to post
Share on other sites
quote:
Original post by jeickmann
Yes, each triangle has two u/v''s (usually you can use texgen for it, which, on modern cards, is probably faster than sending 4 floats per vertex).
For the transition-triangles, you use additive blending:
glBlendFunc(GL_ONE, GL_ONE);

if you want to speed up rendering, you should also add an alpha-test that only allows fragments with alpha>0.0f to pass on to the blending stage. This prevents the black fragments from taking up memory bandwith for the blending.
glAlphaFunc(GL_GREATER, 0.0f);
glEnable(GL_ALPHA_TEST);

Jan



Actually, the memory bandwidth stays the same I think no matter how many pixels are blocked by the alpha test. The alpha test isn''t performed until halfway into the pipeline, so its already been passed through memory into the GPU''s processor.

Share this post


Link to post
Share on other sites
quote:
Original post by oconnellseanm
Actually, the memory bandwidth stays the same I think no matter how many pixels are blocked by the alpha test. The alpha test isn''t performed until halfway into the pipeline, so its already been passed through memory into the GPU''s processor.


Not if you do the additive blending with the framebuffer.
The alpha-test prevents the blending from being performed for black pixels and saves you a read-from-fb, write-to-fb, which are quite costly.
You are right in saying that the AGP-bandwidth stays the same.

quote:
Original post by lesni_bleble
i see.
but roam algorithm split far triangles, which uv and texture i have to use then?
or should i look for another terrain visualisation algorithm, which will be better suitable with texturing?

eL



You can use an object-linear texgen mode. This lets the OpenGL calculate the texure-coordinates from the object-space vertex positions.
You basicly scale the x/z-coordinate (assuming your terrain lies in the x/z-plane).
Google for automatic texture generation OpenGL or look it up in the red book.

Jan

Share this post


Link to post
Share on other sites
lesli_beble has mentioned that he has to bind a large number of textures.That means that jeickmann''s solution needs one pass per texture,so I don''t think it''s very viable.I think the best solution,as okonomiyaki suggested,is batching and it can work in combination with ROAM and VBOs.You just have to use one VBO for each texture.When you calculate the triangles on the fly,you put the data in the correct VBO,according to the texture index.In the end,you just render the VBOs with the appropriate texture binding.

Share this post


Link to post
Share on other sites
Yes, but if you only sort the triangles by texture, you will get very weird popping once a triangle with texture A splits into two triangles with textures A and B.

You could always go for a hybrid approach by sorting by texture but putting a triangle into the VBO''s for all textures that influence it and then use the alpha-texture. This way, you save the T&L for the vertices that aren''t used at all by the texture.
Additionally, you get nice fading where different textures meet if you also add triangles close to the textured area.

Jan

Share this post


Link to post
Share on other sites

  • Advertisement