diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp
index 9ef0dac9..b9256fd1 100644
--- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp
+++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp
@@ -242,5 +242,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
}
}
+ Graphics::API::EndLoadingModels();
+
this->privData->nextState = ClientState::ClientState_Game;
}
diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h
index 9d7d4301..77aecdc8 100644
--- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h
+++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h
@@ -95,7 +95,8 @@ namespace Oyster
{
Math::Matrix WV;
Math::Matrix WVP;
- TintData td;
+ Math::Float3 Tint;
+ Math::Float3 GTint;
};
}
}
diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp
index 4e61c7f3..d4c48957 100644
--- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp
+++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp
@@ -141,7 +141,26 @@ namespace Oyster
void API::EndLoadingModels()
{
//TODO finalize instance buffers and create rendering map;
+ int maxModels = 0;
+ for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ )
+ {
+ if((*i).second->Models > maxModels)
+ {
+ maxModels = (*i).second->Models;
+ }
+ (*i).second->rid = new Definitions::RenderInstanceData[(*i).second->Models+1];
+ }
+
+ Core::Buffer::BUFFER_INIT_DESC desc;
+
+ desc.ElementSize = sizeof(Definitions::RenderInstanceData);
+ desc.Type = Core::Buffer::VERTEX_BUFFER;
+ desc.Usage = Core::Buffer::BUFFER_CPU_WRITE_DISCARD;
+ desc.InitData = 0;
+ desc.NumElements = maxModels;
+
+ Render::Resources::Gather::InstancedData.Init(desc);
}
//returns null for invalid filenames
@@ -163,14 +182,17 @@ namespace Oyster
delete mi;
return NULL;
}
-
- if(Core::loader.GetResourceCount(m->info) == 1)
+
+ if(!m->info->Animated)
{
- Render::Resources::RenderData[m->info] = new Render::Resources::ModelDataWrapper();
- }
- else
- {
- Render::Resources::RenderData[m->info]->Models++;
+ if(Core::loader.GetResourceCount(m->info) == 1)
+ {
+ Render::Resources::RenderData[m->info] = new Render::Resources::ModelDataWrapper();
+ }
+ else
+ {
+ Render::Resources::RenderData[m->info]->Models++;
+ }
}
return m;
@@ -207,6 +229,12 @@ namespace Oyster
SAFE_RELEASE(Core::deviceContext);
SAFE_RELEASE(Core::device);
+ for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ )
+ {
+ SAFE_DELETE((*i).second->rid);
+ SAFE_DELETE((*i).second);
+ }
+
}
void API::AddLight(Definitions::Pointlight light)
@@ -228,9 +256,9 @@ namespace Oyster
void API::StartRenderWireFrame()
{
- Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL);
+ Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::AnimatedPass.RTV.size(),&Render::Resources::Gather::AnimatedPass.RTV[0],NULL);
Core::deviceContext->RSSetState(wire);
- Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL);
+ Core::deviceContext->OMSetRenderTargets((UINT)Render::Resources::Gather::AnimatedPass.RTV.size(),&Render::Resources::Gather::AnimatedPass.RTV[0],NULL);
}
void API::RenderDebugCube(Math::Matrix world)
diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj b/Code/OysterGraphics/OysterGraphics.vcxproj
index 8faf4d0f..f4a3d130 100644
--- a/Code/OysterGraphics/OysterGraphics.vcxproj
+++ b/Code/OysterGraphics/OysterGraphics.vcxproj
@@ -239,13 +239,25 @@
Vertex
Vertex
+
+ Pixel
+ Pixel
+ Pixel
+ Pixel
+
+
+ Vertex
+ Vertex
+ Vertex
+ Vertex
+
Compute
Compute
Compute
Compute
-
+
Pixel
Pixel
Pixel
@@ -281,7 +293,7 @@
Compute
5.0
-
+
Vertex
Vertex
Vertex
@@ -328,8 +340,9 @@
+
-
+
diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.filters b/Code/OysterGraphics/OysterGraphics.vcxproj.filters
index d76a066f..83731090 100644
--- a/Code/OysterGraphics/OysterGraphics.vcxproj.filters
+++ b/Code/OysterGraphics/OysterGraphics.vcxproj.filters
@@ -100,8 +100,6 @@
-
-
@@ -109,6 +107,10 @@
+
+
+
+
@@ -117,8 +119,9 @@
-
+
+
\ No newline at end of file
diff --git a/Code/OysterGraphics/Render/DefaultRenderer.cpp b/Code/OysterGraphics/Render/DefaultRenderer.cpp
index 7d0d987b..a735f4b3 100644
--- a/Code/OysterGraphics/Render/DefaultRenderer.cpp
+++ b/Code/OysterGraphics/Render/DefaultRenderer.cpp
@@ -19,7 +19,6 @@ namespace Oyster
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0));
Preparations::Basic::ClearDepthStencil(Resources::Gui::depth);
Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0));
- Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass);
Lights[1];
void* data;
@@ -39,15 +38,37 @@ namespace Oyster
data = Resources::Light::PointLightsData.Map();
memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights);
Resources::Light::PointLightsData.Unmap();
+
+ for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ )
+ {
+ (*i).second->Models=0;
+ }
}
void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime)
{
for(int i = 0; i < count; ++i)
{
- if(&models[i] == NULL)
+ if(&models[i] == NULL || !models[i].Visible)
continue;
- if(models[i].Visible)
+
+ Model::ModelInfo* info = models[i].info;
+ if(!info->Animated)
+ {
+ Definitions::RenderInstanceData rid;
+ Math::Float3x3 normalTransform;
+ normalTransform = Math::Float3x3(models[i].WorldMatrix.v[0].xyz, models[i].WorldMatrix.v[1].xyz, models[i].WorldMatrix.v[2].xyz);
+ normalTransform.Transpose().Invert();
+ Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f));
+ rid.WV = View * m;
+ rid.WVP = Projection * View * models[i].WorldMatrix;
+
+ rid.Tint = models[i].Tint;
+ rid.GTint = models[i].GlowTint;
+
+ Resources::RenderData[info]->rid[Resources::RenderData[info]->Models++] = rid;
+ }
+ else
{
Definitions::PerModel pm;
Math::Float3x3 normalTransform;
@@ -55,7 +76,6 @@ namespace Oyster
normalTransform.Transpose().Invert();
Math::Matrix m = Math::Matrix(Math::Vector4(normalTransform.v[0],0.0f), Math::Vector4(normalTransform.v[1],0.0f), Math::Vector4(normalTransform.v[2],0.0f), Math::Vector4(0.0f));
pm.WV = View * m;
- //pm.WV = models[i].WorldMatrix.GetTranspose().GetInverse();
pm.WVP = Projection * View * models[i].WorldMatrix;
Model::ModelInfo* info = models[i].info;
@@ -207,9 +227,48 @@ namespace Oyster
Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1);
}
+ void RenderModel(Model::ModelInfo* info, Definitions::RenderInstanceData* rid , int count)
+ {
+ if(info->Material.size())
+ {
+ Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0]));
+ }
+ info->Vertices->Apply();
+ if(info->Indexed)
+ {
+ info->Indecies->Apply();
+ }
+
+ void* data = Resources::Gather::InstancedData.Map();
+ memcpy(data, rid, sizeof(Definitions::RenderInstanceData)*count);
+ Resources::Gather::InstancedData.Unmap();
+
+ if(info->Indexed)
+ {
+ Core::deviceContext->DrawIndexedInstanced(info->IndexCount,count,0,0,0);
+ //Core::deviceContext->DrawIndexed(info->IndexCount,0,0);
+ }
+ else
+ {
+ Core::deviceContext->DrawInstanced(info->VertexCount,count,0,0);
+ //Core::deviceContext->Draw(info->VertexCount,0);
+ }
+ }
+
void DefaultRenderer::EndFrame()
{
+ Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::InstancedPass);
+ Resources::Gather::InstancedData.Apply(1);
+
+ for(auto i = Render::Resources::RenderData.begin(); i != Render::Resources::RenderData.end(); i++ )
+ {
+ for(int m = 0; m <(*i).second->Models; ++m)
+ {
+ RenderModel((*i).first,(*i).second->rid, (*i).second->Models);
+ }
+ }
+
Core::PipelineManager::SetRenderPass(Resources::Light::Pass);
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
diff --git a/Code/OysterGraphics/Render/Resources.cpp b/Code/OysterGraphics/Render/Resources.cpp
index 4c203cf9..91317114 100644
--- a/Code/OysterGraphics/Render/Resources.cpp
+++ b/Code/OysterGraphics/Render/Resources.cpp
@@ -33,7 +33,8 @@ namespace Oyster
ID3D11UnorderedAccessView* Resources::Blur::BufferUAV = {0};
ID3D11ShaderResourceView* Resources::Blur::BufferSRV = {0};
- Shader::RenderPass Resources::Gather::Pass;
+ Shader::RenderPass Resources::Gather::AnimatedPass;
+ Shader::RenderPass Resources::Gather::InstancedPass;
Shader::RenderPass Resources::Light::Pass;
Shader::RenderPass Resources::Post::Pass;
Shader::RenderPass Resources::Gui::Pass;
@@ -43,6 +44,7 @@ namespace Oyster
Buffer Resources::Gather::ModelData = Buffer();
Buffer Resources::Gather::AnimationData = Buffer();
+ Buffer Resources::Gather::InstancedData = Buffer();
Buffer Resources::Light::LightConstantsData = Buffer();
Buffer Resources::Gui::Data = Buffer();
Buffer Resources::Color = Buffer();
@@ -78,8 +80,12 @@ namespace Oyster
std::wstring end = L".cso";
#endif
//Load Shaders
- Core::PipelineManager::Init(path + L"GatherPixel" + end, ShaderType::Pixel, L"Gather");
- Core::PipelineManager::Init(path + L"GatherVertex" + end, ShaderType::Vertex, L"Gather");
+ Core::PipelineManager::Init(path + L"GatherAnimPixel" + end, ShaderType::Pixel, L"AGather");
+ Core::PipelineManager::Init(path + L"GatherAnimVertex" + end, ShaderType::Vertex, L"AGather");
+
+
+ Core::PipelineManager::Init(path + L"GatherInstPixel" + end, ShaderType::Pixel, L"IGather");
+ Core::PipelineManager::Init(path + L"GatherInstVertex" + end, ShaderType::Vertex, L"IGather");
#ifdef _DEBUG
path = PathToHLSL+L"Light\\";
#endif
@@ -153,6 +159,7 @@ namespace Oyster
desc.NumElements = MAX_LETTER_COUNT;
Gui::Text::Vertex.Init(desc);
+
return Core::Init::Success;
}
@@ -358,10 +365,11 @@ namespace Oyster
{
////---------------- Geometry Pass Setup ----------------------------
- Gather::Pass.Shaders.Pixel = GetShader::Pixel(L"Gather");
- Gather::Pass.Shaders.Vertex = GetShader::Vertex(L"Gather");
+#pragma region Animated Pass
+ Gather::AnimatedPass.Shaders.Pixel = GetShader::Pixel(L"Gather");
+ Gather::AnimatedPass.Shaders.Vertex = GetShader::Vertex(L"Gather");
- D3D11_INPUT_ELEMENT_DESC indesc[] =
+ D3D11_INPUT_ELEMENT_DESC AnimInDesc[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
@@ -370,20 +378,166 @@ namespace Oyster
{ "BONEWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
- Shader::CreateInputLayout(indesc,5,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout);
- Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
- Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData);
- Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData);
- Gather::Pass.CBuffers.Pixel.push_back(Color);
- Gather::Pass.RenderStates.Rasterizer = RenderStates::rs;
- Gather::Pass.RenderStates.SampleCount = 1;
- Gather::Pass.RenderStates.SampleState = RenderStates::ss;
- Gather::Pass.RenderStates.DepthStencil = RenderStates::dsState;
+ Shader::CreateInputLayout(AnimInDesc,5,GetShader::Vertex(L"Gather"),Gather::AnimatedPass.IAStage.Layout);
+ Gather::AnimatedPass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
+ Gather::AnimatedPass.CBuffers.Vertex.push_back(Gather::AnimationData);
+ Gather::AnimatedPass.CBuffers.Vertex.push_back(Gather::ModelData);
+ Gather::AnimatedPass.CBuffers.Pixel.push_back(Color);
+ Gather::AnimatedPass.RenderStates.Rasterizer = RenderStates::rs;
+ Gather::AnimatedPass.RenderStates.SampleCount = 1;
+ Gather::AnimatedPass.RenderStates.SampleState = RenderStates::ss;
+ Gather::AnimatedPass.RenderStates.DepthStencil = RenderStates::dsState;
for(int i = 0; i