// Data from application vertex buffer [XNA]
struct appdata
{
float3 Position : POSITION0;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL0;
float4 Tangent : TANGENT0;
float4 Binormal : BINORMAL0;
};
vertexOutput VertexShaderFunction(appdata IN,
uniform float4x4 WorldITXf, // our four standard "untweakable" xforms
uniform float4x4 WorldXf,
uniform float4x4 ViewIXf,
uniform float4x4 WvpXf,
uniform float3 LampDir
)
{
vertexOutput OUT = (vertexOutput)0;
OUT.WorldNormal = mul(WorldITXf,IN.Normal).xyz;
OUT.WorldTangent = mul(WorldITXf,IN.Tangent).xyz;
OUT.WorldBinormal = mul(WorldITXf,IN.Binormal).xyz;
float4 Po = float4(IN.Position.xyz,1); // Homogeneous location coordinates (object)
float4 Pw = mul(WorldXf,Po); // Convert to "world" space
#ifdef OBJECT_SPACE_LIGHTS
float4 Lo = float4(LampDir.xyz,0.0); // Light in object space
float4 Lw = mul(WorldXf,Lo); // Convert to "world" space
OUT.LightVec = -normalize(Lw).xyz;
#else /* !OBJECT_SPACE_LIGHTS -- standard world-space lights */
OUT.LightVec = -normalize(LampDir);
#endif
#ifdef FLIP_TEXTURE_Y
OUT.UV = float2(IN.UV.x,(1.0-IN.UV.y));
#else
OUT.UV = IN.UV.xy;
#endif
OUT.WorldView = normalize(float3(ViewIXf[0].w,ViewIXf[1].w,ViewIXf[2].w) - Pw.xyz);
OUT.HPosition = mul(WvpXf,Po);
return OUT;
}
is producing this result:
instead of draw a box.
I'm setting the HLSL parameters as follows:
effect.Parameters["gViewIXf"].SetValue(Matrix.Invert(game.ActiveCamera.ViewMatrix));
effect.Parameters["gWorldXf"].SetValue(worldTransform);
effect.Parameters["gWorldITXf"].SetValue(Matrix.Invert(Matrix.Transpose(worldTransform)));
effect.Parameters["gWvpXf"].SetValue(worldTransform * game.ActiveCamera.ViewProjectionMatrix);
The model used has all the correct elements in its vertex format for input:
struct appdata
{
float3 Position : POSITION0;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL0;
float4 Tangent : TANGENT0;
float4 Binormal : BINORMAL0;
};
My view matrix is created as follows:
// Make our view matrix
Matrix.CreateFromQuaternion(ref orientation, out matrix_View);
matrix_View.M41 = -Vector3.Dot(Right, position);
matrix_View.M42 = -Vector3.Dot(Up, position);
matrix_View.M43 = -Vector3.Dot(-Forward, position);
matrix_View.M44 = 1.0f;
// Create the combined view-projection matrix
Matrix.Multiply(ref matrix_View, ref matrix_Projection, out matrix_ViewProj);
My projection matrix is created like so:
private void Perspective(float aspect_Ratio, float z_NearClipPlane, float z_FarClipPlane)
{
nearClipPlaneZ = z_NearClipPlane;
farClipPlaneZ = z_FarClipPlane;
float yZoom = 1.0f / (float)Math.Tan(MathHelper.ToRadians(GlobalSettings.FOV_X) * 0.5f);
float xZoom = yZoom / aspect_Ratio;
matrix_Projection.M11 = xZoom;
matrix_Projection.M12 = 0.0f;
matrix_Projection.M13 = 0.0f;
matrix_Projection.M14 = 0.0f;
matrix_Projection.M21 = 0.0f;
matrix_Projection.M22 = yZoom;
matrix_Projection.M23 = 0.0f;
matrix_Projection.M24 = 0.0f;
matrix_Projection.M31 = 0.0f;
matrix_Projection.M32 = 0.0f;
matrix_Projection.M33 = z_FarClipPlane / (nearClipPlaneZ - farClipPlaneZ);
matrix_Projection.M34 = -1.0f;
matrix_Projection.M41 = 0.0f;
matrix_Projection.M42 = 0.0f;
matrix_Projection.M43 = (nearClipPlaneZ * farClipPlaneZ) / (nearClipPlaneZ - farClipPlaneZ);
matrix_Projection.M44 = 0.0f;
}
Can anyone please explain what might be causing this issue as I can't figure it out.