diff --git a/Code/OysterGraphics/Core/Buffer.cpp b/Code/OysterGraphics/Core/Buffer.cpp index 87eb9c3e..b34dd9c4 100644 --- a/Code/OysterGraphics/Core/Buffer.cpp +++ b/Code/OysterGraphics/Core/Buffer.cpp @@ -1,19 +1,18 @@ -#include "Buffer.h" #include "Core.h" using namespace Oyster::Graphics; -Buffer::Buffer() +Core::Buffer::Buffer() { mBuffer = NULL; } -Buffer::~Buffer() +Core::Buffer::~Buffer() { SAFE_RELEASE(mBuffer); } -HRESULT Buffer::Apply(UINT32 misc) const +HRESULT Core::Buffer::Apply(UINT32 misc) const { HRESULT hr = S_OK; @@ -59,7 +58,7 @@ HRESULT Buffer::Apply(UINT32 misc) const return hr; } -HRESULT Buffer::Init(const BUFFER_INIT_DESC& initDesc) +HRESULT Core::Buffer::Init(const BUFFER_INIT_DESC& initDesc) { D3D11_BUFFER_DESC bufferDesc; @@ -154,13 +153,13 @@ HRESULT Buffer::Init(const BUFFER_INIT_DESC& initDesc) if(FAILED(hr)) { - MessageBox(NULL, L"Unable to create buffer.", L"Slenda Error", MB_ICONERROR | MB_OK); + //MessageBox(NULL, L"Unable to create buffer.", L"Slenda Error", MB_ICONERROR | MB_OK); } return hr; } -void* Buffer::Map() +void* Core::Buffer::Map() { void* ret = NULL; if(mUsage == BUFFER_CPU_WRITE || mUsage == BUFFER_CPU_READ || mUsage == BUFFER_CPU_WRITE_DISCARD) @@ -192,17 +191,17 @@ void* Buffer::Map() } -void Buffer::Unmap() +void Core::Buffer::Unmap() { Core::deviceContext->Unmap( mBuffer, 0 ); } -Buffer::operator ID3D11Buffer *() +Core::Buffer::operator ID3D11Buffer *() { return this->mBuffer; } -Buffer::operator const ID3D11Buffer *() const +Core::Buffer::operator const ID3D11Buffer *() const { return this->mBuffer; } \ No newline at end of file diff --git a/Code/OysterGraphics/Core/Buffer.h b/Code/OysterGraphics/Core/Buffer.h deleted file mode 100644 index 1a52d3f8..00000000 --- a/Code/OysterGraphics/Core/Buffer.h +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once -#ifndef CoreBuffer -#define CoreBuffer - -#include "CoreIncludes.h" - -namespace Oyster -{ - namespace Graphics - { - class Buffer - { - public: - enum BUFFER_TYPE - { - VERTEX_BUFFER, - INDEX_BUFFER, - CONSTANT_BUFFER_VS, - CONSTANT_BUFFER_GS, - CONSTANT_BUFFER_PS, - CONSTANT_BUFFER_CS, - STRUCTURED_BUFFER, - BUFFER_TYPE_COUNT - }; - - enum BUFFER_USAGE - { - BUFFER_DEFAULT, - BUFFER_STREAM_OUT_TARGET, - BUFFER_CPU_WRITE, - BUFFER_CPU_WRITE_DISCARD, - BUFFER_CPU_READ, - BUFFER_USAGE_COUNT, - BUFFER_USAGE_IMMUTABLE - }; - - struct BUFFER_INIT_DESC - { - BUFFER_TYPE Type; - UINT32 NumElements; - UINT32 ElementSize; - BUFFER_USAGE Usage; - void* InitData; - - BUFFER_INIT_DESC() - { - InitData = NULL; - Usage = BUFFER_DEFAULT; - } - }; - protected: - ID3D11Buffer* mBuffer; - BUFFER_TYPE mType; - BUFFER_USAGE mUsage; - - UINT32 mElementSize; - UINT32 mElementCount; - public: - Buffer(); - virtual ~Buffer(); - - HRESULT Init(const BUFFER_INIT_DESC& initDesc); - - void* Map(); - void Unmap(); - - operator ID3D11Buffer*(); - operator const ID3D11Buffer*() const; - - HRESULT Apply(UINT32 misc = 0) const; - - ID3D11Buffer* GetBufferPointer(); - UINT32 GetVertexSize(); - UINT32 GetElementCount(); - }; - } -} - -#endif \ No newline at end of file diff --git a/Code/OysterGraphics/Core/Core.h b/Code/OysterGraphics/Core/Core.h index bc93777f..fa56c7b9 100644 --- a/Code/OysterGraphics/Core/Core.h +++ b/Code/OysterGraphics/Core/Core.h @@ -6,7 +6,6 @@ #include "CoreIncludes.h" #include -#include "Buffer.h" #include "OysterMath.h" namespace Oyster @@ -35,6 +34,72 @@ namespace Oyster static D3D11_VIEWPORT* viewPort; static Oyster::Math::Float2 resolution; + + class Buffer + { + public: + enum BUFFER_TYPE + { + VERTEX_BUFFER, + INDEX_BUFFER, + CONSTANT_BUFFER_VS, + CONSTANT_BUFFER_GS, + CONSTANT_BUFFER_PS, + CONSTANT_BUFFER_CS, + STRUCTURED_BUFFER, + BUFFER_TYPE_COUNT + }; + + enum BUFFER_USAGE + { + BUFFER_DEFAULT, + BUFFER_STREAM_OUT_TARGET, + BUFFER_CPU_WRITE, + BUFFER_CPU_WRITE_DISCARD, + BUFFER_CPU_READ, + BUFFER_USAGE_COUNT, + BUFFER_USAGE_IMMUTABLE + }; + + struct BUFFER_INIT_DESC + { + BUFFER_TYPE Type; + UINT32 NumElements; + UINT32 ElementSize; + BUFFER_USAGE Usage; + void* InitData; + + BUFFER_INIT_DESC() + { + InitData = NULL; + Usage = BUFFER_DEFAULT; + } + }; + protected: + ID3D11Buffer* mBuffer; + BUFFER_TYPE mType; + BUFFER_USAGE mUsage; + + UINT32 mElementSize; + UINT32 mElementCount; + public: + Buffer(); + virtual ~Buffer(); + + HRESULT Init(const BUFFER_INIT_DESC& initDesc); + + void* Map(); + void Unmap(); + + operator ID3D11Buffer*(); + operator const ID3D11Buffer*() const; + + HRESULT Apply(UINT32 misc = 0) const; + + ID3D11Buffer* GetBufferPointer(); + UINT32 GetVertexSize(); + UINT32 GetElementCount(); + }; class ShaderManager diff --git a/Code/OysterGraphics/Definitions/GraphicalDefinition.h b/Code/OysterGraphics/Definitions/GraphicalDefinition.h index 8a254fe5..88f63fe2 100644 --- a/Code/OysterGraphics/Definitions/GraphicalDefinition.h +++ b/Code/OysterGraphics/Definitions/GraphicalDefinition.h @@ -19,6 +19,18 @@ namespace Oyster Oyster::Math::Matrix V; Oyster::Math::Matrix P; }; + + struct FinalVertex + { + Oyster::Math::Float3 pos; + Oyster::Math::Float2 uv; + Oyster::Math::Float3 normal; + Oyster::Math::Float3 tangent; + Oyster::Math::Float3 biTangent; + Oyster::Math::Float4 boneIndex; + Oyster::Math::Float4 boneWeights; + }; + } } } \ No newline at end of file diff --git a/Code/OysterGraphics/DllInterfaces/SimpleInterface.h b/Code/OysterGraphics/DllInterfaces/SimpleInterface.h index 8475b6f7..a2591956 100644 --- a/Code/OysterGraphics/DllInterfaces/SimpleInterface.h +++ b/Code/OysterGraphics/DllInterfaces/SimpleInterface.h @@ -19,11 +19,11 @@ public: State Init(HWND Window, bool MSAA_Quality, bool Fullscreen); //! @brief from Oyster::Math Float4x4, expects corect methods static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection); - static void RenderScene(Oyster::Graphics::Render::Model* models, int count); + static void RenderScene(Oyster::Graphics::Model::Model* models, int count); static void EndFrame(); - static Oyster::Graphics::Render::Model* CreateModel(std::wstring filename); + static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename); + static void DeleteModel(Oyster::Graphics::Model::Model* model); static State SetOptions(Option); - }; diff --git a/Code/OysterGraphics/FileLoader/ObjReader.cpp b/Code/OysterGraphics/FileLoader/ObjReader.cpp index 4077a7dc..22a2ec2f 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.cpp +++ b/Code/OysterGraphics/FileLoader/ObjReader.cpp @@ -1,6 +1,5 @@ #include "OBJReader.h" #include "..\Definitions\GraphicalDefinition.h" -#include "..\Core\Buffer.h" #include #include @@ -96,17 +95,17 @@ void OBJReader::readOBJFile( std::wstring fileName ) inStream.close(); } -Oyster::Graphics::Render::ModelInfo* OBJReader::toModel() +Oyster::Graphics::Model::ModelInfo* OBJReader::toModel() { - Oyster::Graphics::Buffer* b = new Oyster::Graphics::Buffer(); - Oyster::Graphics::Buffer::BUFFER_INIT_DESC desc; - Oyster::Graphics::Render::ModelInfo* modelInfo = new Oyster::Graphics::Render::ModelInfo(); + Oyster::Graphics::Core::Buffer* b = new Oyster::Graphics::Core::Buffer(); + Oyster::Graphics::Core::Buffer::BUFFER_INIT_DESC desc; + Oyster::Graphics::Model::ModelInfo* modelInfo = new Oyster::Graphics::Model::ModelInfo(); desc.ElementSize = 32; desc.InitData = &this->_myOBJ[0]; desc.NumElements = this->_myOBJ.size(); - desc.Type = Oyster::Graphics::Buffer::BUFFER_TYPE::VERTEX_BUFFER; - desc.Usage = Oyster::Graphics::Buffer::BUFFER_DEFAULT; + desc.Type = Oyster::Graphics::Core::Buffer::BUFFER_TYPE::VERTEX_BUFFER; + desc.Usage = Oyster::Graphics::Core::Buffer::BUFFER_DEFAULT; HRESULT hr = S_OK; hr = b->Init(desc); diff --git a/Code/OysterGraphics/FileLoader/ObjReader.h b/Code/OysterGraphics/FileLoader/ObjReader.h index 6760ac09..ed579023 100644 --- a/Code/OysterGraphics/FileLoader/ObjReader.h +++ b/Code/OysterGraphics/FileLoader/ObjReader.h @@ -49,7 +49,7 @@ class OBJReader ~OBJReader(); void readOBJFile( std::wstring fileName); - Oyster::Graphics::Render::ModelInfo* toModel(); + Oyster::Graphics::Model::ModelInfo* toModel(); }; #endif \ No newline at end of file diff --git a/Code/OysterGraphics/Model/Model.h b/Code/OysterGraphics/Model/Model.h index df8f82b8..e24b420a 100644 --- a/Code/OysterGraphics/Model/Model.h +++ b/Code/OysterGraphics/Model/Model.h @@ -2,22 +2,16 @@ #ifndef Mesh_h #define Mesh_h -#include "ModelInfo.h" - - namespace Oyster { namespace Graphics { - namespace Render + namespace Model { struct Model { - - void* const info; - //ModelInfo* info; - void* data; - int size; + void* info; + Oyster::Math::Float4x4 WorldMatrix; bool Visible; }; } diff --git a/Code/OysterGraphics/Model/ModelInfo.h b/Code/OysterGraphics/Model/ModelInfo.h index 91a8cf45..6c1d0cfe 100644 --- a/Code/OysterGraphics/Model/ModelInfo.h +++ b/Code/OysterGraphics/Model/ModelInfo.h @@ -3,19 +3,18 @@ #define MODELINFO_h -#include "..\Core\CoreIncludes.h" -#include "..\Core\Buffer.h" +#include "..\Core\Core.h" namespace Oyster { namespace Graphics { - namespace Render + namespace Model { struct ModelInfo { std::vector Material; - Buffer *Vertices,*Indecies; + Core::Buffer *Vertices,*Indecies; bool Indexed; int VertexCount; }; diff --git a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp index c43e165c..cbefee45 100644 --- a/Code/OysterGraphics/Render/Rendering/BasicRender.cpp +++ b/Code/OysterGraphics/Render/Rendering/BasicRender.cpp @@ -1,6 +1,7 @@ #include "Render.h" #include "../Resources/Resources.h" #include "../../Definitions/GraphicalDefinition.h" +#include "../../Model/ModelInfo.h" namespace Oyster { @@ -28,27 +29,30 @@ namespace Oyster Resources::VPData.Apply(); } - void Basic::RenderScene(Model* models, int count) + void Basic::RenderScene(Model::Model* models, int count) { for(int i = 0; i < count; ++i) { if(models[i].Visible) { void* data = Resources::ModelData.Map(); - memcpy(data,&(models[i].data),64); + memcpy(data,&(models[i].WorldMatrix),64); Resources::ModelData.Unmap(); //Set Materials :: NONE - models[i].info->Vertices->Apply(); - if(models[i].info->Indexed) + Model + ::ModelInfo* info = (Model::ModelInfo*)models[i].info; + + info->Vertices->Apply(); + if(info->Indexed) { - models[i].info->Indecies->Apply(); - Oyster::Graphics::Core::deviceContext->DrawIndexed(models[i].info->VertexCount,0,0); + info->Indecies->Apply(); + Oyster::Graphics::Core::deviceContext->DrawIndexed(info->VertexCount,0,0); } else { - Oyster::Graphics::Core::deviceContext->Draw(models[i].info->VertexCount,0); + Oyster::Graphics::Core::deviceContext->Draw(info->VertexCount,0); } } } diff --git a/Code/OysterGraphics/Render/Rendering/Render.h b/Code/OysterGraphics/Render/Rendering/Render.h index 1764ba3d..5aa61742 100644 --- a/Code/OysterGraphics/Render/Rendering/Render.h +++ b/Code/OysterGraphics/Render/Rendering/Render.h @@ -17,7 +17,7 @@ namespace Oyster public: static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection); - static void RenderScene(Model* models, int count); + static void RenderScene(Model::Model* models, int count); static void EndFrame(); }; } diff --git a/Code/OysterGraphics/Render/Resources/Resources.cpp b/Code/OysterGraphics/Render/Resources/Resources.cpp index da372888..80dc5975 100644 --- a/Code/OysterGraphics/Render/Resources/Resources.cpp +++ b/Code/OysterGraphics/Render/Resources/Resources.cpp @@ -11,6 +11,7 @@ const std::wstring PixelRed = L"DebugPixel"; typedef Oyster::Graphics::Core::ShaderManager::ShaderType ShaderType; typedef Oyster::Graphics::Core::ShaderManager::Get GetShader; typedef Oyster::Graphics::Core::ShaderManager Shader; +typedef Oyster::Graphics::Core::Buffer Buffer; namespace Oyster { @@ -99,7 +100,6 @@ namespace Oyster obj.RenderStates.Rasterizer = rs; #pragma endregion - return Core::Init::Sucsess; } } diff --git a/Code/OysterGraphics/Render/Resources/Resources.h b/Code/OysterGraphics/Render/Resources/Resources.h index dc10c8e8..daf77760 100644 --- a/Code/OysterGraphics/Render/Resources/Resources.h +++ b/Code/OysterGraphics/Render/Resources/Resources.h @@ -16,8 +16,8 @@ namespace Oyster { public: static Core::ShaderManager::ShaderEffect obj; - static Buffer ModelData; - static Buffer VPData; + static Core::Buffer ModelData; + static Core::Buffer VPData; static Core::Init::State Init(); }; diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Gather/PixelGatherData.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Gather/PixelGatherData.hlsl new file mode 100644 index 00000000..501771e7 --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Gather/PixelGatherData.hlsl @@ -0,0 +1,25 @@ +struct VertexOut +{ + float4 pos : SV_POSITION; + float4 ViewPos: POSITION; + float2 UV : TEXCOORD; + float4 normal : NORMAL; +}; + +struct PixelOut +{ + float4 Diffuse3Glow1 : SV_TARGET0; + float4 Normal3Specular1 : SV_TARGET1; + float4 VPos : SV_TARGET2; +}; + +Texture2D Diffuse; +Texture2D Specular; + +PixelOut main(VertexOut input) +{ + PixelOut output; + output.Diffuse3Glow1 = float4(1.0f, 0.0f, 0.0f, 1.0f); + output.Normal3Specular1 = float4(input.normal, 1.0f); + return output; +} \ No newline at end of file diff --git a/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Gather/VertexGatherData.hlsl b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Gather/VertexGatherData.hlsl new file mode 100644 index 00000000..6844635a --- /dev/null +++ b/Code/OysterGraphics/Shader/HLSL/Deffered Shaders/Gather/VertexGatherData.hlsl @@ -0,0 +1,37 @@ +cbuffer PerFrame : register(b0) +{ + matrix View; + float4x4 Projection; + matrix VP; +} + +cbuffer PerModel : register(b1) +{ + matrix World; +} + +struct VertexIn +{ + float3 pos : POSITION; + float2 UV : TEXCOORD; + float3 normal : NORMAL; +}; + +struct VertexOut +{ + float4 pos : SV_POSITION; + float4 ViewPos: POSITION; + float2 UV : TEXCOORD; + float4 normal : NORMAL; +}; + +VertexOut main( VertexIn input ) +{ + VertexOut output; + matrix WV = mul(View, World); + output.ViewPos = mul(WV, float4(input.pos,1)); + output.pos = mul(Projection, output.ViewPos); + output.UV = input.UV; + output.normal = float4(input.normal, 0); + return output; +} \ No newline at end of file diff --git a/Code/Tester/MainTest.cpp b/Code/Tester/MainTest.cpp index db2a567f..aa0ade78 100644 --- a/Code/Tester/MainTest.cpp +++ b/Code/Tester/MainTest.cpp @@ -19,7 +19,7 @@ //-------------------------------------------------------------------------------------- HINSTANCE g_hInst = NULL; HWND g_hWnd = NULL; -Oyster::Graphics::Render::Model* m = new Oyster::Graphics::Render::Model(); +Oyster::Graphics::Model::Model* m = new Oyster::Graphics::Model::Model(); Oyster::Math::Float4x4 V; Oyster::Math::Float4x4 P; @@ -178,7 +178,8 @@ HRESULT InitDirect3D() #pragma region Obj OBJReader or; or.readOBJFile(L"bth.obj"); - m->info = or.toModel(); + m->info = (void*)or.toModel(); + m->Visible=true; #pragma endregion //*((Oyster::Math::Matrix)m->data) = Oyster::Math::Matrix::identity;