Hey!
It's me again haha.
I recently changed from Monogame to XNA as for several reasons (including ContentPipeline and Shaders) and
decided to redo my Icosphere-Project a little.
Heck a little is not quite it, I'm going from scratch, as I got to the edge, where the compiler is telling me, that no more Primitives can be hold for one TriangleLine and I do need quite more for nice Terrain on a Sphere.
So I looked up some concepts of others, including the QuadTree, which seems logic to me as I need more Primitives but don't want to get limited by XNA or to calculate the mass of Data if I could hold the required amount of vertices.
As I am learning quite in a different way than other would recommend, I want to come up with own Ideas to create such a thing and after that, read what others did or what the "official solution" is.
I'll keep it short to not more you (haha).
My concept is to have a struct Quad which contains its 4 Positions and 6 Indices (as made from triangles) and its 4 Child-Quads
(It is like a linked List with 4 Nexts haha).
public struct Quad
{
VertexPositionColorNormal[] positions;
Quad[] children;
int[] indices;
public Quad(Vector3 p1,Vector3 p2,Vector3 p3,Vector3 p4)
{
positions = new VertexPositionColorNormal[4];
positions[0].Position = p1;
positions[1].Position = p2;
positions[2].Position = p3;
positions[3].Position = p4;
indices = new int[6];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 0;
indices[4] = 2;
indices[5] = 3;
children = new Quad[4];
}
public void addChildren(Quad c1,Quad c2,Quad c3,Quad c4)
{
children[0] = c1;
children[0] = c2;
children[0] = c3;
children[0] = c4;
}
This is wrapped by another struct as I want to have 6 Root-Squares forming a Cube.
public struct QuadContainer
{
public List<Quad> quadList;
public QuadContainer()
{
quadList = new List<Quad>();
}
public void AddQuad(Vector3 p1,Vector3 p2,Vector3 p3,Vector3 p4)
{
if (quadList.Count < 6)
{
quadList.Add(new Quad(p1, p2, p3, p4));
}
}
}
This is, what I made so far.
Now my further Thoughts:
- I'll have a function which creates the Quads and it's childs to an extend, that I want, so every of the 6 Roots have n^n childs.
I do not care about double Indices , which happens when calcing the halves for a new vertex, at this point ,as it would require a global List of Indices which would make things rather complicated. - I normalize each vector and multiply it by a given scale to have the desired size and a sphere at all.
- I'll have a function which takes the view's position, look at, Up-Vector and angle to Calculate the distance to the Construct and which of the vectors are seen at all to built a a list which contains only the seen Vertices and Indices. Further it calculates the distance to the Quads to see which resolution it should have.
Problem here: This would require to go through all Parental Quads and see if they are close enough and run through each child as it proves true (recoursive spoken). This might have an inpact on Calculation-Time needed. I do reduce it by not regard those quads not seen but either way this should be consuming. Any Ideas here?
- As Filling the Index-Buffer and VertexBuffer, I'll check for any double Vertex and sort them out to replace the index in the IndexBuffer with the index of the first Vertex occured.
Promlem here: Same as above but can be done in the calculation of Distance and Frustum, so it won't consume any extra time
Is that acceptable till here?
Cuz now there is my little problem I didn't think quite enough of yet.
When adding terrain, should I do it in the Step where the vectors are normalized and scaled? Like adding up the height?
This would result in a If(terrainWished) case, so I still can make Spheres without Terrain.
The other case, namely adding the terrain at the end of creation would give me problems with runtime again, as
it would go through all quads again (and this truly sucks even though I tried this with the max limit of Primitives per Buffer and with 10 Spheres with just a little delay on first draw. But I need to keep in mind that I want whole Solar-Systems with dynamic shaders for Atmospheres etc)
What do you think?
Edit:
Totally forgot to ask:
Which Noise Generator should I implement?
Perlin or fbm or ridged multifractal?