Vertex Shader Input problem in DirectX 11

  • Thread starter Thread starter Manda Rajo
  • Start date Start date
M

Manda Rajo

Guest
Hi, I have a problem on the Vertex Shader Input, it's like a bug. Can someone help me please.
My question is: "I cannot use position as float3", if the position is float3 then the color result is wrong but the positions of the vertices are always correct in all cases which means that the "size of the data" is correct, but the error is only on "texCoord".

Vertex Shader:

cbuffer cb0 : register(b0)
{
matrix g_worldMatrix : packoffset(c0);
matrix g_worldViewProjectionMatrix : packoffset(c4);
}

struct ShaderVertex
{
float4 position : POSITION; // <--- Some Microsoft Examples use float3
float3 normal : NORMAL; // <--- If I remove this Normal then the result is worse.
float2 texCoord : TEXCOORD;
};

struct PS_Input
{
float4 position : SV_Position;
float2 texCoord : TEXCOORD;
};

struct PS_Output
{
float4 color : SV_Target;
};

void main(in ShaderVertex input, out PS_Input output)
{
output.position = mul(float4(input.position.xyz, 1), g_worldViewProjectionMatrix);
output.texCoord = input.texCoord;
}






Pixel Shader: Here is the most important to read in order to understand how the results work.

...

void main(in PS_Input input, out PS_Output output)
{
output.color = float4(input.texCoord.xy, 0, 1);
}


There are 2 screenshots below, the image on the top is correct, the result should be like that if there is no error and the image on the bottom is wrong, there is an error.

1413477.jpg

The data is as below for the position as float4:

struct ShaderVertex
{
Vector4 position;
Vector3 normal;
Vector2 texCoord;
};
ShaderVertex verts[3*3];
verts[0].position = Vector4(...);
verts[0].normal = ...
verts[0].texCoord = Vector2(...);
verts[1].position = Vector4(...);
verts[1].normal = ...
verts[1].texCoord = Vector2(...);
verts[2].position = Vector4(...);
verts[2].normal = ...
verts[2].texCoord = Vector2(...);
...
verts[8].position = Vector4(...);
verts[8].normal = ...
verts[8].texCoord = Vector2(...);

Continue reading...
 
Back
Top