GPWiki.org
GPWiki.org
It is currently Mon May 20, 2013 7:51 pm

All times are UTC




Post new topic Reply to topic  [ 38 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat Jun 18, 2011 10:08 am 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
Ok well some you know i am on a mission to create a procedural planet renderer, i am getting there slowly, just trying out a few things. I have done geomipmaps, spherical clipmaps, clipmaps, quadtrees. Well i have finally picked one. I have decided to stick with a 6 clipmap, method, uaing a cube the morphing it in to a sphere. Well now i am trying to snyc the 6 planes the problem i am having is the camera centers do not align together and i am trying to figure out the best way to do this.

Image

as you can see in my picture they do sncy and as i move forward they move away i have managed to get them sunwhat closer but i am a bit confused as to how i am going to get this to work properly. That is the hard question.

Question 2; I have been racking my breains for ages trying to generate a sphere which i can cull the front face, i can generate a perfect sphere, using various maths i have seen on the net and examples, but they seem to create clockqise and counterclockwise strips at the same time, so when i cull them i get a sphere with each other triangle missing, i was thinking maybe a geosphere or something. The reason i need to be able to generate this is beacuse, the atmosphere code must be dynamic, depending on the size of the planet. I basically need to generate a sphere the exact way that MDX sphere mesh used to work, i cant seem to find out how or maybe im just crap at maths lol.

Any help is always apreciated. Thanx in advance. :)


Top
 Profile  
 
PostPosted: Sat Jun 18, 2011 1:36 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
here it is morphed on to a sphere so you can get some perspective on what i am tring to do, the res is small its only 1000 radius just for debuging but should really be much much bigger to show the heightmap properly.

Image


Top
 Profile  
 
PostPosted: Sat Jun 18, 2011 7:44 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
It looks like you're doing an orthogonal projection of the texture onto the sphere. That's why it's stretched to infinity along the left side, where the projectors are tangential to the surface.

You need to use a radial projection, not an orthogonal one.

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Sat Jun 18, 2011 8:18 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
yeah im just using it for now just to get the gyometry side working then ill worry about the texturing later. :) My atmospheric scattering shader works lovely just cant seem to generate the right sphere for it.


Top
 Profile  
 
PostPosted: Sun Jun 19, 2011 11:21 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
I'm afraid I don't know what you mean by "the camera centers do not align together".

What do you want the geometry to be?

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Sun Jun 19, 2011 11:26 am 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
on a gyometry clipmap, the camera point is the center if the clipmap its the highest LOD, when you use 6 and make them a cube they have dif x,y,z coords depending on which face. The normal way tot o do it is to take the camera x,z and ignoor the y, as my object is basically a sphere that dosent work and the centers do not align with the camera.


Top
 Profile  
 
PostPosted: Sun Jun 19, 2011 6:54 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
i was thinking maybe for the atmosphere to use an icosahedron beacuse everything else dosent seem to cull properly the whole point is to cull the front face, when i generate a sphere using normal sphere maths i get triangle gaps beacuse the triangles wind in both directions.


Top
 Profile  
 
PostPosted: Sun Jun 19, 2011 10:20 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
What is your normal sphere maths?

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Mon Jun 20, 2011 6:04 am 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
I have used a few different aproaches, prefarably ones you have showed me before, but then i needed something with indices, i managed to find one for ogre, there all basically similar. At the moment im using this code, its for a triagnle strip. try it and then turn on culing and see what happens, the same happens with all the other aproaches i have tryed.

Code:

        Public Sub New(ByVal Dev As GraphicsDevice, ByVal Cam As Camera2, ByVal PlMap As PlanetaryMap, ByVal FromSpaceShader As Effect, ByVal Stacks As Integer, ByVal Slices As Integer, ByVal Radius As Single, ByVal GRadius As Single)
            Device = Dev
            Camera = Cam
            Planet = PlMap

            Me.radius = Radius
            Me.GroundRadius = GRadius

            Dim elm() As VertexElement = {New VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0)}
            Declaration = New VertexDeclaration(Device, elm)

            ' Calculates the resulting number of vertices and indices
            Dim numberVertices = (Stacks + 1) * (Slices + 1)
            Dim numberIndices = (3 * Stacks * (Slices + 1)) * 2
            Dim indices As Integer() = New Integer(numberIndices - 1) {}
            Dim vertices As Vector3() = New Vector3(numberVertices - 1) {}

            Dim StackAngle As Single = MathHelper.Pi / CSng(Stacks)
            Dim SliceAngle As Single = CSng(Math.PI * 2.0) / CSng(Slices)

            ' Generate the group of Stacks for the sphere 
            Dim wVertexIndex As Integer = 0
            Dim vertexCount As Integer = 0
            Dim indexCount As Integer = 0

            For stack As Integer = 0 To (Stacks + 1) - 1

                Dim r As Single = CSng(Math.Sin(CSng(stack) * StackAngle))
                Dim y As Single = CSng(Math.Cos(CSng(stack) * StackAngle))

                ' Generate the group of segments for the current Stack 
                For slice As Integer = 0 To (Slices + 1) - 1
                    Dim x As Single = r * CSng(Math.Sin(CSng(slice) * SliceAngle))
                    Dim z As Single = r * CSng(Math.Cos(CSng(slice) * SliceAngle))

                    vertices(vertexCount) = New Vector3(x * Radius, y * Radius, z * Radius)

                    'vertices(vertexCount).Normal = Vector3.Normalize(New Vector3(x, y, z))

                    'vertices(vertexCount).TextureCoordinate = New Vector2(CSng(slice) / CSng(Slices), CSng(stack) / CSng(Stacks))
                    vertexCount += 1

                    If Not (stack = (Stacks - 1)) Then
                        ' First Face
                        indices(indexCount) = wVertexIndex + (Slices + 1)
                        indexCount += 1

                        indices(indexCount) = wVertexIndex
                        indexCount += 1

                        indices(indexCount) = wVertexIndex + 1
                        indexCount += 1

                        ' Second Face
                        indices(indexCount) = wVertexIndex + (Slices)
                        indexCount += 1

                        indices(indexCount) = wVertexIndex
                        indexCount += 1

                        indices(indexCount) = wVertexIndex + (Slices + 1)
                        indexCount += 1

                        wVertexIndex += 1
                    End If
                Next
            Next

            Me.IndexCount = indexCount
            Me.VertexCount = wVertexIndex

            Vertexbuffer = New VertexBuffer(Device, GetType(Vector3), numberVertices, BufferUsage.None)
            Vertexbuffer.SetData(vertices, 0, vertices.Length)
            IndexBuffer = New IndexBuffer(Device, GetType(Integer), numberIndices, BufferUsage.None)
            IndexBuffer.SetData(indices, 0, indices.Length)
            AtmosphereEffect = FromSpaceShader
        End Sub


my scattering works fine and well check budinga.blogspot.com. Thats not the problem when your in space you have to cull all the front faces of the sphere so you can see the planet inside the atmosphere.


Top
 Profile  
 
PostPosted: Wed Jun 22, 2011 7:27 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
edit: post deleted because I want to think about this a bit more. :P
edit2:

(1) What I'm noticing is that Slice runs from 0 to Slice+1-1

The +1 is to join the end of the strip with the beginning of the strip, and the -1 is because you start counting at zero.

That makes sense... but it means you have Slices+1 vertices in a stack.

But in your triangle definitions, you are indexing vertexindex on the assumption there are Slices vertices in a stack. One less than there actually are.

I'm guessing this will cause things to not line up, but in itself it won't lead to some of the triangles being oriented the wrong way, but there should be a single triangle permanently missing from one of your poles.



(2) Now, you say you are passing this as a triangle strip?

With triangle strips, we don't define three vertices for every triangle. A triangle occurs with each triple of vertices, so a list of 6 indices will define 4 triangles like this:
(123)456
1(234)56
12(345)6
123(456)

Naturally, these alternate in clockwise/anticlockwise handedness.

But your code looks like your defining triangles separately, and not creating triangle strips. Calling the two triangles 1 and 2, you are passing 6 indices. Three for triangle 1 and three for triangle 2. The graphics card is going to be drawing these four triangles from your 6 indexes because you're telling it to draw a triangle strip:

(111)222 -- clockwise & needed
1(112)22 -- anticlockwise & redundant
11(122)2 -- clockwise & redundant
111(222) -- anticlockwise & needed

As you can see the handedness alternates in a triangle strip. The first and last of these four are the ones you intended to draw, and they are being rendered with opposing handedness, causing backface culling to produce something that looks like a sponge..


:)

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 6:25 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
ohh my days i have been racking my brains about this for ages i think your on to something, its soo simple but i missed it :). I can see it now ill let you know how i go.


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 6:53 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
You are great, my atmosphere problem is solved. i now need to figure out the lod problem and i am onmy way :).

Image

Image

Uploaded with ImageShack.us

It has also fixed the artifacts i was getting
only a couple of things i have to fix 1, disable depth buffer and use alpha blending. add the atmospheric scattering to the terrain, already got a shader that works but need to fix, the LOD first, and i am pretty sure could be wrong but i think the atmosphere is meant to face to blue not full white could be wrong.


Top
 Profile  
 
PostPosted: Thu Jun 23, 2011 7:35 pm 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
That looks great :)

budinga wrote:
i now need to figure out the lod problem and i am onmy way :)


Is the lod problem the one with the cube?

I don't really know about clipmaps. I have only read this about them :- http://http.developer.nvidia.com/GPUGem ... ter02.html

The article talks about keeping the geometry constant, and adjusting height using a 2D vertex texture, whatever that is.

If you want to update the geometry each time the camera is moved, then there are two parts to this problem I think:
(1) Consider each square face, and identify the point that is directly below the camera. The point may be beyond the edges of the square.
(2) To create the LOD mesh about that point. If the point is beyond the edges of the square, then we must be able to construct the mesh such that the higher detail bits overlap the edge.

Quote:
i think the atmosphere is meant to face to blue not full white could be wrong.


In reality, the atmosphere has several layers. This is how it looks from the space station. I expect the vivid orange is due to sunset during summertime, and is an exaggeration of the normal colour.

Image

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
PostPosted: Fri Jun 24, 2011 6:29 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
It seems to me with the atmosphere i need to add some adition effect.

1. bloom post procesing
2. some blur for the space scene
3. a nice cloud layer with atmospheric scattering

the clipmap side of things i got a flat clipmap working, very well, but when i morph it to sphere i need to work out how each side of the cube will inetract with the lod.

Thanx for the info youve been a great help. :)


Top
 Profile  
 
PostPosted: Sat Jul 09, 2011 2:40 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
Finallt got it working properly and also got terrain lod and added some nice effects, just wanted to share my hard work with everybody.

Image


Top
 Profile  
 
PostPosted: Sat Jul 09, 2011 8:50 pm 
Bibliotherapist
User avatar

Joined: Wed Nov 03, 2004 1:28 pm
Posts: 6708
Location: Lincoln, Englandshire
Looking very cool. 8)

The IoTD needs images, mind if I re-feature these?

_________________
10 PRINT "Bad Monkey ";
20 GOTO 10


Top
 Profile  
 
PostPosted: Sun Jul 10, 2011 6:48 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
That looks very awesome indeed! Nice one! 8)

Lens flares are one of my pet peeves, but that's the only complaint I have ;)

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Mon Jul 11, 2011 2:42 am 
Game Programming Guru

Joined: Mon Aug 16, 2004 8:24 pm
Posts: 1137
Location: USA, New York
Wow! That must have been satisfying to create!


Top
 Profile  
 
PostPosted: Mon Jul 11, 2011 6:33 pm 
Grossly Helpful

Joined: Wed Apr 12, 2006 6:22 pm
Posts: 154
I would love you to feature them. Belive me there will be more may take while but im getting there. Can you please feature this new one as i have now added clouds, and water, with atmospheric scattering on both. I even managed to add some primative foam. I dont really like lens flares but i have to have it for realisim, and it brogtens it up nicely. One for you IGTHORN without the lens flare :)

The framerate is not great from space at the moment, i get 20fps on my machine and 10 on others, this is beacuse i have to render the terrain 3 times, 1 for colormap of the water 1 for reflectionmap, and 1 for well the terrain. :) I need to optimize my code alot, but its getting there. This implementation uses a mixture of all my work, but its based on Geomipmap at the moment and eventualy i want to hybread it to chunked lod. But for now i just need to work out a more eficiant way fo doing the terrain rendering.

Image

Just Use the caption, "My quest to recreate the universe.." To be continued.... :)


Top
 Profile  
 
PostPosted: Thu Jul 14, 2011 8:31 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3735
Location: South Africa
budinga wrote:
One for you IGTHORN without the lens flare :)

:lol :thumbs


Can't you disable the reflection mapping at a certain distance for a speed boost?

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group