Jump to content

  • Log In with Google      Sign In   
  • Create Account


Imprecision

Member Since 08 Mar 2012
Offline Last Active Oct 23 2013 01:23 PM

Topics I've Started

Vertex Normals In A QuadTree Terrain

18 October 2013 - 07:32 AM

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:

shitnormals0lp68.png

 

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:

ddtrkkil.png

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:

f4333nntb7abt.png

 

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;
        }

GLFW 3 GetCursorPos() only zero

11 July 2013 - 12:26 PM

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?


Slowdowns / 'Anti-Hotspot'

25 September 2012 - 11:46 AM

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:

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

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?

OOP design question

10 July 2012 - 08:07 AM

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.

Initialize variables out of a loop?

29 April 2012 - 09:09 AM

Hey, I have some lopps that repeat more than 1000 times.
In these loops, I use alot of new variables like so

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
        }
}

that means to me, that I allocate new memory everytime I run trough the loop.

When done something like this:

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
	  }
}

isn't that pretty much faster?
Because I use the same memory for every loop, instead of allocate evertime new one?

PARTNERS