Jump to content
  • Advertisement
Sign in to follow this  
drake7707

[SlimDX][SM4.0] Feedback requested

This topic is 2603 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

Over the past month or so I've dabbled into XNA4.0 and SlimDX to create a voxel engine. I am completely new at DirectX and related frameworks, but I've written a raytracer in C# before and my work involves pressing keys to form c# code, so I know my way around C#.

I know what you might be thinking, yet another another one wanting to mimic minecraft and while it's certainly true that I take elements from it, the main reason was to create a platform where i can experiment with procedural content generation in 3D, without the need to make 3D models to get anything remotely feasible (and 2D -> 3D , pixels -> voxels is just easier to interpret :P).

Anyway, I've had some success writing stuff, but being completely new I probably made a lot of newbie mistakes. Things like you shouldn't initialize your shader this way, you shouldn't use constant buffers in that way, etc, etc. It's those things that I would like to eliminate and this is why I need some feedback from more experienced users. I had a hard time finding examples that would suit my needs (I probably looked in the wrong place), so I experimented a lot.

If you look into the code, the parts I'm most concerned about is the AbstractDXManager and DXManager, those contain the initialization parts and the voxelshader.fx, which contains the vertex, geometry and pixel shader.

To briefly describe how the engine works:

- The terrain manager has an array of chunks, each chunk has an array of cells (blocks).

- Each chunk has a vertex buffer, when a cell changes, the vertex buffer is scheduled to be rebuild (in a seperate thread, running in the ChunkRebuilder class). The vertex buffer contains 1 vertex per voxel, of type VoxelVertex.

- A voxel vertex has:

*) a position

*) a face mask to determine which sides have to be created

*) a shade for each face (byte) that says how dark the face is

*) a resolution, which tells the shader how big the voxel should be.

- Based on the distance of the camera, chunks differ in resolution. Further away means the resolution of the voxels is higher (and I just realised this naming is the opposite of what it actually does), so multiple cells are grouped together into 1 to reduce the amount of triangles to be rendered.

- In the render loop, every chunk that intersects with the viewing frustrum is sent to the shader. I'm using a chunk octree to reduce the intersections to O(log(n)) (average case), O(n) worst case. As the chunks are axis aligned, the octree doesn't contain duplicate chunks in the leaves.

- I also have an fixed array of dynamic lights (max 1024), that does dynamic lighting (no really!). This really slows things down to a crawl so I determine the number of visible lights by those that are less than a certain distance away from the camera to the shader. A light itself contains the position and the radius.

- The vertex shader does nothing, it only passes the in struct to the geometry shader

- The geometry shader does the most work:

*) It checks if the face has to be rendered by checking the face mask and does a standard backface culling check (dot product with the normal)

*) If it has to be rendered, it determines the amount of light received from the dynamic lights (GetLightShadingForPos) (only once per voxel, it's slow enough as it is, to do it per vertex of each face would be unfeasible) . Then creates 4 vertices of the face and send them to the output stream.

- The pixel shader calculates the color by taking the ambient and sampling the texture * the calculated shade.

That's about it, I think.



I've reduced the size of the world because not everyone has 8gb ram and a x64 cpu, so it shouldn't go over the 2gb boundary now. (It's still targeted to x64 though). You'll also need to install the latest SlimDX if you want to run it.
(I can't post links due to my post count, sorry about that)


Class diagram: i.imgur.com/YdL5E.png

Youtube video of engine at work (but without dynamic lights): youtube.com/ watch?v=XQ-u3R8l4aA

Screenshot with dynamic lights: i.imgur.com/V4T9g.jpg
Source: dl.dropbox.com/u/8797691/VoxelRenderer.rar


I'm not sure if this should be in the beginner's section or in the DirectX and XNA section, so feel free to move it :)



Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!