Imprecision

Members
  • Content count

    15
  • Joined

  • Last visited

Community Reputation

194 Neutral

About Imprecision

  • Rank
    Member
  1. I think you assume, that I have a global heightmap. I forgot to say that I this is procedural terrain. The heightdata is generated per Node on the GPU, so no global heightmap data.   Someone might say "Then make the heightmap one pixel larger in every direction" - That dosen"t work either. When the node is on the edge of the cube, I would have to make a 3D heightmap, what would require to know the different side while creating the heightmap and increases the memory consumption by at least 3 times.
  2. I finally managed it to get my terrain stitching working on a globe with six quadtrees. I used a index system similiar to this one http://img406.imageshack.us/img406/2153/screen4ya3.png. Everything looks fine so far (no cracks, no shifted heightdata), except for the lighting. The vertex normals on the edges are sh*t.   See the image below:   Is there any way how to calculate/interpolate the edges, so they have the same normal? One of the problems that I cant "fix in my head" are the differences between LODs I cant just copy the vertices of my neighbor because maybe its larger or smaller than me: Node (1) needs the vertex data (red and green slice) from node (2), (3) and (4)  to calculate correct normals. This means data from these nodes must be extracted (slice) and some of it must be skipped (because node (1) has a lower resolution) by the difference of the specific neighbor depth. This is complicated, but not that much.   The other way around is giving me headache. Node (2) needs the border vertex slice from (1) (the blue one). The problem is, that it just needs a specific "range" of the slice, so it needs to determine what exact position it (2) has compared to the border of the node (1) and calculate the index of the first vertex to extract. WTF?!     Next problem with this is, the 3D aspect. I have different behavior when my neighbors are on other sides of the node:   For Node (4) I need three slices to get correct normals for the north and west edge. One from (5) one from (6) and the last vertex for the corner from Node (1). When I have the same situation with the neighbors beeing on anthoder side, i just have 2 slices, because I don't have a corner at all.    -   Even if i would have a super algorithm that calculates how much shifted a smaller node to a bigger node is handling different sides of the cube... there must be another way. I found 1000 topics of neighbor finding and crack fixing problems for quadtrees. But not a single one who has problems with vertex normals.   This makes me suspicious that I make something fundamentally wrong.   Btw. here is the code how I calc the normals: private static Vector3d[] create(Vector3d[] vertices, int[] indices) { // Prefilling result int vertLength = vertices.Length; Vector3d[] result = new Vector3d[vertLength]; for (int i = 0; i < vertLength; i++) { result[i] = Vector3d.Zero; } // Calculating normals int length = (int)(indices.Length / 3); for (int i = 0; i < length; i++) { Vector3d v1 = vertices[indices[i * 3]]; Vector3d v2 = vertices[indices[i * 3 + 1]]; Vector3d v3 = vertices[indices[i * 3 + 2]]; Vector3d ab = v1 - v2; Vector3d ac = v1 - v3; Vector3d vCross; Vector3d.Cross(ref ab, ref ac, out vCross); result[indices[i * 3]] += vCross; result[indices[i * 3 + 1]] += vCross; result[indices[i * 3 + 2]] += vCross; } // Normalize for (int i = 0; i < vertLength; i++) { result[i].Normalize(); } return result; }
  3. I already suspected this when I saw the doc example using doubles and I am using int. Yes the "out" Parameters are call-by-reference in C#.   Thanks for your help  I will open a issue on Pencil.Gaming
  4. Hey, I'm using GLFW on C# with Pencil.Gaming   My problem is that GetCursorPos only returns 0 (i and j).     My code: static void Main(string[] args) { if (!Glfw.Init()) { Console.WriteLine("ERROR"); return; } GlfwMonitorPtr monitor = Glfw.GetPrimaryMonitor(); GlfwWindowPtr window = Glfw.CreateWindow(1280, 720, "SharpFloat", GlfwMonitorPtr.Null, GlfwWindowPtr.Null); Glfw.MakeContextCurrent(window); int i; int j; while (!Glfw.WindowShouldClose(window)) { GL.Clear(ClearBufferMask.ColorBufferBit); Glfw.GetCursorPos(window, out i, out j); Console.WriteLine(i + " " + j); Glfw.SwapBuffers(window); Glfw.PollEvents(); } Glfw.Terminate(); } Do I read it wrong? Or do I have to do something before I can read it?
  5. [quote name='Telastyn' timestamp='1348606320' post='4983732'] There's always a reason. For C#, that reason is usually the garbage collector. [/quote] Can I avoid this problem by creating nodes in a new thread? [quote name='Adam_42' timestamp='1348615263' post='4983798'] What you need to diagnose the issues is a [url="http://stackoverflow.com/questions/10644/any-decent-c-sharp-profilers-out-there"]profiler[/url]. [/quote] Mh... I don't think this is what I need. It's not that I don't understand which parts of code lines are slow, I don't know why the are getting slow by random.
  6. Hi, I'm working on my Quad-Tree for a while now, to generate the landcape. I optimized it pretty nicely so its able to produce new quads in 1 - 2ms. The problem is that C# slows down when there wasn't create a new quad for a while (while means starting from 500ms). Here an example: [CODE]Node gen; total 106ms noise 69 vert 11 rest Node gen; total 2ms noise 1 vert 0 rest 1 Node gen; total 2ms noise 0 vert 0 rest 1 Node gen; total 2ms noise 0 vert 0 rest 1 Node gen; total 3ms noise 0 vert 0 rest 2 Node gen; total 4ms noise 2 vert 0 rest 1 Node gen; total 7ms noise 1 vert 0 rest 6 Node gen; total 4ms noise 2 vert 0 rest 2 Node gen; total 37ms noise 1 vert 0 rest 35 Node gen; total 3ms noise 1 vert 0 rest 1 Node gen; total 19ms noise 17 vert 0 rest 1 Node gen; total 18ms noise 17 vert 0 rest 1 Node gen; total 19ms noise 17 vert 0 rest 1 Node gen; total 19ms noise 17 vert 0 rest 1 Node gen; total 2ms noise 1 vert 0 rest 1 Node gen; total 2ms noise 1 vert 0 rest 1 Node gen; total 22ms noise 16 vert 0 rest 4 Node gen; total 2ms noise 1 vert 0 rest 1 Node gen; total 18ms noise 17 vert 0 rest 1 Node gen; total 19ms noise 17 vert 0 rest 1 Node gen; total 19ms noise 17 vert 0 rest 1 Node gen; total 18ms noise 15 vert 0 rest 2 Node gen; total 19ms noise 17 vert 0 rest 1 Node gen; total 18ms noise 17 vert 0 rest 1 Node gen; total 2ms noise 1 vert 0 rest 1 Node gen; total 18ms noise 16 vert 0 rest 1 Node gen; total 2ms noise 1 vert 0 rest 1 Node gen; total 19ms noise 17 vert 0 rest 1 Node gen; total 2ms noise 0 vert 0 rest 1 Node gen; total 2ms noise 1 vert 0 rest 1[/CODE] As you can see the time for the generation CAN be very fast, but it slows down for no reason The difficulty of the data to create dosen't change at all. I know that C# / .NET optimizes parts of code that are 'in heavy use'like the hotspot technology in JVM. Is there any way to enable it manually? How do you handle it?
  7. Hi there, I asking myself for a while how to design correctly. Let me get an example: (C#) [source lang="csharp"]class SimpleClass { private int a = 0; private int b = 0; private int c = 0; public SimpleClass(int a, int b) { this.a = a; this.b = b; CalcC(); // CALL DESIGN A this.c = CalcC(this.a, this.b); // CALL DESIGN B } //METHOD DESIGN A private void CalcC() { c = a + b; } //METHOD DESIGN B private int CalcC(int first, int second) { return first + second; } }[/source] I always used variant A when working with private methods. But then I realised that I can't put my methods in unit tests, because they are working with the class properties and don't return any values. I working like variant A since years, and it would be nice if somebody can tell me something about this and the dos and don'ts of this. Thanks.
  8. [quote name='rip-off' timestamp='1335720128' post='4935846'] [...] Remember, if it is a trivial and safe transformation, the compiler writers will probably have already implemented it. [/quote] I don't count on that since I've read that this: [CODE] int length = List.Count for (int i = 0; i < length; i++ { //Run through list } [/CODE] is several times faster than [CODE] for (int i = 0; i < List.Count; i++ { //Run through list } [/CODE] One line of code optimization. [quote name='rip-off' timestamp='1335720128' post='4935846'] Finally, are you sure you need all these variables? For optimisation, the fastest code is the code that doesn't have to run. Perhaps some of these values are actually redundant. [/quote] It generates a planet chunk with curvature, trianglelist, heighmap and textures coordinates at once. Yes I need that many variables [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img] But thanks for all your answers. Now I'm able to clean up my code a bit
  9. Hey, I have some lopps that repeat more than 1000 times. In these loops, I use alot of new variables like so [CODE] for (int i = 0; i > 500; i++) { for (int j = 0; j > 500; j++) { int foo = 0; int bar = 2; double a; double b; double c; double x; double y; double z; // Do Something } } [/CODE] that means to me, that I allocate new memory everytime I run trough the loop. When done something like this: [CODE] int foo = 0; int bar = 2; double a; double b; double c; double x; double y; double z; for (int i = 0; i > 500; i++) { for (int j = 0; j > 500; j++) { // Do Something } } [/CODE] isn't that pretty much faster? Because I use the same memory for every loop, instead of allocate evertime new one?
  10. No, its definatly not z-fighting caused by two chunks. It seems that the texture wrapping runs out of precision. The values on the screenshot are the near /far- planes of the chunks. I calculate it on how close I'm to the surface, because the accuracy gets lost when i take 0.0000001 to 10000. The closer I get to the surface the smaller are the values for the planes.
  11. Hi, I get some artifacts on my texture when it's applied on a small chunk: [img]http://www.abload.de/img/unbenannt-208z3y.png[/img] (Normally there would be a sharp edge between blue and brown) Does someone know why this happens and how to solve it ?
  12. Hi swiftcoder. Thanks for the keywords [left]"fractal brownian motion" and "ridged multifractal" thats exactly what I was looking for! Now I got tons of new material [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img][/left] [left][size=4][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]NEW Question:[/font][/color][/size][/left] [left][size=4][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]Is the only way to get a seamless cubemap for terrain, to generate 3D noise? Or is there an algorithm to map 2D data seamless on a cube? [/font][/color][/size][/left]
  13. Hi guys, I'm using my Perlin Noise algorithm as a height map (I don't store as a texture, I use the values directly on my vertices). Representing an earth scale planet I need a height map for at least 510 million km². My problem is now, that I don't know how to make a "more detailed" noise on higher LOD. There must be another way than making an array of 32000*32000 random numbers for perlin noise to get acceptable terrain on highest LOD. Are there any techniques to get this done?
  14. [quote name='return0' timestamp='1331246804' post='4920526'] May I ask what the cell edge length actually is at the 18th subdivision of a quadree face for a cube representing, say the size of earth? [/quote] Earth has 510,000,000km², one side is one 6th: 85,000,000km² divided by 4[sup]18[/sup] is 0,0012km² or [u]1,237m² with a edge length of 35m[/u] Still huge in my opinion. [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] [quote name='Adam_42' timestamp='1331252258' post='4920540'] [quote name='Imprecision' timestamp='1331244191' post='4920519']The quadtree depth is at 18 that means that the smallest chunk is one 262144th of the original chunk in sidelength.[/quote] That's a subdivision size of about 24 metres, on the earth. Do you need to get that close in? [/quote] The 24m (or 35m) could be enough, (better would be a depth of 22 divisions) but i get imperfections already on depth of 14 which is definitely to big for me [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] [quote name='Adam_42' timestamp='1331252258' post='4920540'] The mantissa in a float is effectively stored with 24 bits of precision. At 18x subdivision you're left with 6 bits of precision, which isn't much - errors will be up to about 1/64th of the actual value. If you need to get that close in and have the surface look smooth I'd suggest using double precision. That means you will probably to do at least some of the transformation work on the CPU because most GPUs don't handle doubles[/quote] [quote name='hupsilardee' timestamp='1331248380' post='4920530'] ...Use double precision? [/quote] I already use double precision. All calculations are one the CPU made with double precision. When I send the vertices to the vertexbuffer the're converted to 32bit float. Matrice transformations are on 32bit too. Limiting factor is the graphicscard is working with 32bit float [quote name='Adam_42' timestamp='1331252258' post='4920540'] . You could just give the GPU screen space coordinates. Alternatively move the origin dynamically so 0,0,0 is on the bit of the surface you're looking at - it's currently about 6 million metres away! You might find [url="http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/"]http://randomascii.w...hat-in-a-float/[/url] and the other articles in that series helpful too. [/quote] I tried that out (putting the top surface to (0,0,0), but it didn't helped. I already got the highest precision in range of -1 to 1. [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
  15. Hello, because sometimes it's hard to follow an explanation only in mind I added a few pictures to this post. Sorry for those which have a slow internet connection. First of all, I'm programming a planet renderer. Im using the cube to sphere algorithm from mathproofs: [url="http://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html"]http://mathproofs.bl...-to-sphere.html[/url] My problem is that it running into the common floation point error because the algorithm forces me into a specific range (imho), and I don't know how to getting arround it. The algo morphes all 6 sides of a cube in to a sphere. One side look like this after morphing: [img]http://www.abload.de/img/prob471dty.png[/img] Using the algo on all 6 sides I get a sphere inbetween -1 and 1 (scale 1): [img]http://www.abload.de/img/prob3m2db7.png[/img] That LOD is implemented as an quadtree. When coming closer the chunk is seperated in 4 smaller chunks each with the same amount of vertices as the old chunk. [img]http://www.abload.de/img/prob513ffd.png[/img] These chunks can be seperated too, so I get a smooth surface even if im extremly close to the planet (in theory). This is how it look like if I create a really deep tree and zoom out: [img]http://www.abload.de/img/prob6mbdnw.png[/img] Here comes the trouble. On the tiny chunks the curvature is extrem small. Its so small that I run into floating point imprecision and the result is that: [img]http://www.abload.de/img/prob2zfcq9.png[/img] As you can see the surface is not flat and when I change the angle of the camera everything is "wobbeling". The quadtree depth is at 18 that means that the smallest chunk is one 262144th of the original chunk in sidelength. Visualising this on 2D it looks like this: [img]http://www.abload.de/img/prob16gde4.png[/img] What can I do to solve this problem? I already fixed my camera to Vector3.Zero and just move the world around me to get highest precision near to my camera, but I still got the problem. I appreciate every comment. Thanks.