Instanced Rendering

This commit is contained in:
lanariel 2014-02-24 14:44:36 +01:00
parent 7bb67b6a85
commit 37e9d47207
14 changed files with 439 additions and 50 deletions

View File

@ -242,5 +242,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
} }
} }
Graphics::API::EndLoadingModels();
this->privData->nextState = ClientState::ClientState_Game; this->privData->nextState = ClientState::ClientState_Game;
} }

View File

@ -95,7 +95,8 @@ namespace Oyster
{ {
Math::Matrix WV; Math::Matrix WV;
Math::Matrix WVP; Math::Matrix WVP;
TintData td; Math::Float3 Tint;
Math::Float3 GTint;
}; };
} }
} }

View File

@ -141,7 +141,26 @@ namespace Oyster
void API::EndLoadingModels() void API::EndLoadingModels()
{ {
//TODO finalize instance buffers and create rendering map; //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 //returns null for invalid filenames
@ -164,6 +183,8 @@ namespace Oyster
return NULL; return NULL;
} }
if(!m->info->Animated)
{
if(Core::loader.GetResourceCount(m->info) == 1) if(Core::loader.GetResourceCount(m->info) == 1)
{ {
Render::Resources::RenderData[m->info] = new Render::Resources::ModelDataWrapper(); Render::Resources::RenderData[m->info] = new Render::Resources::ModelDataWrapper();
@ -172,6 +193,7 @@ namespace Oyster
{ {
Render::Resources::RenderData[m->info]->Models++; Render::Resources::RenderData[m->info]->Models++;
} }
}
return m; return m;
} }
@ -207,6 +229,12 @@ namespace Oyster
SAFE_RELEASE(Core::deviceContext); SAFE_RELEASE(Core::deviceContext);
SAFE_RELEASE(Core::device); 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) void API::AddLight(Definitions::Pointlight light)
@ -228,9 +256,9 @@ namespace Oyster
void API::StartRenderWireFrame() 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->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) void API::RenderDebugCube(Math::Matrix world)

View File

@ -239,13 +239,25 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
</FxCompile> </FxCompile>
<FxCompile Include="Shader\Passes\Gather\GatherInstPixel.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="Shader\Passes\Gather\GatherInstVertex.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="Shader\Passes\Light\LightPass.hlsl"> <FxCompile Include="Shader\Passes\Light\LightPass.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compute</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Compute</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType>
</FxCompile> </FxCompile>
<FxCompile Include="Shader\Passes\Gather\GatherPixel.hlsl"> <FxCompile Include="Shader\Passes\Gather\GatherAnimPixel.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
@ -281,7 +293,7 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel> <ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">5.0</ShaderModel>
</FxCompile> </FxCompile>
<FxCompile Include="Shader\Passes\Gather\GatherVertex.hlsl"> <FxCompile Include="Shader\Passes\Gather\GatherAnimVertex.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType> <ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
@ -328,8 +340,9 @@
<ItemGroup> <ItemGroup>
<None Include="Shader\Passes\2D\Header.hlsli" /> <None Include="Shader\Passes\2D\Header.hlsli" />
<None Include="Shader\Passes\2D\Text\Header.hlsli" /> <None Include="Shader\Passes\2D\Text\Header.hlsli" />
<None Include="Shader\Passes\Gather\InstHeader.hlsli" />
<None Include="Shader\Passes\Light\Defines.hlsli" /> <None Include="Shader\Passes\Light\Defines.hlsli" />
<None Include="Shader\Passes\Gather\Header.hlsli" /> <None Include="Shader\Passes\Gather\AnimHeader.hlsli" />
<None Include="Shader\Passes\Light\LightCalc.hlsli" /> <None Include="Shader\Passes\Light\LightCalc.hlsli" />
<None Include="Shader\Passes\Light\PosManipulation.hlsli" /> <None Include="Shader\Passes\Light\PosManipulation.hlsli" />
<None Include="Shader\Passes\Light\SSAO.hlsli" /> <None Include="Shader\Passes\Light\SSAO.hlsli" />

View File

@ -100,8 +100,6 @@
<FxCompile Include="Shader\HLSL\SimpleDebug\TextureDebug.hlsl" /> <FxCompile Include="Shader\HLSL\SimpleDebug\TextureDebug.hlsl" />
<FxCompile Include="Shader\Passes\Light\LightPass.hlsl" /> <FxCompile Include="Shader\Passes\Light\LightPass.hlsl" />
<FxCompile Include="Shader\Passes\Post\PostPass.hlsl" /> <FxCompile Include="Shader\Passes\Post\PostPass.hlsl" />
<FxCompile Include="Shader\Passes\Gather\GatherPixel.hlsl" />
<FxCompile Include="Shader\Passes\Gather\GatherVertex.hlsl" />
<FxCompile Include="Shader\Passes\2D\2DVertex.hlsl" /> <FxCompile Include="Shader\Passes\2D\2DVertex.hlsl" />
<FxCompile Include="Shader\Passes\2D\2DPixel.hlsl" /> <FxCompile Include="Shader\Passes\2D\2DPixel.hlsl" />
<FxCompile Include="Shader\Passes\2D\2DGeometry.hlsl" /> <FxCompile Include="Shader\Passes\2D\2DGeometry.hlsl" />
@ -109,6 +107,10 @@
<FxCompile Include="Shader\Passes\Blur\BlurVert.hlsl" /> <FxCompile Include="Shader\Passes\Blur\BlurVert.hlsl" />
<FxCompile Include="Shader\Passes\2D\Text\2DTextVertex.hlsl" /> <FxCompile Include="Shader\Passes\2D\Text\2DTextVertex.hlsl" />
<FxCompile Include="Shader\Passes\2D\Text\2DTextGeometry.hlsl" /> <FxCompile Include="Shader\Passes\2D\Text\2DTextGeometry.hlsl" />
<FxCompile Include="Shader\Passes\Gather\GatherAnimPixel.hlsl" />
<FxCompile Include="Shader\Passes\Gather\GatherAnimVertex.hlsl" />
<FxCompile Include="Shader\Passes\Gather\GatherInstVertex.hlsl" />
<FxCompile Include="Shader\Passes\Gather\GatherInstPixel.hlsl" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Shader\HLSL\SimpleDebug\Debug.hlsl" /> <None Include="Shader\HLSL\SimpleDebug\Debug.hlsl" />
@ -117,8 +119,9 @@
<None Include="Shader\Passes\Light\PosManipulation.hlsli" /> <None Include="Shader\Passes\Light\PosManipulation.hlsli" />
<None Include="Shader\Passes\Light\SSAO.hlsli" /> <None Include="Shader\Passes\Light\SSAO.hlsli" />
<None Include="Shader\Passes\2D\Header.hlsli" /> <None Include="Shader\Passes\2D\Header.hlsli" />
<None Include="Shader\Passes\Gather\Header.hlsli" />
<None Include="Shader\Passes\Blur\BlurSharedData.hlsli" /> <None Include="Shader\Passes\Blur\BlurSharedData.hlsli" />
<None Include="Shader\Passes\2D\Text\Header.hlsli" /> <None Include="Shader\Passes\2D\Text\Header.hlsli" />
<None Include="Shader\Passes\Gather\AnimHeader.hlsli" />
<None Include="Shader\Passes\Gather\InstHeader.hlsli" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -19,7 +19,6 @@ namespace Oyster
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0)); Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(0,0,0,0));
Preparations::Basic::ClearDepthStencil(Resources::Gui::depth); Preparations::Basic::ClearDepthStencil(Resources::Gui::depth);
Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0)); Preparations::Basic::ClearRTV(Resources::GBufferRTV,Resources::GBufferSize,Math::Float4(0,0,0,0));
Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Gather::Pass);
Lights[1]; Lights[1];
void* data; void* data;
@ -39,15 +38,37 @@ namespace Oyster
data = Resources::Light::PointLightsData.Map(); data = Resources::Light::PointLightsData.Map();
memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights); memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights);
Resources::Light::PointLightsData.Unmap(); 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) void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection, float deltaTime)
{ {
for(int i = 0; i < count; ++i) for(int i = 0; i < count; ++i)
{ {
if(&models[i] == NULL) if(&models[i] == NULL || !models[i].Visible)
continue; 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; Definitions::PerModel pm;
Math::Float3x3 normalTransform; Math::Float3x3 normalTransform;
@ -55,7 +76,6 @@ namespace Oyster
normalTransform.Transpose().Invert(); 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)); 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 = View * m;
//pm.WV = models[i].WorldMatrix.GetTranspose().GetInverse();
pm.WVP = Projection * View * models[i].WorldMatrix; pm.WVP = Projection * View * models[i].WorldMatrix;
Model::ModelInfo* info = models[i].info; 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); 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() 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::PipelineManager::SetRenderPass(Resources::Light::Pass);
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1); Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);

View File

@ -33,7 +33,8 @@ namespace Oyster
ID3D11UnorderedAccessView* Resources::Blur::BufferUAV = {0}; ID3D11UnorderedAccessView* Resources::Blur::BufferUAV = {0};
ID3D11ShaderResourceView* Resources::Blur::BufferSRV = {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::Light::Pass;
Shader::RenderPass Resources::Post::Pass; Shader::RenderPass Resources::Post::Pass;
Shader::RenderPass Resources::Gui::Pass; Shader::RenderPass Resources::Gui::Pass;
@ -43,6 +44,7 @@ namespace Oyster
Buffer Resources::Gather::ModelData = Buffer(); Buffer Resources::Gather::ModelData = Buffer();
Buffer Resources::Gather::AnimationData = Buffer(); Buffer Resources::Gather::AnimationData = Buffer();
Buffer Resources::Gather::InstancedData = Buffer();
Buffer Resources::Light::LightConstantsData = Buffer(); Buffer Resources::Light::LightConstantsData = Buffer();
Buffer Resources::Gui::Data = Buffer(); Buffer Resources::Gui::Data = Buffer();
Buffer Resources::Color = Buffer(); Buffer Resources::Color = Buffer();
@ -78,8 +80,12 @@ namespace Oyster
std::wstring end = L".cso"; std::wstring end = L".cso";
#endif #endif
//Load Shaders //Load Shaders
Core::PipelineManager::Init(path + L"GatherPixel" + end, ShaderType::Pixel, L"Gather"); Core::PipelineManager::Init(path + L"GatherAnimPixel" + end, ShaderType::Pixel, L"AGather");
Core::PipelineManager::Init(path + L"GatherVertex" + end, ShaderType::Vertex, L"Gather"); 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 #ifdef _DEBUG
path = PathToHLSL+L"Light\\"; path = PathToHLSL+L"Light\\";
#endif #endif
@ -153,6 +159,7 @@ namespace Oyster
desc.NumElements = MAX_LETTER_COUNT; desc.NumElements = MAX_LETTER_COUNT;
Gui::Text::Vertex.Init(desc); Gui::Text::Vertex.Init(desc);
return Core::Init::Success; return Core::Init::Success;
} }
@ -358,10 +365,11 @@ namespace Oyster
{ {
////---------------- Geometry Pass Setup ---------------------------- ////---------------- Geometry Pass Setup ----------------------------
Gather::Pass.Shaders.Pixel = GetShader::Pixel(L"Gather"); #pragma region Animated Pass
Gather::Pass.Shaders.Vertex = GetShader::Vertex(L"Gather"); 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 }, { "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 }, { "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 } { "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); Shader::CreateInputLayout(AnimInDesc,5,GetShader::Vertex(L"Gather"),Gather::AnimatedPass.IAStage.Layout);
Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; Gather::AnimatedPass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData); Gather::AnimatedPass.CBuffers.Vertex.push_back(Gather::AnimationData);
Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData); Gather::AnimatedPass.CBuffers.Vertex.push_back(Gather::ModelData);
Gather::Pass.CBuffers.Pixel.push_back(Color); Gather::AnimatedPass.CBuffers.Pixel.push_back(Color);
Gather::Pass.RenderStates.Rasterizer = RenderStates::rs; Gather::AnimatedPass.RenderStates.Rasterizer = RenderStates::rs;
Gather::Pass.RenderStates.SampleCount = 1; Gather::AnimatedPass.RenderStates.SampleCount = 1;
Gather::Pass.RenderStates.SampleState = RenderStates::ss; Gather::AnimatedPass.RenderStates.SampleState = RenderStates::ss;
Gather::Pass.RenderStates.DepthStencil = RenderStates::dsState; Gather::AnimatedPass.RenderStates.DepthStencil = RenderStates::dsState;
for(int i = 0; i<GBufferSize;++i) for(int i = 0; i<GBufferSize;++i)
{ {
Gather::Pass.RTV.push_back(GBufferRTV[i]); Gather::AnimatedPass.RTV.push_back(GBufferRTV[i]);
} }
Gather::Pass.depth = Core::depthStencil; Gather::AnimatedPass.depth = Core::depthStencil;
#pragma endregion
#pragma region Instanced Pass
Gather::InstancedPass.Shaders.Pixel = GetShader::Pixel(L"IGather");
Gather::InstancedPass.Shaders.Vertex = GetShader::Vertex(L"IGather");
D3D11_INPUT_ELEMENT_DESC InstInDesc[15];
InstInDesc[0].AlignedByteOffset = 0;
InstInDesc[0].SemanticName = "POSITION";
InstInDesc[0].SemanticIndex = 0;
InstInDesc[0].InputSlot = 0;
InstInDesc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
InstInDesc[0].InstanceDataStepRate = 0;
InstInDesc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
InstInDesc[1].AlignedByteOffset = 12;
InstInDesc[1].SemanticName = "TEXCOORD";
InstInDesc[1].SemanticIndex = 0;
InstInDesc[1].InputSlot = 0;
InstInDesc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
InstInDesc[1].InstanceDataStepRate = 0;
InstInDesc[1].Format = DXGI_FORMAT_R32G32_FLOAT;
InstInDesc[2].AlignedByteOffset = 20;
InstInDesc[2].SemanticName = "NORMAL";
InstInDesc[2].SemanticIndex = 0;
InstInDesc[2].InputSlot = 0;
InstInDesc[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
InstInDesc[2].InstanceDataStepRate = 0;
InstInDesc[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
InstInDesc[3].AlignedByteOffset = 36;
InstInDesc[3].SemanticName = "BONEINDEX";
InstInDesc[3].SemanticIndex = 0;
InstInDesc[3].InputSlot = 0;
InstInDesc[3].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
InstInDesc[3].InstanceDataStepRate = 0;
InstInDesc[3].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[4].AlignedByteOffset = 48;
InstInDesc[4].SemanticName = "BONEWEIGHT";
InstInDesc[4].SemanticIndex = 0;
InstInDesc[4].InputSlot = 0;
InstInDesc[4].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
InstInDesc[4].InstanceDataStepRate = 0;
InstInDesc[4].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
/// Set WV
InstInDesc[5].AlignedByteOffset = 0;
InstInDesc[5].SemanticName = "WV";
InstInDesc[5].SemanticIndex = 0;
InstInDesc[5].InputSlot = 1;
InstInDesc[5].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[5].InstanceDataStepRate = 1;
InstInDesc[5].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[6].AlignedByteOffset = 16;
InstInDesc[6].SemanticName = "WV";
InstInDesc[6].SemanticIndex = 1;
InstInDesc[6].InputSlot = 1;
InstInDesc[6].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[6].InstanceDataStepRate = 1;
InstInDesc[6].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[7].AlignedByteOffset = 32;
InstInDesc[7].SemanticName = "WV";
InstInDesc[7].SemanticIndex = 2;
InstInDesc[7].InputSlot = 1;
InstInDesc[7].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[7].InstanceDataStepRate = 1;
InstInDesc[7].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[8].AlignedByteOffset = 48;
InstInDesc[8].SemanticName = "WV";
InstInDesc[8].SemanticIndex = 3;
InstInDesc[8].InputSlot = 1;
InstInDesc[8].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[8].InstanceDataStepRate = 1;
InstInDesc[8].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
//WVP
InstInDesc[9].AlignedByteOffset = 64;
InstInDesc[9].SemanticName = "WVP";
InstInDesc[9].SemanticIndex = 0;
InstInDesc[9].InputSlot = 1;
InstInDesc[9].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[9].InstanceDataStepRate = 1;
InstInDesc[9].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[10].AlignedByteOffset = 80;
InstInDesc[10].SemanticName = "WVP";
InstInDesc[10].SemanticIndex = 1;
InstInDesc[10].InputSlot = 1;
InstInDesc[10].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[10].InstanceDataStepRate = 1;
InstInDesc[10].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[11].AlignedByteOffset = 96;
InstInDesc[11].SemanticName = "WVP";
InstInDesc[11].SemanticIndex = 2;
InstInDesc[11].InputSlot = 1;
InstInDesc[11].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[11].InstanceDataStepRate = 1;
InstInDesc[11].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[12].AlignedByteOffset = 112;
InstInDesc[12].SemanticName = "WVP";
InstInDesc[12].SemanticIndex = 3;
InstInDesc[12].InputSlot = 1;
InstInDesc[12].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[12].InstanceDataStepRate = 1;
InstInDesc[12].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
InstInDesc[13].AlignedByteOffset = 128;
InstInDesc[13].SemanticName = "TINT";
InstInDesc[13].SemanticIndex = 0;
InstInDesc[13].InputSlot = 1;
InstInDesc[13].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[13].InstanceDataStepRate = 1;
InstInDesc[13].Format = DXGI_FORMAT_R32G32B32_FLOAT;
InstInDesc[14].AlignedByteOffset = 140;
InstInDesc[14].SemanticName = "GTINT";
InstInDesc[14].SemanticIndex = 0;
InstInDesc[14].InputSlot = 1;
InstInDesc[14].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
InstInDesc[14].InstanceDataStepRate = 1;
InstInDesc[14].Format = DXGI_FORMAT_R32G32B32_FLOAT;
Shader::CreateInputLayout(InstInDesc,15,GetShader::Vertex(L"IGather"),Gather::InstancedPass.IAStage.Layout);
Gather::InstancedPass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
Gather::InstancedPass.CBuffers.Vertex.push_back(Gather::AnimationData);
Gather::InstancedPass.CBuffers.Vertex.push_back(Gather::ModelData);
Gather::InstancedPass.CBuffers.Pixel.push_back(Color);
Gather::InstancedPass.RenderStates.Rasterizer = RenderStates::rs;
Gather::InstancedPass.RenderStates.SampleCount = 1;
Gather::InstancedPass.RenderStates.SampleState = RenderStates::ss;
Gather::InstancedPass.RenderStates.DepthStencil = RenderStates::dsState;
for(int i = 0; i<GBufferSize;++i)
{
Gather::InstancedPass.RTV.push_back(GBufferRTV[i]);
}
Gather::InstancedPass.depth = Core::depthStencil;
#pragma endregion
////---------------- Light Pass Setup ---------------------------- ////---------------- Light Pass Setup ----------------------------
Light::Pass.Shaders.Compute = GetShader::Compute(L"LightPass"); Light::Pass.Shaders.Compute = GetShader::Compute(L"LightPass");
@ -498,6 +652,7 @@ namespace Oyster
{ {
Gather::ModelData.~Buffer(); Gather::ModelData.~Buffer();
Gather::AnimationData.~Buffer(); Gather::AnimationData.~Buffer();
Gather::InstancedData.~Buffer();
Light::LightConstantsData.~Buffer(); Light::LightConstantsData.~Buffer();
Light::PointLightsData.~Buffer(); Light::PointLightsData.~Buffer();
Gui::Data.~Buffer(); Gui::Data.~Buffer();
@ -524,20 +679,21 @@ namespace Oyster
SAFE_RELEASE(LBufferSRV[i]); SAFE_RELEASE(LBufferSRV[i]);
} }
SAFE_RELEASE(Gather::Pass.IAStage.Layout); SAFE_RELEASE(Gather::AnimatedPass.IAStage.Layout);
SAFE_RELEASE(Gather::InstancedPass.IAStage.Layout);
SAFE_RELEASE(Gather::Pass.RenderStates.BlendState); SAFE_RELEASE(Gather::AnimatedPass.RenderStates.BlendState);
SAFE_RELEASE(Gather::Pass.RenderStates.DepthStencil); SAFE_RELEASE(Gather::AnimatedPass.RenderStates.DepthStencil);
SAFE_RELEASE(Gather::Pass.RenderStates.Rasterizer); SAFE_RELEASE(Gather::AnimatedPass.RenderStates.Rasterizer);
for(int i = 0; i < Gather::Pass.RenderStates.SampleCount; ++i) for(int i = 0; i < Gather::AnimatedPass.RenderStates.SampleCount; ++i)
{ {
SAFE_RELEASE(Gather::Pass.RenderStates.SampleState[i]); SAFE_RELEASE(Gather::AnimatedPass.RenderStates.SampleState[i]);
} }
SAFE_DELETE_ARRAY(Gather::Pass.RenderStates.SampleState); SAFE_DELETE_ARRAY(Gather::AnimatedPass.RenderStates.SampleState);
SAFE_RELEASE(Gui::Pass.IAStage.Layout); SAFE_RELEASE(Gui::Pass.IAStage.Layout);

View File

@ -54,9 +54,11 @@ namespace Oyster
struct Gather struct Gather
{ {
static Core::PipelineManager::RenderPass Pass; static Core::PipelineManager::RenderPass AnimatedPass;
static Core::PipelineManager::RenderPass InstancedPass;
static Core::Buffer ModelData; static Core::Buffer ModelData;
static Core::Buffer AnimationData; static Core::Buffer AnimationData;
static Core::Buffer InstancedData;
}; };
struct Light struct Light

View File

@ -1,4 +1,4 @@
struct VertexIn struct AnimVertexIn
{ {
float3 pos : POSITION; float3 pos : POSITION;
float2 UV : TEXCOORD; float2 UV : TEXCOORD;

View File

@ -1,4 +1,4 @@
#include "Header.hlsli" #include "AnimHeader.hlsli"
@ -42,7 +42,7 @@ PixelOut main(VertexOut input)
PixelOut output; PixelOut output;
float4 DiffGlow = Diffuse.Sample(S1, input.UV); float4 DiffGlow = Diffuse.Sample(S1, input.UV);
float3 tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; float3 tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w;
tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w; //tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w;
output.DiffuseGlow = DiffGlow * float4(tint,1); output.DiffuseGlow = DiffGlow * float4(tint,1);
//NORMALIZE //NORMALIZE

View File

@ -1,6 +1,6 @@
#include "Header.hlsli" #include "AnimHeader.hlsli"
VertexOut main( VertexIn input ) VertexOut main( AnimVertexIn input )
{ {
VertexOut output; VertexOut output;

View File

@ -0,0 +1,63 @@
#include "InstHeader.hlsli"
float3x3 cotangent_frame( float3 N, float3 p, float2 uv )
{
// get edge vectors of the pixel triangle
float3 dp1 = ddx( p );
float3 dp2 = ddy( p );
float2 duv1 = ddx( uv );
float2 duv2 = ddy( uv );
// solve the linear system
float3 dp2perp = cross( dp2, N );
float3 dp1perp = cross( N, dp1 );
float3 T = dp2perp * duv1.x + dp1perp * duv2.x;
float3 B = dp2perp * duv1.y + dp1perp * duv2.y;
// construct a scale-invariant frame
float invmax = rsqrt( max( dot(T,T), dot(B,B) ) );
return transpose(float3x3( T * invmax, B * invmax, N ));
}
float3 perturb_normal( float3 N, float3 V, float2 texcoord )
{
// assume N, the interpolated vertex normal and
// V, the view vector (vertex to eye)
float3 map = Normal.Sample(S1,texcoord).xyz;
map = map * 255./127. - 128./127.;
#ifdef WITH_NORMALMAP_2CHANNEL
map.z = sqrt( 1. - dot( map.xy, map.xy ) );
#endif
#ifdef WITH_NORMALMAP_GREEN_UP
map.y = -map.y;
#endif
float3x3 TBN = cotangent_frame( N, -V, texcoord );
return normalize( mul(transpose(TBN), map) );
}
PixelOut main(VertexOut input)
{
PixelOut output;
float4 DiffGlow = Diffuse.Sample(S1, input.UV);
float3 tint = input.tint * (1-DiffGlow.w) + input.gtint * DiffGlow.w;
//tint = Color*(1-DiffGlow.w) + GlowColor * DiffGlow.w;
output.DiffuseGlow = DiffGlow * float4(tint,1);
//NORMALIZE
float3x3 CoTangentFrame = cotangent_frame(input.normal, normalize(input.ViewPos), input.UV);
float3 map = Normal.Sample(S1,input.UV).xyz;
//map = normalize((map * 2) -1);
map = map * 255./127. - 128./127.;
//map = map * 255;
float3 normal = normalize(mul(CoTangentFrame, map));
//normal = perturb_normal( normal, normalize(-input.ViewPos), input.UV );
output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*255);
//output.NormalSpec = float4(input.normal, Normal.Sample(S1, input.UV).w * 0);
//output.NormalSpec = float4(map,0);
return output;
}

View File

@ -0,0 +1,18 @@
#include "InstHeader.hlsli"
VertexOut main( InstVertexIn input )
{
VertexOut output;
matrix WV = transpose(matrix(input.wv1, input.wv2, input.wv3, input.wv4));
matrix WVP = transpose(matrix(input.wvp1, input.wvp2, input.wvp3, input.wvp4));
output.pos = mul(WVP, float4(input.pos,1));
output.ViewPos = mul(WV, float4(input.pos,1));
output.normal = mul(WV, float4(input.normal,0)).xyz;
output.UV = input.UV;
output.tint = input.Tint;
output.gtint = input.GlowTint;
return output;
}

View File

@ -0,0 +1,44 @@
struct InstVertexIn
{
float3 pos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
float4 boneIndex : BONEINDEX;
float4 boneWeight : BONEWEIGHT;
//instance Data
//WV MATRIX
float4 wv1 : WV0;
float4 wv2 : WV1;
float4 wv3 : WV2;
float4 wv4 : WV3;
//WVP MATRIX
float4 wvp1 : WVP0;
float4 wvp2 : WVP1;
float4 wvp3 : WVP2;
float4 wvp4 : WVP3;
float3 Tint : TINT;
float3 GlowTint : GTINT;
};
struct VertexOut
{
float4 pos : SV_POSITION;
float4 ViewPos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
float3 tint : TINT;
float3 gtint : GTINT;
};
struct PixelOut
{
float4 DiffuseGlow : SV_TARGET0;
float4 NormalSpec : SV_TARGET1;
};
Texture2D Diffuse : register(t0);
Texture2D Normal : register(t1);
SamplerState S1 : register(s0);