• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
winsrp

geometry shader basic example

4 posts in this topic

So here is the thing,

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
0

Share this post


Link to post
Share on other sites
Why do you need these examples specifically? Here is the basic skeleton of a point-sprite geometry shader (point->screen space quad), so you can understand how it works (it's in fact a little more complex especially with the different coordinate spaces but the idea is there). For Example #2 it's just a matter of streaming per-vertex parameters (in this case, color) from the geometry shader to the pixel shader, pretty trivial. Example #3 does not build on the geometry shader (the brightness calculation is done in the pixel shader). Here is the skeleton:


[code]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!
}[/code]
0

Share this post


Link to post
Share on other sites
Just realised you might also want how to use the geometry shader within the SlimDX code, well, unless you are going to use stream output it's pretty much identical to how you handle vertex and pixel shaders. If you're using the effects framework you just have to add the GS declaration in the technique, and if you're using raw shaders you just compile it as you would compile a PS or a VS but using the gs_4_0 (or gs_5_0) compiler.

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

Share this post


Link to post
Share on other sites
I'm making a proof of concept of a terrain made of cubes, with several techniques on XNA, I have made some tests with optimization on the CPU, maximizing the view distance, but I seem to be needing more, someone told me i should try the GS, but its not available in XNA as it uses DX9, so, I'm tring some simple examples in slimDX, and wanted to start playing around with the GS but I could not find an example code.

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)?
0

Share this post


Link to post
Share on other sites
It's making a point sprite which is just a 2D texture drawn onto the screen (since that's one of the most common uses of geometry shaders). If you want to create a 3D face of a cube instead you can adapt the code to modify the output vertices.

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).
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0