How to fill triangle with different colors on front and back sides?

Started by
11 comments, last by Yura 11 years, 3 months ago
I don't think doubling each point is a good idea because my polygon is quite big. In better way vertex buffer contain 50 000 points, in worst - 10 000 000 and more (sometimes it just can't be drawn). Now I'm trying to reduce number of vertices by using Indexes, unfortinutly without success. There is other topic with more information about my project http://www.gamedev.net/topic/635625-fastest-way-to-draw-rectangles-with-slimdx-sharpdx/
Advertisement
That is quite big. Let us look at the numbers:

Your current vertex size is 20 (4 floats, 4 bytes each for position, 4 bytes for the color)
10 million vertices.
This alone gives you approx 200 Mb of vertex data.

With a naive setup (add quads/tris as they come) this number will be scaled by factor of 6 or 3 respectively, so you've probably already blown the GPU memory limit of an average consumer card (or the limit the driver gives you). As you say: One draw call impossible. True, duplicating vertices further (or adding additional vertex data) is undesirable.

Sure you can now massage the API to make it work , but with these numbers I'm inclined to suggest an non-realtime approach (you could still use D3D for rendering though). Have you tried a GDI-setup (with low render quality) ?

Anyway, here some suggestions for D3D optimizations.
  • No need to use a Vector4 for position if your w is always 1. The D3D runtime will do that automatically for Vector3 (D3DDECLTYPE_FLOAT3 )
  • Reduce precision of your vertex elements. Half-floats/shorts for positions ? Scalar for the color ? With shaders you can even do sophisticated packing (custom format).
  • Why rely on big memory or insist on few draw calls ? Split your mesh into parts the API/GPU can cope with one at a time. You can still get good performance with that. It's sort of streaming.
  • Indexing, as Dynamo_Maestro suggested. To get familiar with start with something real simple (triangle, quad, two adjacent quads, grid, a sphere...).
  • Shaders: As mentioned, greater flexibility.
  • Instancing. Is a way to render "the same" geometry multiple times with different position/color/whatever. In your case this would be the quads for the geometry and the position and color for the instances. Consider this advanced D3D API, it needs SM 3.
But always know: no API-trick (or even using a "faster" API like D3D) is a silver bullet. You can setup a complex system reducing e.g. payload and the thing still renders slower.
Do some research and chose wisely which path you wanna go because I think you have a challenging problem.

That is quite big. Let us look at the numbers:

Your current vertex size is 20 (4 floats, 4 bytes each for position, 4 bytes for the color)
10 million vertices.
This alone gives you approx 200 Mb of vertex data.

With a naive setup (add quads/tris as they come) this number will be scaled by factor of 6 or 3 respectively, so you've probably already blown the GPU memory limit of an average consumer card (or the limit the driver gives you). As you say: One draw call impossible. True, duplicating vertices further (or adding additional vertex data) is undesirable.

Sure you can now massage the API to make it work , but with these numbers I'm inclined to suggest an non-realtime approach (you could still use D3D for rendering though). Have you tried a GDI-setup (with low render quality) ?

Anyway, here some suggestions for D3D optimizations.

  • No need to use a Vector4 for position if your w is always 1. The D3D runtime will do that automatically for Vector3 (D3DDECLTYPE_FLOAT3 )
  • Reduce precision of your vertex elements. Half-floats/shorts for positions ? Scalar for the color ? With shaders you can even do sophisticated packing (custom format).
  • Why rely on big memory or insist on few draw calls ? Split your mesh into parts the API/GPU can cope with one at a time. You can still get good performance with that. It's sort of streaming.
  • Indexing, as Dynamo_Maestro suggested. To get familiar with start with something real simple (triangle, quad, two adjacent quads, grid, a sphere...).
  • Shaders: As mentioned, greater flexibility.
  • Instancing. Is a way to render "the same" geometry multiple times with different position/color/whatever. In your case this would be the quads for the geometry and the position and color for the instances. Consider this advanced D3D API, it needs SM 3.
But always know: no API-trick (or even using a "faster" API like D3D) is a silver bullet. You can setup a complex system reducing e.g. payload and the thing still renders slower.
Do some research and chose wisely which path you wanna go because I think you have a challenging problem.

Thanks for your interest to my problem!
So, about your suggestions, I've already made changes in Vectors, now they are Vector3. It works fine. Now I'm trying to implement Indexes. It seems to be easy, with triangle list it realy is, but I can't force it to draw line list. But it is my bad, i'll do it soon.
I'm not very good in DirectX programming, so I have no idea what is SM 3, but idea with multiple geometry is very seductive. I'll try to figure out with this.
About shaders, I read about them but I didn't find how to solve any of my problems with their help... They are too difficult for me)

This topic is closed to new replies.

Advertisement