# Imprecision

Members

15

194 Neutral

• Rank
Member
1. ## Vertex Normals In A QuadTree Terrain

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. ## Vertex Normals In A QuadTree Terrain

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. ## GLFW 3 GetCursorPos() only zero

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. ## GLFW 3 GetCursorPos() only zero

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. ## Slowdowns / 'Anti-Hotspot'

[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. ## Slowdowns / 'Anti-Hotspot'

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. ## OOP design question

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. ## Initialize variables out of a loop?

[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. ## Initialize variables out of a loop?

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. ## Texture artifacts

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. ## Texture artifacts

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. ## LOD with Perlin Noise "zoom"

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. ## LOD with Perlin Noise "zoom"

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?