• 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
lomateron

stream output to vertex buffer (not working as it should)

14 posts in this topic

i cant still get it working as it should, i did this in the .cpp file, first the layout:

[code] D3D10_INPUT_ELEMENT_DESC vertexDesc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
{ "VEL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "MA", 0, DXGI_FORMAT_R32_FLOAT, 0, 40, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = sizeof( vertexDesc) / sizeof( vertexDesc[0] );

D3D10_PASS_DESC PassDesc;
g_pTechnique->GetPassByIndex(0)->GetDesc(&PassDesc);
hr = g_pd3dDevice->CreateInputLayout(vertexDesc, numElements,PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize,&g_pVertexLayout);
if( FAILED( hr ) )
return hr;
g_pd3dDevice->IASetInputLayout(g_pVertexLayout);[/code]

now the buffer: i have 2 buffers one with the original vertex data and another where the modified vertex buffer is gonna be
[code] SimpleVertex vertices2[] =
{
{ D3DXVECTOR3( 0.0f, 1.0f, 0.0f ), D3DXCOLOR( 0.0f, 0.0f, 1.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
{ D3DXVECTOR3( 1.0f, 0.0f, 0.0f ), D3DXCOLOR( 0.0f, 1.0f, 0.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
{ D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXCOLOR( 0.0f, 1.0f, 1.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
{ D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), D3DXCOLOR( 1.0f, 0.0f, 0.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
};
bd.Usage = D3D10_USAGE_DEFAULT;
bd.ByteWidth = sizeof( SimpleVertex ) * 4;
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_STREAM_OUTPUT;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
initData.pSysMem = vertices2;
hr = g_pd3dDevice->CreateBuffer( &bd, &initData, &g_pVertexBuffer2 );//first buffer where the original info is
if( FAILED( hr ) )
return hr;
hr = g_pd3dDevice->CreateBuffer( &bd, 0, &g_pVertexBuffer3 );//second buffer where the info form the first is gona be after modified
if( FAILED( hr ) )
return hr;[/code]

and now this is how i render it, i change the buffers each frame ping pong metod

[code]if(g)
{
g_pd3dDevice->SOSetTargets(1, &g_pVertexBuffer3 , &offset);
g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer2, &stride, &offset);
g=false;
}
else
{
g_pd3dDevice->SOSetTargets(1, &g_pVertexBuffer2 , &offset);
g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer3, &stride, &offset);
g=true;
}
g_pd3dDevice->IASetIndexBuffer( g_pIndexBuffer2, DXGI_FORMAT_R32_UINT, 0 );
g_pWorldVariable->SetMatrix( ( float* )&g_World2 );
g_pTechnique2->GetPassByIndex( 0 )->Apply( 0 );
g_pd3dDevice->DrawIndexed( 12, 0, 0 );
g_pSwapChain->Present( 0, 0 );[/code]

the .fx is like this, there are no errors any more, the vertex shader only returns the same position, the tetrahedron never moves.

[code]struct VS_INPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
float3 Vel : VEL;
float Ma : MA;
};
struct VS_INPUTT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
float3 Vel : VEL;
float Ma : MA;
};
VS_INPUTT VS2( VS_INPUT input )
{
VS_INPUTT output = (VS_INPUTT)0;
output.Pos = mul( input.Pos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Color = input.Color;
output.Vel.x = input.Vel.x+(Time*Force.x);
output.Vel.y = input.Vel.y+(Time*Force.y);
output.Vel.z = input.Vel.z+(Time*Force.z);
output.Ma = input.Ma;
return output;
}[/code]

and at the end of the .fx file is this

[code]VertexShader vss = CompileShader( vs_4_0, VS2() );
GeometryShader gss= ConstructGSWithSO( vss, "SV_POSITION.xyz; COLOR.xyzw; VEL.xyz; MA.x" );
technique10 Pa
{
pass P0
{
SetVertexShader( vss );
SetGeometryShader( gss );
SetPixelShader( CompileShader( ps_4_0, PS2() ) );
}
}[/code]

what happens is that there is no error anywere,but it works rare, the first frame i render it renders ok, the tetrahedron is in its place, then the second frame some vertex of the tetrahedron are in its place and the others are like very far away up, and then in the next frame it disapears.
0

Share this post


Link to post
Share on other sites
plz help me i want to know why my tetrahedron is disappearing, this is getting me into a big stuck depressing hole, i have been reading and using now a geometry shader were my tetrahedron will still be in its place but the same happens, it disappears.
0

Share this post


Link to post
Share on other sites
Hi!

You transform your positions each frame over and over again with the transformation matrices. Points closer to the origin will stay a few iterations longer but eventually all your vertices will fly away. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

So, modify a little the output of your vertex shader.
Output both the clipping space position and the world position. Write the world position back into the stream output and pass the clipping space position to the rasterizer only.

[CODE]struct VS_OUTPUTT
{
float4 Pos : WORLDPOS; // position in world space (for the stream output)
float4 ClipPos : SV_POSITION; // position in clipping space (for the rasterizer)
float4 Color : COLOR;
float3 Vel : VEL;
float Ma : MA;
};

VS_OUTPUTT VS2( VS_INPUT input )
{
VS_OUTPUTT output = (VS_OUTPUTT)0;
output.Pos = input.Pos; // bypass the geometry (or deform somehow with your velocity)

// better pass in your geometry in world space!
// output.ClipPos = mul( input.Pos, World );
output.ClipPos = mul( output.Pos, View );
output.ClipPos = mul( output.ClipPos, Projection );
output.Color = input.Color;
output.Vel.x = input.Vel.x+(Time*Force.x);
output.Vel.y = input.Vel.y+(Time*Force.y);
output.Vel.z = input.Vel.z+(Time*Force.z);
output.Ma = input.Ma;
return output;
}

// Tell the geometry shader to output the world space position.
GeometryShader gss= ConstructGSWithSO( vss, "WORLDPOS.xyz; COLOR.xyzw; VEL.xyz; MA.x" );[/CODE]

Hope that helps! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
Cheers!
1

Share this post


Link to post
Share on other sites
hoo man this things that i dot see are insane, thank you i like will always need another person to tell me something because i become blind with my own mistakes.
0

Share this post


Link to post
Share on other sites
hey master is my SOSetTargets()metod ok because now my problem is that the last vertex in my vertex structure isn't changing of place, color, etc, any attribute is changing
0

Share this post


Link to post
Share on other sites
Only the last vertex causes trouble? So the first three vertices behave as they should?
That sounds to me like the number of vertices/primitives in the draw call, the input assembler or stream output setup doesn’t fit. Though, both your SOSetTarget and IASetVertexBuffer look fine, if your offset=0 and the stride=44=sizeof(SimpleVertex). 12 indices for a tet sounds reasonable, too. The primitive topology is a triangle list, I guess?

Do you unbind the vertex buffers from the input assembler and the stream output after rendering?
[CODE]ID3D11Buffer* noVB[] = {NULL};
UINT noOffset[] = {0};
UINT noStride[] = {0};
g_pd3dDevice->SOSetTargets(1, noVB, noOffset);
g_pd3dDevice->IASetVertexBuffers(0, 1, noVB, noStride, noOffset);[/CODE]
Otherwise D3D could complain (only with warnings in d3d debug mode) in the next rendering loop, when you bind your vertex buffer to the stream output stage that the vertex buffer is still but as input at the input assembler.

Could you please paste an updated version of the input assembler setup, the shader and the creation of your vertex and index buffer, here?
Or maybe just attach the program, so that I or someone else can do a debug run. A PIX dump would work for me too.
0

Share this post


Link to post
Share on other sites
here it is all the projects
https://rapidshare.com/files/1943985478/yea.rar

Run it and you can control the camera with the movement of the mouse, the camera is pointing up by default so move the mouse all the way down and you will see the tetrahedron moving just in one direction for simplicity, you can use your "W"S"A"D" to move the camera too.
0

Share this post


Link to post
Share on other sites
Hi!

It seems to be a problem with the index buffer.
Your tet transforms just fine if you duplicate your vertices in the vertex buffer.

When using the index buffer, in PIX the buffer at the stream output stage is totally messed up, and if rendered with another topology but pointlists PIX crashes, when I try to look at the mesh.

If you don’t like duplicating your vertices here is an alternative: Usually I have a first pass in which I invoke one vertex shader / geometry shader per vertex by rendering the whole geometry as a pointlist. Thereby I stream the data out to another buffer and disable the rasterizer. Afterwards I render in a second pass the updated vertex buffer in combination with some index buffer to actually create geometry with topology.
0

Share this post


Link to post
Share on other sites
:( .... thats bad news but... thanks!, do you know any complete example were they do the stream output and render? i really wana do it this way.. its faster no?
0

Share this post


Link to post
Share on other sites
but how can the index buffer be a problem, is there something similar between the index buffer and the buffer used for stream output? i mean, do one interfere with the other in something?
0

Share this post


Link to post
Share on other sites
The stream output captures the triangles, not the vertices. Since the draw call emits 12 vertices and the vertex buffer bound to the stream output has only room for 4 we get an overflow. When looking at the index buffer we see that the first four vertices are: 0,1,2,0. More isn’t written. This matches with my observations with PIX. Vertex 3 became equal to vertex 0, when using pointlists.

If the index buffer would start with 0,1,2,3,… then it would be a hack, but it would be fine, except:
The stream output only writes, if the primitive fits into the available space, so the second triangle starting with 3,… would never be written, because there is no room for the remaining two vertices.
Well, but if you make your vertex buffer bigger, by extending it with two dummy vertices (which are never used for rendering and only receive two vertices from the stream output we already know), everything works as it should.

It is a little hack though. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
So adapt your index buffer to start with 0,1,2,3 and add two more vertices to your vertex buffer.

Cheers!
0

Share this post


Link to post
Share on other sites
skills!!!
ohhhh shiii that thing was in front of my face look
http://msdn.microsoft.com/en-us/library/windows/desktop/bb509661%28v=vs.85%29.aspx

so by default it is returning the triangle stream because i am compiling the vertex shader intead of the geometry, so i have to make a geometry shader and define to return a pointStream, and because i will most likely use the geometry shader in the future, i am gona put it there, doing nothing for now.

damm i tried and now at the end rendered image is drawing points, but its working! but its drawing points hahaha. It didnt matter if i put
g_pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
before drawing.
So finally i am gona go for the way you told me, its working too! thanks!
0

Share this post


Link to post
Share on other sites
Damn Directx is to limited. No

I have stream out working fine using dx10 Irender a point list to a buffer of a skinned mesh then to shadows and colur render with the streamed out VB works fine.
I think there is a sample in the sdk stream out skinning or something like that.
Also try looking at you index buffer it will need to be same as the original Indexbuffer.
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