diff --git a/CodeWalker.Core/GameFiles/Resources/Drawable.cs b/CodeWalker.Core/GameFiles/Resources/Drawable.cs index 47de0f7..11ebd0e 100644 --- a/CodeWalker.Core/GameFiles/Resources/Drawable.cs +++ b/CodeWalker.Core/GameFiles/Resources/Drawable.cs @@ -802,7 +802,7 @@ namespace CodeWalker.GameFiles //used by CW for animating skeletons. public Quaternion AnimRotation; public Vector3 AnimTranslation; - + public Matrix AnimTransform; /// @@ -844,6 +844,7 @@ namespace CodeWalker.GameFiles AnimRotation = Rotation; AnimTranslation = Translation; + AnimTransform = Matrix.AffineTransformation(1.0f, AnimRotation, AnimTranslation); } /// diff --git a/Rendering/Renderable.cs b/Rendering/Renderable.cs index 4ad78da..6952040 100644 --- a/Rendering/Renderable.cs +++ b/Rendering/Renderable.cs @@ -77,6 +77,8 @@ namespace CodeWalker.Rendering public ClipMapEntry ClipMapEntry; public Dictionary ModelBoneLinks; + public Matrix3_s[] BoneTransforms; + public override void Init(DrawableBase drawable) { @@ -297,6 +299,28 @@ namespace CodeWalker.Rendering } } } + + + + + + //populate the bonetransforms array + Matrix[] bonetrans = (fragtransforms != null) ? fragtransforms : (modeltransforms != null) ? modeltransforms : null; + if (bonetrans != null) + { + BoneTransforms = new Matrix3_s[bonetrans.Length]; + for (int i = 0; i < bonetrans.Length; i++) + { + Matrix b = bonetrans[i]; + Matrix3_s bt = new Matrix3_s(); + bt.Row1 = b.Row1; + bt.Row2 = b.Row2; + bt.Row3 = b.Row3; + BoneTransforms[i] = bt; + } + } + + } private RenderableModel InitModel(DrawableModel dm) @@ -445,17 +469,6 @@ namespace CodeWalker.Rendering for (int i = 0; i < bones.Count; i++) { var bone = bones[i]; - - RenderableModel bmodel = null; - ModelBoneLinks?.TryGetValue(bone.Id, out bmodel); - if (bmodel == null) - { continue; } - - if (((bmodel.SkeletonBinding >> 8) & 0xFF) > 0) //skin mesh? //TODO: see eg. p_oil_pjack_03_s - { continue; } - - //update model's transform from animated bone - var pos = bone.AnimTranslation; var ori = bone.AnimRotation; var pbone = bone.Parent; @@ -465,8 +478,19 @@ namespace CodeWalker.Rendering ori = pbone.AnimRotation * ori; pbone = pbone.Parent; } + bone.AnimTransform = Matrix.AffineTransformation(1.0f, ori, pos); - bmodel.Transform = Matrix.AffineTransformation(1.0f, ori, pos); + + //update model's transform from animated bone + RenderableModel bmodel = null; + ModelBoneLinks?.TryGetValue(bone.Id, out bmodel); + if (bmodel == null) + { continue; } + + if (((bmodel.SkeletonBinding >> 8) & 0xFF) > 0) //skin mesh? //TODO: see eg. p_oil_pjack_03_s + { continue; } + + bmodel.Transform = bone.AnimTransform; } diff --git a/Rendering/Shaders/BasicShader.cs b/Rendering/Shaders/BasicShader.cs index e35f96f..9e9bbc4 100644 --- a/Rendering/Shaders/BasicShader.cs +++ b/Rendering/Shaders/BasicShader.cs @@ -122,6 +122,7 @@ namespace CodeWalker.Rendering VertexShader basicvspnct; VertexShader basicvspnctt; + VertexShader basicvspncttt; VertexShader basicvspncct; VertexShader basicvspncctt; VertexShader basicvspnccttt; @@ -131,6 +132,13 @@ namespace CodeWalker.Rendering VertexShader basicvspnccttx; VertexShader basicvspnctttx; VertexShader basicvspncctttx; + VertexShader basicvspbbnct; + VertexShader basicvspbbnctx; + VertexShader basicvspbbnctt; + VertexShader basicvspbbncttt; + VertexShader basicvspbbncct; + VertexShader basicvspbbncctx; + VertexShader basicvspbbncttx; VertexShader basicvsbox; VertexShader basicvssphere; VertexShader basicvscapsule; @@ -144,6 +152,7 @@ namespace CodeWalker.Rendering GpuVarsBuffer PSGeomVars; GpuVarsBuffer InstGlobalVars; GpuVarsBuffer InstLocalVars; + GpuABuffer BoneMatrices; SamplerState texsampler; SamplerState texsampleranis; SamplerState texsamplertnt; @@ -172,6 +181,7 @@ namespace CodeWalker.Rendering { byte[] vspnctbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCT.cso"); byte[] vspncttbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCTT.cso"); + byte[] vspnctttbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCTTT.cso"); byte[] vspncctbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCT.cso"); byte[] vspnccttbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCTT.cso"); byte[] vspncctttbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCTTT.cso"); @@ -181,6 +191,15 @@ namespace CodeWalker.Rendering byte[] vspnccttxbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCTTX.cso"); byte[] vspnctttxbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCTTTX.cso"); byte[] vspncctttxbytes = File.ReadAllBytes("Shaders\\BasicVS_PNCCTTTX.cso"); + + byte[] vspbbnctbytes = File.ReadAllBytes("Shaders\\BasicVS_PBBNCT.cso"); + byte[] vspbbnctxbytes = File.ReadAllBytes("Shaders\\BasicVS_PBBNCTX.cso"); + byte[] vspbbncttbytes = File.ReadAllBytes("Shaders\\BasicVS_PBBNCTT.cso"); + byte[] vspbbnctttbytes = File.ReadAllBytes("Shaders\\BasicVS_PBBNCTTT.cso"); + byte[] vspbbncctbytes = File.ReadAllBytes("Shaders\\BasicVS_PBBNCCT.cso"); + byte[] vspbbncctxbytes = File.ReadAllBytes("Shaders\\BasicVS_PBBNCCTX.cso"); + byte[] vspbbncttxbytes = File.ReadAllBytes("Shaders\\BasicVS_PBBNCTTX.cso"); + byte[] vsboxbytes = File.ReadAllBytes("Shaders\\BasicVS_Box.cso"); byte[] vsspherebytes = File.ReadAllBytes("Shaders\\BasicVS_Sphere.cso"); byte[] vscapsulebytes = File.ReadAllBytes("Shaders\\BasicVS_Capsule.cso"); @@ -189,6 +208,7 @@ namespace CodeWalker.Rendering basicvspnct = new VertexShader(device, vspnctbytes); basicvspnctt = new VertexShader(device, vspncttbytes); + basicvspncttt = new VertexShader(device, vspnctttbytes); basicvspncct = new VertexShader(device, vspncctbytes); basicvspncctt = new VertexShader(device, vspnccttbytes); basicvspnccttt = new VertexShader(device, vspncctttbytes); @@ -198,6 +218,13 @@ namespace CodeWalker.Rendering basicvspnccttx = new VertexShader(device, vspnccttxbytes); basicvspnctttx = new VertexShader(device, vspnctttxbytes); basicvspncctttx = new VertexShader(device, vspncctttxbytes); + basicvspbbnct = new VertexShader(device, vspbbnctbytes); + basicvspbbnctx = new VertexShader(device, vspbbnctxbytes); + basicvspbbnctt = new VertexShader(device, vspbbncttbytes); + basicvspbbncttt = new VertexShader(device, vspbbnctttbytes); + basicvspbbncct = new VertexShader(device, vspbbncctbytes); + basicvspbbncctx = new VertexShader(device, vspbbncctxbytes); + basicvspbbncttx = new VertexShader(device, vspbbncttxbytes); basicvsbox = new VertexShader(device, vsboxbytes); basicvssphere = new VertexShader(device, vsspherebytes); basicvscapsule = new VertexShader(device, vscapsulebytes); @@ -212,49 +239,47 @@ namespace CodeWalker.Rendering PSGeomVars = new GpuVarsBuffer(device); InstGlobalVars = new GpuVarsBuffer(device); InstLocalVars = new GpuVarsBuffer(device); + BoneMatrices = new GpuABuffer(device, 255); InitInstGlobalVars(); //supported layouts - requires Position, Normal, Colour, Texcoord layouts.Add(VertexType.Default, new InputLayout(device, vspnctbytes, VertexTypeDefault.GetLayout())); - layouts.Add(VertexType.PNCH2, new InputLayout(device, vspnctbytes, VertexTypePNCH2.GetLayout())); - layouts.Add(VertexType.PBBNCT, new InputLayout(device, vspnctbytes, VertexTypePBBNCT.GetLayout())); - + layouts.Add(VertexType.PNCH2, new InputLayout(device, vspnctbytes, VertexTypePNCH2.GetLayout()));//TODO? layouts.Add(VertexType.PNCTT, new InputLayout(device, vspncttbytes, VertexTypePNCTT.GetLayout())); - layouts.Add(VertexType.PNCTTT, new InputLayout(device, vspncttbytes, VertexTypePNCTTT.GetLayout())); - layouts.Add(VertexType.PBBNCTT, new InputLayout(device, vspncttbytes, VertexTypePBBNCTT.GetLayout())); - layouts.Add(VertexType.PBBNCTTT, new InputLayout(device, vspncttbytes, VertexTypePBBNCTTT.GetLayout())); - + layouts.Add(VertexType.PNCTTT, new InputLayout(device, vspnctttbytes, VertexTypePNCTTT.GetLayout())); layouts.Add(VertexType.PNCCT, new InputLayout(device, vspncctbytes, VertexTypePNCCT.GetLayout())); - layouts.Add(VertexType.PBBNCCT, new InputLayout(device, vspncctbytes, VertexTypePBBNCCT.GetLayout())); - layouts.Add(VertexType.PNCCTT, new InputLayout(device, vspnccttbytes, VertexTypePNCCTT.GetLayout())); - - layouts.Add(VertexType.PNCCTTTT, new InputLayout(device, vspncctttbytes, VertexTypePNCCTTTT.GetLayout())); + layouts.Add(VertexType.PNCCTTTT, new InputLayout(device, vspncctttbytes, VertexTypePNCCTTTT.GetLayout()));//TODO..? //normalmap layouts - requires Position, Normal, Colour, Texcoord, Tangent (X) layouts.Add(VertexType.DefaultEx, new InputLayout(device, vspnctxbytes, VertexTypeDefaultEx.GetLayout())); layouts.Add(VertexType.PCCH2H4, new InputLayout(device, vspnctxbytes, VertexTypePCCH2H4.GetLayout())); - layouts.Add(VertexType.PBBNCTX, new InputLayout(device, vspnctxbytes, VertexTypePBBNCTX.GetLayout())); - layouts.Add(VertexType.PNCCTX, new InputLayout(device, vspncctxbytes, VertexTypePNCCTX.GetLayout())); - layouts.Add(VertexType.PBBNCCTX, new InputLayout(device, vspncctxbytes, VertexTypePBBNCCTX.GetLayout())); - layouts.Add(VertexType.PNCTTX, new InputLayout(device, vspncttxbytes, VertexTypePNCTTX.GetLayout())); - layouts.Add(VertexType.PBBNCTTX, new InputLayout(device, vspncttxbytes, VertexTypePBBNCTTX.GetLayout())); - layouts.Add(VertexType.PBBNCTTTX, new InputLayout(device, vspncttxbytes, VertexTypePBBNCTTTX.GetLayout())); - layouts.Add(VertexType.PNCCTTX, new InputLayout(device, vspnccttxbytes, VertexTypePNCCTTX.GetLayout())); layouts.Add(VertexType.PNCCTTX_2, new InputLayout(device, vspnccttxbytes, VertexTypePNCCTTX_2.GetLayout())); layouts.Add(VertexType.PNCTTTX, new InputLayout(device, vspnctttxbytes, VertexTypePNCTTTX.GetLayout())); layouts.Add(VertexType.PNCTTTX_2, new InputLayout(device, vspnctttxbytes, VertexTypePNCTTTX_2.GetLayout())); layouts.Add(VertexType.PNCTTTX_3, new InputLayout(device, vspnctttxbytes, VertexTypePNCTTTX_3.GetLayout())); - layouts.Add(VertexType.PNCTTTTX, new InputLayout(device, vspnctttxbytes, VertexTypePNCTTTTX.GetLayout())); + layouts.Add(VertexType.PNCTTTTX, new InputLayout(device, vspnctttxbytes, VertexTypePNCTTTTX.GetLayout()));//TODO layouts.Add(VertexType.PNCCTTTX, new InputLayout(device, vspncctttxbytes, VertexTypePNCCTTTX.GetLayout())); - layouts.Add(VertexType.PBBNCCTTX, new InputLayout(device, vspnccttxbytes, VertexTypePBBNCCTTX.GetLayout())); + + + + //skinned layouts + layouts.Add(VertexType.PBBNCT, new InputLayout(device, vspbbnctbytes, VertexTypePBBNCT.GetLayout())); + layouts.Add(VertexType.PBBNCTX, new InputLayout(device, vspbbnctxbytes, VertexTypePBBNCTX.GetLayout())); + layouts.Add(VertexType.PBBNCTT, new InputLayout(device, vspbbncttbytes, VertexTypePBBNCTT.GetLayout())); + layouts.Add(VertexType.PBBNCTTT, new InputLayout(device, vspbbnctttbytes, VertexTypePBBNCTTT.GetLayout())); + layouts.Add(VertexType.PBBNCCT, new InputLayout(device, vspbbncctbytes, VertexTypePBBNCCT.GetLayout())); + layouts.Add(VertexType.PBBNCCTX, new InputLayout(device, vspbbncctxbytes, VertexTypePBBNCCTX.GetLayout())); + layouts.Add(VertexType.PBBNCTTX, new InputLayout(device, vspbbncttxbytes, VertexTypePBBNCTTX.GetLayout())); + layouts.Add(VertexType.PBBNCTTTX, new InputLayout(device, vspbbncttxbytes, VertexTypePBBNCTTTX.GetLayout()));//TODO + layouts.Add(VertexType.PBBNCCTTX, new InputLayout(device, vspbbncctxbytes, VertexTypePBBNCCTTX.GetLayout()));//TODO @@ -366,17 +391,15 @@ namespace CodeWalker.Rendering { case VertexType.Default: case VertexType.PNCH2: - case VertexType.PBBNCT: vs = basicvspnct; break; case VertexType.PNCTT: - case VertexType.PNCTTT: - case VertexType.PBBNCTT: - case VertexType.PBBNCTTT: vs = basicvspnctt; break; + case VertexType.PNCTTT: + vs = basicvspncttt; + break; case VertexType.PNCCT: - case VertexType.PBBNCCT: vs = basicvspncct; break; case VertexType.PNCCTT://not used? @@ -387,23 +410,16 @@ namespace CodeWalker.Rendering break; case VertexType.DefaultEx: case VertexType.PCCH2H4: - case VertexType.PBBNCTX: vs = basicvspnctx; break; - - case VertexType.PBBNCCTX: case VertexType.PNCCTX: vs = basicvspncctx; break; - case VertexType.PNCTTX: - case VertexType.PBBNCTTX: vs = basicvspncttx; break; - case VertexType.PNCCTTX://not used? case VertexType.PNCCTTX_2://not used? - case VertexType.PBBNCCTTX://not used? vs = basicvspnccttx; break; @@ -411,7 +427,6 @@ namespace CodeWalker.Rendering case VertexType.PNCTTTX_2: case VertexType.PNCTTTX_3: case VertexType.PNCTTTTX: //not using last texcoords! - case VertexType.PBBNCTTTX: vs = basicvspnctttx; break; @@ -419,6 +434,34 @@ namespace CodeWalker.Rendering vs = basicvspncctttx; break; + case VertexType.PBBNCT: + vs = basicvspbbnct; + break; + case VertexType.PBBNCTT: + vs = basicvspbbnctt; + break; + case VertexType.PBBNCTTT: + vs = basicvspbbncttt; + break; + case VertexType.PBBNCCT: + vs = basicvspbbncct; + break; + case VertexType.PBBNCTX: + vs = basicvspbbnctx; + break; + case VertexType.PBBNCCTX: + vs = basicvspbbncctx; + break; + case VertexType.PBBNCTTX: + vs = basicvspbbncttx; + break; + case VertexType.PBBNCCTTX://not used? + vs = basicvspbbncctx;//TODO + break; + case VertexType.PBBNCTTTX: + vs = basicvspbbncttx;//TODO + break; + default: break; @@ -514,6 +557,14 @@ namespace CodeWalker.Rendering public override void SetModelVars(DeviceContext context, RenderableModel model) { + if (((model.SkeletonBinding >> 8) & 0xFF) > 0) + { + if (model.Owner.BoneTransforms != null) + { + SetBoneMatrices(context, model.Owner.BoneTransforms); + } + } + if (!model.UseTransform) return; VSModelVars.Vars.Transform = Matrix.Transpose(model.Transform); VSModelVars.Update(context); @@ -730,6 +781,12 @@ namespace CodeWalker.Rendering } } + public void SetBoneMatrices(DeviceContext context, Matrix3_s[] matrices) + { + BoneMatrices.Update(context, matrices); + BoneMatrices.SetVSCBuffer(context, 7); + } + public void SetInstanceVars(DeviceContext context, RenderableInstanceBatch batch) { @@ -920,10 +977,12 @@ namespace CodeWalker.Rendering PSGeomVars.Dispose(); InstGlobalVars.Dispose(); InstLocalVars.Dispose(); + BoneMatrices.Dispose(); basicps.Dispose(); basicvspnct.Dispose(); basicvspnctt.Dispose(); + basicvspncttt.Dispose(); basicvspncct.Dispose(); basicvspncctt.Dispose(); basicvspnccttt.Dispose(); @@ -933,6 +992,13 @@ namespace CodeWalker.Rendering basicvspnccttx.Dispose(); basicvspnctttx.Dispose(); basicvspncctttx.Dispose(); + basicvspbbnct.Dispose(); + basicvspbbnctx.Dispose(); + basicvspbbnctt.Dispose(); + basicvspbbncttt.Dispose(); + basicvspbbncct.Dispose(); + basicvspbbncctx.Dispose(); + basicvspbbncttx.Dispose(); basicvsbox.Dispose(); basicvssphere.Dispose(); basicvscapsule.Dispose(); diff --git a/Rendering/Utils/GpuBuffers.cs b/Rendering/Utils/GpuBuffers.cs index 5300b45..871199b 100644 --- a/Rendering/Utils/GpuBuffers.cs +++ b/Rendering/Utils/GpuBuffers.cs @@ -52,6 +52,48 @@ namespace CodeWalker.Rendering } } + + public class GpuABuffer where T : struct //Dynamic GPU buffer of items updated by CPU, for array of structs used as a constant buffer + { + public int StructSize; + public int StructCount; + public int BufferSize; + public Buffer Buffer; + + public GpuABuffer(Device device, int count) + { + StructCount = count; + StructSize = System.Runtime.InteropServices.Marshal.SizeOf(); + BufferSize = StructCount * StructSize; + Buffer = new Buffer(device, BufferSize, ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0); + } + public void Dispose() + { + if (Buffer != null) + { + Buffer.Dispose(); + Buffer = null; + } + } + public void Update(DeviceContext context, T[] data) + { + var dataBox = context.MapSubresource(Buffer, 0, MapMode.WriteDiscard, MapFlags.None); + Utilities.Write(dataBox.DataPointer, data, 0, data.Length); + context.UnmapSubresource(Buffer, 0); + } + + public void SetVSCBuffer(DeviceContext context, int slot) + { + context.VertexShader.SetConstantBuffer(slot, Buffer); + } + public void SetPSCBuffer(DeviceContext context, int slot) + { + context.PixelShader.SetConstantBuffer(slot, Buffer); + } + + } + + public class GpuSBuffer where T : struct //for static struct data as resource view { public int StructSize; @@ -147,6 +189,12 @@ namespace CodeWalker.Rendering Utilities.Write(dataBox.DataPointer, DataArray, 0, CurrentCount); context.UnmapSubresource(Buffer, 0); } + public void Update(DeviceContext context, T[] data) + { + var dataBox = context.MapSubresource(Buffer, 0, MapMode.WriteDiscard, MapFlags.None); + Utilities.Write(dataBox.DataPointer, data, 0, data.Length); + context.UnmapSubresource(Buffer, 0); + } public void SetVSResource(DeviceContext context, int slot) { diff --git a/Shaders/BasicVS.hlsli b/Shaders/BasicVS.hlsli index 0b38ac5..fe52ada 100644 --- a/Shaders/BasicVS.hlsli +++ b/Shaders/BasicVS.hlsli @@ -56,7 +56,10 @@ cbuffer VSInstLocals : register(b6) float3 gLodFadeInstRange; // Offset: 352 Size: 12 [unused] uint gUseComputeShaderOutputBuffer;// Offset: 364 Size: 4 } - +cbuffer BoneMatrices : register(b7) //rage_bonemtx +{ + row_major float3x4 gBoneMtx[255]; // Offset: 0 Size: 12240 +} struct VS_OUTPUT { @@ -254,6 +257,35 @@ float3 GetGrassInstancePosition(float3 ipos, float3 vc0, float3 vc1, uint iid) } +float3x4 BoneMatrix(float4 weights, float4 indices) +{ + uint4 binds = (uint4)(indices * 255.001953); + float3x4 b0 = gBoneMtx[binds.x]; + float3x4 b1 = gBoneMtx[binds.y]; + float3x4 b2 = gBoneMtx[binds.z]; + float3x4 b3 = gBoneMtx[binds.w]; + float4 t0 = b0[0]*weights.x + b1[0]*weights.y + b2[0]*weights.z + b3[0]*weights.w; + float4 t1 = b0[1]*weights.x + b1[1]*weights.y + b2[1]*weights.z + b3[1]*weights.w; + float4 t2 = b0[2]*weights.x + b1[2]*weights.y + b2[2]*weights.z + b3[2]*weights.w; + return float3x4(t0, t1, t2); +} +float3 BoneTransform(float3 ipos, float3x4 m) +{ + float3 r; + float4 p = float4(ipos, 1); + r.x = dot(m[0], p); + r.y = dot(m[1], p); + r.z = dot(m[2], p); + return r; +} +float3 BoneTransformNormal(float3 inorm, float3x4 m) +{ + float3 r; + r.x = dot(m[0].xyz, inorm); + r.y = dot(m[1].xyz, inorm); + r.z = dot(m[2].xyz, inorm); + return r; +} float3 ModelTransform(float3 ipos, float3 vc0, float3 vc1, uint iid) { if (IsInstanced) diff --git a/Shaders/BasicVS_PBBNCCT.cso b/Shaders/BasicVS_PBBNCCT.cso new file mode 100644 index 0000000..b2b8008 Binary files /dev/null and b/Shaders/BasicVS_PBBNCCT.cso differ diff --git a/Shaders/BasicVS_PBBNCCT.hlsl b/Shaders/BasicVS_PBBNCCT.hlsl new file mode 100644 index 0000000..bcf6228 --- /dev/null +++ b/Shaders/BasicVS_PBBNCCT.hlsl @@ -0,0 +1,46 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 BlendWeights : BLENDWEIGHTS; + float4 BlendIndices : BLENDINDICES; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float4 Colour1 : COLOR1; + float2 Texcoord0 : TEXCOORD0; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3x4 bone = BoneMatrix(input.BlendWeights, input.BlendIndices); + float3 bpos = BoneTransform(input.Position.xyz, bone); + float3 opos = ModelTransform(bpos, input.Colour0.xyz, input.Colour1.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = BoneTransformNormal(input.Normal, bone); + float3 onorm = NormalTransform(bnorm); + float3 otang = 0.5; // NormalTransform(float3(1, 0, 0)); //no tangent to use on this vertex type... + + float4 tnt = ColourTint(input.Colour0.b, input.Colour1.b, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = onorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = 0.5; // input.Texcoord; + output.Texcoord2 = 0.5; // input.Texcoord; + output.Colour0 = input.Colour0; + output.Colour1 = input.Colour1; + output.Tint = tnt; + output.Tangent = float4(otang, 1); + output.Bitangent = float4(cross(otang, onorm), 0); + return output; +} + diff --git a/Shaders/BasicVS_PBBNCCTX.cso b/Shaders/BasicVS_PBBNCCTX.cso new file mode 100644 index 0000000..88e45a4 Binary files /dev/null and b/Shaders/BasicVS_PBBNCCTX.cso differ diff --git a/Shaders/BasicVS_PBBNCCTX.hlsl b/Shaders/BasicVS_PBBNCCTX.hlsl new file mode 100644 index 0000000..02ebae2 --- /dev/null +++ b/Shaders/BasicVS_PBBNCCTX.hlsl @@ -0,0 +1,49 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 BlendWeights : BLENDWEIGHTS; + float4 BlendIndices : BLENDINDICES; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float4 Colour1 : COLOR1; + float2 Texcoord0 : TEXCOORD0; + float4 Tangent : TANGENT; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3x4 bone = BoneMatrix(input.BlendWeights, input.BlendIndices); + float3 bpos = BoneTransform(input.Position.xyz, bone); + float3 opos = ModelTransform(bpos, input.Colour0.xyz, input.Colour1.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = BoneTransformNormal(input.Normal.xyz, bone); + float3 btang = BoneTransformNormal(input.Tangent.xyz, bone); + float3 onorm = NormalTransform(bnorm); + float3 otang = NormalTransform(btang); + + float4 tnt = ColourTint(input.Colour0.b, input.Colour1.b, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = onorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = 0.5; // input.Texcoord; + output.Texcoord2 = 0.5; // input.Texcoord; + output.Colour0 = input.Colour0; + output.Colour1 = input.Colour1; + output.Tint = tnt; + output.Tangent = float4(otang, input.Tangent.w); + output.Bitangent = float4(cross(otang, onorm) * input.Tangent.w, 0); + return output; +} + + diff --git a/Shaders/BasicVS_PBBNCT.cso b/Shaders/BasicVS_PBBNCT.cso new file mode 100644 index 0000000..4c54fdc Binary files /dev/null and b/Shaders/BasicVS_PBBNCT.cso differ diff --git a/Shaders/BasicVS_PBBNCT.hlsl b/Shaders/BasicVS_PBBNCT.hlsl new file mode 100644 index 0000000..eb3f6e8 --- /dev/null +++ b/Shaders/BasicVS_PBBNCT.hlsl @@ -0,0 +1,45 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 BlendWeights : BLENDWEIGHTS; + float4 BlendIndices : BLENDINDICES; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float2 Texcoord0 : TEXCOORD0; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3x4 bone = BoneMatrix(input.BlendWeights, input.BlendIndices); + float3 bpos = BoneTransform(input.Position.xyz, bone); + float3 opos = ModelTransform(bpos, input.Colour0.xyz, input.Colour0.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = BoneTransformNormal(input.Normal, bone); + float3 onorm = NormalTransform(bnorm); + float3 otang = 0.5; // NormalTransform(float3(1, 0, 0)); //no tangent to use on this vertex type... + + float4 tnt = ColourTint(input.Colour0.b, 0, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = onorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = 0.5; // input.Texcoord; + output.Texcoord2 = 0.5; // input.Texcoord; + output.Colour0 = input.Colour0; + output.Colour1 = float4(0.5, 0.5, 0.5, 1); //input.Colour + output.Tint = tnt; + output.Tangent = float4(otang, 1); + output.Bitangent = float4(cross(otang, onorm), 0); + return output; +} + diff --git a/Shaders/BasicVS_PBBNCTT.cso b/Shaders/BasicVS_PBBNCTT.cso new file mode 100644 index 0000000..7382149 Binary files /dev/null and b/Shaders/BasicVS_PBBNCTT.cso differ diff --git a/Shaders/BasicVS_PBBNCTT.hlsl b/Shaders/BasicVS_PBBNCTT.hlsl new file mode 100644 index 0000000..f9adba2 --- /dev/null +++ b/Shaders/BasicVS_PBBNCTT.hlsl @@ -0,0 +1,46 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 BlendWeights : BLENDWEIGHTS; + float4 BlendIndices : BLENDINDICES; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float2 Texcoord0 : TEXCOORD0; + float2 Texcoord1 : TEXCOORD1; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3x4 bone = BoneMatrix(input.BlendWeights, input.BlendIndices); + float3 bpos = BoneTransform(input.Position.xyz, bone); + float3 opos = ModelTransform(bpos, input.Colour0.xyz, input.Colour0.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = BoneTransformNormal(input.Normal, bone); + float3 onorm = NormalTransform(bnorm); + float3 otang = 0.5; // NormalTransform(float3(1, 0, 0)); //no tangent to use on this vertex type... + + float4 tnt = ColourTint(input.Colour0.b, 0, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = onorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = input.Texcoord1; + output.Texcoord2 = 0.5; // input.Texcoord; + output.Colour0 = input.Colour0; + output.Colour1 = float4(0.5, 0.5, 0.5, 1); //input.Colour; + output.Tint = tnt; + output.Tangent = float4(otang, 1); + output.Bitangent = float4(cross(otang, onorm), 0); + return output; +} + diff --git a/Shaders/BasicVS_PBBNCTTT.cso b/Shaders/BasicVS_PBBNCTTT.cso new file mode 100644 index 0000000..979f5b6 Binary files /dev/null and b/Shaders/BasicVS_PBBNCTTT.cso differ diff --git a/Shaders/BasicVS_PBBNCTTT.hlsl b/Shaders/BasicVS_PBBNCTTT.hlsl new file mode 100644 index 0000000..3a61265 --- /dev/null +++ b/Shaders/BasicVS_PBBNCTTT.hlsl @@ -0,0 +1,47 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 BlendWeights : BLENDWEIGHTS; + float4 BlendIndices : BLENDINDICES; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float2 Texcoord0 : TEXCOORD0; + float2 Texcoord1 : TEXCOORD1; + float2 Texcoord2 : TEXCOORD2; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3x4 bone = BoneMatrix(input.BlendWeights, input.BlendIndices); + float3 bpos = BoneTransform(input.Position.xyz, bone); + float3 opos = ModelTransform(bpos, input.Colour0.xyz, input.Colour0.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = BoneTransformNormal(input.Normal, bone); + float3 onorm = NormalTransform(bnorm); + float3 otang = 0.5; // NormalTransform(float3(1, 0, 0)); //no tangent to use on this vertex type... + + float4 tnt = ColourTint(input.Colour0.b, 0, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = onorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = input.Texcoord1; + output.Texcoord2 = input.Texcoord2; + output.Colour0 = input.Colour0; + output.Colour1 = float4(0.5, 0.5, 0.5, 1); //input.Colour + output.Tint = tnt; + output.Tangent = float4(otang, 1); + output.Bitangent = float4(cross(otang, onorm), 0); + return output; +} + diff --git a/Shaders/BasicVS_PBBNCTTX.cso b/Shaders/BasicVS_PBBNCTTX.cso new file mode 100644 index 0000000..cf5cc02 Binary files /dev/null and b/Shaders/BasicVS_PBBNCTTX.cso differ diff --git a/Shaders/BasicVS_PBBNCTTX.hlsl b/Shaders/BasicVS_PBBNCTTX.hlsl new file mode 100644 index 0000000..14d7743 --- /dev/null +++ b/Shaders/BasicVS_PBBNCTTX.hlsl @@ -0,0 +1,47 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 BlendWeights : BLENDWEIGHTS; + float4 BlendIndices : BLENDINDICES; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float2 Texcoord0 : TEXCOORD0; + float2 Texcoord1 : TEXCOORD1; + float4 Tangent : TANGENT; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3x4 bone = BoneMatrix(input.BlendWeights, input.BlendIndices); + float3 bpos = BoneTransform(input.Position.xyz, bone); + float3 opos = ModelTransform(bpos, input.Colour0.xyz, input.Colour0.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = BoneTransformNormal(input.Normal.xyz, bone); + float3 btang = BoneTransformNormal(input.Tangent.xyz, bone); + float3 onorm = NormalTransform(bnorm); + float3 otang = NormalTransform(btang); + + float4 tnt = ColourTint(input.Colour0.b, 0, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = onorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = input.Texcoord1; + output.Texcoord2 = 0.5; // input.Texcoord; + output.Colour0 = input.Colour0; + output.Colour1 = float4(0.5, 0.5, 0.5, 1); //input.Colour + output.Tint = tnt; + output.Tangent = float4(otang, input.Tangent.w); + output.Bitangent = float4(cross(otang, onorm) * input.Tangent.w, 0); + return output; +} \ No newline at end of file diff --git a/Shaders/BasicVS_PBBNCTX.cso b/Shaders/BasicVS_PBBNCTX.cso new file mode 100644 index 0000000..6bc8835 Binary files /dev/null and b/Shaders/BasicVS_PBBNCTX.cso differ diff --git a/Shaders/BasicVS_PBBNCTX.hlsl b/Shaders/BasicVS_PBBNCTX.hlsl new file mode 100644 index 0000000..a34b847 --- /dev/null +++ b/Shaders/BasicVS_PBBNCTX.hlsl @@ -0,0 +1,47 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float4 BlendWeights : BLENDWEIGHTS; + float4 BlendIndices : BLENDINDICES; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float2 Texcoord0 : TEXCOORD0; + float4 Tangent : TANGENT; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3x4 bone = BoneMatrix(input.BlendWeights, input.BlendIndices); + float3 bpos = BoneTransform(input.Position.xyz, bone); + float3 opos = ModelTransform(bpos, input.Colour0.xyz, input.Colour0.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = BoneTransformNormal(input.Normal.xyz, bone); + float3 btang = BoneTransformNormal(input.Tangent.xyz, bone); + float3 onorm = NormalTransform(bnorm); + float3 otang = NormalTransform(btang); + + float4 tnt = ColourTint(input.Colour0.b, 0, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = onorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = 0.5; // input.Texcoord; + output.Texcoord2 = 0.5; // input.Texcoord; + output.Colour0 = input.Colour0; + output.Colour1 = float4(0.5, 0.5, 0.5, 1); //input.Colour + output.Tint = tnt; + output.Tangent = float4(otang, input.Tangent.w); + output.Bitangent = float4(cross(otang, onorm) * input.Tangent.w, 0); + return output; +} + diff --git a/Shaders/BasicVS_PNCTTT.cso b/Shaders/BasicVS_PNCTTT.cso new file mode 100644 index 0000000..6f91fa1 Binary files /dev/null and b/Shaders/BasicVS_PNCTTT.cso differ diff --git a/Shaders/BasicVS_PNCTTT.hlsl b/Shaders/BasicVS_PNCTTT.hlsl new file mode 100644 index 0000000..5b08aa6 --- /dev/null +++ b/Shaders/BasicVS_PNCTTT.hlsl @@ -0,0 +1,41 @@ +#include "BasicVS.hlsli" + +struct VS_INPUT +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float4 Colour0 : COLOR0; + float2 Texcoord0 : TEXCOORD0; + float2 Texcoord1 : TEXCOORD1; + float2 Texcoord2 : TEXCOORD2; +}; + + +VS_OUTPUT main(VS_INPUT input, uint iid : SV_InstanceID) +{ + VS_OUTPUT output; + float3 opos = ModelTransform(input.Position.xyz, input.Colour0.xyz, input.Colour0.xyz, iid); + float4 cpos = ScreenTransform(opos); + float3 bnorm = NormalTransform(input.Normal); + float3 btang = 0.5; // NormalTransform(float3(1, 0, 0)); //no tangent to use on this vertex type... + + float4 tnt = ColourTint(input.Colour0.b, 0, iid); //colour tinting if enabled + + float4 lightspacepos; + float shadowdepth = ShadowmapSceneDepth(opos, lightspacepos); + output.LightShadow = lightspacepos; + output.Shadows = float4(shadowdepth, 0, 0, 0); + + output.Position = cpos; + output.CamRelPos = opos; + output.Normal = bnorm; + output.Texcoord0 = GlobalUVAnim(input.Texcoord0); + output.Texcoord1 = input.Texcoord1; + output.Texcoord2 = input.Texcoord2; + output.Colour0 = input.Colour0; + output.Colour1 = float4(0.5, 0.5, 0.5, 1); //input.Colour + output.Tint = tnt; + output.Tangent = float4(btang, 1); + output.Bitangent = float4(cross(btang, bnorm), 0); + return output; +} \ No newline at end of file diff --git a/Shaders/CodeWalkerShaders.vcxproj b/Shaders/CodeWalkerShaders.vcxproj index fe475e3..33c135b 100644 --- a/Shaders/CodeWalkerShaders.vcxproj +++ b/Shaders/CodeWalkerShaders.vcxproj @@ -150,6 +150,76 @@ Vertex Vertex + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex Vertex @@ -206,6 +276,16 @@ Vertex 4.0 + + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex + 4.0 + Vertex Vertex diff --git a/Shaders/CodeWalkerShaders.vcxproj.filters b/Shaders/CodeWalkerShaders.vcxproj.filters index 4309be7..290c326 100644 --- a/Shaders/CodeWalkerShaders.vcxproj.filters +++ b/Shaders/CodeWalkerShaders.vcxproj.filters @@ -66,6 +66,14 @@ + + + + + + + +