2013-11-20 16:51:53 +01:00
|
|
|
#include "Render.h"
|
2013-12-18 20:28:06 +01:00
|
|
|
#include "../Resources/Deffered.h"
|
2013-11-21 18:31:16 +01:00
|
|
|
#include "../../Definitions/GraphicalDefinition.h"
|
2013-11-26 09:09:35 +01:00
|
|
|
#include "../../Model/ModelInfo.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
|
|
|
|
{
|
|
|
|
namespace Rendering
|
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
Definitions::Pointlight pl;
|
2013-11-20 16:51:53 +01:00
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights)
|
2013-11-20 16:51:53 +01:00
|
|
|
{
|
2013-11-28 14:34:52 +01:00
|
|
|
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1));
|
2013-12-18 20:28:06 +01:00
|
|
|
Preparations::Basic::ClearRTV(Resources::Deffered::GBufferRTV,Resources::Deffered::GBufferSize,Math::Float4(1,0,0,1));
|
|
|
|
Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Deffered::GeometryPass);
|
2013-11-21 18:31:16 +01:00
|
|
|
|
|
|
|
Definitions::VP vp;
|
|
|
|
vp.V = View;
|
|
|
|
vp.P = Projection;
|
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
void* data = Resources::Deffered::VPData.Map();
|
2013-11-21 18:31:16 +01:00
|
|
|
memcpy(data, &vp, sizeof(Definitions::VP));
|
2013-12-18 20:28:06 +01:00
|
|
|
Resources::Deffered::VPData.Unmap();
|
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
|
|
|
|
|
|
|
data = Resources::Deffered::LightConstantsData.Map();
|
|
|
|
memcpy(data, &lc, sizeof(Definitions::LightConstants));
|
|
|
|
Resources::Deffered::LightConstantsData.Unmap();
|
|
|
|
|
|
|
|
data = Resources::Deffered::PointLightsData.Map();
|
|
|
|
memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights);
|
|
|
|
Resources::Deffered::PointLightsData.Unmap();
|
2013-11-20 16:51:53 +01:00
|
|
|
}
|
2013-11-21 18:31:16 +01:00
|
|
|
|
2014-01-08 07:01:59 +01:00
|
|
|
void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection)
|
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;
|
|
|
|
pm.WV = View * models[i].WorldMatrix;
|
|
|
|
pm.WVP = Projection * pm.WV;
|
|
|
|
|
2013-12-18 20:28:06 +01:00
|
|
|
void* data = Resources::Deffered::ModelData.Map();
|
2014-01-08 07:01:59 +01:00
|
|
|
memcpy(data,&(pm),sizeof(pm));
|
2013-12-18 20:28:06 +01:00
|
|
|
Resources::Deffered::ModelData.Unmap();
|
2013-11-21 13:50:43 +01:00
|
|
|
|
2013-11-28 14:34:52 +01:00
|
|
|
|
|
|
|
Model::ModelInfo* info = (Model::ModelInfo*)models[i].info;
|
|
|
|
|
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
|
|
|
|
{
|
2013-11-26 09:09:35 +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
|
|
|
}
|
|
|
|
void Basic::EndFrame()
|
|
|
|
{
|
2013-12-18 20:28:06 +01:00
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Deffered::LightPass);
|
|
|
|
|
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-01-08 07:01:59 +01:00
|
|
|
Core::PipelineManager::SetRenderPass(Resources::Deffered::PostPass);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|