Writing my own Depth Buffer Functionality.

Started by
2 comments, last by kalle_h 9 years, 2 months ago

I am taking a graphics class at my University. For the latest assignment, we are required to implement the functionality of a depth buffer for rendering our geometry. However, this assignment is supposed to be implemented in OpenGL using a separate set of skeleton code. Because I am more familiar with DirectX I would like to implement it in that API. That being said, I am wondering if there is a way to replace the standard depth-stencil functionality of DirectX with my own code (which will do the same thing) in order to complete the requirements of the assignment?

J.W.
Advertisement

Would recommend against it if you have an OpenGL skeleton set up for it already.

You need a buffer that you can both write to and read from manually in the shader.. so unordered access view of a 2D surface, calculate the depth manually in the pixel shader and compare it to what is currently in the surface and either discard the pixel or output its color. https://msdn.microsoft.com/en-us/library/windows/desktop/ff476335(v=vs.85).aspx has some info.

You probably want https://msdn.microsoft.com/en-us/library/windows/desktop/ff471409%28v=vs.85%29.aspx to compare and set the depth atomically.

There is no way to reach in and replace the depth buffer functionality from the API. However, like Erik mentioned you can use the API to allow you to write shaders that perform more or less the same operations. You have to note that it isn't possible to render directly to a depth stencil view though - only the fixed functionality of the API can do that.

One other alternative that I would find more interesting is to write the whole thing in some compute shaders. That would require you to do the rasterization yourself, but there is publicly available code that you can reference for that. I would find that more compelling than working through the existing pipeline, but that may be beyond what your assignment is asking for.

This is sounds bit odd assignment. Depth buffers are super simple in theory but quite quirky to implement with API like openGL. But maybe the idea is to learn API and not theory.

This topic is closed to new replies.

Advertisement