• 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
bluepig.man

About input slot and vertex buffer

4 posts in this topic

Hey,guys.

l am study Directx 11.And recently,l'm studying vertex buffer.But l got a problem about it.

The problem is, when l split position and color info into 2 vertex buffer and use 2 input slot(1 vertex buffer put in 1 input slot ),

but the cube's color is difference with the code use 1 input slot and 1 vertex buffer(The position and color info put in one vertex).

And then l also try using 1 input slot but using 2 vertex buffer,the cube's color difference with the first two cube.

The index buffer is same between this three cube.So why this happen?

Sorry if have any mistakes,my English level is poor.

Thanks!

0

Share this post


Link to post
Share on other sites

Can you post the input layout that you use in both cases?  Also, please post the vertex shader that you are using in both cases too - this should help us to find what is happening.

 

One final thing - can you describe in more detail what is the difference in the new method that doesn't look correct?

1

Share this post


Link to post
Share on other sites

Oh,sorry. l forgot that, thanks for your remind  Tthis is the vertex shader,and three situation shared it.

?cbuffer cbPerObject
{
    float4x4 gWorldViewProj;
};

struct VertexIn
{
    float3 Pos   : POSITION;
    float4 Color : COLOR;
};

struct VertexOut
{
    float4 PosH  : SV_POSITION;
    float4 Color : COLOR;
};

VertexOut VS(VertexIn vin)
{
    VertexOut vout;

    // Transform to homogeneous clip space.
    vout.PosH = mul(float4(vin.Pos, 1.0f), gWorldViewProj);
	
    // Just pass vertex color into the pixel shader.
    vout.Color = vin.Color;
    
    return vout;
}

float4 PS(VertexOut pin) : SV_Target
{
    return pin.Color ;//* sin(0.4f * gTime);
}

technique11 ColorTech
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_5_0, VS() ) );
	SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_5_0, PS() ) );
    }
}

And then there is a namespace named Colors,it used to store color info.

namespace Colors
{
	XMGLOBALCONST XMVECTORF32 White     = {1.0f, 1.0f, 1.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Black     = {0.0f, 0.0f, 0.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Red       = {1.0f, 0.0f, 0.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Green     = {0.0f, 1.0f, 0.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Blue      = {0.0f, 0.0f, 1.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Yellow    = {1.0f, 1.0f, 0.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Cyan      = {0.0f, 1.0f, 1.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Magenta   = {1.0f, 0.0f, 1.0f, 1.0f};
	XMGLOBALCONST XMVECTORF32 Silver    = {0.75f, 0.75f, 0.75f, 1.0f};
	XMGLOBALCONST XMVECTORF32 LightSteelBlue = {0.69f, 0.77f, 0.87f, 1.0f};
}

 

 

 

Situation 1: use one input slot and one vertex buffer.

it's the input layout:

 

D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
};

The vertex buffer and indices buffer:

 

Vertex vertices[] =
{
        //Cube vertex

        { XMFLOAT3(-1.0f, -1.0f, -1.0f), (const float*)&Colors::White },
        { XMFLOAT3(-1.0f, +1.0f, -1.0f), (const float*)&Colors::Black },
        { XMFLOAT3(+1.0f, +1.0f, -1.0f), (const float*)&Colors::Red },
        { XMFLOAT3(+1.0f, -1.0f, -1.0f), (const float*)&Colors::Green },
        { XMFLOAT3(-1.0f, -1.0f, +1.0f), (const float*)&Colors::Blue },
        { XMFLOAT3(-1.0f, +1.0f, +1.0f), (const float*)&Colors::Yellow },
        { XMFLOAT3(+1.0f, +1.0f, +1.0f), (const float*)&Colors::Cyan },
        { XMFLOAT3(+1.0f, -1.0f, +1.0f), (const float*)&Colors::Magenta },
};

D3D11_BUFFER_DESC vbd;
vbd.Usage = D3D11_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex) * 13;
vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
vbd.StructureByteStride = 0;

D3D11_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = vertices;
HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));

UINT indices[] = {
    // front face
    0, 1, 2,
    0, 2, 3,

    // back face
    4, 6, 5,
    4, 7, 6,

    // left face
    4, 5, 1,
    4, 1, 0,

    // right face
    3, 2, 6,
    3, 6, 7,

    // top face
    1, 5, 6,
    1, 6, 2,

    // bottom face
    4, 0, 3, 
    4, 3, 7,

};

D3D11_BUFFER_DESC ibd;
ibd.Usage = D3D11_USAGE_IMMUTABLE;
ibd.ByteWidth = sizeof(UINT) * 36;
ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
ibd.CPUAccessFlags = 0;
ibd.MiscFlags = 0;
ibd.StructureByteStride = 0;

D3D11_SUBRESOURCE_DATA iinitData;
iinitData.pSysMem = indices;
HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mBoxIB));

 

 

 

The indices buffer also shared by three situation.

Then the code bind vertex buffer and indices buffer.

    UINT stride = sizeof(Vertex);
    UINT offset = 0;
    md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVB, &stride, &offset);
    md3dImmediateContext->IASetIndexBuffer(mBoxIB, DXGI_FORMAT_R32_UINT, 0);

 

 

In this situation,every surface have 4 colors.

 

 

 

 

 

Situation 2 : use two input slot and two vertex buffer.

 

The inputlayout is changed:

D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
};

 

 

 

This is the two vertexbuffer.

	// Create vertex buffer
    Vertex vertices[] =
    {
		//Cube vertex

		{ XMFLOAT3(-1.0f, -1.0f, -1.0f)  },
		{ XMFLOAT3(-1.0f, +1.0f, -1.0f)  },
		{ XMFLOAT3(+1.0f, +1.0f, -1.0f)  },
		{ XMFLOAT3(+1.0f, -1.0f, -1.0f), (const float*)&Colors::Green   },
		{ XMFLOAT3(-1.0f, -1.0f, +1.0f), (const float*)&Colors::Blue    },
		{ XMFLOAT3(-1.0f, +1.0f, +1.0f), (const float*)&Colors::Yellow  },
		{ XMFLOAT3(+1.0f, +1.0f, +1.0f), (const float*)&Colors::Cyan    },
		{ XMFLOAT3(+1.0f, -1.0f, +1.0f), (const float*)&Colors::Magenta },

		//Pyramid vertex
/*
		{ XMFLOAT3( 0.0f,  2.0f,  0.0f), (const float*)&Colors::Red   },
		{ XMFLOAT3(-2.0f, -2.0f, -2.0f), (const float*)&Colors::Green },
		{ XMFLOAT3(+2.0f, -2.0f, -2.0f), (const float*)&Colors::Green },
		{ XMFLOAT3(-2.0f, -2.0f, +2.0f), (const float*)&Colors::Green },
		{ XMFLOAT3(+2.0f, -2.0f, +2.0f), (const float*)&Colors::Green },
		*/
    };

    D3D11_BUFFER_DESC vbd;
    vbd.Usage = D3D11_USAGE_IMMUTABLE;
    vbd.ByteWidth = sizeof(Vertex) * 8;
    vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd.CPUAccessFlags = 0;
    vbd.MiscFlags = 0;
    vbd.StructureByteStride = 0;
    D3D11_SUBRESOURCE_DATA vinitData;
    vinitData.pSysMem = vertices;
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB));	

    Color my_color[] = {

	{ (const float*)&Colors::White	 },
	{ (const float*)&Colors::Black	 },
	{ (const float*)&Colors::Red	 },
	{ (const float*)&Colors::Green   },
	{ (const float*)&Colors::Blue    },
	{ (const float*)&Colors::Yellow  },
	{ (const float*)&Colors::Cyan    },
	{ (const float*)&Colors::Magenta },

   };

    D3D11_BUFFER_DESC vbd2;
    vbd2.Usage = D3D11_USAGE_IMMUTABLE;
    vbd2.ByteWidth = sizeof(Vertex) * 5;
    vbd2.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vbd2.CPUAccessFlags = 0;
    vbd2.MiscFlags = 0;
    vbd2.StructureByteStride = 0;
    D3D11_SUBRESOURCE_DATA vinitData2;
    vinitData2.pSysMem = vertices;
    HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB2));

 

Then bind vertex buffer

 

    UINT stride2 =sizeof(Color);
    md3dImmediateContext->IASetVertexBuffers(1, 1, &mBoxVB2, &stride2, &offset);

 

And then color of the shape is different with before.Some surface have five colors.But some surface just have three colors.

 

Situation 3 : use two vertex buffer and one input slot.

 

The two vertex buffer and index buffer is same with the situation 2.

 

D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
};

The code bind two buffer.

 

    ID3D11Buffer *mBoxvb[] = { mBoxVB,mBoxVB2 };
    UINT stride[] = { sizeof(Vertex), sizeof(Color) };
    UINT offset[] = { 0, 0 };
    md3dImmediateContext->IASetVertexBuffers(0, 2, mBoxvb, stride, offset);

 

In this situation the color are block-shaped.

And in situaion 1 and 2,the color are radial.

Edited by bluepig.man
0

Share this post


Link to post
Share on other sites

You should use situation 2's input layout, but use the code binding from situation 3.  I suspect that the strides are incorrect in situation 2, since you should have two different strides but you are only specifying one.  Try this combination, and see how it turns out.

1

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