• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=Mr. Smartass;31929632]I'm rendering terrain using a triangle list with a series of vertecies in XNA. I want to draw the triangles one way, but I have no idea how to do it. Here's an example of what I mean [img]http://i.imgur.com/s7jpE.png[/img] How would I achieve this?[/QUOTE] not sure how you would do it with XNA, but I would reorder the way indices are generated. And assuming you are using triangle strips or whatever it's called in DirectX/XNA, you would have to switch to plain triangles. Your index array will take up take up 1.5x it's current space. Also, you'll still get the artifacts and whatnot, it'll just be in alternating directions as opposed to the same direction. I would instead work on making a higher detail terrain and writing some shaders to smooth out the lighting.
[QUOTE=robmaister12;31929891]And assuming you are using triangle strips or whatever it's called in DirectX/XNA, you would have to switch to plain triangles.[/QUOTE] But that's a triangle fan, isn't it? If DirectX supports triangle fans you could use one for those and just loop through all the points in a middle-then-border-clockwise (or counterclockwise, not sure) manner
[QUOTE=esalaka;31930987]But that's a triangle fan, isn't it? If DirectX supports triangle fans you could use one for those and just loop through all the points in a middle-then-border-clockwise (or counterclockwise, not sure) manner[/QUOTE] I totally forgot about triangle fans... good call. Oh and apparently DX10 doesn't support them, but if XNA sticks to DX9 then you're good to go.
snip
[QUOTE=esalaka;31930987]But that's a triangle fan, isn't it? If DirectX supports triangle fans you could use one for those and just loop through all the points in a middle-then-border-clockwise (or counterclockwise, not sure) manner[/QUOTE] I'm not sure about how it is in D3D, but in OpenGL that would dramatically increase the number of draw calls necessary. Whereas a strip or triangle array can define an entire mesh at once, a triangle fan is 'stuck' to the first vertex you enter. You end up having to do a draw call per 2x2 square instead of a single draw call for everything.
No, you can use [url=http://www.opengl.org/wiki/Vertex_Specification#Primitive_Restart]primitive restart[/url] to combine lots of separate fans into a single draw call.
So wait, would doing it the way I want to actually be worse than what I already have? I want to make the terrain much less detailed, so that I can realistically make it bigger, but the current method generates terrain that looks like ass up close.
Try it and see. It doesn't add any triangles, but it does make the element array a bit longer (for a whole terrain, not the little 9-point example above). That could potentially have a performance cost if memory bandwidth is your bottleneck, but I doubt that's the case. So performance-wise it should be about the same, and it should look better. [editline]25th August 2011[/editline] Oh, you said you're using XNA, so Direct3D, not OpenGL. I don't know much about the D3D API, but see if it has something analogous to OGL's primitive restart feature; I'd be surprised if it didn't.
I have a question about C#. Is ToString() that bad? How else would I display information to the HUD about non-string items. Is the only viable solution to only update the field when the value changes? Also, should I use StringBuilder.
So, I just got back into C++ development, and- whoah, did it always take this long to compile? I'm using libtorrent, which in turn uses boost, and even projects of only ~100 lines take several minutes to compile. Obviously it's the libraries, but is there a way to mitigate this? I mean, there's no reason for it to recompile that shit every time, right? I'm assuming I did something wrong, so please point it out and laugh at me so I can develop efficiently.
[QUOTE=RyanDv3;31942168]So, I just got back into C++ development, and- whoah, did it always take this long to compile? I'm using libtorrent, which in turn uses boost, and even projects of only ~100 lines take several minutes to compile. Obviously it's the libraries, but is there a way to mitigate this? I mean, there's no reason for it to recompile that shit every time, right? I'm assuming I did something wrong, so please point it out and laugh at me so I can develop efficiently.[/QUOTE] Are you clicking rebuild every time?
I hit f7/"Build solution". Is that wrong?
[QUOTE=RyanDv3;31942730]I hit f7/"Build solution". Is that wrong?[/QUOTE] try F5
It's a dll, does that make a difference? I mean, I would have been using f5, except the project doesn't actually execute.
Unless your rebuilding the whole project every time, it should only need to compile new files/modified files. So you must be doing something wrong
Exactly
Well, if you change a header-file, all files including that will need to be re-compiled. That might also trickle down to further header-files of course. I'm not sure if some form of caching is used for including other header-files that were not changed. You can try to avoid some of that by using forward declarations and not putting unrelated stuff into a single header file. [editline]26th August 2011[/editline] Oh, and take a look at precompiled headers. External headers will be an excellent choice for that.
For some reason, the first page of this thread 404'd. It works all the way back to page 2, but when you get to the first one it breaks. Maybe Garry needs help with something?
[QUOTE=jalb;31922891]-Helpful Post-[/QUOTE] Ah thanks for putting me on the right track, I've been put off implementing function pointers because I still don't quite understand what to use them for. The second solution you posted seems pretty close to what I had in mind. Thank you!
[QUOTE=Wyzard;31936374]Try it and see. It doesn't add any triangles, but it does make the element array a bit longer (for a whole terrain, not the little 9-point example above). That could potentially have a performance cost if memory bandwidth is your bottleneck, but I doubt that's the case. So performance-wise it should be about the same, and it should look better. [editline]25th August 2011[/editline] Oh, you said you're using XNA, so Direct3D, not OpenGL. I don't know much about the D3D API, but see if it has something analogous to OGL's primitive restart feature; I'd be surprised if it didn't.[/QUOTE] I really don't think that triangle fans are a good idea for this at all. Indices (indexes?) were practically made for terrain like this. All 9 outer vertices (counting the one already duplicated for the fan to complete) in the triangle fan would have to be duplicated for each surrounding fan which is an insane amount of waste, and it would just be a huge mess in generating and editing. Not to mention the indices can take any order you want, you could change the triangulation of bad terrain areas. Maybe this is brash, but triangle fans are near worthless now, probably why they have been removed from direct3d10 and up.
[QUOTE=NotoriousSpy;31941408]I have a question about C#. Is ToString() that bad? How else would I display information to the HUD about non-string items. Is the only viable solution to only update the field when the value changes? Also, should I use StringBuilder.[/QUOTE] I would like confirmation on this question as well. I've used ToString() is it frowned upon for some reason?
[QUOTE=chimitos;31944377]For some reason, the first page of this thread 404'd. It works all the way back to page 2, but when you get to the first one it breaks. Maybe Garry needs help with something?[/QUOTE] [url=http://www.facepunch.com/threads/1092921-What-do-you-need-help-with-V.-3.0/page1]This link works.[/url]
For everyone suggesting using fans, I unfortunately cannot as triangle fans have been inexplicably removed from XNA 4.0. How would I get that same shape?
[QUOTE=Philly c;31944992]I really don't think that triangle fans are a good idea for this at all. Indices (indexes?) were practically made for terrain like this. All 9 outer vertices (counting the one already duplicated for the fan to complete) in the triangle fan would have to be duplicated for each surrounding fan which is an insane amount of waste, and it would just be a huge mess in generating and editing. Not to mention the indices can take any order you want, you could change the triangulation of bad terrain areas. Maybe this is brash, but triangle fans are near worthless now, probably why they have been removed from direct3d10 and up.[/QUOTE] You can still use an index buffer with triangle fans, and infact in opengl you would be pretty much required to use an index buffer to make use of [url=http://www.opengl.org/sdk/docs/man4/xhtml/glPrimitiveRestartIndex.xml]primitive restart[/url] in this situation. In this case using primitive restart would save you a couple of indices per triangle fan so the memory usage would be slightly lower than an indexed triangle list. Triangle fans still core in opengl 4. I believe they were removed for performance reasons from Direct3D 10 though, so they should probably still be avoided. If you can find official word on that I'd like to hear it. [QUOTE=Mr. Smartass;31945162]For everyone suggesting using fans, I unfortunately cannot as triangle fans have been inexplicably removed from XNA 4.0. How would I get that same shape?[/QUOTE] Generate a vertex buffer which contains a list of grid points, then generate an index buffer which contains a triangle list.
[QUOTE=bean_xp;31945683]Generate a vertex buffer which contains a list of grid points, then generate an index buffer which contains a triangle list.[/QUOTE] That's exactly what I'm doing, and it comes out in the typical fashion it should- squares made of 2 triangles. [t]http://i.imgur.com/UqlVd.png[/t]
[QUOTE=Mr. Smartass;31945902]That's exactly what I'm doing, and it comes out in the typical fashion it should- squares made of 2 triangles.[/QUOTE] Then it's just down to the order you put the indices into the index buffer. Keep in mind that every 3 indices you put into the buffer forms a triangle. If you're still having trouble creating the triangle layout you want, try hard coding the indices or writing out the list on paper that you'd use to make the shape in your diagram. Then think about how you'd repeat that across the terrain patch.
[QUOTE=bean_xp;31946047]Then it's just down to the order you put the indices into the index buffer. Keep in mind that every 3 indices you put into the buffer forms a triangle. If you're still having trouble creating the triangle layout you want, try hard coding the indices or writing out the list on paper that you'd use to make the shape in your diagram. Then think about how you'd repeat that across the terrain patch.[/QUOTE] I don't understand though, wouldn't I have to have at least1 blank triangle in the middle that's 0 units big to be able to have 8 triangles sharing the same middle?
[QUOTE=NotoriousSpy;31941408]I have a question about C#. Is ToString() that bad? How else would I display information to the HUD about non-string items. Is the only viable solution to only update the field when the value changes? Also, should I use StringBuilder.[/QUOTE] ToString() is fine, where on earth did you hear it was bad
Wohoo, got my problem fixed. I had to calculate every odd one, and then tell it how to position that particular vertecie. [csharp] private void SetUpIndices() { indices = new int[(terrainWidth - 1) * (terrainHeight - 1) * 6]; //sets the counter to default to 0. int counter = 0; for (int y = 0; y < terrainHeight - 1; y++) { for (int x = 0; x < terrainWidth - 1; x++) { // tells what the lower left, top left, lower right, and top right corners are, and where they are positioned. int lowerLeft = x + y * terrainWidth; int lowerRight = (x + 1) + y * terrainWidth; int topLeft = x + (y + 1) * terrainWidth; int topRight = (x + 1) + (y + 1) * terrainWidth; //calculates what is defined as a slanted up cell, and what is not bool slantUp = true; if ((y % 2 == 0) && (x % 2 == 0)) slantUp = false; if ((y % 2 == 1) && (x % 2 == 1)) slantUp = false; //if the slant is up, tells it how it should calculate the tri's. if (slantUp) { indices[counter++] = topLeft; indices[counter++] = topRight; indices[counter++] = lowerLeft; indices[counter++] = topRight; indices[counter++] = lowerRight; indices[counter++] = lowerLeft; } // if the slant is NOT up, how it should calculate the tri's. else { indices[counter++] = topLeft; indices[counter++] = lowerRight; indices[counter++] = lowerLeft; indices[counter++] = topLeft; indices[counter++] = topRight; indices[counter++] = lowerRight; } } } } [/csharp] [editline]26th August 2011[/editline] What would be the best method for storing map data? Currently I use grayscale heightmaps.
XML! [code] <triangle> <vertex> <value>1.0f</value> <value>0.0f</value> <value>1.3f</value> </vertex> <vertex> <value>0.0f</value> <value>0.0f</value> <value>0.3f</value> </vertex> <vertex> <value>1.0f</value> <value>1.0f</value> <value>0.3f</value> </vertex> </triangle> [/code] :smug: no, but seriously, grayscale heightmaps are excellent because images can be compressed pretty well. It's much more compact than most model formats out there and parsing it is a breeze (especially in C#)
Sorry, you need to Log In to post a reply to this thread.