Skin mesh now using correct bone transforms

This commit is contained in:
dexy
2019-11-03 22:43:39 +11:00
Unverified
parent 9f84ba8ad0
commit 6be0d5cb30
9 changed files with 342 additions and 84 deletions
+71 -10
View File
@@ -57,12 +57,14 @@ namespace CodeWalker.Rendering
bool disposed = false;
VertexShader shadowvs;
VertexShader shadowvs_skin;
PixelShader shadowps;
GpuVarsBuffer<ShadowShaderVSSceneVars> VSSceneVars;
GpuVarsBuffer<ShadowShaderVSEntityVars> VSEntityVars;
GpuVarsBuffer<ShadowShaderVSModelVars> VSModelVars;
GpuVarsBuffer<ShadowShaderGeomVars> GeomVars;
GpuABuffer<Matrix3_s> BoneMatrices;
SamplerState texsampler;
SamplerState texsamplerc;
@@ -70,15 +72,20 @@ namespace CodeWalker.Rendering
public Vector4 WindVector { get; set; }
Matrix3_s[] defaultBoneMatrices;
bool defaultBoneMatricesBound = false;
private Dictionary<VertexType, InputLayout> layouts = new Dictionary<VertexType, InputLayout>();
public ShadowShader(Device device)
{
byte[] vsbytes = File.ReadAllBytes("Shaders\\ShadowVS.cso");
byte[] vssbytes = File.ReadAllBytes("Shaders\\ShadowVS_Skin.cso");
byte[] psbytes = File.ReadAllBytes("Shaders\\ShadowPS.cso");
shadowvs = new VertexShader(device, vsbytes);
shadowvs_skin = new VertexShader(device, vssbytes);
shadowps = new PixelShader(device, psbytes);
@@ -86,6 +93,7 @@ namespace CodeWalker.Rendering
VSEntityVars = new GpuVarsBuffer<ShadowShaderVSEntityVars>(device);
VSModelVars = new GpuVarsBuffer<ShadowShaderVSModelVars>(device);
GeomVars = new GpuVarsBuffer<ShadowShaderGeomVars>(device);
BoneMatrices = new GpuABuffer<Matrix3_s>(device, 255);
//supported layouts - requires Position, Normal, Colour, Texcoord
@@ -93,8 +101,6 @@ namespace CodeWalker.Rendering
layouts.Add(VertexType.DefaultEx, new InputLayout(device, vsbytes, VertexTypeDefaultEx.GetLayout()));
layouts.Add(VertexType.PNCCT, new InputLayout(device, vsbytes, VertexTypePNCCT.GetLayout()));
layouts.Add(VertexType.PNCCTTTT, new InputLayout(device, vsbytes, VertexTypePNCCTTTT.GetLayout()));
layouts.Add(VertexType.PBBNCCTTX, new InputLayout(device, vsbytes, VertexTypePBBNCCTTX.GetLayout()));
layouts.Add(VertexType.PBBNCCT, new InputLayout(device, vsbytes, VertexTypePBBNCCT.GetLayout()));
layouts.Add(VertexType.PNCTTTX, new InputLayout(device, vsbytes, VertexTypePNCTTTX.GetLayout()));
layouts.Add(VertexType.PNCTTTX_2, new InputLayout(device, vsbytes, VertexTypePNCTTTX_2.GetLayout()));
layouts.Add(VertexType.PNCTTTX_3, new InputLayout(device, vsbytes, VertexTypePNCTTTX_3.GetLayout()));
@@ -103,19 +109,25 @@ namespace CodeWalker.Rendering
layouts.Add(VertexType.PNCCTTX, new InputLayout(device, vsbytes, VertexTypePNCCTTX.GetLayout()));
layouts.Add(VertexType.PNCCTTX_2, new InputLayout(device, vsbytes, VertexTypePNCCTTX_2.GetLayout()));
layouts.Add(VertexType.PNCCTTTX, new InputLayout(device, vsbytes, VertexTypePNCCTTTX.GetLayout()));
layouts.Add(VertexType.PBBNCCTX, new InputLayout(device, vsbytes, VertexTypePBBNCCTX.GetLayout()));
layouts.Add(VertexType.PBBNCTX, new InputLayout(device, vsbytes, VertexTypePBBNCTX.GetLayout()));
layouts.Add(VertexType.PBBNCT, new InputLayout(device, vsbytes, VertexTypePBBNCT.GetLayout()));
layouts.Add(VertexType.PNCCTT, new InputLayout(device, vsbytes, VertexTypePNCCTT.GetLayout()));
layouts.Add(VertexType.PNCCTX, new InputLayout(device, vsbytes, VertexTypePNCCTX.GetLayout()));
layouts.Add(VertexType.PNCH2, new InputLayout(device, vsbytes, VertexTypePNCH2.GetLayout()));
layouts.Add(VertexType.PCCH2H4, new InputLayout(device, vsbytes, VertexTypePCCH2H4.GetLayout()));
layouts.Add(VertexType.PBBNCTT, new InputLayout(device, vsbytes, VertexTypePBBNCTT.GetLayout()));
layouts.Add(VertexType.PBBNCTTX, new InputLayout(device, vsbytes, VertexTypePBBNCTTX.GetLayout()));
layouts.Add(VertexType.PBBNCTTT, new InputLayout(device, vsbytes, VertexTypePBBNCTTT.GetLayout()));
layouts.Add(VertexType.PNCTT, new InputLayout(device, vsbytes, VertexTypePNCTT.GetLayout()));
layouts.Add(VertexType.PNCTTT, new InputLayout(device, vsbytes, VertexTypePNCTTT.GetLayout()));
layouts.Add(VertexType.PBBNCTTTX, new InputLayout(device, vsbytes, VertexTypePBBNCTTTX.GetLayout()));
layouts.Add(VertexType.PBBNCT, new InputLayout(device, vssbytes, VertexTypePBBNCT.GetLayout()));
layouts.Add(VertexType.PBBNCTX, new InputLayout(device, vssbytes, VertexTypePBBNCTX.GetLayout()));
layouts.Add(VertexType.PBBNCTT, new InputLayout(device, vssbytes, VertexTypePBBNCTT.GetLayout()));
layouts.Add(VertexType.PBBNCTTT, new InputLayout(device, vssbytes, VertexTypePBBNCTTT.GetLayout()));
layouts.Add(VertexType.PBBNCCT, new InputLayout(device, vssbytes, VertexTypePBBNCCT.GetLayout()));
layouts.Add(VertexType.PBBNCCTT, new InputLayout(device, vssbytes, VertexTypePBBNCCTT.GetLayout()));//TODO
layouts.Add(VertexType.PBBNCCTX, new InputLayout(device, vssbytes, VertexTypePBBNCCTX.GetLayout()));
layouts.Add(VertexType.PBBNCTTX, new InputLayout(device, vssbytes, VertexTypePBBNCTTX.GetLayout()));
layouts.Add(VertexType.PBBNCTTTX, new InputLayout(device, vssbytes, VertexTypePBBNCTTTX.GetLayout()));//TODO
layouts.Add(VertexType.PBBNCCTTX, new InputLayout(device, vssbytes, VertexTypePBBNCCTTX.GetLayout()));//TODO
//PBBCCT todo
//PBBNC todo
@@ -146,13 +158,22 @@ namespace CodeWalker.Rendering
MipLodBias = 0,
});
defaultBoneMatrices = new Matrix3_s[255];
for (int i = 0; i < 255; i++)
{
defaultBoneMatrices[i].Row1 = Vector4.UnitX;
defaultBoneMatrices[i].Row2 = Vector4.UnitY;
defaultBoneMatrices[i].Row3 = Vector4.UnitZ;
}
}
public override void SetShader(DeviceContext context)
{
context.VertexShader.Set(shadowvs);
context.PixelShader.Set(shadowps);
}
@@ -161,6 +182,26 @@ namespace CodeWalker.Rendering
InputLayout l;
if (layouts.TryGetValue(type, out l))
{
VertexShader vs = shadowvs;
switch (type)
{
case VertexType.PBBNCT:
case VertexType.PBBNCTX:
case VertexType.PBBNCTT:
case VertexType.PBBNCTTT:
case VertexType.PBBNCCT:
case VertexType.PBBNCCTT:
case VertexType.PBBNCCTX:
case VertexType.PBBNCTTX:
case VertexType.PBBNCTTTX:
case VertexType.PBBNCCTTX:
vs = shadowvs_skin;
break;
}
context.VertexShader.Set(vs);
context.InputAssembler.InputLayout = l;
return true;
}
@@ -192,6 +233,17 @@ namespace CodeWalker.Rendering
public override void SetModelVars(DeviceContext context, RenderableModel model)
{
if (model.Owner.BoneTransforms != null)
{
SetBoneMatrices(context, model.Owner.BoneTransforms);
defaultBoneMatricesBound = false;
}
else if (!defaultBoneMatricesBound)
{
SetBoneMatrices(context, defaultBoneMatrices);
defaultBoneMatricesBound = true;
}
if (!model.UseTransform) return;
VSModelVars.Vars.Transform = Matrix.Transpose(model.Transform);
VSModelVars.Update(context);
@@ -306,6 +358,13 @@ namespace CodeWalker.Rendering
}
}
public void SetBoneMatrices(DeviceContext context, Matrix3_s[] matrices)
{
BoneMatrices.Update(context, matrices);
BoneMatrices.SetVSCBuffer(context, 7);
}
public override void UnbindResources(DeviceContext context)
{
context.VertexShader.SetConstantBuffer(0, null);
@@ -341,10 +400,12 @@ namespace CodeWalker.Rendering
VSEntityVars.Dispose();
VSModelVars.Dispose();
GeomVars.Dispose();
BoneMatrices.Dispose();
shadowps.Dispose();
shadowvs.Dispose();
shadowvs_skin.Dispose();
disposed = true;
}