2014-02-07 15:52:07 +01:00
|
|
|
#include "DefaultRenderer.h"
|
|
|
|
#include "Resources.h"
|
|
|
|
#include "../Definitions/GraphicalDefinition.h"
|
|
|
|
#include "../Model/ModelInfo.h"
|
|
|
|
#include "../DllInterfaces/GFXAPI.h"
|
2013-12-05 14:56:34 +01:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2013-11-20 16:51:53 +01:00
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Graphics
|
|
|
|
{
|
|
|
|
namespace Render
|
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
Definitions::Pointlight pl;
|
2013-11-20 16:51:53 +01:00
|
|
|
|
2014-02-12 08:24:24 +01:00
|
|
|
void DefaultRenderer::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights)
|
2013-11-20 16:51:53 +01:00
|
|
|
{
|
2014-02-18 09:32:10 +01:00
|
|
|
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0));
|
|
|
|
Preparations::Basic::ClearDepthStencil(Resources::Gui::depth);
|
2014-02-10 01:03:10 +01:00
|
|
|
Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0));
|
2014-02-07 15:52:07 +01:00
|
|
|
Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass);
|
2014-02-12 08:24:24 +01:00
|
|
|
Lights[1];
|
2013-11-21 18:31:16 +01:00
|
|
|
|
2014-01-27 14:24:13 +01:00
|
|
|
void* data;
|
2013-11-21 18:31:16 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
Definitions::LightConstants lc;
|
|
|
|
lc.InvProj = Projection.GetInverse();
|
|
|
|
lc.Pixels = Core::resolution;
|
|
|
|
lc.Lights = numLights;
|
2013-12-18 20:36:41 +01:00
|
|
|
lc.View = View;
|
2014-01-08 07:01:59 +01:00
|
|
|
lc.Proj = Projection;
|
|
|
|
lc.SSAORadius = 3;
|
2013-12-18 20:28:06 +01:00
|
|
|
|
2014-02-07 15:52:07 +01:00
|
|
|
data = Resources::Light::LightConstantsData.Map();
|
2013-12-18 20:28:06 +01:00
|
|
|
memcpy(data, &lc, sizeof(Definitions::LightConstants));
|
2014-02-07 15:52:07 +01:00
|
|
|
Resources::Light::LightConstantsData.Unmap();
|
2013-12-18 20:28:06 +01:00
|
|
|
|
2014-02-07 15:52:07 +01:00
|
|
|
data = Resources::Light::PointLightsData.Map();
|
2014-02-12 08:24:24 +01:00
|
|
|
memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights);
|
2014-02-07 15:52:07 +01:00
|
|
|
Resources::Light::PointLightsData.Unmap();
|
2013-11-20 16:51:53 +01:00
|
|
|
}
|
2013-11-21 18:31:16 +01:00
|
|
|
|
2014-02-10 13:59:45 +01:00
|
|
|
void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime)
|
2013-11-20 16:51:53 +01:00
|
|
|
{
|
2013-11-21 13:50:43 +01:00
|
|
|
for(int i = 0; i < count; ++i)
|
|
|
|
{
|
2014-01-16 09:30:01 +01:00
|
|
|
if(&models[i] == NULL)
|
|
|
|
continue;
|
2013-11-21 13:50:43 +01:00
|
|
|
if(models[i].Visible)
|
|
|
|
{
|
2014-01-08 07:01:59 +01:00
|
|
|
Definitions::PerModel pm;
|
2014-02-18 09:56:28 +01:00
|
|
|
pm.WV = View * models[i].WorldMatrix.GetInverse().GetTranspose();
|
2014-01-08 07:01:59 +01:00
|
|
|
pm.WVP = Projection * pm.WV;
|
|
|
|
|
2014-02-07 13:15:38 +01:00
|
|
|
Model::ModelInfo* info = models[i].info;
|
2014-02-03 12:09:11 +01:00
|
|
|
|
|
|
|
Definitions::AnimationData am; //final
|
2014-02-10 13:59:45 +01:00
|
|
|
if(info->Animated && models[i].Animation.AnimationPlaying != NULL)
|
2014-01-27 14:24:13 +01:00
|
|
|
{
|
2014-02-10 13:59:45 +01:00
|
|
|
models[i].Animation.AnimationTime += deltaTime;
|
2014-02-04 17:59:04 +01:00
|
|
|
////store inverse absolut transform
|
2014-02-05 16:00:28 +01:00
|
|
|
Math::Matrix SkinTransform[100];
|
|
|
|
Math::Matrix BoneAnimated[100];
|
|
|
|
Math::Matrix BoneAbsAnimated[100];
|
2014-02-04 14:59:51 +01:00
|
|
|
|
2014-02-04 17:59:04 +01:00
|
|
|
|
2014-02-04 14:59:51 +01:00
|
|
|
|
2014-02-03 12:09:11 +01:00
|
|
|
for(int b = 0; b <info->BoneCount; ++b)
|
2014-01-27 14:24:13 +01:00
|
|
|
{
|
2014-02-04 14:59:51 +01:00
|
|
|
Model::Bone Bone = info->bones[b];
|
|
|
|
SkinTransform[b] = Bone.Absolute.GetInverse();
|
|
|
|
BoneAnimated[b] = Bone.Relative;
|
|
|
|
BoneAbsAnimated[b] = Bone.Absolute;
|
|
|
|
}
|
2014-02-05 16:00:28 +01:00
|
|
|
int b = 0;
|
2014-02-10 13:59:45 +01:00
|
|
|
Model::Animation A = *models[i].Animation.AnimationPlaying;
|
2014-02-12 09:32:15 +01:00
|
|
|
while(models[i].Animation.AnimationTime>A.duration && models[i].Animation.LoopAnimation)
|
2014-02-10 13:59:45 +01:00
|
|
|
models[i].Animation.AnimationTime -= (float)A.duration;
|
2014-02-05 16:00:28 +01:00
|
|
|
|
2014-02-10 13:59:45 +01:00
|
|
|
float position = models[i].Animation.AnimationTime;
|
2014-02-05 16:00:28 +01:00
|
|
|
for(int b = 0; b < A.Bones;++b)
|
|
|
|
{
|
|
|
|
//find current frame
|
|
|
|
int nrOfFrames = A.Frames[b];
|
|
|
|
Model::Frame PFrame = A.Keyframes[b][nrOfFrames-1];
|
|
|
|
Model::Frame NFrame = A.Keyframes[b][nrOfFrames-1];
|
|
|
|
bool FrameFound = false;
|
|
|
|
for (int i = 0; i < nrOfFrames; i++)
|
|
|
|
{
|
|
|
|
if(position < A.Keyframes[b][i].time)
|
|
|
|
{
|
|
|
|
PFrame = A.Keyframes[b][i-1];
|
|
|
|
NFrame = A.Keyframes[b][i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-07 08:34:01 +01:00
|
|
|
float denominator = (float)(NFrame.time - PFrame.time);
|
2014-02-05 16:00:28 +01:00
|
|
|
if(denominator == 0)
|
|
|
|
{
|
|
|
|
BoneAnimated[PFrame.bone.Parent] = PFrame.bone.Relative;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
float inter = (float)((position - PFrame.time) / denominator);
|
|
|
|
Math3D::InterpolateOrientation_UsingNonRigidNlerp(PFrame.bone.Relative,NFrame.bone.Relative,inter, BoneAnimated[PFrame.bone.Parent]);
|
|
|
|
}
|
2014-02-04 17:59:04 +01:00
|
|
|
|
|
|
|
////calculate Absolute Animation Transform
|
2014-02-04 14:59:51 +01:00
|
|
|
for(int b = 0; b < info->BoneCount; ++b)
|
|
|
|
{
|
|
|
|
BoneAbsAnimated[b] = BoneAbsAnimated[info->bones[b].Parent] * BoneAnimated[b];
|
|
|
|
}
|
|
|
|
|
|
|
|
//write data to am
|
|
|
|
for(int b = 0; b < info->BoneCount; ++b)
|
|
|
|
{
|
2014-02-05 16:00:28 +01:00
|
|
|
am.AnimatedData[b] = (BoneAbsAnimated[b] * SkinTransform[b]);
|
2014-01-27 14:24:13 +01:00
|
|
|
}
|
2014-02-04 14:59:51 +01:00
|
|
|
|
2014-02-07 13:15:38 +01:00
|
|
|
|
2014-02-07 15:52:07 +01:00
|
|
|
void *data = Resources::Gather::AnimationData.Map();
|
2014-02-07 13:15:38 +01:00
|
|
|
memcpy(data,&am,sizeof(Definitions::AnimationData));
|
2014-02-07 15:52:07 +01:00
|
|
|
Resources::Gather::AnimationData.Unmap();
|
2014-02-04 17:59:04 +01:00
|
|
|
|
2014-02-07 13:15:38 +01:00
|
|
|
pm.Animated = 1;
|
2014-01-27 14:24:13 +01:00
|
|
|
}
|
|
|
|
else
|
2014-02-07 13:15:38 +01:00
|
|
|
pm.Animated = 0;
|
2014-01-27 14:24:13 +01:00
|
|
|
|
2014-02-07 15:52:07 +01:00
|
|
|
void* data = Resources::Gather::ModelData.Map();
|
2014-02-07 13:15:38 +01:00
|
|
|
memcpy(data,&(pm),sizeof(pm));
|
2014-02-07 15:52:07 +01:00
|
|
|
Resources::Gather::ModelData.Unmap();
|
2014-01-27 14:24:13 +01:00
|
|
|
|
2014-02-12 16:21:46 +01:00
|
|
|
data = Render::Resources::Color.Map();
|
|
|
|
memcpy(data,&models[i].Tint,sizeof(Math::Float3));
|
|
|
|
Render::Resources::Color.Unmap();
|
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
if(info->Material.size())
|
|
|
|
{
|
2014-01-16 09:30:01 +01:00
|
|
|
Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0]));
|
2013-12-18 20:28:06 +01:00
|
|
|
}
|
2013-11-21 13:50:43 +01:00
|
|
|
|
2013-11-26 09:09:35 +01:00
|
|
|
|
|
|
|
info->Vertices->Apply();
|
|
|
|
if(info->Indexed)
|
2013-11-21 13:50:43 +01:00
|
|
|
{
|
2013-11-26 09:09:35 +01:00
|
|
|
info->Indecies->Apply();
|
2014-01-17 08:51:12 +01:00
|
|
|
Oyster::Graphics::Core::deviceContext->DrawIndexed(info->IndexCount,0,0);
|
2013-11-21 13:50:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-04 14:59:51 +01:00
|
|
|
Oyster::Graphics::Core::deviceContext->Draw(info->VertexCount,0);
|
2013-11-21 13:50:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-20 16:51:53 +01:00
|
|
|
}
|
2014-01-27 14:24:13 +01:00
|
|
|
|
2014-02-13 15:24:19 +01:00
|
|
|
void BlurGlow()
|
|
|
|
{
|
|
|
|
Definitions::BlurrData bd;
|
|
|
|
bd.BlurMask = Math::Float4(1,1,1,1);
|
|
|
|
bd.StopX = Core::resolution.x/2;
|
|
|
|
bd.StopY = Core::resolution.y;
|
|
|
|
bd.StartX = 0;
|
|
|
|
bd.StartY = Core::resolution.y/2;
|
|
|
|
|
|
|
|
void* data = Resources::Blur::Data.Map();
|
|
|
|
memcpy(data,&bd,sizeof(Definitions::BlurrData));
|
|
|
|
Resources::Blur::Data.Unmap();
|
|
|
|
|
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass);
|
|
|
|
Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1);
|
|
|
|
|
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass);
|
|
|
|
Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlurSSAO()
|
|
|
|
{
|
|
|
|
Definitions::BlurrData bd;
|
|
|
|
bd.BlurMask = Math::Float4(0,0,0,1);
|
|
|
|
bd.StopX = Core::resolution.x/2;
|
|
|
|
bd.StopY = Core::resolution.y/2;
|
|
|
|
bd.StartX = 0;
|
|
|
|
bd.StartY = 0;
|
|
|
|
|
|
|
|
void* data = Resources::Blur::Data.Map();
|
|
|
|
memcpy(data,&bd,sizeof(Definitions::BlurrData));
|
|
|
|
Resources::Blur::Data.Unmap();
|
|
|
|
|
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass);
|
|
|
|
Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1);
|
|
|
|
|
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass);
|
|
|
|
Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1);
|
|
|
|
}
|
|
|
|
|
2014-01-27 14:24:13 +01:00
|
|
|
|
2014-02-07 15:52:07 +01:00
|
|
|
void DefaultRenderer::EndFrame()
|
2013-11-20 16:51:53 +01:00
|
|
|
{
|
2014-02-07 15:52:07 +01:00
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Light::Pass);
|
2013-12-18 20:28:06 +01:00
|
|
|
|
2014-01-16 09:30:01 +01:00
|
|
|
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
|
2013-12-18 20:28:06 +01:00
|
|
|
|
2014-02-13 15:24:19 +01:00
|
|
|
BlurGlow();
|
2014-02-07 13:46:55 +01:00
|
|
|
|
2014-02-13 15:24:19 +01:00
|
|
|
BlurSSAO();
|
2014-02-07 13:46:55 +01:00
|
|
|
|
2014-02-07 16:51:35 +01:00
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Post::Pass);
|
2014-01-08 07:01:59 +01:00
|
|
|
|
2014-01-16 09:30:01 +01:00
|
|
|
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
|
2014-01-08 07:01:59 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
Core::swapChain->Present(0,0);
|
2013-11-20 16:51:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|