From 34f58d41406f357019e25b5561420c378322776b Mon Sep 17 00:00:00 2001 From: lanariel Date: Mon, 3 Feb 2014 12:09:11 +0100 Subject: [PATCH] Anim Testing --- .../Render/Rendering/BasicRender.cpp | 69 ++++--------------- .../HLSL/Deffered Shaders/LightPass.hlsl | 2 +- .../HLSL/Deffered Shaders/PostPass.hlsl | 2 +- Code/Tester/MainTest.cpp | 12 ++-- 4 files changed, 20 insertions(+), 65 deletions(-) diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index 113d7b6f..e9f988d2 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -40,6 +40,14 @@ namespace Oyster Resources::Deffered::PointLightsData.Unmap(); } + Math::Matrix RecursiveBindPos(int index, Model::ModelInfo* mi) + { + if(mi->bones[index].Parent == index) + return mi->bones[index].Transform; + + return mi->bones[index].Transform.GetInverse() * RecursiveBindPos(mi->bones[index].Parent,mi); + } + void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection) { for(int i = 0; i < count; ++i) @@ -57,69 +65,16 @@ namespace Oyster Resources::Deffered::ModelData.Unmap(); Model::ModelInfo* info = (Model::ModelInfo*)models[i].info; - - - Definitions::AnimationData am; + + Definitions::AnimationData am; //final if(info->Animated && models[i].AnimationPlaying != -1) { - - Definitions::AnimationData am2; - //write default data - for (int b = 0; b < info->BoneCount; b++) + for(int b = 0; b BoneCount; ++b) { - am2.animatedData[b] = info->bones[b].Transform; + am.animatedData[b] = RecursiveBindPos(b,info); } - //loop bones in animation am.Animated = 1; - - - Model::Frame Prev, Next; - - models[i].AnimationTime = fmod(models[i].AnimationTime,info->Animations[models[i].AnimationPlaying].duration); - - for(int x = 0; x < info->Animations[models[i].AnimationPlaying].Bones; ++x) - { - //loop frame per bone - Prev.bone.Parent = 0; - Next = Prev; - for(int y = 0; y < info->Animations[models[i].AnimationPlaying].Frames[x]; ++y) - { - ///TODO replace with binary search? - Model::Frame f = info->Animations[models[i].AnimationPlaying].Keyframes[x][y]; - - //if we hit frame - if(models[i].AnimationTime == f.time) - { - Prev = f; - Next = f; - break; - } - - //if time is larger than frame time, store frames - if(models[i].AnimationTime < f.time) - { - Next = f; - Prev = info->Animations[models[i].AnimationPlaying].Keyframes[x][y-1]; - break; - } - } - - - //calculate interpolated bone position - - //rebase model time to between prev and next - float interpoation =(models[i].AnimationTime - Prev.time) / (Next.time - Prev.time); - - //interpolate - Math::Matrix Interpolated; - Math3D::InterpolateOrientation_UsingNonRigidNlerp(Prev.bone.Transform,Next.bone.Transform,interpoation, Interpolated); - - //write magic to animated data - am2.animatedData[Prev.bone.Parent] = Interpolated * am2.animatedData[info->bones[Prev.bone.Parent].Parent]; - //sneaky write do correct data buffer - am.animatedData[x] = (am2.animatedData[Prev.bone.Parent] * info->bones[Prev.bone.Parent].Transform.GetInverse()); - } } else am.Animated = 0; diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl index 483f2889..b1203085 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl @@ -34,7 +34,7 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID ) if(DTid.x & 1 && DTid.y & 1 ) { float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy/2); - Ambient[DTid.xy/2] = AmbValue; + Ambient[DTid.xy/2] = float4(DiffuseGlow[DTid.xy].xyz, AmbValue); } } \ 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 d029535b..1b00d607 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl @@ -8,6 +8,6 @@ RWTexture2D Output; void main( uint3 DTid : SV_DispatchThreadID ) { //Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/2].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW - Output[DTid.xy] = Ambient[DTid.xy/2]; + Output[DTid.xy] = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 1); //Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy]; } \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index dcafe91f..d3f63c48 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -161,7 +161,7 @@ HRESULT InitDirect3D() m = Oyster::Graphics::API::CreateModel(L"untitled.dan"); m2 = Oyster::Graphics::API::CreateModel(L"still.dan"); - m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); + 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; //m3 = Oyster::Graphics::API::CreateModel(L"box_2.dan"); @@ -171,7 +171,7 @@ HRESULT InitDirect3D() P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1280.0f/720.0f,.1f,10000); Oyster::Graphics::API::SetProjection(P); - V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,200,500.4f)); + V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f)); V = V.GetInverse(); @@ -192,11 +192,11 @@ 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,-4,0),Oyster::Math::Float3::null); Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity; - ma *= 50; - ma.m44 = 1; - m2->WorldMatrix = m2->WorldMatrix * ma; + //ma *= 50; + //ma.m44 = 1; + //m2->WorldMatrix = m2->WorldMatrix * ma; m2->AnimationTime += deltaTime * 0.5f; //m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null); return S_OK;