Sign in to follow this  
Kamo16

Vertex Shader parameters

Recommended Posts

Kamo16    102
I'm new to HLSL and I'm a little confused on a particular quirk that is occurring in my program. It was my understanding that the parameters to the Vertex shader are the input elements defined in your input layout. For example in my application code I set the input layout as follows...

[code]
D3D10_INPUT_ELEMENT_DESC Layout[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
D3D10_INPUT_PER_VERTEX_DATA, 0},

{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12,
D3D10_INPUT_PER_VERTEX_DATA, 0},

{"DIFFUSE", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24,
D3D10_INPUT_PER_VERTEX_DATA, 0},

{"SPECULAR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 40,
D3D10_INPUT_PER_VERTEX_DATA, 0} };
[/code]

In my effect file however, this is the definition of the Vertex Shader I'm using...

[code]
VSOut VS_1(float4 Norm : NORMAL, float4 Pos : POSITION, float4 diffuse: DIFFUSE, float4 specular: SPECULAR)
[/code]

I want to have the last two parameters diffuse and specular so that I can calculate lighting based on the properties of the material as well, not just the color of the light and it's intensity.

My program runs fine when I only have the first two parameters defined, Norm and Pos, but as soon as I add the additional parameter diffuse: DIFFUSE, my object disappears. I have looked everywhere as to why this might happen but I'm not having any luck. Any advice or insight is highly appreciated.

Share this post


Link to post
Share on other sites
MJP    19755
By "disappears" do you mean that it renders all black, or that it doesn't render at all? Either way, you should try using PIX to get a closer look at what's going on. It can show you the individual values for each vertex in your vertex buffer as well as the outputs from your vertex shader, or you can even step into your vertex shader and debug it.

Share this post


Link to post
Share on other sites
Kamo16    102
[quote name='MJP' timestamp='1306616297' post='4816909']
By "disappears" do you mean that it renders all black, or that it doesn't render at all? Either way, you should try using PIX to get a closer look at what's going on. It can show you the individual values for each vertex in your vertex buffer as well as the outputs from your vertex shader, or you can even step into your vertex shader and debug it.
[/quote]

Everything that isn't being drawn with vertices still renders, such as the clear color I've set and FPS/MPF text I've drawn. It's as if the DIFFUSE and SPECULAR semantic I attach to variables corrupts the vertex shader somehow. I don't know how else to input the diffuse and specular properties of each vertex without feeding it through the input layout. All of the lighting tutorials I look at simply define global variables for light color and intensity in the effect file and use those in the calculations, which just results in everything being colored the same, obviously an impractical approach. Again any information on this would be greatly appreciated, thanks.

Share this post


Link to post
Share on other sites
Jason Z    6434
Are you using the diffuse variables in your shader? Is the data loaded into the vertex buffer initialized to something other than 0.0? In either case, MJP is right - you should just use PIX to see what is going on in the draw call.

Share this post


Link to post
Share on other sites
katsh    140
make sure your vertex data contain diffuse value and specular value.
it sound like you only have coord and normal data in your vertex buffer. (i mean you just define those 2 element without actual data of those)

if you define vertex in direct(in source code)
it looks like this
SimpleVertex vertices[]=
{ coord normal duffse specular
D3DXVECTOR3( -0.5,-0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3(-0.5,0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3( 0.5,-0.5,0),D3DXVECTOR3( 0,0,1),D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3( 0.5,0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
};


or you load mesh data from outer file such as obj fbx x ..etc
you need check if thres is diffuse value and specular value.(with every vertex)

Share this post


Link to post
Share on other sites
Kamo16    102
[quote name='katsh' timestamp='1306618293' post='4816930']
make sure your vertex data contain diffuse value and specular value.
it sound like you only have coord and normal data in your vertex buffer. (i mean you just define those 2 element without actual data of those)

if you define vertex in direct(in source code)
it looks like this
SimpleVertex vertices[]=
{ coord normal duffse specular
D3DXVECTOR3( -0.5,-0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3(-0.5,0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3( 0.5,-0.5,0),D3DXVECTOR3( 0,0,1),D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3( 0.5,0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
};


or you load mesh data from outer file such as obj fbx x ..etc
you need check if thres is diffuse value and specular value.(with every vertex)
[/quote]

I have a single function that generates all of the vertices' coordinates as a simple grid and set the y value via y = f(x,z). I then calculate the normals of the vertices via normal averaging, and based on the height of the generated y value, I set the vertex diffuse and specular property. So I'm fairly certain I'm setting all 4 of these properties correctly (the geometry and lighting are correct). It's just when I try to use a variable with DIFFUSE or SPECULAR attached to it, the geometry doesn't render. I'll take your guys' advice and take a look at PIX, although I've never used it before so that should be fun lol. Thanks again for the replies and I welcome any further advice.

Share this post


Link to post
Share on other sites
Kamo16    102
[quote name='Kamo16' timestamp='1306619083' post='4816934']
[quote name='katsh' timestamp='1306618293' post='4816930']
make sure your vertex data contain diffuse value and specular value.
it sound like you only have coord and normal data in your vertex buffer. (i mean you just define those 2 element without actual data of those)

if you define vertex in direct(in source code)
it looks like this
SimpleVertex vertices[]=
{ coord normal duffse specular
D3DXVECTOR3( -0.5,-0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3(-0.5,0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3( 0.5,-0.5,0),D3DXVECTOR3( 0,0,1),D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
D3DXVECTOR3( 0.5,0.5,0),D3DXVECTOR3( 0,0,1), D3DXVECTOR4( 0.2,0.3,0.4,1.0),D3DXVECTOR4( 0.5,0.5,0.5,1.0),
};


or you load mesh data from outer file such as obj fbx x ..etc
you need check if thres is diffuse value and specular value.(with every vertex)
[/quote]

I have a single function that generates all of the vertices' coordinates as a simple grid and set the y value via y = f(x,z). I then calculate the normals of the vertices via normal averaging, and based on the height of the generated y value, I set the vertex diffuse and specular property. So I'm fairly certain I'm setting all 4 of these properties correctly (the geometry and lighting are correct). It's just when I try to use a variable with DIFFUSE or SPECULAR attached to it, the geometry doesn't render. I'll take your guys' advice and take a look at PIX, although I've never used it before so that should be fun lol. Thanks again for the replies and I welcome any further advice.
[/quote]

Conclusion: I'm an idiot. As you guys suggested I looked in PIX (not that I had any idea what I was doing with that) but I was clicking around on tabs and noticed my input layout was only showing the first two elements although I defined 4. It then hit me that I probably didn't change the second parameter of CreateInputLayout() to the increased number of elements. Thanks a lot for the help guys, maybe this will help someone else with a similar problem.

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