I read GPU Gems 3 from NVidia about procedural terrain.
It's quite interesting but not applicable for me because I only read the online version without the shipped DVD so I'm not able to download the source for these samples (I got a shrinked version only). The shaders are split into Vertex, Geometry and Pixel Shader which I can't use because I'm using the SharpDX Toolkit and I don't have the possibility to use these shaders.

Now I thought of using the methods of NVidia to implement my own terrain generation - which is created by hand in a Editor-View - without random noise etc.
What I want to do is to send my chunks (List<VertexPositionNormalColor>) to a shader which creates the triangle list on the gpu without the need of generating it on the cpu. At the moment I have a list of possible connections (comparable to Marching Cubes) which is populated while runtime on the cpu which takes up much memory and time.

The idea what I want to do now is to create a RenderTarget3D holding all positions per chunk and generating the triangle list afterward. The generation is based on my own algorithms for vertex generation.
Things you might help me with are:

  • How do I generate a RenderTarget3D in SharpDX Toolkit which stores my VertexPositionNormalColor (which will be changed to VertexPositionColor after I finished the generation on the gpu) - finished.
  • How can I load the positions out of the RenderTarget3D to generate the vertices?
    • Can I use the Geometry Shader for this and how?

Some information which might help: SharpDX Toolkit; custom terrain (not generated); Chunks are used to separate the positions

If you need anything to help me with this problem tell me what you need.

Edit #1:
I managed to get the texture3d generated as I want them to be created but I have a problem with the geometry shader. The code for the geometry shader:

void mainGS(point gsInput input[1], inout TriangleStream<psInput> Stream) {
    float4 position = input[0].position;
        bool anyNot = false;

    for (int i = 0; i < connectionPositionCount; i++) {
        anyNot = anyNot | !hasConnection(position, connectionPositions[i]);

    if (anyNot) {
        for (int i = 0; i < connectionCount; i++) {
            if (
                hasConnection(position, connections[i][0]) &&
                hasConnection(position, connections[i][1]) &&
                hasConnection(position, connections[i][2]) &&
                (connections[i][3] == 13 || !hasConnection(position, connections[i][3]))
                ) {
                    psInput vec1 = (psInput)0;
                    psInput vec2 = (psInput)0;
                    psInput vec3 = (psInput)0;

                    vec1.position = mul(mul(position + connections[i][0], World), View * Projection);
                    vec2.position = mul(mul(position + connections[i][1], World), View * Projection);
                    vec3.position = mul(mul(position + connections[i][2], World), View * Projection);

                    vec1.normal = float3(0, 1, 0);
                    vec2.normal = float3(0, 1, 0);
                    vec3.normal = float3(0, 1, 0);

                    vec1.color = isSet(position + connections[i][0]);
                    vec2.color = isSet(position + connections[i][1]);
                    vec3.color = isSet(position + connections[i][2]);


The Tkfxc throws three errors on Stream.Append(vecX): emitting a system-interpreted value which is not written in every execution path of the shader.
How can I fix this error in the shader above?

  • \$\begingroup\$ geisswerks.com/about_terrain.html here is the source from GPU Gems, also I don't know of any reason why you cannot use SharpDX to implement this algorithm, I did. \$\endgroup\$ – gareththegeek Jul 15 '13 at 15:50
  • \$\begingroup\$ sure, I got it from Geisswerks but I'm not able to read through C/++-Code (because my own code-style is completely different to NVidias). I don't want to implement the algorithm but manipulate the algorithm to allow my own terrain (manipulated through editor) to be generated by the GPU instead of on the CPU. \$\endgroup\$ – AliveDevil Jul 15 '13 at 15:57
  • \$\begingroup\$ I managed to get a volume texture working with geometry shader. Now I want to loop through every item in the volume and build the vertices based on some tables. The problem: emitting a system-interpreted value which is not written in every execution path of the shader l: 139/140/141 r: 26 shrinked source of the shader: gist.github \$\endgroup\$ – AliveDevil Jul 16 '13 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.