From bab3ab0a78b189c8b5d6c4064969b2b31e7012f3 Mon Sep 17 00:00:00 2001 From: lanariel Date: Fri, 7 Feb 2014 11:09:59 +0100 Subject: [PATCH] Shader Restructure --- .../Definitions/GraphicalDefinition.h | 7 +- Code/OysterGraphics/OldResourses/Buffers.cpp | 44 ---- Code/OysterGraphics/OldResourses/Buffers.h | 22 -- .../OldResourses/GraphicsDefinitions.h | 34 --- Code/OysterGraphics/OldResourses/Manager.cpp | 47 ---- Code/OysterGraphics/OldResourses/Manager.h | 20 -- .../OldResourses/PipelineResources.cpp | 228 ------------------ .../OldResourses/PipelineResources.h | 66 ----- .../OldResourses/ShaderEffects.cpp | 100 -------- .../OldResourses/ShaderEffects.h | 23 -- Code/OysterGraphics/OysterGraphics.vcxproj | 41 +++- .../OysterGraphics.vcxproj.filters | 27 ++- .../Render/Rendering/BasicRender.cpp | 1 - .../Render/Resources/Deffered.cpp | 56 ++++- .../Render/Resources/Deffered.h | 7 +- .../Shader/Passes/2D/2DGeometry.hlsl | 22 ++ .../Shader/Passes/2D/2DPixel.hlsl | 6 + .../Shader/Passes/2D/2DVertex.hlsl | 6 + .../Shader/Passes/2D/Header.hlsli | 18 ++ .../Gather/GatherPixel.hlsl} | 2 +- .../Gather/GatherVertex.hlsl} | 7 +- .../Gather/Header.hlsli} | 2 - .../Light}/Defines.hlsli | 9 +- .../Light}/LightCalc.hlsli | 0 .../Light}/LightPass.hlsl | 0 .../Light}/PosManipulation.hlsli | 0 .../Light}/SSAO.hlsli | 0 .../Post}/PostPass.hlsl | 0 28 files changed, 163 insertions(+), 632 deletions(-) delete mode 100644 Code/OysterGraphics/OldResourses/Buffers.cpp delete mode 100644 Code/OysterGraphics/OldResourses/Buffers.h delete mode 100644 Code/OysterGraphics/OldResourses/GraphicsDefinitions.h delete mode 100644 Code/OysterGraphics/OldResourses/Manager.cpp delete mode 100644 Code/OysterGraphics/OldResourses/Manager.h delete mode 100644 Code/OysterGraphics/OldResourses/PipelineResources.cpp delete mode 100644 Code/OysterGraphics/OldResourses/PipelineResources.h delete mode 100644 Code/OysterGraphics/OldResourses/ShaderEffects.cpp delete mode 100644 Code/OysterGraphics/OldResourses/ShaderEffects.h create mode 100644 Code/OysterGraphics/Shader/Passes/2D/2DGeometry.hlsl create mode 100644 Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl create mode 100644 Code/OysterGraphics/Shader/Passes/2D/2DVertex.hlsl create mode 100644 Code/OysterGraphics/Shader/Passes/2D/Header.hlsli rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders/PixelGatherData.hlsl => Passes/Gather/GatherPixel.hlsl} (86%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders/VertexGatherData.hlsl => Passes/Gather/GatherVertex.hlsl} (67%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders/GBufferHeader.hlsli => Passes/Gather/Header.hlsli} (92%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders => Passes/Light}/Defines.hlsli (71%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders => Passes/Light}/LightCalc.hlsli (100%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders => Passes/Light}/LightPass.hlsl (100%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders => Passes/Light}/PosManipulation.hlsli (100%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders => Passes/Light}/SSAO.hlsli (100%) rename Code/OysterGraphics/Shader/{HLSL/Deffered Shaders => Passes/Post}/PostPass.hlsl (100%) diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index 93273b30..ae7bbeb8 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -52,12 +52,15 @@ namespace Oyster struct AnimationData { Math::Float4x4 AnimatedData[100]; - Math::Float4x4 BindPoseData[100]; - Math::Float4x4 RotationData[100]; int Animated; Math::Float3 Pad; }; + struct GuiData + { + Math::Matrix Translation; + }; + } } } \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/Buffers.cpp b/Code/OysterGraphics/OldResourses/Buffers.cpp deleted file mode 100644 index e36b3790..00000000 --- a/Code/OysterGraphics/OldResourses/Buffers.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "Buffers.h" - -namespace Oyster -{ - namespace Resources - { - Buffer Buffers::V2DSprites = Buffer(); - Buffer Buffers::CbufferVS = Buffer(); - Buffer Buffers::CBufferGs = Buffer(); - Buffer Buffers::CBufferPipelineCs = Buffer(); - - void Buffers::Init() - { - Buffer::BUFFER_INIT_DESC desc; - - desc.ElementSize=sizeof(Math::Float2); - desc.NumElements=1; - desc.Type = Buffer::BUFFER_TYPE::VERTEX_BUFFER; - desc.Usage = Buffer::BUFFER_USAGE::BUFFER_DEFAULT; - desc.InitData = &Math::Float2(0,0); - - V2DSprites.Init(desc); - - desc.Type=Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS; - desc.Usage = Buffer::BUFFER_USAGE::BUFFER_CPU_WRITE_DISCARD; - desc.ElementSize=sizeof(Math::Float4x4); - desc.InitData=0; - - CbufferVS.Init(desc); - - desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_GS; - - CBufferGs.Init(desc); - - desc.ElementSize=sizeof(Oyster::Resources::BufferDefinitions::LightStructureBuffer); - desc.NumElements=1; - desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_CS; - desc.Usage = Buffer::BUFFER_USAGE::BUFFER_CPU_WRITE_DISCARD; - desc.InitData = NULL; - - CBufferPipelineCs.Init(desc); - } - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/Buffers.h b/Code/OysterGraphics/OldResourses/Buffers.h deleted file mode 100644 index ec445b6c..00000000 --- a/Code/OysterGraphics/OldResourses/Buffers.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "../EngineIncludes.h" - -namespace Oyster -{ - namespace Resources - { - struct Buffers - { - static Buffer V2DSprites; - - static Buffer CbufferVS; - - static Buffer CBufferGs; - - static Buffer CBufferPipelineCs; - - static void Init(); - }; - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/GraphicsDefinitions.h b/Code/OysterGraphics/OldResourses/GraphicsDefinitions.h deleted file mode 100644 index 12a85d5f..00000000 --- a/Code/OysterGraphics/OldResourses/GraphicsDefinitions.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - - -#include "..\EngineIncludes.h" - -namespace Oyster -{ - namespace Resources - { - - namespace BufferDefinitions - { - struct LightStructureBuffer - { - ::Oyster::Math::Float4x4 viewMatrix, projectionMatrix; - ::LinearAlgebra::Vector3 numDispatches; - unsigned int reservedPadding; - }; - - struct ScreenTileFrustrum - { - ::Oyster::Math::Float rawElement[6 * 4]; - }; - - class PointLightDescription - { - public: - struct{ ::Oyster::Math::Float3 center; ::Oyster::Math::Float radius; } pos; - ::Oyster::Math::Float3 color; - ::Oyster::Math::Float intensty; - }; - }; - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/Manager.cpp b/Code/OysterGraphics/OldResourses/Manager.cpp deleted file mode 100644 index 47aa5eaf..00000000 --- a/Code/OysterGraphics/OldResourses/Manager.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "Manager.h" - -std::unordered_map< std::string, Oyster::Render::ModelInfo*> Oyster::Resources::Manager::loadedModels = std::unordered_map< std::string, Oyster::Render::ModelInfo*>(); - -Oyster::Render::Model* Oyster::Resources::Manager::LoadModel(std::string Filename, Matrix Scale) -{ - ////TODO: Add redundncy sheck, to ensure not recreating model - - ////Loop to find filename - - ////If found Return Model - - ////else Create Model - - //Oyster::FileLoaders::ObjReader *reader = Oyster::FileLoaders::ObjReader::LoadFile(Filename, Scale); - //Oyster::FileLoaders::ObjReader::Vertex** vertex = new Oyster::FileLoaders::ObjReader::Vertex*[1]; - //int vcount; - //std::map textures; - //reader->GetVertexData( vertex, vcount, textures ); - - //Oyster::Buffer::BUFFER_INIT_DESC desc; - //desc.ElementSize=sizeof(Oyster::FileLoaders::ObjReader::Vertex); - //desc.NumElements = vcount; - //desc.InitData = *vertex; - //desc.Type = Oyster::Buffer::VERTEX_BUFFER; - //desc.Usage = Oyster::Buffer::BUFFER_DEFAULT; - // - //ID3D11ShaderResourceView *srv = textures["Diffuse"]; - - //Oyster::Render::ModelInfo* m = new Oyster::Render::ModelInfo(); - // - //m->Vertices = *(Oyster::Engine::Init::Buffers::CreateBuffer(desc)); - //m->VertexCount = vcount; - //m->Material.push_back(srv); - //srv = textures["Specular"]; - //m->Material.push_back(srv); - //srv = textures["Glow"]; - //m->Material.push_back(srv); - //m->Indexed=false; - // - //Oyster::Render::Model* model = new Oyster::Render::Model(); - //model->info=m; - //model->Visible = true; - //model->World = &Oyster::Math::Float4x4(Oyster::Math::Float4x4::identity); - return NULL; -} - diff --git a/Code/OysterGraphics/OldResourses/Manager.h b/Code/OysterGraphics/OldResourses/Manager.h deleted file mode 100644 index 6de367e3..00000000 --- a/Code/OysterGraphics/OldResourses/Manager.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "../EngineIncludes.h" -#include - -namespace Oyster -{ - namespace Resources - { - struct Manager - { - //Expects to be deleted either trough manager or after a clean - static Oyster::Render::Model* LoadModel(std::string Filename, Matrix Scale); - static void Clean(); - - private: - static std::unordered_map< std::string, Oyster::Render::ModelInfo*> loadedModels; - }; - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/PipelineResources.cpp b/Code/OysterGraphics/OldResourses/PipelineResources.cpp deleted file mode 100644 index 27947c41..00000000 --- a/Code/OysterGraphics/OldResourses/PipelineResources.cpp +++ /dev/null @@ -1,228 +0,0 @@ -#include "PipelineResources.h" - -using namespace Oyster::Resources; - -ID3D11UnorderedAccessView* PipeLineResourses::TempUav = 0; -ID3D11ShaderResourceView* PipeLineResourses::TempSrv = 0; - -ID3D11ShaderResourceView* PipeLineResourses::GeometryOut[5] = {0}; -ID3D11RenderTargetView* PipeLineResourses::GeometryTarget[5] = {0}; - -ID3D11ShaderResourceView* PipeLineResourses::ComputeResources[4] = {0}; -Oyster::Buffer* PipeLineResourses::Resources[2] = {0}; - -ID3D11ShaderResourceView* PipeLineResourses::LightOut[4] = {0}; -ID3D11UnorderedAccessView* PipeLineResourses::LightTarget[4] = {0}; - -ID3D11RenderTargetView* PipeLineResourses::RtvNulls[16] = {0}; -ID3D11ShaderResourceView* PipeLineResourses::SrvNulls[16] = {0}; -ID3D11UnorderedAccessView* PipeLineResourses::uavNULL[16] = {0}; - -//Oyster::Collision3D::Frustrum* PipeLineResourses::SubFrustrums = 0; -int PipeLineResourses::FrustrumSize = 0; -LinearAlgebra::Vector3 PipeLineResourses::FrustrumDimensions = LinearAlgebra::Vector3(); - -Oyster::Resources::BufferDefinitions::LightStructureBuffer PipeLineResourses::LightData = Oyster::Resources::BufferDefinitions::LightStructureBuffer(); - -void PipeLineResourses::Init(int sizeX, int sizeY) -{ - InitGeometry(sizeX, sizeY); - - InitSSAOData(); - InitSubFrustrums(sizeX, sizeY); - InitPointLights(); - InitLightData(); - - InitLighting(sizeX, sizeY); -} - -void PipeLineResourses::InitGeometry(int sizeX, int sizeY) -{ - D3D11_TEXTURE2D_DESC Tdesc; - Tdesc.Width = sizeX; - Tdesc.Height = sizeY; - Tdesc.MipLevels = Tdesc.ArraySize = 1; - Tdesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; - Tdesc.SampleDesc.Count = 1; - Tdesc.SampleDesc.Quality=0; - Tdesc.Usage = D3D11_USAGE_DEFAULT; - Tdesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - Tdesc.CPUAccessFlags = 0; - Tdesc.MiscFlags = 0; - - ID3D11Texture2D *pTexture; - HRESULT hr; - - //Geometry stage resourses - for( int i = 0; i < 5; ++i ) - { - hr = Oyster::Core::Device->CreateTexture2D( &Tdesc, NULL, &pTexture ); - hr = Oyster::Core::Device->CreateShaderResourceView(pTexture,0,&GeometryOut[i]); - hr = Oyster::Core::Device->CreateRenderTargetView(pTexture,0,&GeometryTarget[i]); - pTexture->Release(); - } -} - -void PipeLineResourses::InitSSAOData() -{ - //create Half Spheres and Random Data - - Oyster::Buffer::BUFFER_INIT_DESC desc; - HRESULT hr; - - int NrOfSamples = Oyster::Engine::States::GetNrOfSSAOSamples(); - int SampleSpread = Oyster::Engine::States::GetSSAOSampleSpread(); - - Oyster::Math::Vector3* kernel = new Oyster::Math::Vector3[ NrOfSamples ]; - Oyster::Math::Vector3* random = new Oyster::Math::Vector3[ SampleSpread ]; - - for(int i = 0; i < NrOfSamples; ++i) - { - kernel[i] = Oyster::Math::Vector3::null; - while( kernel[i] == Oyster::Math::Vector3::null ) - { - kernel[i] = Oyster::Math::Vector3( - (float)rand() / (RAND_MAX + 1) * (1 - -1) + -1, - (float)rand() / (RAND_MAX + 1) * (1 - -1) + -1, - (float)rand() / (RAND_MAX + 1) * (1 - 0) + 0); - } - kernel[i].Normalize(); - - float scale = float(i) / float(NrOfSamples); - scale = (0.1f*(1 - scale * scale) + 1.0f *( scale * scale)); - kernel[i] *= scale; - - if( i < SampleSpread) - { - random[i] = Oyster::Math::Vector3::null; - while( random[i] == Oyster::Math::Vector3::null ) - { - random[i] = Oyster::Math::Vector3( - (float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1, - (float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1, - 0.0f); - } - random[i].Normalize(); - } - } - - - D3D11_TEXTURE1D_DESC T1desc; - T1desc.Width = NrOfSamples; - T1desc.MipLevels = T1desc.ArraySize = 1; - T1desc.Format = DXGI_FORMAT_R32G32B32_FLOAT; - T1desc.Usage = D3D11_USAGE_DEFAULT; - T1desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - T1desc.CPUAccessFlags = 0; - T1desc.MiscFlags = 0; - - D3D11_SUBRESOURCE_DATA sphere; - sphere.pSysMem = kernel; - - D3D11_SUBRESOURCE_DATA rnd; - rnd.pSysMem = random; - - - ID3D11Texture1D *pTexture1[2]; - - hr = Oyster::Core::Device->CreateTexture1D( &T1desc, &sphere, &pTexture1[0] ); - hr = Oyster::Core::Device->CreateShaderResourceView( pTexture1[0], 0, &ComputeResources[3] ); - pTexture1[0]->Release(); - delete[] kernel; - - T1desc.Width = SampleSpread; - hr = Oyster::Core::Device->CreateTexture1D( &T1desc, &rnd, &pTexture1[1] ); - hr = Oyster::Core::Device->CreateShaderResourceView( (pTexture1[1]), 0, &ComputeResources[2] ); - pTexture1[1]->Release(); - delete[] random; -} - -void PipeLineResourses::InitSubFrustrums(int sizeX, int sizeY) -{ - FrustrumDimensions.x = (sizeX + 15U) / 16U; - FrustrumDimensions.y = (sizeY + 15U) / 16U; - FrustrumDimensions.z = 1; - FrustrumSize = FrustrumDimensions.x * FrustrumDimensions.y * FrustrumDimensions.z; - //if(SubFrustrums!=0) - //delete[] SubFrustrums; - //SubFrustrums = new Collision3D::Frustrum[ FrustrumSize ]; - - Oyster::Buffer::BUFFER_INIT_DESC desc; - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - - //buffer description for SubFrustrums - desc.Usage = Oyster::Buffer::BUFFER_CPU_WRITE_DISCARD; - desc.Type = Oyster::Buffer::STRUCTURED_BUFFER; - desc.ElementSize = sizeof( ::Oyster::Resources::BufferDefinitions::ScreenTileFrustrum); - desc.NumElements = FrustrumSize; - desc.InitData = NULL; - - //create matching srv - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; - srvDesc.Format = DXGI_FORMAT_UNKNOWN; - srvDesc.Buffer.FirstElement = 0; - srvDesc.Buffer.NumElements = FrustrumSize; - - PipeLineResourses::Resources[0] = Oyster::Engine::Init::Buffers::CreateBuffer(desc); - - HRESULT hr = Oyster::Core::Device->CreateShaderResourceView( *PipeLineResourses::Resources[0], &srvDesc, &Oyster::Resources::PipeLineResourses::ComputeResources[0] ); -} - -void PipeLineResourses::InitPointLights() -{ - D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; - Oyster::Buffer::BUFFER_INIT_DESC desc; - HRESULT hr; - - //buffer description for pointlight - desc.Usage = Oyster::Buffer::BUFFER_CPU_WRITE_DISCARD; - desc.Type = Oyster::Buffer::STRUCTURED_BUFFER; - desc.ElementSize = sizeof(Oyster::Resources::BufferDefinitions::PointLightDescription); - desc.NumElements = Oyster::Engine::States::GetMaxPointlights(); - desc.InitData = NULL; - - PipeLineResourses::Resources[1] = Oyster::Engine::Init::Buffers::CreateBuffer(desc); - - //create matching srv - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; - srvDesc.Format = DXGI_FORMAT_UNKNOWN; - srvDesc.Buffer.FirstElement = 0; - srvDesc.Buffer.NumElements = Oyster::Engine::States::GetMaxPointlights(); - - hr = Oyster::Core::Device->CreateShaderResourceView( *PipeLineResourses::Resources[1], &srvDesc, &Oyster::Resources::PipeLineResourses::ComputeResources[1] ); -} - -void PipeLineResourses::InitLightData() -{ - LightData.numDispatches = FrustrumDimensions; -} - -void PipeLineResourses::InitLighting(int sizeX, int sizeY) -{ - D3D11_TEXTURE2D_DESC Tdesc; - Tdesc.Width = sizeX; - Tdesc.Height = sizeY; - Tdesc.MipLevels = Tdesc.ArraySize = 1; - Tdesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; - Tdesc.SampleDesc.Count = 1; - Tdesc.SampleDesc.Quality=0; - Tdesc.Usage = D3D11_USAGE_DEFAULT; - Tdesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS; - Tdesc.CPUAccessFlags = 0; - Tdesc.MiscFlags = 0; - - ID3D11Texture2D *pTexture; - HRESULT hr; - for(int i = 0; i < 4; ++i ) - { - hr = Oyster::Core::Device->CreateTexture2D( &Tdesc, NULL, &pTexture ); - hr = Oyster::Core::Device->CreateShaderResourceView( pTexture, 0, &(LightOut[i]) ); - hr = Oyster::Core::Device->CreateUnorderedAccessView( pTexture, 0, &(LightTarget[i]) ); - pTexture->Release(); - } - - hr = Oyster::Core::Device->CreateTexture2D( &Tdesc, NULL, &pTexture ); - hr = Oyster::Core::Device->CreateShaderResourceView( pTexture, 0, &TempSrv ); - hr = Oyster::Core::Device->CreateUnorderedAccessView( pTexture, 0, &TempUav ); - pTexture->Release(); -} \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/PipelineResources.h b/Code/OysterGraphics/OldResourses/PipelineResources.h deleted file mode 100644 index 47f89c2d..00000000 --- a/Code/OysterGraphics/OldResourses/PipelineResources.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#ifndef PipeLineResources_H -#define PipeLineResources_H - -#include "..\EngineIncludes.h" - -namespace Oyster -{ - namespace Resources - { - struct PipeLineResourses - { - //0 = Diffuse - //1 = Specular - //2 = Glow - //3 = Pos - //4 = Normal - static ID3D11ShaderResourceView* GeometryOut[5]; - static ID3D11RenderTargetView* GeometryTarget[5]; - - - //0 = TileBuffer - //1 = PointList - //2 = Random - //3 = Sphere - static ID3D11ShaderResourceView* ComputeResources[4]; - static Oyster::Buffer* Resources[2]; - - - //0 = Diffuse - //1 = Specular - //2 = Glow - //3 = SSAO - static ID3D11ShaderResourceView* LightOut[4]; - static ID3D11UnorderedAccessView* LightTarget[4]; - - //0 = BlurTempStorage - static ID3D11UnorderedAccessView* TempUav; - static ID3D11ShaderResourceView* TempSrv; - - static ID3D11RenderTargetView* RtvNulls[16]; - static ID3D11ShaderResourceView* SrvNulls[16]; - static ID3D11UnorderedAccessView* uavNULL[16]; - - //static Oyster::Collision3D::Frustrum* SubFrustrums; - static int FrustrumSize; - static LinearAlgebra::Vector3 FrustrumDimensions; - - static Oyster::Resources::BufferDefinitions::LightStructureBuffer LightData; - - static void Init(int sizeX, int sizeY); - - static void InitGeometry(int sizeX, int sizeY); - - static void InitSSAOData(); - static void InitSubFrustrums(int sizeX, int sizeY); - static void InitPointLights(); - static void InitLightData(); - - static void InitLighting(int sizeX, int sizeY); - }; - } -} - -#endif \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/ShaderEffects.cpp b/Code/OysterGraphics/OldResourses/ShaderEffects.cpp deleted file mode 100644 index 33de3c05..00000000 --- a/Code/OysterGraphics/OldResourses/ShaderEffects.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "ShaderEffects.h" - -namespace Oyster -{ - namespace Resources - { - Core::ShaderManager::ShaderEffect ShaderEffects::BasicSprite = Core::ShaderManager::ShaderEffect(); - Core::ShaderManager::ShaderEffect ShaderEffects::Text2DEffect = Core::ShaderManager::ShaderEffect(); - Core::ShaderManager::ShaderEffect ShaderEffects::ModelEffect = Core::ShaderManager::ShaderEffect(); - - void ShaderEffects::Init() - { - BasicSprite.IAStage.Topology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; - BasicSprite.Shaders.Vertex = Oyster::Core::ShaderManager::Get::Vertex(L"2D"); - BasicSprite.Shaders.Geometry = Oyster::Core::ShaderManager::Get::Geometry(L"2D"); - BasicSprite.Shaders.Pixel = Oyster::Core::ShaderManager::Get::Pixel(L"Texture0"); - - D3D11_BLEND_DESC blendDesc; - blendDesc.AlphaToCoverageEnable=false; - blendDesc.IndependentBlendEnable=false; - blendDesc.RenderTarget[0].BlendEnable=true; - - blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - - blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; - blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MAX; - - blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - - ID3D11BlendState* blender; - - Oyster::Core::Device->CreateBlendState(&blendDesc,&blender); - - BasicSprite.RenderStates.BlendState = blender; - - ID3D11InputLayout* layout; - - Oyster::Core::ShaderManager::CreateInputLayout(SpriteVertexDesc,1,Oyster::Core::ShaderManager::Get::Vertex(L"2D"),layout); - - BasicSprite.IAStage.Layout = layout; - - Text2DEffect.IAStage.Topology=D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; - Text2DEffect.Shaders.Vertex = Oyster::Core::ShaderManager::Get::Vertex(L"Text"); - Text2DEffect.Shaders.Geometry = Oyster::Core::ShaderManager::Get::Geometry(L"Text"); - Text2DEffect.Shaders.Pixel = Oyster::Core::ShaderManager::Get::Pixel(L"Texture0"); - - Oyster::Core::ShaderManager::CreateInputLayout(Text2DDesc,3,Oyster::Core::ShaderManager::Get::Vertex(L"Text"),layout); - - Text2DEffect.IAStage.Layout = layout; - - blendDesc.AlphaToCoverageEnable = true; - Oyster::Core::Device->CreateBlendState(&blendDesc,&blender); - Text2DEffect.RenderStates.BlendState = blender; - - ModelEffect.IAStage.Topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; - Oyster::Core::ShaderManager::CreateInputLayout(ModelDesc,3,Oyster::Core::ShaderManager::Get::Vertex(L"OBJ"),layout); - ModelEffect.IAStage.Layout = layout; - - ModelEffect.Shaders.Vertex = Oyster::Core::ShaderManager::Get::Vertex(L"OBJ"); - ModelEffect.Shaders.Pixel = Oyster::Core::ShaderManager::Get::Pixel(L"OBJDEF"); - - Oyster::Buffer::BUFFER_INIT_DESC desc; - - desc.ElementSize=sizeof(Oyster::Math::Float4x4); - desc.NumElements = 1; - desc.Usage = Oyster::Buffer::BUFFER_CPU_WRITE_DISCARD; - desc.Type = Oyster::Buffer::CONSTANT_BUFFER_VS; - desc.InitData = NULL; - - ModelEffect.CBuffers.Vertex.push_back(Oyster::Engine::Init::Buffers::CreateBuffer(desc)); - ModelEffect.CBuffers.Vertex.push_back(Oyster::Engine::Init::Buffers::CreateBuffer(desc)); - - //use Oyster::Resources::Buffers::CbufferVS for per object data - //perObject = Oyster::Engine::Init::Buffers::CreateBuffer(desc); - - } - - D3D11_INPUT_ELEMENT_DESC ShaderEffects::SpriteVertexDesc[1] = - { - {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, - }; - - D3D11_INPUT_ELEMENT_DESC ShaderEffects::Text2DDesc[3] = - { - {"Position",0, DXGI_FORMAT_R32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"Offset",0, DXGI_FORMAT_R32_SINT, 0, 4, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"CharOffset",0, DXGI_FORMAT_R32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0}, - }; - - D3D11_INPUT_ELEMENT_DESC ShaderEffects::ModelDesc[3] = - { - {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0}, - }; - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/OldResourses/ShaderEffects.h b/Code/OysterGraphics/OldResourses/ShaderEffects.h deleted file mode 100644 index 766d63a9..00000000 --- a/Code/OysterGraphics/OldResourses/ShaderEffects.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "../Engine.h" -#include "Buffers.h" - -namespace Oyster -{ - namespace Resources - { - struct ShaderEffects - { - static Oyster::Core::ShaderManager::ShaderEffect BasicSprite; - static Oyster::Core::ShaderManager::ShaderEffect Text2DEffect; - static Oyster::Core::ShaderManager::ShaderEffect ModelEffect; - - static void Init(); - - static D3D11_INPUT_ELEMENT_DESC SpriteVertexDesc[1]; - static D3D11_INPUT_ELEMENT_DESC Text2DDesc[3]; - static D3D11_INPUT_ELEMENT_DESC ModelDesc[3]; - }; - } -} \ No newline at end of file diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj b/Code/OysterGraphics/OysterGraphics.vcxproj index e9b8ff72..f0bcb60b 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj +++ b/Code/OysterGraphics/OysterGraphics.vcxproj @@ -206,19 +206,41 @@ - + + Geometry + 5.0 + Geometry + 4.0 + Geometry + 4.0 + Geometry + 4.0 + + + Pixel + Pixel + Pixel + Pixel + + + Vertex + Vertex + Vertex + Vertex + + Compute Compute Compute Compute - + Pixel Pixel Pixel Pixel - + Compute 5.0 Compute @@ -228,7 +250,7 @@ Compute 5.0 - + Vertex Vertex Vertex @@ -273,11 +295,12 @@ - - - - - + + + + + + diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.filters b/Code/OysterGraphics/OysterGraphics.vcxproj.filters index 11d05dde..d53ddc07 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.filters +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.filters @@ -45,10 +45,10 @@ Source Files - + Source Files - + Source Files @@ -86,24 +86,27 @@ Header Files - - Header Files - - - - + + + + + + + - - - - + + + + + + \ No newline at end of file diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index d44eeedc..24059331 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -158,7 +158,6 @@ namespace Oyster for(int b = 0; b < info->BoneCount; ++b) { am.AnimatedData[b] = (BoneAbsAnimated[b] * SkinTransform[b]); - am.BindPoseData[b] = info->bones[b].Absolute;//Math3D::ExtractRotationMatrix(am.animatedData[b]); } //retore to draw animated model diff --git a/Code/OysterGraphics/Render/Resources/Deffered.cpp b/Code/OysterGraphics/Render/Resources/Deffered.cpp index 8313bf0f..c922a826 100644 --- a/Code/OysterGraphics/Render/Resources/Deffered.cpp +++ b/Code/OysterGraphics/Render/Resources/Deffered.cpp @@ -8,7 +8,7 @@ typedef Oyster::Graphics::Core::PipelineManager::Get GetShader; typedef Oyster::Graphics::Core::PipelineManager Shader; typedef Oyster::Graphics::Core::Buffer Buffer; -const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\Deffered Shaders\\"; +const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\Passes\\"; const std::wstring PathToCSO = L"..\\Content\\Shaders\\"; const int KernelSize = 10; @@ -32,10 +32,12 @@ namespace Oyster Shader::RenderPass Deffered::GeometryPass; Shader::RenderPass Deffered::LightPass; Shader::RenderPass Deffered::PostPass; + Shader::RenderPass Deffered::GuiPass; Buffer Deffered::ModelData = Buffer(); Buffer Deffered::AnimationData = Buffer(); Buffer Deffered::LightConstantsData = Buffer(); + Buffer Deffered::GuiData = Buffer(); Buffer Deffered::PointLightsData = Buffer(); ID3D11ShaderResourceView* Deffered::PointLightView = NULL; @@ -46,18 +48,31 @@ namespace Oyster Core::Init::State Deffered::InitShaders() { - #ifdef _DEBUG - std::wstring path = PathToHLSL; +#ifdef _DEBUG + std::wstring path = PathToHLSL+L"Gather\\"; std::wstring end = L".hlsl"; #else std::wstring path = PathToCSO; std::wstring end = L".cso"; #endif //Load Shaders - Core::PipelineManager::Init(path + L"PixelGatherData" + end, ShaderType::Pixel, L"Geometry"); - Core::PipelineManager::Init(path + L"VertexGatherData" + end, ShaderType::Vertex, L"Geometry"); + Core::PipelineManager::Init(path + L"GatherPixel" + end, ShaderType::Pixel, L"Gather"); + Core::PipelineManager::Init(path + L"GatherVertex" + end, ShaderType::Vertex, L"Gather"); +#ifdef _DEBUG + path = PathToHLSL+L"Light\\"; +#endif Core::PipelineManager::Init(path + L"LightPass" + end, ShaderType::Compute, L"LightPass"); - Core::PipelineManager::Init(path + L"PostPass" + end, ShaderType::Compute, L"PostPass"); +#ifdef _DEBUG + path = PathToHLSL+L"Post\\"; +#endif + Core::PipelineManager::Init(path + L"PostPass" + end, ShaderType::Compute, L"PostPass"); +#ifdef _DEBUG + path = PathToHLSL+L"2D\\"; +#endif + Core::PipelineManager::Init(path + L"2DVertex" + end,ShaderType::Vertex, L"2D"); + Core::PipelineManager::Init(path + L"2DGeometry" + end,ShaderType::Geometry, L"2D"); + Core::PipelineManager::Init(path + L"2DPixel" + end,ShaderType::Pixel, L"2D"); + return Core::Init::State::Success; } @@ -79,6 +94,10 @@ namespace Oyster desc.ElementSize = sizeof(Definitions::AnimationData); AnimationData.Init(desc); + desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_GS; + desc.NumElements = 1; + desc.ElementSize = sizeof(Definitions::GuiData); + desc.ElementSize = sizeof(Definitions::LightConstants); desc.NumElements = 1; desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_CS; @@ -240,8 +259,8 @@ namespace Oyster ////Create ShaderEffects ////---------------- Geometry Pass Setup ---------------------------- - GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Geometry"); - GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Geometry"); + GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Gather"); + GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Gather"); D3D11_INPUT_ELEMENT_DESC indesc[] = { @@ -254,7 +273,7 @@ namespace Oyster { "BONEWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 72, D3D11_INPUT_PER_VERTEX_DATA, 0 } }; - Shader::CreateInputLayout(indesc,7,GetShader::Vertex(L"Geometry"),GeometryPass.IAStage.Layout); + Shader::CreateInputLayout(indesc,7,GetShader::Vertex(L"Gather"),GeometryPass.IAStage.Layout); GeometryPass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; GeometryPass.CBuffers.Vertex.push_back(AnimationData); GeometryPass.CBuffers.Vertex.push_back(ModelData); @@ -262,7 +281,7 @@ namespace Oyster GeometryPass.RenderStates.SampleCount = 1; GeometryPass.RenderStates.SampleState = ss; GeometryPass.RenderStates.DepthStencil = dsState; - for(int i = 0; i Quads) +{ + Pixel2DIn output; + output.Pos = mul(float4(-1,-1,0,1) ,Translation); + output.Uv = float2(0,1); + Quads.Append(output); + + output.Pos = mul(float4(-1,1,0,1), Translation); + output.Uv = float2(0,0); + Quads.Append(output); + + output.Pos = mul(float4(1,-1,0,1), Translation); + output.Uv = float2(1,1); + Quads.Append(output); + + output.Pos = mul(float4(1,1,0,1), Translation); + output.Uv = float2(1,0); + Quads.Append(output); +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl b/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl new file mode 100644 index 00000000..a09111b9 --- /dev/null +++ b/Code/OysterGraphics/Shader/Passes/2D/2DPixel.hlsl @@ -0,0 +1,6 @@ +#include "Header.hlsli" + +float4 main(Pixel2DIn input) : SV_Target0 +{ + return Material.Sample(LinearSampler,input.Uv); +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/2D/2DVertex.hlsl b/Code/OysterGraphics/Shader/Passes/2D/2DVertex.hlsl new file mode 100644 index 00000000..447d3535 --- /dev/null +++ b/Code/OysterGraphics/Shader/Passes/2D/2DVertex.hlsl @@ -0,0 +1,6 @@ +#include "Header.hlsli" + +Vertex2DIn main(Vertex2DIn input) +{ + return input; +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli b/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli new file mode 100644 index 00000000..5a026d34 --- /dev/null +++ b/Code/OysterGraphics/Shader/Passes/2D/Header.hlsli @@ -0,0 +1,18 @@ +struct Vertex2DIn +{ + float2 Pos : Position; +}; + +cbuffer EveryObject2D : register(c0) +{ + float4x4 Translation; +}; + +struct Pixel2DIn +{ + float4 Pos : SV_Position; + float2 Uv : TEXCOORD; +}; + +Texture2D Material : register(t0); +SamplerState LinearSampler : register(s0); \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PixelGatherData.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl similarity index 86% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PixelGatherData.hlsl rename to Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl index cad03013..b0a2f40f 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PixelGatherData.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherPixel.hlsl @@ -1,4 +1,4 @@ -#include "GBufferHeader.hlsli" +#include "Header.hlsli" PixelOut main(VertexOut input) { diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl b/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl similarity index 67% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl rename to Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl index 7880d66e..4042c224 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/VertexGatherData.hlsl +++ b/Code/OysterGraphics/Shader/Passes/Gather/GatherVertex.hlsl @@ -1,14 +1,9 @@ -#include "GBufferHeader.hlsli" +#include "Header.hlsli" VertexOut main( VertexIn input ) { VertexOut output; - float3 offsetX = input.pos - BindPoseData[input.boneIndex.x][3].xyz; - float3 offsetY = input.pos - BindPoseData[input.boneIndex.y][3].xyz; - float3 offsetZ = input.pos - BindPoseData[input.boneIndex.z][3].xyz; - float3 offsetW = input.pos - BindPoseData[input.boneIndex.w][3].xyz; - Matrix boneTrans = AnimatedData[input.boneIndex.x]*input.boneWeight.x + AnimatedData[input.boneIndex.y]*input.boneWeight.y + AnimatedData[input.boneIndex.z]*input.boneWeight.z + diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli similarity index 92% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli rename to Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli index b87b7235..06583cd6 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/GBufferHeader.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Gather/Header.hlsli @@ -33,8 +33,6 @@ SamplerState S1 : register(s0); cbuffer Animation : register(b0) { float4x4 AnimatedData[100]; - float4x4 BindPoseData[100]; - float4x4 RotationData[100]; int Animated; float3 Pad; } diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli b/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli similarity index 71% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli rename to Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli index 1f1061d1..adf01e9d 100644 --- a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Defines.hlsli +++ b/Code/OysterGraphics/Shader/Passes/Light/Defines.hlsli @@ -27,12 +27,13 @@ cbuffer LightConstants : register(b0) Texture2D DiffuseGlow : register(t0); Texture2D NormalSpec : register(t1); -Texture2D DepthTexture : register(t2); +Texture2D GUI : register(t2); +Texture2D DepthTexture : register(t3); -StructuredBuffer Points : register(t3); +StructuredBuffer Points : register(t4); -Texture1D SSAOKernel : register(t4); -Texture2D SSAORand : register(t5); +Texture1D SSAOKernel : register(t5); +Texture2D SSAORand : register(t6); RWTexture2D Diffuse : register(u0); RWTexture2D Specular : register(u1); diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli b/Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli similarity index 100% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightCalc.hlsli rename to Code/OysterGraphics/Shader/Passes/Light/LightCalc.hlsli diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl b/Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl similarity index 100% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/LightPass.hlsl rename to Code/OysterGraphics/Shader/Passes/Light/LightPass.hlsl diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PosManipulation.hlsli b/Code/OysterGraphics/Shader/Passes/Light/PosManipulation.hlsli similarity index 100% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PosManipulation.hlsli rename to Code/OysterGraphics/Shader/Passes/Light/PosManipulation.hlsli diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli b/Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli similarity index 100% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/SSAO.hlsli rename to Code/OysterGraphics/Shader/Passes/Light/SSAO.hlsli diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl b/Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl similarity index 100% rename from Code/OysterGraphics/Shader/HLSL/Deffered Shaders/PostPass.hlsl rename to Code/OysterGraphics/Shader/Passes/Post/PostPass.hlsl