• 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
~Helgon

Linestrip with GeometryShader

9 posts in this topic

Hi,

my problem is that if i try to expand my vertex with the GeometryShader DirectX seems to not connect the lines anymore and also it doesn't draw all lines

[code]md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); // SAME PROBLEM WITH LINELIST[/code]


[CODE]
UINT count = 10;
std::vector<Vertex::Geo> vertices(count);
for(UINT i = 0; i < count; ++i)
{
vertices[i].Pos = XMFLOAT3(i*1.0f, 1.0f, 1.0f);
vertices[i].Size = XMFLOAT2(16.0f, 16.0f);
}
[/CODE]


[CODE]
[maxvertexcount(2)]
void GS(point VertexOut gin[1],
inout LineStream<GeoOut> stream)
{

float3 up = float3(0.0f, 1.0f, 0.0f);
float3 look = gEyePosW - gin[0].CenterW;
look.y = 0.0f; // y-axis aligned, so project to xz-plane
look = normalize(look);
float3 right = cross(up, look);

float halfWidth = 0.5f*gin[0].SizeW.x;
float halfHeight = 0.5f*gin[0].SizeW.y;

float4 v[2];
v[0] = float4(gin[0].CenterW + halfHeight*up, 1.0f);
v[1] = float4(gin[0].CenterW - halfHeight*up, 1.0f);

GeoOut gout;
[unroll]
for(int i = 0; i < 2; ++i)
{
gout.PosH = mul(v[i], gViewProj);
gout.PosW = v[i].xyz;
gout.NormalW = look;

stream.Append(gout);
}
}

[/CODE]

I have 2 Problems. First that i get this warning:
[CODE]D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The declared input primitive type in the current Geometry Shader does not match the current input topology. [ EXECUTION ERROR #360: DEVICE_DRAW_GS_INPUT_PRIMITIVE_MISMATCH][/CODE]

EDIT: Seems that if i use D3D11_PRIMITIVE_TOPOLOGY_POINTLIST as primitiveTopology i dont get the warnig (but why if the inout is LineStream?)

the inout is LineStream so that should not be the problem :/ and as IASetPrimitiveTopology i tried line list and line strip.. both gave me this error

and the second probem is: as u can see i create 10 vertices - should mean at least 5 lines.. and after adding one point with the geometry shader it should be 10 (or?) but all i get are 2 lines

hope that someone can give me a hint

regards helgon

EDIT 2: pretty strange if i use the Draw Method it at least draw 9 lines (count - 1) if i want all 10 i have to draw 11.. pretty strange also
[code]md3dImmediateContext->Draw(10, 0);[/code]

if i draw indexed i get just the two lines like in the screenshot (independent which indexCount i use)
[code]md3dImmediateContext->DrawIndexed(10, 0, 0);[/code]

but the lines still are linelists and not linestrips

Edited by ~Helgon
0

Share this post


Link to post
Share on other sites
The geometry shader will be executed once for each primitive it is passed. In this case, you are using point lists as the input primitive type, so for each point that makes its way to the input of the geometry shader, you will execute your geometry shader program. From what I see there, you are creating two points and the output primitive type is a line stream. In this scenario, the image you have shown is perfectly correct - you should get one line consisting of two vertices for each point that was passed into the GS.

Where I think you are getting mixed up is that the stream is only active for a given geometry shader invocation. So subsequent point primitives won't add their lines to the same output stream - only the vertices that are added within one GS invocation are included in the same stream!
1

Share this post


Link to post
Share on other sites
Ah thanks for the answer. it helped me a bit to understand better what happens

so i changed the topology to:

[quote]md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);[/quote]

and if i expand one point in the GS it works.. for testing reasons i expended one point to 20

[CODE]
[maxvertexcount(20)]
void GS(point VertexOut gin[1],
inout LineStream<GeoOut> stream)
{
float3 up = float3(0.0f, 1.0f, 0.0f);
float3 look = gEyePosW - gin[0].CenterW;
look.y = 0.0f; // y-axis aligned, so project to xz-plane
look = normalize(look);
float3 right = cross(up, look);

float4 v[20];
for(int i = 0; i < 20; ++i)
{
if(i%2 == 0)
{
v[i] = float4(gin[0].CenterW + i*1.0f, 1.0f);
}
else
{
v[i] = float4(gin[0].CenterW - i*1.0f, 1.0f);
}
}
GeoOut gout;
[unroll]
for(int i = 0; i < 20; ++i)
{
gout.PosH = mul(v[i], gViewProj);
gout.PosW = v[i].xyz;
gout.NormalW = look;

stream.Append(gout);
}
}
[/CODE]

it works fine.. if i set the inout in the GS to PointStream directx draws all the single points and if i set it to LineStream i get single lines, but that is the problem. what i in fact want are connected lines (like the LINESTRIP topology) so how can i achieve that?

my thought was that maybe something like stream.ContinueStrip() exists (like RestartStrip()) but i didn't found anything

would be happy if u can give me another hint or short give me a snippet how to implement a LineStrip (with the points generated by the GS)


regards helgon Edited by ~Helgon
0

Share this post


Link to post
Share on other sites
If you want to produce connected lines then each invocation of the GS has to know where the previous invocation put its last point, otherwise it won't know where to start its own line. So you sould use a line strip as your input primitive to the pipeline, then the GS would know both the current and the next point's location, and you could act accordingly when placing the output vertices. However, this would require double computation in the GS, which probably isn't that efficient - but if efficiency isn't what you are after, then that might work for you.

Otherwise, you could probably use the tessellation stages to produce the primitives that you want to manipulate in the GS, then you just amplify the data in the GS... It really just depends on what you are looking to do...

One other option is to do a stream out to a buffer of the point data that you are generating now, and then to re-render them in the pipeline... That would work fairly easily too!
1

Share this post


Link to post
Share on other sites
[quote name='Jason Z' timestamp='1354146366' post='5005129']
If you want to produce connected lines then each invocation of the GS has to know where the previous invocation put its last point, otherwise it won't know where to start its own line. So you sould use a line strip as your input primitive to the pipeline, then the GS would know both the current and the next point's location, and you could act accordingly when placing the output vertices. However, this would require double computation in the GS, which probably isn't that efficient - but if efficiency isn't what you are after, then that might work for you.
[/quote]

Did i understand it right that i just shall add another point to the location where the second line is draw? so its just a "faked" connection because there are two points on the exakt same location?

[quote]So you sould use a line strip as your input primitive to the pipeline[/quote]
Sorry if this question is dumb, but what is my input primitive ? IASetPrimitiveTopology this one? if you mean that - if i use something beside the POINTLIST i get the error

[code]D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The declared input primitive type in the current Geometry Shader does not match the current input topology. [ EXECUTION ERROR #360: DEVICE_DRAW_GS_INPUT_PRIMITIVE_MISMATCH]
[/code] Edited by ~Helgon
0

Share this post


Link to post
Share on other sites
[quote name='~Helgon' timestamp='1354147117' post='5005137']
Did i understand it right that i just shall add another point to the location where the second line is draw? so its just a "faked" connection because there are two points on the exakt same location?
[/quote]

You are partially right. By specifying that the input primitive to the input assembler is a line strip, you are actually providing a list of points that will produce n-1 lines for n points. Your vertex buffer will remain the same, just your topology is changed so that lines are assembled instead of points to be passed into the pipeline.

[quote name='~Helgon' timestamp='1354147117' post='5005137']
Sorry if this question is dumb, but what is my input primitive ? IASetPrimitiveTopology this one? if you mean that - if i use something beside the POINTLIST i get the error

[code]D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The declared input primitive type in the current Geometry Shader does not match the current input topology. [ EXECUTION ERROR #360: DEVICE_DRAW_GS_INPUT_PRIMITIVE_MISMATCH]
[/code]
[/quote]

That is because after you change your input assembler setting (via IASetPrimitiveTopology) then the pipeline is creating lines, but your geometry shader is expecting points (as indicated by the stream type declared as the input to the GS function). So you need to change your stream type back to a linestream, and then you will have access to both the current and the next vertices from within that line. It will then be up to you to determine how many output vertices and where you should put them - but you have access to both of the points that should be needed for your calculations.
1

Share this post


Link to post
Share on other sites
The problem is, that it doesn't matter which inout type i set in the GS - i also get this error if inout is specified as a LineStream (and the IA as TPOLOGY_LINELSTRIP)

In fact it's so that i always get the error if the IA is set to something else beside POINTLIST
0

Share this post


Link to post
Share on other sites
Ah thanks for the sample. I already tried something like this but not totally correct. After seeing your .fx file i understood all. Thank you very much
0

Share this post


Link to post
Share on other sites
Hi Helgon, what problem are you trying to solve? Do you want to draw line strip of arbitrary width with D3D? If yes, here is a pixel shader solution at [url="http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter22.html"]http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter22.html[/url].
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