with vertex shaders, does the input need to be fully similar to what you are sending to it? so does the input struct need to be the same as the vertex declaration?
this is the hlsl code:
struct VertexToPixel
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 TexCoords : TEXCOORD0;
};
struct PixelToFrame
{
float4 Color : COLOR0;
};
float4x4 xWorldViewProjection;
Texture xColoredTexture;
sampler ColoredTextureSampler = sampler_state { texture = <xColoredTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;AddressU = wrap; AddressV = wrap;};
VertexToPixel SimplestVertexShader( float4 inPos : POSITION, float3 inNormal : NORMAL, float2 inTexCoords : TEXCOORD0
)
{
VertexToPixel Output = (VertexToPixel)0;
Output.Position = mul(inPos, xWorldViewProjection);
Output.TexCoords = inTexCoords;
Output.Normal = mul(inNormal, xWorldViewProjection);
return Output;
}
PixelToFrame OurFirstPixelShader(VertexToPixel PSIn)
{
PixelToFrame Output = (PixelToFrame)0;
Output.Color = tex2D(ColoredTextureSampler, PSIn.TexCoords);
return Output;
}
technique Simplest
{
pass Pass0
{
VertexShader = compile vs_3_0 SimplestVertexShader();
PixelShader = compile ps_3_0 OurFirstPixelShader();
}
}
and this is my own vertex class, with the declaration in it:
public struct VertexCollada : IVertex
{
private SlimDX.Vector4 position;
public SlimDX.Vector3 Normal;
public SlimDX.Vector2 TextureCoordinates;
public SlimDX.Vector3 Tangent;
public SlimDX.Vector3 Binormal;
public SlimDX.Vector4 Position
{
get { return position; }
set { position = value; }
}
public VertexCollada(SlimDX.Vector4 Position, SlimDX.Vector2 TextureCoordinates, SlimDX.Vector3 Normal, SlimDX.Vector3 Tangent, SlimDX.Vector3 Binormal)
{
this.position = Position;
this.TextureCoordinates = TextureCoordinates;
this.Normal = Normal;
//this.Color = Color;
this.Tangent = Tangent;
this.Binormal = Binormal;
}
private static Framework.Graphics.VertexElement[] vertexElements = {
new Framework.Graphics.VertexElement(0, 0, Framework.Graphics.DeclarationType.Float4, Framework.Graphics.DeclarationMethod.Default, Framework.Graphics.DeclarationUsage.Position, 0),
new Framework.Graphics.VertexElement(0, 16, Framework.Graphics.DeclarationType.Float3, Framework.Graphics.DeclarationMethod.Default, Framework.Graphics.DeclarationUsage.Normal, 0),
new Framework.Graphics.VertexElement(0, 28, Framework.Graphics.DeclarationType.Float2, Framework.Graphics.DeclarationMethod.Default, Framework.Graphics.DeclarationUsage.TextureCoordinate, 0),
new Framework.Graphics.VertexElement(0, 36, Framework.Graphics.DeclarationType.Float3, Framework.Graphics.DeclarationMethod.Default, Framework.Graphics.DeclarationUsage.Tangent, 0),
new Framework.Graphics.VertexElement(0, 48, Framework.Graphics.DeclarationType.Float3, Framework.Graphics.DeclarationMethod.Default, Framework.Graphics.DeclarationUsage.Binormal, 0)
};
public static Framework.Graphics.VertexElement[] VertexElements
{
get { return vertexElements; }
}
private static int sizeBytes = Marshal.SizeOf(typeof(VertexCollada));
public static int SizeBytes
{
get { return sizeBytes; }
}
public static Framework.Graphics.VertexFormat VertexFormat
{
get
{
return VertexFormat.Position | VertexFormat.Normal | VertexFormat.Texture | VertexFormat.Tangent | VertexFormat.Binormal;
}
}
}
the result is that the positions are right, but the texture coordinates are totally screwed up. I am 100% sure that the texture coordinates in the vertexBuffer are allright. The loading code is ported from an XNA importer.
it almost looks right, but it's just not fully correct. Does anyone have a clue if i am doing something wrong in the above codes?
[Edited by - Slaaitjuh on March 25, 2008 9:02:48 AM]