Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Both graphics APIs (OpenGL and DirectX) devise a well defined pipeline in which several stages are programmable. These programmable stages require to take a fixed minimum amount of data and are supposed to do a well defined range of operations on it, and output some defined minimum output, so that data can be passed on to the next stage correctly. It seems as if these pipelines are designed to work with only a limited amount of types of geometric data, which in the case of both D3D and OGL are vertex data and texture co-ordinates.

But, if given a case when the application I plan to make doesn't use vertices ( or even voxels ) to represent its geometric data and does not exactly do transformations or projections or rasterisation or interpolation or anything like that, such limitations of the APIs or the pipeline make things difficult.

So, is there a way in which we can change graphics pipeline in a way so that the functionality of what each stage does to the data and the type of data that is outputted in each stage is changed to my advantage? If not, then is there a way by which I can use the 'raw' API functions to construct my own pipeline? If not, then please mention why it isn't possible.

EDIT : My Application uses density functions to represent geometry. The function has a value at each point in space. I divide the frustum of the camera into a 3d grid, each block can be projected as a pixel. On each block, I integrate the density function and check if its value is more than a required value. If yes, then its is assumed that something exists in that block and that pixel corresponding to that block is rendered. so, now in my renderer, I want to pass the function ( which i represent with a string ) to the graphics hardware instead of vertex data in vertex buffers. this also implies that the vertex shader won't have vertices to transform into homogeniouse clip space and the fragment shader doesn't get pixel info. instead, now most of the looking up and evaluation happens per pixel.

share|improve this question
Is 'function density function' a tautology? – Pharap Aug 3 '14 at 4:17
@Pharap, that was a typo. its simply "desity functon" which represents the presence of "matter" in the space. – The Light Spark Aug 3 '14 at 6:40
It sounds like you just want to build an isosurface, which is a well studied problem. Have you seen or searched on Metaballs, point cloud visualization, isosurface extraction, or volume rendering? Also, what kind of performance do you require, that will make a huge difference on the choice of technique you search for when combined with the complexity of your calculations. I think that you'll also find that per-pixel will cause shimmering when the camera moves, and sub-pixel will be required. – Patrick Hughes Aug 3 '14 at 19:19
up vote 18 down vote accepted

You can absolutely use the GPU to render volumetric data.

Since you want to evaluate a set of functions per pixel on the screen, a simple approach is to render a full-screen triangle. This is just a single triangle that covers the entire screen (actually, it covers more than the screen, since the screen isn't triangular, but the parts off-screen are discarded by the GPU). You can then use the pixel shader (which receives the screen coordinates of the pixel it's shading) to construct a ray through your volume, evaluate functions, whatever you need to do.

(In contrast to the other answers, I don't recommend a compute shader because it sounds like you want to do per-pixel operations, and a full-screen triangle + pixel shader is generally more efficient for that than a compute shader—although compute shaders will certainly also work.)

The full-screen triangle method is very common in real-time graphics for postprocessing operations, so you can probably find all the information you need on it with a bit of googling.

BTW, it may interest you to read Rendering Worlds with Two Triangles by Iñigo Quílez, a talk which describes how to render 3D scenes composed using mathematical functions (specifically, distance fields) using the full-screen pixel shader technique.

share|improve this answer
So does the pixel shader take in arbitrary inputs (like strings or other types of user defined objects) so i can pass in my functions? – The Light Spark Aug 3 '14 at 15:24
I doubt that you would want to try running a parser and/or language on arbitrary function strings on GPU, that would be awkward since GPUs are not really general purpose. Most likely you would want to create the shader itself dynamically in your main code, then let the graphics system compile and run the resulting shader. – Patrick Hughes Aug 3 '14 at 17:59
@TheLightSpark Right, you wouldn't pass strings to the shader (shading languages don't even have a string type), you'd want to generate and compile shader code for your desired functions. That can be done at runtime if necessary. – Nathan Reed Aug 3 '14 at 19:09
+1 for a link to an Iñigo Quílez presentation. – wil Aug 6 '14 at 0:44
Started reading your answer, I imagined a triangle shaped monitor ;) Does it have an advantage to use only a single triangle instead of two which cover the screen without discarding pixels? – danijar Aug 22 '14 at 19:16

Ray tracing and other techniques are commonly done with Compute Shaders, which Direct3D has supported since the release of D3D11 and OpenGL has supported since 4.3 (and longer via the use of OpenCL and some contortions).

share|improve this answer

It sounds very much like you want to use a GPU compute shader, or utilize a "Shader Storage Buffer" object to help augment the pipeline to fit your needs. Mathematicians, scientists, and other people who look to the GPU for computation on things that don't exactly translate into standard graphics use this kind of thing.

Although the contemporary graphics pipeline is very flexible, developers still tend to stumble on some restrictions. The compute shaders feature, however, makes life easier for us to not think about pipeline stages as we are used to thinking about vertex and fragment. We are no longer restricted by the inputs and outputs of certain pipeline stages. The Shader Storage Buffer Object (SSBO) feature for instance has been introduced along with compute shaders and that gives additional possibilities for exchanging data between pipeline stages, as well as being flexible input and output for compute shaders.

If this does not point you in the right direction, would you mind expanding the concept of yours that doesn't fit the vertex/fragment paradigm?

share|improve this answer
I edited my answer to include what i am doing. compute shader seem to be the answers, but just tell me if there is something else that i may do. – The Light Spark Aug 3 '14 at 3:09

It is very possible that you may be able to restructure your algorithm to work as a set of shaders, but I recall hearing a talk on the Mantle API a while ago and thought maybe that's something you could look into as an alternative to the graphics APIs mentioned (OpenGL/DirectX)... I think it lets you program graphics hardware at a lower level thus allowing you to make your own pipeline :)

Regarding say fragment/pixel shaders taking a fixed amount of data as input... I don't think that's strictly true, as you can read a somewhat arbitrary number of samples from a texture input eg. as used in this paper:

share|improve this answer
Mantle doesn't change the graphics pipeline as exposed by OpenGL and DirectX, or let you "make your own pipeline". It's simply a lower-CPU-overhead interface to the same hardware. – Nathan Reed Aug 3 '14 at 19:10
The "own pipeline" bit echoed the OPs question, I agreed it's not the correct phrase for what he/she means. However, as per the Mantle Whitepaper, it does allow control over the pipeline that you don't get from OpenGL/DirectX: "Mantle includes innovative features that provide control over task scheduling and execution, enabling the implementation of algorithms previously impossible on GPUs. Command buffers can be constructed with multiple monolithic and/or compute pipelines and conditional execution..." – Nat Aug 3 '14 at 22:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.