I'm learning HLSL, and my VertexShader is compiling fine, but it isn't displaying anything. Why?
Here's my shader:
float4x4 BoneMatrix;
float4x4 World;
float4x4 View;
float4x4 Projection;
float4 AmbientColor = float4(1, 1, 1, 1);
float AmbientIntensity = 0.1;
struct VertexShaderHeadInput
{
float4 Position : POSITION0;
float4 Normal : NORMAL0;
float4 TexPosition : TEXCOORD0;
};
struct VertexShaderHeadOutput
{
float4 Position : POSITION0;
float4 Normal : NORMAL0;
float4 TexPosition : TEXCOORD0;
};
VertexShaderHeadOutput TransformHead(VertexShaderHeadInput Input)
{
VertexShaderHeadOutput Output;
float4 WorldPosition = mul(Input.Position, World);
float4 ViewPosition = mul(WorldPosition, View);
Output.Position = mul(ViewPosition, Projection);
Output.Normal = mul(ViewPosition, Projection);
Output.TexPosition = mul(ViewPosition, Projection);
Output.Position *= mul(Input.Position, BoneMatrix);
Output.Normal *= mul(Input.Normal, BoneMatrix);
Output.TexPosition *= Input.TexPosition;
return Output;
}
float4 PixelShaderFunction(VertexShaderHeadOutput Input) : COLOR0
{
return AmbientColor * AmbientIntensity;
}
technique TransformHeadTechnique
{
pass Pass1
{
VertexShader = compile vs_3_0 TransformHead();
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}
Here's my usage code:
m_HeadShader.Parameters["World"].SetValue(WorldMatrix);
m_HeadShader.Parameters["View"].SetValue(ViewMatrix);
m_HeadShader.Parameters["Projection"].SetValue(ProjectionMatrix);
m_HeadShader.Parameters["BoneMatrix"].SetValue(Skel.Bones[16].AbsoluteMatrix);
foreach(EffectPass Pass in m_HeadShader.CurrentTechnique.Passes)
{
Pass.Apply();
foreach (Vector3 Fce in HeadMesh.Faces)
{
VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
Vertex[0] = HeadMesh.RealVertices[(int)Fce.X];
Vertex[1] = HeadMesh.RealVertices[(int)Fce.Y];
Vertex[2] = HeadMesh.RealVertices[(int)Fce.Z];
Vertex[0].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.X].TextureCoordinate;
Vertex[1].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
Vertex[2].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.Z].TextureCoordinate;
Vertex[0].Normal = HeadMesh.RealVertices[(int)Fce.X].Normal;
Vertex[1].Normal = HeadMesh.RealVertices[(int)Fce.Y].Normal;
Vertex[2].Normal = HeadMesh.RealVertices[(int)Fce.Z].Normal;
m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
}
}
My worldmatrix:
/// <summary>
/// This avatar's world matrix. Used for rendering.
/// </summary>
public Matrix WorldMatrix
{
get
{
if (m_WorldIsDirty)
{
m_World = Matrix.CreateRotationX(m_RotateX) * Matrix.CreateRotationY(m_RotateY) * Matrix.CreateRotationZ(m_RotateZ) * Matrix.CreateScale(m_Scale) * Matrix.CreateTranslation(m_Position);
m_WorldIsDirty = false;
}
return m_World;
}
}
This is the code I've been trying to convert to HLSL (High Level Shader Language):
case MeshType.Head:
for (int i = 0; i < Msh.TotalVertexCount; i++)
{
//Transform the head vertices' position by the absolute transform
//for the headbone (which is always bone 17) to render the head in place.
Msh.TransformedVertices[i].Position = Vector3.Transform(Msh.RealVertices[i].Position,
Skel.Bones[16].AbsoluteMatrix);
Msh.TransformedVertices[i].TextureCoordinate = Msh.RealVertices[i].TextureCoordinate;
//Transform the head normals' position by the absolute transform
//for the headbone (which is always bone 17) to render the head in place.
Msh.TransformedVertices[i].Normal = Vector3.Transform(Msh.RealVertices[i].Normal,
Skel.Bones[16].AbsoluteMatrix);
}
return;
I might add that I tried to debug the shader using RenderDoc, but it actually crashed as it was loading its log. :|