**1**

###
#1
Members - Reputation: **273**

Posted 24 March 2012 - 10:07 PM

I need a really really basic example of a GS with SlimDX, more specifically I would like an example of how to do the following.

Example #1: I would like to send a single vertex point to the GS and have the GS make a square (1 face of a cube).

Example #2: I would like to send a single vertex point to the GS with a color assignment and have the GS convert that vertex into a cube of the desired color (all faces with the same color).

Example #3: Send the single vertex, with a color, and brightness of 1 to 16, and have the cube made on the GS lit from 1/16 to 16/16, based on that number.

I would be of great help in my new project, as this is the first time I use some other than XNA, and all this stuff is new to me overall.

Appreciate all the help, tx

###
#2
Crossbones+ - Reputation: **10221**

Posted 25 March 2012 - 06:00 AM

struct GeometryIn // geometry shader input { float4 p: POSITION; // point sprite's center (in clip space) }; struct PixelIn // pixel shader input vertex { float4 p: SV_POSITION; // rasterized position float2 uv: TEXCOORD0; // uv coordinates (for texturing) }; [maxvertexcount(4)] // point sprite quad, so 4 vertices void main( point GeometryIn input[1], inout TriangleStream<PixelIn> stream ) { // size of your quad (you can make this a shader variable, or even a per-vertex parameter, if you must) static const float scale = 0.01; // find the four vertices of the quad from the point sprite float4 v1 = input[0].p + float4(+scale * 0.5, +scale * 0.5, 0, 0); float4 v2 = input[0].p + float4(+scale * 0.5, -scale * 0.5, 0, 0); float4 v3 = input[0].p + float4(-scale * 0.5, -scale * 0.5, 0, 0); float4 v4 = input[0].p + float4(-scale * 0.5, +scale * 0.5, 0, 0); // stream out each vertex with the proper UV's PixelIn output; output.uv = float2(1, 1); output.p = v1; stream.Append(output); output.uv = float2(1, 0); output.p = v2; stream.Append(output); output.uv = float2(0, 0); output.p = v3; stream.Append(output); output.uv = float2(0, 1); output.p = v4; stream.Append(output); // we're done! }

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- *Pessimal Algorithms and Simplexity Analysis*

###
#3
Crossbones+ - Reputation: **10221**

Posted 25 March 2012 - 03:43 PM

If you're using stream output it becomes fairly more complex but I think you don't need that just yet.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- *Pessimal Algorithms and Simplexity Analysis*

###
#4
Members - Reputation: **273**

Posted 26 March 2012 - 11:27 AM

ok, so in the example you just put, you are doing like a front quad face from a point, without moving on the Z axis, am I correct?, but how does it know how to put the faces together (make the lines between the vertexes)?

###
#5
Crossbones+ - Reputation: **10221**

Posted 26 March 2012 - 03:08 PM

The GPU knows how to link the vertices because you are streaming out the vertices in a TriangleStream. Thus when you append vertices via the Append() method it creates triangle strips (if you call RestartStrip(), you restart the strip, so calling it every three vertices will create a triangle list instead).

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

- *Pessimal Algorithms and Simplexity Analysis*