Jump to content
  • Advertisement
Sign in to follow this  
Dekowta

How do shaders link with my code

This topic is 2526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

This is going to be a fairly stupid question but hay.

Im currently programming a very very very basic "Engine" for a project. I'm currently using the OBJ model format and will do for most of the project.

At the moment I can load in the positions and indexs fine and with a pre written basic shader I can set a colour and it will render the model as a solid colour.

The issue I have is when I start to load in Positions, Normals, Texture coords and indexs. I still only want to display the model as a solid colour for the moment but I cant use the same shader.

The shader I have is as followed http://pastebin.com/i58GK3C5

Im also using the following vertex layout and structure


/// <summary> full layout structure </summary>
typedef struct
{
D3DXVECTOR3 Vertex;
D3DXVECTOR2 Texture;
D3DXVECTOR3 Normal;
D3DXCOLOR Colour;

}VertexData4;


/// <summary> layout for vertexdata4 </summary>
static const D3D10_INPUT_ELEMENT_DESC Vlayout4[] =
{
{ "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 },
{ "TEXTURE0", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};



If anyone has any information on how shaders relate to the code in C++ that would be enough for me to go on. Just can't get my head round what im doing wrong.


Thanks Chris

Share this post


Link to post
Share on other sites
Advertisement
That D3D10_INPUT_ELEMENT_DESC looks wrong compared to the struct to me for two reasons:

1. Normals and UVs are in a different order.
2. The colour is specified as 4 floats. I believe you want DXGI_FORMAT_R8G8B8A8_UNORM instead.

Share this post


Link to post
Share on other sites
I changed the structure and layout description to the same order and kept the shader the same.

This was the result which should be a white square.

http://i.imgur.com/0Smwl.png


If I Change the shader inputs to the following

struct PS_INPUT
{
float4 Pos : SV_POSITION;
float3 Norm : NORMAL;
float2 Texture : TEXTURE0;
float4 Color : COLOR;
};

struct VS_INPUT
{
float4 Pos : POSITION;
float3 Norm : NORMAL;
float2 Texture : TEXTURE0;
float4 Color : COLOR;
};


It wont render anything.

I don't know if my structure is getting the correct data but I swear its something Im doing wrong with the shader. I'll check the data and post it later.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!