Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 05 Jul 2009
Offline Last Active Aug 28 2015 08:18 AM

Topics I've Started

Voxel Ray Tracing

01 August 2015 - 10:29 AM

Hello all, I want to start an exploratory discussion on ray tracing voxels and get some ideas on how it works.


A few weeks ago I found this game called Voxelnauts, which is being developed by John Olick from IDSoft. Short video of the game in action can be found here and longer trailer here. At first glance it's a typical Minecraft clone...but as I studied the videos and screen shots closer, the rendering technology looks much different from most voxel games.




Aside from the higher resolution voxels, what I noticed is that there isn't shading on each individual voxel. Typically, the different sides of the cubes are light or darker depending on whether or not they are facing the light. Each voxel is lit depending on the distance from the light source.


I did a ton of digging, and found that they are raytracing sparse voxel octrees.


My goal is NOT to create yet another Minecraft-clone infinite modifiable worlds, but rather imitate the art style. My assumption is, polygonizing meshes at this resolution would wreck havok on GPUs as scenes get more complex...which is why I am looking into raytracing (If i'm wrong, let me know). The problem is...all the information on the internet is basically Masters and PHd thesis/research papers on SVO construction/traversal instead of rendering implementations. And they are all focused on extremely high resolution data sets, realistic rendering, or offline rendering. Not much information for this kind of interactive semi-high resolution rendering


Here is what I know:


1) Voxelnauts uses CUDA to perform raytracing on the GPU, this is essentially required to get interactive frame rates

2) Ray tracing is by looping through each pixel on the screen casting a ray against an octree to find the voxel and resultant color of that pixel.

3) This is a very complicated way of rendering 3d graphics


One method I found is to basically use 3D textures (or SVOs I suppose) for voxel data, render a cube for each "object" using standard triangles, then in the ray trace the voxels in the fragment shader. This is probably the most straight forward way to do things, but I'm not sure if it's a viable method. Full 3D textures would have to be stored, which could be slow and take up a lot of memory, and tracing every fragment of the cube even if they are transparent could be slow.


The alternative is to go all out and ray trace against a massive octree to be able to render full scenes, which I'm not entirely sure how well it would work. It seems like a bad idea to store a large scene in one giant octree, but that's what it seems like Voxelnauts is doing.



I'm looking for ideas, tips, comments, information, experience, anything that might give me a better understanding of how this works or alternative ideas. I done a tone of googling and have read several of the thesis papers on this stuff...but it's still foggy to me. 

Monogame: can't figure out the Matrix functions

20 May 2015 - 08:10 PM

My ultimate goal is to get 0,0 to be in the top left of the window, with +y going down and +x going right


Current results: http://i.imgur.com/86DJOXg.png


If I use

Matrix.CreateOrthographic(1280.0F, 720.0F, -1.0F, 1.0F);

I get the result from the first 1/3 of the image above. My squares are centered, but is inverted/mirrored on the y axis.



If I use

Matrix.CreateOrthographicOffCenter(0.0F, 1280.0F, 720F, 0F, 0F, 1.0F);


I get the result from the last 1/3 of the image above. No matter how I translate it via view or world matrix translations, my vertex buffer is never visible on screen. The Matrices do seem to be calculate correctly (if I manually type in the numbers matching the orthographic formula into a calculator, the numbers match), so something else weird is happening.



CreateOrthographic matrix: http://i.imgur.com/Dke62yU.png

CreateOrthographicOffCenter: http://i.imgur.com/35Bky94.png (nothing changes if I remove the fragment offset. it simply shifts by -0.5F)

Vertices of the first square: http://i.imgur.com/N1TAang.png

Code snippet: http://pastebin.com/1cENgaS0

Can't get Lidgren client to connect to local server

06 May 2015 - 07:41 AM

I'm trying to get Lidgren working, however my client won't connect to the server for some reason. Server doesn't receive any messages, so I'm guessing the problem is entirely with the client. Client gets a "StatusChanged" message, but client never connects. Full source here:


        static void Main(string[] args)
            Console.WriteLine("Otrera Server");

            NetPeerConfiguration config = new NetPeerConfiguration("OtreraServer");
            config.Port = 14242;
            config.MaximumConnections = 5;
            NetServer server = new NetServer(config);


            if(server.Status == NetPeerStatus.Running)
                Console.WriteLine("Server is running on port " + config.Port);
                Console.WriteLine("Server not started...");

            NetIncomingMessage msg;
                while((msg = server.ReadMessage()) != null)
                        case NetIncomingMessageType.ConnectionApproval:
                            Console.WriteLine("Connection Approved");
                        case NetIncomingMessageType.StatusChanged:
                            Console.WriteLine("Status changed");
                        case NetIncomingMessageType.Data:
                            Console.WriteLine("Recieved message");
                            Console.WriteLine("Unkown message of type"+msg.MessageType.ToString());


            if(client == null)
                NetPeerConfiguration config = new NetPeerConfiguration("OtreraClient");
                client = new NetClient(config);


                client.Connect("localhost", 14242);


            NetIncomingMessage msg;

            while((msg = client.ReadMessage()) != null)
                    case NetIncomingMessageType.DiscoveryResponse:
                    case NetIncomingMessageType.Error:
                        Console.WriteLine("Connection error");
                    case NetIncomingMessageType.StatusChanged:
                        Console.WriteLine("Status changed");
                    case NetIncomingMessageType.Data:
                        Console.WriteLine("Received message");
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.WarningMessage:
                        Console.WriteLine("Warning message");

Where is my frustum culling broken?

14 March 2015 - 02:24 PM

I'm trying to implement frustum culling, however I can't figure out where/how it's breaking.

Frustum culling on
How it should look

It's almost like it's rendering the opposite of what is expected, however that's not constantly the case. It's highly dependent on the view rotation and position.

Frustum code
Frustum viewFrustum(renderContext.projectionMatrix()*renderContext.viewMatrix());
Frustum::Frustum(const glm::mat4& matrix)
    // Extract the frustum faces from the projection*view matrix
    // http://web.archive.org/web/20120531231005/http://crazyjoke.free.fr/doc/3D/plane%20extraction.pdf
    mPlanes[Face::LEFT].n.x = matrix[3][0] + matrix[0][0];
    mPlanes[Face::LEFT].n.y = matrix[3][1] + matrix[1][0];
    mPlanes[Face::LEFT].n.y = matrix[3][2] + matrix[2][0];
    mPlanes[Face::LEFT].d = matrix[3][3] + matrix[3][0];

    mPlanes[Face::RIGHT].n.x = matrix[3][0] - matrix[0][0];
    mPlanes[Face::RIGHT].n.y = matrix[3][1] - matrix[1][0];
    mPlanes[Face::RIGHT].n.y = matrix[3][2] - matrix[2][0];
    mPlanes[Face::RIGHT].d = matrix[3][3] - matrix[3][0];

    mPlanes[Face::DOWN].n.x = matrix[3][0] + matrix[0][1];
    mPlanes[Face::DOWN].n.y = matrix[3][1] + matrix[1][1];
    mPlanes[Face::DOWN].n.y = matrix[3][2] + matrix[2][1];
    mPlanes[Face::DOWN].d = matrix[3][3] + matrix[3][1];

    mPlanes[Face::UP].n.x = matrix[3][0] - matrix[0][1];
    mPlanes[Face::UP].n.y = matrix[3][1] - matrix[1][1];
    mPlanes[Face::UP].n.y = matrix[3][2] - matrix[2][1];
    mPlanes[Face::UP].d = matrix[3][3] - matrix[3][1];

    mPlanes[Face::FAR].n.x = matrix[3][0] - matrix[0][2];
    mPlanes[Face::FAR].n.y = matrix[3][1] - matrix[1][2];
    mPlanes[Face::FAR].n.y = matrix[3][2] - matrix[2][2];
    mPlanes[Face::FAR].d = matrix[3][3] - matrix[3][2];

    mPlanes[Face::NEAR].n.x = matrix[3][0] + matrix[0][2];
    mPlanes[Face::NEAR].n.y = matrix[3][1] + matrix[1][2];
    mPlanes[Face::NEAR].n.y = matrix[3][2] + matrix[2][2];
    mPlanes[Face::NEAR].d = matrix[3][3] + matrix[3][2];

    for (int i = 0; i < 6; i++)

bool Frustum::sphereIntersects(const glm::vec3& pos, float radius)
    // cheack against each plane
    for (int i = 0; i < 6; i++)
        if (glm::dot(mPlanes[i].n, pos) + mPlanes[i].d + radius <= 0)
            return false;

    return true;
Where I check each point
            glm::vec4 point = renderContext.projectionMatrix()*renderContext.viewMatrix() * 
                glm::vec4((float)x*World::CHUNK_SIZE, (float)c*World::CHUNK_SIZE, (float)z*World::CHUNK_SIZE, 0);

            if (!viewFrustum.sphereIntersects(glm::vec3(point.x, point.y, point.z), 16.f))

Can't figure out vertex winding

01 March 2015 - 06:50 PM

I'm working on a project with OpenGL and am trying to figure out vertex winding. I understand that, by default OpenGL considers faces where the vertices are "wound" counter-clock wise are front facing. I've built a cube out of individual faces, however, OpenGL keeps culling them away...which I have narrowed down to being a vertex winding issue.
Currently, for the front face (pointing towards the +z axis, camera is pointing down the -z axis) is wound as such:
|     /
|   /
1 /
    / |
   /  |
  /   |
Which, to me....looks counter clockwise. However, the triangles are only visible when I turn on glCullFace(GL_FRONT). Does it have something to do with the direction that the final edge connection is going?
Is there something I'm not understanding about what is considered front-facing or something with counter-clock wise winding?
Note: I'm rendering with GL_TRIANGLES