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

DrawIndexedPrimitive and texcoords

6 posts in this topic

Hi,

 

I'm fairly new to DX, but I'll try not to be confusing.  I'm having a problem with applying a texture with a shader when I use DrawIndexedPrimitive and I suspect I'm not setting up my texture coordinates correctly.  Currently, the shader is coloring the entire polygon with pixel (0,0). 

 

The shader works fine with DrawPrimitive calls and the texture gets applied correctly if I used the fixed pipeline and call DrawIndexedPrimitive, so I'm a little lost on what might be going wrong.

 

My vertex is pretty basic:

 

struct MyVert {

  float[3] vert;

  float[3] norm;

  float[2] tc;

};

 

Anyone have any ideas where to start?

 

 

0

Share this post


Link to post
Share on other sites

What does your vertex declaration look like? What values are going into your vertex buffer? What values are going into your index buffer? What do your vertex and pixel shaders look like?

1

Share this post


Link to post
Share on other sites

The vertex decl is:

   D3DVERTEXELEMENT9 decl[MAX_VERTEXDECL];
   size_t uDeclCount = 1;

   // Position declaration
   decl[0].Stream = 0;
   decl[0].Offset = 0;
   decl[0].Type = D3DDECLTYPE_FLOAT3;
   decl[0].Method = D3DDECLMETHOD_DEFAULT;
   decl[0].Usage = D3DDECLUSAGE_POSITION;
   decl[0].UsageIndex = 0;

   // Normal declaration
   if ((FVF & D3DFVF_NORMAL) != 0) {

      decl[uDeclCount].Stream = 0;
      decl[uDeclCount].Offset = sizeof(float) * 3;
      decl[uDeclCount].Type = D3DDECLTYPE_FLOAT3;
      decl[uDeclCount].Method = D3DDECLMETHOD_DEFAULT;
      decl[uDeclCount].Usage = D3DDECLUSAGE_NORMAL;
      decl[uDeclCount].UsageIndex = 0;
      uDeclCount++;
   }
   
   // Texture declaration
   if ((FVF & D3DFVF_TEX1) != 0) {
      decl[uDeclCount].Stream = 0;
      decl[uDeclCount].Offset = sizeof(float) * 3 * uDeclCount;
      decl[uDeclCount].Type = D3DDECLTYPE_FLOAT2;
      decl[uDeclCount].Method = D3DDECLMETHOD_DEFAULT;
      decl[uDeclCount].Usage = D3DDECLUSAGE_TEXCOORD;
      decl[uDeclCount].UsageIndex = 0;
      uDeclCount++;
   }

   // End of declarations
   decl[uDeclCount].Stream = 0xFF;
   decl[uDeclCount].Offset = 0;
   decl[uDeclCount].Type = D3DDECLTYPE_UNUSED;
   decl[uDeclCount].Method = 0;
   decl[uDeclCount].Usage = 0;
   decl[uDeclCount].UsageIndex = 0;

The values for the vertex buffer are procedurally generated, so posting those exactly would just be noisy.  But, you can imagine a cuboid:


          v4    v5
           +---+
          /|  /|
         / | / |
        /  |/  |
       /   /   |
      /   /|   |
  v2 +---+v3   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | +---+v7
     |   |/v6 /
     |   |   /
     |  /|  /
     | / | /
     |/  |/
     +---+
    v0   v1

 

With indices: 

4, 2, 0 
0, 6, 4
1, 3, 7
5, 7, 3
1, 2, 0
1, 3, 2
5, 6, 4
5, 7, 6
3, 2, 4
3, 4, 5
 

The shaders are extremely simple:

struct VS_INPUT {
    float4 position : POSITION;
    float3 normal : NORMAL;
    float2 Texture : TEXCOORD0;
};

struct VS_OUTPUT {
	float4 position : POSITION;
	float2 Texture : TEXCOORD0;
	float3 normal : TEXCOORD1;
	float4 color : COLOR;
};

float4x4 matWVP;
float4x4 matWorld;
bool bIsSelected;

VS_OUTPUT vs_main(in VS_INPUT input)
{
	VS_OUTPUT output;
	
	output.position = mul(float4(input.position.xyz, 1.0f), matWVP);
	output.Texture = input.Texture;
	output.normal = normalize(mul(input.normal, matWorld));
	output.color = float4(1.0f, 1.0f, 1.0f, 1.0f);
	
	return output;
}


struct PS_INPUT {
	float4 position : VPOS;
	float2 Texture : TEXCOORD0;
	float3 normal : TEXCOORD1;
	float4 color : COLOR0;
};

struct PS_OUTPUT {
	float4 color : COLOR0;
};

sampler2D Tex0;

PS_OUTPUT ps_main(in PS_INPUT input)
{
	PS_OUTPUT output;

	output.color = tex2D(Tex0, input.Texture);

	return output;
}
1

Share this post


Link to post
Share on other sites

I haven't messed with shaders in a good while, but don't you need a 'sampler_state' struct setup?

Texture2D texture;
sampler2D sampler = 
sampler_state
{
    Texture = texture;
     mipfilter = LINEAR;
}

something like that? I could be wrong.

 

 

You're doing the Declaration the hard way

 
D3DVERTEXELEMENT9 decl[] =
{
{ 0,0,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_POSITION,0 },
{ 0,12,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_NORMAL,0 },
{ 0,24,D3DDECLTYPE_FLOAT2,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_TEXCOORD,0 },
D3DDECL_END()
};
 
// That's much neater =)
// And if you have different types of vertex declarations, use flags to distinguish each one.

and a little minor note, on calculating your normal in the vertex shader

    output.normal = normalize(mul(input.normal, matWorld));
 
// You might want to do this instead
output.normal = normalize( mul(float4( input.normal,0 ), matWorld) );
 
// So that you don't get all of the position information from the matrix, you just want the rotation stuff
// Unless it automatically puts a '0' there for you and I didn't know that, in which case you're fine :P
Edited by Muzzy A
0

Share this post


Link to post
Share on other sites

 

I haven't messed with shaders in a good while, but don't you need a 'sampler_state' struct setup?

Texture2D texture;
sampler2D sampler = 
sampler_state
{
    Texture = texture;
     mipfilter = LINEAR;
}

something like that? I could be wrong.

 

 

I was hoping that was it, but no luck.  Again, the shader works fine if I use it with a DrawPrimitive call.

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