From a7480ebf700a2a590fa8408385e876521ee3db62 Mon Sep 17 00:00:00 2001 From: lanariel Date: Fri, 7 Feb 2014 08:34:01 +0100 Subject: [PATCH] Proper Animation --- Code/OysterGraphics/FileLoader/DanLoader.cpp | 4 ++-- Code/OysterGraphics/FileLoader/ModelLoader.cpp | 2 +- .../Render/Rendering/BasicRender.cpp | 7 ++++--- .../Render/Resources/Deffered.cpp | 6 +++--- .../HLSL/Deffered Shaders/GBufferHeader.hlsli | 2 +- .../HLSL/Deffered Shaders/PixelGatherData.hlsl | 2 +- .../Shader/HLSL/Deffered Shaders/PostPass.hlsl | 3 ++- .../HLSL/Deffered Shaders/VertexGatherData.hlsl | 17 +++-------------- Code/Tester/MainTest.cpp | 4 ++-- 9 files changed, 19 insertions(+), 28 deletions(-) diff --git a/Code/OysterGraphics/FileLoader/DanLoader.cpp b/Code/OysterGraphics/FileLoader/DanLoader.cpp index 446a7ba2..ac47605c 100644 --- a/Code/OysterGraphics/FileLoader/DanLoader.cpp +++ b/Code/OysterGraphics/FileLoader/DanLoader.cpp @@ -146,7 +146,7 @@ void Oyster::Graphics::Loading::UnloadDAN(void* data) } delete[] info->Animations; } - for(int i =0;iMaterial.size();++i) + for(UINT i =0;iMaterial.size();++i) { Core::loader.ReleaseResource(info->Material[i]); } @@ -351,7 +351,7 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[]) Oyster::Graphics::Model::Animation* anims = new Oyster::Graphics::Model::Animation[animationHeader.numAnims]; - for(int a = 0; a < animationHeader.numAnims; ++a) + for(UINT a = 0; a < animationHeader.numAnims; ++a) { //read name of animation int nameLength; diff --git a/Code/OysterGraphics/FileLoader/ModelLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp index fba207d1..96fa0362 100644 --- a/Code/OysterGraphics/FileLoader/ModelLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -70,7 +70,7 @@ void Oyster::Graphics::Loading::UnloadOBJ(void* data) { SAFE_DELETE(info->Indecies); } - for(int i =0;iMaterial.size();++i) + for(UINT i =0;iMaterial.size();++i) { Core::loader.ReleaseResource(info->Material[i]); } diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index 015a1fdb..d44eeedc 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -82,7 +82,7 @@ namespace Oyster Definitions::AnimationData am; //final if(info->Animated && models[i].AnimationPlaying != -1) { - cube->WorldMatrix == Math::Matrix::identity; + cube->WorldMatrix = Math::Matrix::identity; ////store inverse absolut transform Math::Matrix SkinTransform[100]; Math::Matrix BoneAnimated[100]; @@ -114,7 +114,7 @@ namespace Oyster int b = 0; Model::Animation A = info->Animations[models[i].AnimationPlaying]; while(models[i].AnimationTime>A.duration) - models[i].AnimationTime -= A.duration; + models[i].AnimationTime -= (float)A.duration; float position = models[i].AnimationTime; for(int b = 0; b < A.Bones;++b) @@ -133,7 +133,7 @@ namespace Oyster break; } } - float denominator = (NFrame.time - PFrame.time); + float denominator = (float)(NFrame.time - PFrame.time); if(denominator == 0) { BoneAnimated[PFrame.bone.Parent] = PFrame.bone.Relative; @@ -150,6 +150,7 @@ namespace Oyster //SkinTransform[b] = BoneAbsAnimated[b]; cube->WorldMatrix = Scale; cube->WorldMatrix.v[3] = BoneAbsAnimated[b].v[3]; + cube->WorldMatrix = models[i].WorldMatrix * cube->WorldMatrix; Basic::RenderScene(cube,1,View,Projection); } diff --git a/Code/OysterGraphics/Render/Resources/Deffered.cpp b/Code/OysterGraphics/Render/Resources/Deffered.cpp index c767da77..8313bf0f 100644 --- a/Code/OysterGraphics/Render/Resources/Deffered.cpp +++ b/Code/OysterGraphics/Render/Resources/Deffered.cpp @@ -210,7 +210,7 @@ namespace Oyster D3D11_SUBRESOURCE_DATA rnd; rnd.pSysMem = random; - rnd.SysMemPitch = sqrt(SampleSpread) * sizeof(Oyster::Math::Vector3); + rnd.SysMemPitch = (UINT)(sqrt(SampleSpread) * sizeof(Oyster::Math::Vector3)); ID3D11Texture1D *pTexture1; @@ -226,8 +226,8 @@ namespace Oyster T2desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; T2desc.CPUAccessFlags = 0; T2desc.MiscFlags = 0; - T2desc.Height = sqrt(SampleSpread); - T2desc.Width = SampleSpread/sqrt(SampleSpread); + T2desc.Height = (UINT)sqrt(SampleSpread); + T2desc.Width = (UINT)(SampleSpread/sqrt(SampleSpread)); T2desc.SampleDesc.Quality = 0; T2desc.SampleDesc.Count = 1; diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli index bca4ca25..b87b7235 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli @@ -5,7 +5,7 @@ struct VertexIn float3 normal : NORMAL; float3 tangent : TANGENT; float3 biTangent : BITANGENT; - int4 boneIndex : BONEINDEX; + float4 boneIndex : BONEINDEX; float4 boneWeight : BONEWEIGHT; }; diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PixelGatherData.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PixelGatherData.hlsl index de06ce7f..cad03013 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PixelGatherData.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PixelGatherData.hlsl @@ -4,6 +4,6 @@ PixelOut main(VertexOut input) { PixelOut output; output.DiffuseGlow = Diffuse.Sample(S1, input.UV); - output.NormalSpec = float4(normalize(input.normal), 1.0f); + output.NormalSpec = float4(normalize(input.normal), Normal.Sample(S1,input.UV).w); return output; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl index 36e25514..b3abc0df 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl @@ -10,8 +10,9 @@ RWTexture2D Output; void main( uint3 DTid : SV_DispatchThreadID ) { float4 Light = Diffuse[DTid.xy] + Specular[DTid.xy]; - float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w,1); + float4 Amb = float4(Ambient[DTid.xy/2].xyz,1);// * Ambient[DTid.xy/2].w,1); //Output[DTid.xy] = float4(Ambient[DTid.xy/2].xyz /* * Ambient[DTid.xy/2].w */, 1); //Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy]; Output[DTid.xy] = Light + Amb * AmbFactor; + //Output[DTid.xy] = Ambient[DTid.xy/2].w; } \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl index 19ce9377..7880d66e 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl @@ -12,23 +12,12 @@ VertexOut main( VertexIn input ) Matrix boneTrans = AnimatedData[input.boneIndex.x]*input.boneWeight.x + AnimatedData[input.boneIndex.y]*input.boneWeight.y + AnimatedData[input.boneIndex.z]*input.boneWeight.z + - AnimatedData[input.boneIndex.w]*input.boneWeight.w; + AnimatedData[input.boneIndex.w]*input.boneWeight.w; - input.pos = mul(boneTrans,float4(input.pos,1)) * Animated + input.pos * int(1-Animated); + input.pos = mul(boneTrans,float4(input.pos,1)).xyz * Animated + input.pos * int(1-Animated); - input.normal = mul(boneTrans,input.normal) * Animated + input.normal * int(1-Animated); - /*input.pos = - (mul(BoneAnimation[input.boneIndex.x], input.pos) * input.boneWeight.x * Animated) + - (mul(BoneAnimation[input.boneIndex.y], input.pos) * input.boneWeight.y * Animated) + - (mul(BoneAnimation[input.boneIndex.z], input.pos) * input.boneWeight.z * Animated) + - (mul(BoneAnimation[input.boneIndex.w], input.pos) * input.boneWeight.w * Animated) + - input.pos * int(1-Animated);*/ + input.normal = mul(boneTrans,float4(input.normal,1)).xyz * Animated + input.normal * int(1-Animated); - /*input.pos = mul(BoneAnimation[input.boneIndex.x], input.pos) * Animated + input.pos * int(1-Animated);*/ - - //float4x4 m = matrix(float4(1,0,0,0),float4(0,1,0,0), float4(0,0,1,0), float4(0,0,0,1)); - //input.pos = mul(BoneAnimation[0], float4(input.pos,1)); - //input.pos = mul(m, float4(input.pos,1)); output.pos = mul(WVP, float4(input.pos,1)); output.normal = mul(WV, float4(input.normal,0)).xyz; output.UV = input.UV; diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index 988a75c9..99ba7b76 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -162,7 +162,7 @@ HRESULT InitDirect3D() } m = Oyster::Graphics::API::CreateModel(L"untitled.dan"); - m2 = Oyster::Graphics::API::CreateModel(L"still.dan"); + m2 = Oyster::Graphics::API::CreateModel(L"T_reskinned.dan"); m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null); m2->AnimationPlaying = 0; m2->AnimationTime = 0.0f; @@ -195,7 +195,7 @@ HRESULT Update(float deltaTime) angle += Oyster::Math::pi/16 * deltaTime; //m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle) * Oyster::Math3D::RotationMatrix_AxisX(-Oyster::Math::pi/2); - //m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0)*-Oyster::Math::pi/2,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null); + m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0)*-Oyster::Math::pi/2,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null); Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; //ma *= 50; //ma.m44 = 1;