Sharing vertices & vertex arrays/buffers

Started by
2 comments, last by Ysaneya 23 years, 8 months ago
This question isn''t specific to OpenGL or D3D.. since the vertex arrays/buffers mecanism is almost the same, it doesn''t matter. I''m trying to implement vertex arrays in my landscape engine, because i think it was the "way to go" compared to immediate mode (less overhead calls). Using indexed primitives, i also thought i wouldn''t have to transform my shared vertices more than once.. and it looks like it''s not possible. I explain: To share a vertex (ie, to have many indices refering to a single vertex in the array), it must have the same data: world position, normal, texture coords.. So, i have a landscape. Right. Given a vertex, i can share the world position. Not a problem. Texture coords ? Well, no problem there either, assuming it''s using the same texture. Normals ? I''m averaging them, so, again.. no problem. But what about lightmaps ? I''ve just come to the conclusion that all the vertices have different lightmap coords. So i can''t share my vertices. If my landscape is composed of a mesh of 3000 triangles, i''ll have to use 9000 vertices. No less. A solution may be to use shared vertices in the first pass, and duplicated vertices in the second pass (i want a general solution without using multitexturing) ? But then i''ll have to maintain two different arrays of world positions (and indices, since the indices won''t be the same..).. and i won''t be able to use the cache (compiled vertex arrays) ? Ex: Let''s say i''m doing it in two pass. First pass, i render the triangles with their texture. Second pass, their lightmap. 1. Setup array of world pos. for first pass. 2. Setup array of tex coords. for first pass. 3. Render with indexed primitives. 4. Setup array of lightmap coords. for second pass. 5. Render with indexed primitives. Any thought ? Y.
Advertisement
Hmm i must add that, after checking the Titan (Q3A viewer) source, shared vertices aren''t used at all. Everything is duplicated. Which makes me think there is no real solution to my problem..

Anyway... if you have other suggestions

Y.
Hi,
No, there''s no way to share vertices. This was my first personal holocaust when moving to a 3D api, because in all my old ways of doing 3d, I specified the texture coordinate when I handled the triangle, not when I handled the vertex.

However, I do a landscape of 64x64 squares, so when I don''t share, it''s 16000+ vertices. When I broke it down and used one big texture on it, I gained about 1ms in the rendering time.

I don''t know if the transformations are just that fast, or if Direct3D has some sort of checker to see if it will be rendering the same coordinate over again or not, but since it was only 1ms, I just said fine, I''ll do it this way.

I''ve heard, though, that DirectX8 is going to allow you to share vertices, in the spirit of tardy functionality. God alone knows why this wasn''t implemented in the first place. Maybe it''s part of His plan.




-- Goodlife

-----------------------------
Those whom the gods would destroy, they first drive mad.
--DirectX design team official motto
-- Goodlife-----------------------------Those whom the gods would destroy, they first drive mad.--DirectX design team official motto
And you don''t need to wait for DX8, you could transform your Vertices by Hand, i mean you aren''t using Vertex Lighting, so the you just need to do the Matrix multiplications. One point is you are loosing the Hardware TnL, but if you have Objects on the Landscape, you can use it for that, and you are automatically put some computation time to the CPU and the other to the GPU.

By the Way, when using Lightmaps, you should not use Normals, they are completely useless, cause you get your darker and lighter Areas with your Maps.

I never done an lightmapped terrain, but can''t you just specify one Lightmap, for an Area of Triangles, say 5x5, and then have at least there shared Vertices. Without having to compute an to large Lightmap.

Another way is to use some triangles twice in places where you have Light Sources. That would be a combination of Vertexlighting and Lightmapping. You first render your Terrain, with one global Lightsource (Sun), and have an Basic Shading, but without Shadows, and Lightspots.
Now you render some triangles on those positions where you have shadows or Spotlights.

Hope that helps a bit
Lars

--------> http://www.larswolter.de <---------

This topic is closed to new replies.

Advertisement