Deffered Render Update
This commit is contained in:
parent
fb51881fab
commit
6f48e6a13a
|
@ -205,3 +205,13 @@ Core::Buffer::operator const ID3D11Buffer *() const
|
||||||
{
|
{
|
||||||
return this->mBuffer;
|
return this->mBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UINT32 Core::Buffer::GetElementCount()
|
||||||
|
{
|
||||||
|
return this->mElementCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT32 Core::Buffer::GetVertexSize()
|
||||||
|
{
|
||||||
|
return this->mElementSize;
|
||||||
|
}
|
|
@ -20,7 +20,12 @@ ID3D11RenderTargetView* Core::backBufferRTV = NULL;
|
||||||
ID3D11UnorderedAccessView* Core::backBufferUAV = NULL;
|
ID3D11UnorderedAccessView* Core::backBufferUAV = NULL;
|
||||||
|
|
||||||
ID3D11DepthStencilView* Core::depthStencil = NULL;
|
ID3D11DepthStencilView* Core::depthStencil = NULL;
|
||||||
|
ID3D11ShaderResourceView* Core::depthStencilUAV = NULL;
|
||||||
|
|
||||||
D3D11_VIEWPORT* Core::viewPort = NULL;
|
D3D11_VIEWPORT* Core::viewPort = NULL;
|
||||||
|
|
||||||
Oyster::Math::Float2 Core::resolution = Oyster::Math::Float2::null;
|
Oyster::Math::Float2 Core::resolution = Oyster::Math::Float2::null;
|
||||||
|
|
||||||
|
ID3D11ShaderResourceView* Core::srvNULL[16] = {0};
|
||||||
|
ID3D11RenderTargetView* Core::rtvNULL[8] = {0};
|
||||||
|
ID3D11UnorderedAccessView* Core::uavNULL[8] = {0};
|
|
@ -30,11 +30,16 @@ namespace Oyster
|
||||||
static ID3D11UnorderedAccessView* backBufferUAV;
|
static ID3D11UnorderedAccessView* backBufferUAV;
|
||||||
//DepthStencil
|
//DepthStencil
|
||||||
static ID3D11DepthStencilView* depthStencil;
|
static ID3D11DepthStencilView* depthStencil;
|
||||||
|
static ID3D11ShaderResourceView* depthStencilUAV;
|
||||||
//ViewPort
|
//ViewPort
|
||||||
static D3D11_VIEWPORT* viewPort;
|
static D3D11_VIEWPORT* viewPort;
|
||||||
|
|
||||||
static Oyster::Math::Float2 resolution;
|
static Oyster::Math::Float2 resolution;
|
||||||
|
|
||||||
|
static ID3D11ShaderResourceView* srvNULL[16];
|
||||||
|
static ID3D11RenderTargetView* rtvNULL[8];
|
||||||
|
static ID3D11UnorderedAccessView* uavNULL[8];
|
||||||
|
|
||||||
class Buffer
|
class Buffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -102,10 +107,10 @@ namespace Oyster
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ShaderManager
|
class PipelineManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct ShaderEffect
|
struct RenderPass
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -125,16 +130,36 @@ namespace Oyster
|
||||||
ID3D11SamplerState **SampleState;
|
ID3D11SamplerState **SampleState;
|
||||||
int SampleCount;
|
int SampleCount;
|
||||||
ID3D11BlendState *BlendState;
|
ID3D11BlendState *BlendState;
|
||||||
|
|
||||||
}RenderStates;
|
}RenderStates;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
std::vector<Buffer*> Vertex;
|
std::vector<ID3D11Buffer*> Vertex;
|
||||||
std::vector<Buffer*> Geometry;
|
std::vector<ID3D11Buffer*> Geometry;
|
||||||
std::vector<Buffer*> Pixel;
|
std::vector<ID3D11Buffer*> Pixel;
|
||||||
|
std::vector<ID3D11Buffer*> Compute;
|
||||||
}CBuffers;
|
}CBuffers;
|
||||||
|
|
||||||
ShaderEffect()
|
struct
|
||||||
|
{
|
||||||
|
std::vector<ID3D11ShaderResourceView*> Vertex;
|
||||||
|
std::vector<ID3D11ShaderResourceView*> Geometry;
|
||||||
|
std::vector<ID3D11ShaderResourceView*> Pixel;
|
||||||
|
std::vector<ID3D11ShaderResourceView*> Compute;
|
||||||
|
}SRV;
|
||||||
|
|
||||||
|
std::vector<ID3D11RenderTargetView*> RTV;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
std::vector<ID3D11UnorderedAccessView*> Pixel;
|
||||||
|
std::vector<ID3D11UnorderedAccessView*> Compute;
|
||||||
|
}UAV;
|
||||||
|
|
||||||
|
ID3D11DepthStencilView* depth;
|
||||||
|
|
||||||
|
RenderPass()
|
||||||
{
|
{
|
||||||
RenderStates.BlendState=NULL;
|
RenderStates.BlendState=NULL;
|
||||||
RenderStates.DepthStencil=NULL;
|
RenderStates.DepthStencil=NULL;
|
||||||
|
@ -164,7 +189,7 @@ namespace Oyster
|
||||||
char* data;
|
char* data;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void SetShaderEffect(ShaderEffect);
|
static void SetRenderPass(RenderPass);
|
||||||
|
|
||||||
static void CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout);
|
static void CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout);
|
||||||
|
|
||||||
|
@ -192,6 +217,7 @@ namespace Oyster
|
||||||
};
|
};
|
||||||
|
|
||||||
static void Clean();
|
static void Clean();
|
||||||
|
static void CleanPipeline();
|
||||||
};
|
};
|
||||||
|
|
||||||
//Set resulotion Before Calling Full Init
|
//Set resulotion Before Calling Full Init
|
||||||
|
@ -200,7 +226,7 @@ namespace Oyster
|
||||||
public:
|
public:
|
||||||
enum State
|
enum State
|
||||||
{
|
{
|
||||||
Sucsess,
|
Success,
|
||||||
Fail
|
Fail
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -217,6 +243,12 @@ namespace Oyster
|
||||||
static State FullInit(HWND Window, bool MSAA_Quality, bool Fullscreen);
|
static State FullInit(HWND Window, bool MSAA_Quality, bool Fullscreen);
|
||||||
|
|
||||||
static State ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen);
|
static State ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen);
|
||||||
|
|
||||||
|
static State CreateLinkedShaderResourceFromTexture(ID3D11RenderTargetView** rtv, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav);
|
||||||
|
|
||||||
|
static State CreateLinkedShaderResourceFromStructuredBuffer(Buffer** Structured, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav);
|
||||||
|
static State CreateLinkedShaderResourceFromStructuredBuffer(void* InitData, int numElem, int ElemSize, Buffer** Structured, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav);
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Core::device)
|
if(Core::device)
|
||||||
return Init::Sucsess;
|
return Init::Success;
|
||||||
|
|
||||||
return Init::Fail;
|
return Init::Fail;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ namespace Oyster
|
||||||
|
|
||||||
dxgiFactory->Release();
|
dxgiFactory->Release();
|
||||||
|
|
||||||
return Init::Sucsess;
|
return Init::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Init::State Core::Init::CreateDepthStencil(bool MSAA_Quality, Oyster::Math::Float2 Size)
|
Core::Init::State Core::Init::CreateDepthStencil(bool MSAA_Quality, Oyster::Math::Float2 Size)
|
||||||
|
@ -176,9 +176,9 @@ namespace Oyster
|
||||||
D3D11_TEXTURE2D_DESC desc;
|
D3D11_TEXTURE2D_DESC desc;
|
||||||
desc.MipLevels=1;
|
desc.MipLevels=1;
|
||||||
desc.ArraySize=1;
|
desc.ArraySize=1;
|
||||||
desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
|
desc.Format = DXGI_FORMAT_R32_TYPELESS;
|
||||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
|
||||||
desc.CPUAccessFlags=0;
|
desc.CPUAccessFlags=0;
|
||||||
desc.MiscFlags=0;
|
desc.MiscFlags=0;
|
||||||
desc.Height = (UINT)Size.y;
|
desc.Height = (UINT)Size.y;
|
||||||
|
@ -211,15 +211,32 @@ namespace Oyster
|
||||||
ID3D11Texture2D* depthstencil;
|
ID3D11Texture2D* depthstencil;
|
||||||
|
|
||||||
if(FAILED(Core::device->CreateTexture2D(&desc,0,&depthstencil)))
|
if(FAILED(Core::device->CreateTexture2D(&desc,0,&depthstencil)))
|
||||||
|
{
|
||||||
return Init::Fail;
|
return Init::Fail;
|
||||||
if(FAILED(Core::device->CreateDepthStencilView(depthstencil,0,&Core::depthStencil)))
|
}
|
||||||
|
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
|
||||||
|
dsvDesc.Format = DXGI_FORMAT_D32_FLOAT;
|
||||||
|
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||||
|
dsvDesc.Flags = 0;
|
||||||
|
dsvDesc.Texture2D.MipSlice = 0;
|
||||||
|
if(Core::device->CreateDepthStencilView(depthstencil,&dsvDesc,&Core::depthStencil) != S_OK)
|
||||||
{
|
{
|
||||||
depthstencil->Release();
|
depthstencil->Release();
|
||||||
return Init::Fail;
|
return Init::Fail;
|
||||||
}
|
}
|
||||||
|
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||||
|
srvDesc.Format = DXGI_FORMAT_R32_FLOAT;
|
||||||
|
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||||
|
srvDesc.Texture2D.MipLevels = 1;
|
||||||
|
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||||
|
if(FAILED(Core::device->CreateShaderResourceView(depthstencil,&srvDesc,&Core::depthStencilUAV)))
|
||||||
|
{
|
||||||
|
depthStencil->Release();
|
||||||
|
return Init::Fail;
|
||||||
|
}
|
||||||
depthstencil->Release();
|
depthstencil->Release();
|
||||||
|
|
||||||
return Init::Sucsess;
|
return Init::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Init::State Core::Init::CreateBackBufferViews()
|
Core::Init::State Core::Init::CreateBackBufferViews()
|
||||||
|
@ -261,7 +278,7 @@ namespace Oyster
|
||||||
|
|
||||||
backBuffer->Release();
|
backBuffer->Release();
|
||||||
|
|
||||||
return Init::Sucsess;
|
return Init::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Init::State Core::Init::CreateViewPort(Oyster::Math::Float2 Origin, Oyster::Math::Float2 Size)
|
Core::Init::State Core::Init::CreateViewPort(Oyster::Math::Float2 Origin, Oyster::Math::Float2 Size)
|
||||||
|
@ -277,7 +294,7 @@ namespace Oyster
|
||||||
Core::viewPort->MinDepth = 0.0f;
|
Core::viewPort->MinDepth = 0.0f;
|
||||||
Core::viewPort->MaxDepth = 1.0f;
|
Core::viewPort->MaxDepth = 1.0f;
|
||||||
|
|
||||||
return Init::Sucsess;
|
return Init::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Init::State Core::Init::FullInit(HWND Window, bool MSAA_Quality, bool Fullscreen)
|
Core::Init::State Core::Init::FullInit(HWND Window, bool MSAA_Quality, bool Fullscreen)
|
||||||
|
@ -307,7 +324,7 @@ namespace Oyster
|
||||||
return Init::Fail;
|
return Init::Fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Init::Sucsess;
|
return Init::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::Init::State Core::Init::ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen)
|
Core::Init::State Core::Init::ReInitialize(HWND Window, bool MSAA_Quality, bool Fullscreen)
|
||||||
|
@ -332,7 +349,88 @@ namespace Oyster
|
||||||
return Init::Fail;
|
return Init::Fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Init::Sucsess;
|
return Init::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Init::State Core::Init::CreateLinkedShaderResourceFromTexture(ID3D11RenderTargetView** rtv, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav)
|
||||||
|
{
|
||||||
|
ID3D11Texture2D* tex;
|
||||||
|
D3D11_TEXTURE2D_DESC texDesc;
|
||||||
|
texDesc.Width = Core::resolution.x;
|
||||||
|
texDesc.Height = Core::resolution.y;
|
||||||
|
texDesc.MipLevels = 1;
|
||||||
|
texDesc.ArraySize = 1;
|
||||||
|
texDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
|
||||||
|
texDesc.SampleDesc.Count = 1;
|
||||||
|
texDesc.SampleDesc.Quality = 0;
|
||||||
|
texDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
|
texDesc.CPUAccessFlags = 0;
|
||||||
|
texDesc.MiscFlags = 0;
|
||||||
|
texDesc.BindFlags = 0;
|
||||||
|
if(rtv)
|
||||||
|
{
|
||||||
|
texDesc.BindFlags |= D3D11_BIND_RENDER_TARGET;
|
||||||
|
}
|
||||||
|
if(srv)
|
||||||
|
{
|
||||||
|
texDesc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
|
||||||
|
}
|
||||||
|
if(uav)
|
||||||
|
{
|
||||||
|
texDesc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(FAILED(Core::device->CreateTexture2D(&texDesc,NULL,&tex)))
|
||||||
|
return State::Fail;
|
||||||
|
if(rtv)
|
||||||
|
{
|
||||||
|
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
|
||||||
|
rtvDesc.Format = texDesc.Format;
|
||||||
|
rtvDesc.Texture2D.MipSlice = 0;
|
||||||
|
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
|
||||||
|
|
||||||
|
Core::device->CreateRenderTargetView(tex, &rtvDesc, rtv);
|
||||||
|
}
|
||||||
|
if(srv)
|
||||||
|
{
|
||||||
|
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
|
||||||
|
srvDesc.Texture2D.MipLevels = 1;
|
||||||
|
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||||
|
srvDesc.Format = texDesc.Format;
|
||||||
|
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||||
|
|
||||||
|
Core::device->CreateShaderResourceView(tex,&srvDesc,srv);
|
||||||
|
}
|
||||||
|
if(uav)
|
||||||
|
{
|
||||||
|
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
|
||||||
|
uavDesc.Texture2D.MipSlice = 0;
|
||||||
|
uavDesc.Format = texDesc.Format;
|
||||||
|
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
|
||||||
|
|
||||||
|
Core::device->CreateUnorderedAccessView(tex,&uavDesc,uav);
|
||||||
|
}
|
||||||
|
|
||||||
|
SAFE_RELEASE(tex);
|
||||||
|
|
||||||
|
|
||||||
|
return State::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Init::State Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(Buffer** Structured, ID3D11ShaderResourceView** srv, ID3D11UnorderedAccessView** uav)
|
||||||
|
{
|
||||||
|
D3D11_SHADER_RESOURCE_VIEW_DESC desc;
|
||||||
|
desc.Buffer.FirstElement=0;
|
||||||
|
desc.Buffer.ElementWidth = (*Structured)->GetElementCount();
|
||||||
|
desc.Format = DXGI_FORMAT_UNKNOWN;
|
||||||
|
desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
|
||||||
|
|
||||||
|
if(Core::device->CreateShaderResourceView(**(Structured),&desc, srv)==S_OK)
|
||||||
|
{
|
||||||
|
return State::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
return State::Fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -28,12 +28,14 @@ namespace Oyster
|
||||||
std::map<std::wstring,int> HSMap;
|
std::map<std::wstring,int> HSMap;
|
||||||
|
|
||||||
std::vector<ID3D11VertexShader*> VS;
|
std::vector<ID3D11VertexShader*> VS;
|
||||||
std::vector<Core::ShaderManager::ShaderData> VData;
|
std::vector<Core::PipelineManager::ShaderData> VData;
|
||||||
std::map<std::wstring,int> VSMap;
|
std::map<std::wstring,int> VSMap;
|
||||||
|
|
||||||
|
Core::PipelineManager::RenderPass Current;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region Init
|
#pragma region Init
|
||||||
bool Core::ShaderManager::Init(std::wstring filename, ShaderType type, std::wstring name)
|
bool Core::PipelineManager::Init(std::wstring filename, ShaderType type, std::wstring name)
|
||||||
{
|
{
|
||||||
void* data;
|
void* data;
|
||||||
bool ForceReload;
|
bool ForceReload;
|
||||||
|
@ -44,7 +46,7 @@ namespace Oyster
|
||||||
#endif
|
#endif
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case Oyster::Graphics::Core::ShaderManager::Vertex:
|
case Oyster::Graphics::Core::PipelineManager::Vertex:
|
||||||
if(!VSMap.count(name) || ForceReload)
|
if(!VSMap.count(name) || ForceReload)
|
||||||
{
|
{
|
||||||
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderV, -1, ForceReload);
|
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderV, -1, ForceReload);
|
||||||
|
@ -55,7 +57,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Hull:
|
case Oyster::Graphics::Core::PipelineManager::Hull:
|
||||||
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderH, -1, ForceReload);
|
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderH, -1, ForceReload);
|
||||||
if(!HSMap.count(name) || ForceReload)
|
if(!HSMap.count(name) || ForceReload)
|
||||||
{
|
{
|
||||||
|
@ -66,7 +68,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Domain:
|
case Oyster::Graphics::Core::PipelineManager::Domain:
|
||||||
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderD, -1, ForceReload);
|
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderD, -1, ForceReload);
|
||||||
if(!DSMap.count(name) || ForceReload)
|
if(!DSMap.count(name) || ForceReload)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +79,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Geometry:
|
case Oyster::Graphics::Core::PipelineManager::Geometry:
|
||||||
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderG, -1, ForceReload);
|
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderG, -1, ForceReload);
|
||||||
if(!GSMap.count(name) || ForceReload)
|
if(!GSMap.count(name) || ForceReload)
|
||||||
{
|
{
|
||||||
|
@ -88,7 +90,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Pixel:
|
case Oyster::Graphics::Core::PipelineManager::Pixel:
|
||||||
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderP, -1, ForceReload);
|
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderP, -1, ForceReload);
|
||||||
if(!PSMap.count(name) || ForceReload)
|
if(!PSMap.count(name) || ForceReload)
|
||||||
{
|
{
|
||||||
|
@ -99,7 +101,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Compute:
|
case Oyster::Graphics::Core::PipelineManager::Compute:
|
||||||
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderC, -1, ForceReload);
|
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderC, -1, ForceReload);
|
||||||
if(!CSMap.count(name) || ForceReload)
|
if(!CSMap.count(name) || ForceReload)
|
||||||
{
|
{
|
||||||
|
@ -116,44 +118,44 @@ namespace Oyster
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Core::ShaderManager::CreateShader(Core::ShaderManager::ShaderData data, Core::ShaderManager::ShaderType type)
|
void* Core::PipelineManager::CreateShader(Core::PipelineManager::ShaderData data, Core::PipelineManager::ShaderType type)
|
||||||
{
|
{
|
||||||
|
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case Oyster::Graphics::Core::ShaderManager::Vertex:
|
case Oyster::Graphics::Core::PipelineManager::Vertex:
|
||||||
ID3D11VertexShader* vs;
|
ID3D11VertexShader* vs;
|
||||||
hr = Core::device->CreateVertexShader(data.data,data.size,NULL,&vs);
|
hr = Core::device->CreateVertexShader(data.data,data.size,NULL,&vs);
|
||||||
if(hr == S_OK)
|
if(hr == S_OK)
|
||||||
VData.push_back(data);
|
VData.push_back(data);
|
||||||
return vs;
|
return vs;
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Hull:
|
case Oyster::Graphics::Core::PipelineManager::Hull:
|
||||||
ID3D11HullShader* hs;
|
ID3D11HullShader* hs;
|
||||||
Core::device->CreateHullShader(data.data,data.size,NULL,&hs);
|
Core::device->CreateHullShader(data.data,data.size,NULL,&hs);
|
||||||
delete[] data.data;
|
delete[] data.data;
|
||||||
return hs;
|
return hs;
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Domain:
|
case Oyster::Graphics::Core::PipelineManager::Domain:
|
||||||
ID3D11DomainShader* ds;
|
ID3D11DomainShader* ds;
|
||||||
Core::device->CreateDomainShader(data.data,data.size,NULL,&ds);
|
Core::device->CreateDomainShader(data.data,data.size,NULL,&ds);
|
||||||
delete[] data.data;
|
delete[] data.data;
|
||||||
return ds;
|
return ds;
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Geometry:
|
case Oyster::Graphics::Core::PipelineManager::Geometry:
|
||||||
ID3D11GeometryShader* gs;
|
ID3D11GeometryShader* gs;
|
||||||
Core::device->CreateGeometryShader(data.data,data.size,NULL,&gs);
|
Core::device->CreateGeometryShader(data.data,data.size,NULL,&gs);
|
||||||
delete[] data.data;
|
delete[] data.data;
|
||||||
return gs;
|
return gs;
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Pixel:
|
case Oyster::Graphics::Core::PipelineManager::Pixel:
|
||||||
ID3D11PixelShader* ps;
|
ID3D11PixelShader* ps;
|
||||||
Core::device->CreatePixelShader(data.data,data.size,NULL,&ps);
|
Core::device->CreatePixelShader(data.data,data.size,NULL,&ps);
|
||||||
delete[] data.data;
|
delete[] data.data;
|
||||||
return ps;
|
return ps;
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Compute:
|
case Oyster::Graphics::Core::PipelineManager::Compute:
|
||||||
ID3D11ComputeShader* cs;
|
ID3D11ComputeShader* cs;
|
||||||
Core::device->CreateComputeShader(data.data,data.size,NULL,&cs);
|
Core::device->CreateComputeShader(data.data,data.size,NULL,&cs);
|
||||||
delete[] data.data;
|
delete[] data.data;
|
||||||
|
@ -164,7 +166,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
void Core::ShaderManager::CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout)
|
void Core::PipelineManager::CreateInputLayout(const D3D11_INPUT_ELEMENT_DESC *desc, int ElementCount,int VertexIndex,ID3D11InputLayout *&Layout)
|
||||||
{
|
{
|
||||||
if(VertexIndex==-1)
|
if(VertexIndex==-1)
|
||||||
{
|
{
|
||||||
|
@ -175,79 +177,113 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region Get
|
#pragma region Get
|
||||||
int Core::ShaderManager::Get::Pixel(std::wstring Name)
|
int Core::PipelineManager::Get::Pixel(std::wstring Name)
|
||||||
{
|
{
|
||||||
if(PSMap.count(Name))
|
if(PSMap.count(Name))
|
||||||
return PSMap[Name];
|
return PSMap[Name];
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Core::ShaderManager::Get::Vertex(std::wstring Name)
|
int Core::PipelineManager::Get::Vertex(std::wstring Name)
|
||||||
{
|
{
|
||||||
if(VSMap.count(Name))
|
if(VSMap.count(Name))
|
||||||
return VSMap[Name];
|
return VSMap[Name];
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int Core::ShaderManager::Get::Geometry(std::wstring Name)
|
int Core::PipelineManager::Get::Geometry(std::wstring Name)
|
||||||
{
|
{
|
||||||
if(GSMap.count(Name))
|
if(GSMap.count(Name))
|
||||||
return GSMap[Name];
|
return GSMap[Name];
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Core::ShaderManager::Get::Compute(std::wstring Name)
|
int Core::PipelineManager::Get::Compute(std::wstring Name)
|
||||||
{
|
{
|
||||||
if(CSMap.count(Name))
|
if(CSMap.count(Name))
|
||||||
return CSMap[Name];
|
return CSMap[Name];
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int Core::ShaderManager::Get::Hull(std::wstring Name)
|
int Core::PipelineManager::Get::Hull(std::wstring Name)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int Core::ShaderManager::Get::Domain(std::wstring Name)
|
int Core::PipelineManager::Get::Domain(std::wstring Name)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Set
|
#pragma region Set
|
||||||
/// \todo smart set
|
void Core::PipelineManager::Set::Pixel(int Index)
|
||||||
void Core::ShaderManager::Set::Pixel(int Index)
|
{
|
||||||
|
if(Current.Shaders.Pixel != Index)
|
||||||
{
|
{
|
||||||
if(Index==-1)
|
if(Index==-1)
|
||||||
|
{
|
||||||
Core::deviceContext->PSSetShader( NULL,NULL,0);
|
Core::deviceContext->PSSetShader( NULL,NULL,0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Core::deviceContext->PSSetShader( PS[Index],NULL,0);
|
Core::deviceContext->PSSetShader( PS[Index],NULL,0);
|
||||||
}
|
}
|
||||||
void Core::ShaderManager::Set::Vertex(int Index)
|
Current.Shaders.Pixel=Index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::PipelineManager::Set::Vertex(int Index)
|
||||||
|
{
|
||||||
|
if(Current.Shaders.Vertex != Index)
|
||||||
{
|
{
|
||||||
if(Index==-1)
|
if(Index==-1)
|
||||||
|
{
|
||||||
Core::deviceContext->VSSetShader( NULL,NULL,0);
|
Core::deviceContext->VSSetShader( NULL,NULL,0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Core::deviceContext->VSSetShader( VS[Index],NULL,0);
|
Core::deviceContext->VSSetShader( VS[Index],NULL,0);
|
||||||
}
|
}
|
||||||
void Core::ShaderManager::Set::Geometry(int Index)
|
Current.Shaders.Vertex = Index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::PipelineManager::Set::Geometry(int Index)
|
||||||
|
{
|
||||||
|
if(Current.Shaders.Geometry != Index)
|
||||||
{
|
{
|
||||||
if(Index==-1)
|
if(Index==-1)
|
||||||
|
{
|
||||||
Core::deviceContext->GSSetShader( NULL,NULL,0);
|
Core::deviceContext->GSSetShader( NULL,NULL,0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Core::deviceContext->GSSetShader( GS[Index],NULL,0);
|
Core::deviceContext->GSSetShader( GS[Index],NULL,0);
|
||||||
}
|
}
|
||||||
void Core::ShaderManager::Set::Compute(int Index)
|
Current.Shaders.Geometry = Index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::PipelineManager::Set::Compute(int Index)
|
||||||
|
{
|
||||||
|
if(Current.Shaders.Compute != Index)
|
||||||
{
|
{
|
||||||
if(Index==-1)
|
if(Index==-1)
|
||||||
|
{
|
||||||
Core::deviceContext->CSSetShader( NULL,NULL,0);
|
Core::deviceContext->CSSetShader( NULL,NULL,0);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Core::deviceContext->CSSetShader( CS[Index],NULL,0);
|
Core::deviceContext->CSSetShader( CS[Index],NULL,0);
|
||||||
}
|
}
|
||||||
|
Current.Shaders.Compute = Index;
|
||||||
|
}
|
||||||
|
}
|
||||||
/// \todo set Hull
|
/// \todo set Hull
|
||||||
void Core::ShaderManager::Set::Hull(int Index)
|
void Core::PipelineManager::Set::Hull(int Index)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/// \todo set Domain
|
/// \todo set Domain
|
||||||
void Core::ShaderManager::Set::Domain(int Index)
|
void Core::PipelineManager::Set::Domain(int Index)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -256,33 +292,95 @@ namespace Oyster
|
||||||
/// \todo smart Set ie. not resetting the shader
|
/// \todo smart Set ie. not resetting the shader
|
||||||
/// \todo research states
|
/// \todo research states
|
||||||
/// \todo smart buffer set
|
/// \todo smart buffer set
|
||||||
void Core::ShaderManager::SetShaderEffect(ShaderEffect se)
|
void Core::PipelineManager::SetRenderPass(RenderPass se)
|
||||||
{
|
{
|
||||||
|
CleanPipeline();
|
||||||
Set::Pixel(se.Shaders.Pixel);
|
Set::Pixel(se.Shaders.Pixel);
|
||||||
Set::Vertex(se.Shaders.Vertex);
|
Set::Vertex(se.Shaders.Vertex);
|
||||||
Set::Geometry(se.Shaders.Geometry);
|
Set::Geometry(se.Shaders.Geometry);
|
||||||
Set::Compute(se.Shaders.Compute);
|
Set::Compute(se.Shaders.Compute);
|
||||||
Core::deviceContext->IASetInputLayout(se.IAStage.Layout);
|
Core::deviceContext->IASetInputLayout(se.IAStage.Layout);
|
||||||
Core::deviceContext->IASetPrimitiveTopology(se.IAStage.Topology);
|
Core::deviceContext->IASetPrimitiveTopology(se.IAStage.Topology);
|
||||||
for(unsigned int i=0;i<se.CBuffers.Vertex.size();++i)
|
if(se.CBuffers.Vertex.size())
|
||||||
se.CBuffers.Vertex[i]->Apply(i);
|
{
|
||||||
for(unsigned int i=0;i<se.CBuffers.Geometry.size();++i)
|
deviceContext->VSSetConstantBuffers(0,se.CBuffers.Vertex.size(),&se.CBuffers.Vertex[0]);
|
||||||
se.CBuffers.Geometry[i]->Apply(i);
|
}
|
||||||
for(unsigned int i=0;i<se.CBuffers.Pixel.size();++i)
|
if(se.CBuffers.Pixel.size())
|
||||||
se.CBuffers.Pixel[i]->Apply(i);
|
{
|
||||||
|
deviceContext->PSSetConstantBuffers(0,se.CBuffers.Pixel.size(),&se.CBuffers.Pixel[0]);
|
||||||
|
}
|
||||||
|
if(se.CBuffers.Geometry.size())
|
||||||
|
{
|
||||||
|
deviceContext->GSSetConstantBuffers(0,se.CBuffers.Geometry.size(),&se.CBuffers.Geometry[0]);
|
||||||
|
}
|
||||||
|
if(se.CBuffers.Compute.size())
|
||||||
|
{
|
||||||
|
deviceContext->CSSetConstantBuffers(0,se.CBuffers.Compute.size(),&se.CBuffers.Compute[0]);
|
||||||
|
}
|
||||||
Core::deviceContext->RSSetState(se.RenderStates.Rasterizer);
|
Core::deviceContext->RSSetState(se.RenderStates.Rasterizer);
|
||||||
Core::deviceContext->PSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState);
|
Core::deviceContext->PSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState);
|
||||||
Core::deviceContext->OMSetDepthStencilState(se.RenderStates.DepthStencil,0);
|
Core::deviceContext->OMSetDepthStencilState(se.RenderStates.DepthStencil,0);
|
||||||
float test[4] = {0};
|
float test[4] = {0};
|
||||||
Core::deviceContext->OMSetBlendState(se.RenderStates.BlendState,test,-1);
|
Core::deviceContext->OMSetBlendState(se.RenderStates.BlendState,test,-1);
|
||||||
|
|
||||||
|
if(se.SRV.Vertex.size())
|
||||||
|
{
|
||||||
|
Core::deviceContext->VSSetShaderResources(0,se.SRV.Vertex.size(),&se.SRV.Vertex[0]);
|
||||||
|
}
|
||||||
|
if(se.SRV.Geometry.size())
|
||||||
|
{
|
||||||
|
Core::deviceContext->GSSetShaderResources(0,se.SRV.Geometry.size(),&se.SRV.Geometry[0]);
|
||||||
|
}
|
||||||
|
if(se.SRV.Pixel.size())
|
||||||
|
{
|
||||||
|
Core::deviceContext->PSSetShaderResources(0,se.SRV.Pixel.size(),&se.SRV.Pixel[0]);
|
||||||
|
}
|
||||||
|
if(se.SRV.Compute.size())
|
||||||
|
{
|
||||||
|
Core::deviceContext->CSSetShaderResources(0,se.SRV.Compute.size(),&se.SRV.Compute[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::ShaderManager::Clean()
|
if(se.RTV.size())
|
||||||
|
{
|
||||||
|
if(se.UAV.Pixel.size())
|
||||||
|
{
|
||||||
|
deviceContext->OMSetRenderTargetsAndUnorderedAccessViews(se.RTV.size(),&se.RTV[0],se.depth,se.RTV.size(),se.UAV.Pixel.size(),&se.UAV.Pixel[0],0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
deviceContext->OMSetRenderTargets(se.RTV.size(),&se.RTV[0],se.depth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(se.UAV.Pixel.size())
|
||||||
|
{
|
||||||
|
deviceContext->OMSetRenderTargetsAndUnorderedAccessViews(0,NULL,se.depth,0,se.UAV.Pixel.size(),&se.UAV.Pixel[0],0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(se.UAV.Compute.size())
|
||||||
|
{
|
||||||
|
deviceContext->CSSetUnorderedAccessViews(0,se.UAV.Compute.size(),&se.UAV.Compute[0],0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::PipelineManager::Clean()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)VData.size(); ++i)
|
for(int i = 0; i < (int)VData.size(); ++i)
|
||||||
{
|
{
|
||||||
delete[] VData[i].data;
|
delete[] VData[i].data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::PipelineManager::CleanPipeline()
|
||||||
|
{
|
||||||
|
deviceContext->VSSetShaderResources(0,16,Core::srvNULL);
|
||||||
|
deviceContext->GSSetShaderResources(0,16,Core::srvNULL);
|
||||||
|
deviceContext->PSSetShaderResources(0,16,Core::srvNULL);
|
||||||
|
deviceContext->CSSetShaderResources(0,16,Core::srvNULL);
|
||||||
|
deviceContext->CSSetUnorderedAccessViews(0,8,Core::uavNULL,NULL);
|
||||||
|
deviceContext->OMSetRenderTargets(8,Core::rtvNULL, NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
#include "..\OysterGraphics\Core\Dx11Includes.h"
|
|
||||||
#include "OysterMath.h"
|
#include "OysterMath.h"
|
||||||
|
#pragma once
|
||||||
|
|
||||||
namespace Oyster
|
namespace Oyster
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,22 @@ namespace Oyster
|
||||||
Oyster::Math::Float4 boneWeights;
|
Oyster::Math::Float4 boneWeights;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct LightConstants
|
||||||
|
{
|
||||||
|
Math::Float4x4 InvProj;
|
||||||
|
Math::Float2 Pixels;
|
||||||
|
int Lights;
|
||||||
|
float Pad;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Pointlight
|
||||||
|
{
|
||||||
|
Math::Float3 Pos;
|
||||||
|
float Radius;
|
||||||
|
Math::Float3 Color;
|
||||||
|
float Bright;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#include "GFXAPI.h"
|
#include "GFXAPI.h"
|
||||||
#include "../Core/Core.h"
|
#include "../Core/Core.h"
|
||||||
#include "../Render/Resources/Resources.h"
|
#include "../Render/Resources/Debug.h"
|
||||||
|
#include "../Render/Resources/Deffered.h"
|
||||||
#include "../Render/Rendering/Render.h"
|
#include "../Render/Rendering/Render.h"
|
||||||
#include "../FileLoader/ObjReader.h"
|
#include "../FileLoader/ObjReader.h"
|
||||||
#include "../../Misc/Resource/OysterResource.h"
|
#include "../../Misc/Resource/OysterResource.h"
|
||||||
|
@ -14,6 +15,7 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
Math::Float4x4 View;
|
Math::Float4x4 View;
|
||||||
Math::Float4x4 Projection;
|
Math::Float4x4 Projection;
|
||||||
|
std::vector<Definitions::Pointlight> Lights;
|
||||||
}
|
}
|
||||||
|
|
||||||
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion)
|
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion)
|
||||||
|
@ -24,10 +26,13 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
return API::Fail;
|
return API::Fail;
|
||||||
}
|
}
|
||||||
if(Render::Resources::Init() == Core::Init::Fail)
|
#ifdef _DEBUG
|
||||||
|
if(Render::Resources::Debug::Init() == Core::Init::Fail)
|
||||||
{
|
{
|
||||||
return API::Fail;
|
return API::Fail;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Render::Resources::Deffered::Init();
|
||||||
|
|
||||||
Render::Preparations::Basic::SetViewPort();
|
Render::Preparations::Basic::SetViewPort();
|
||||||
return API::Sucsess;
|
return API::Sucsess;
|
||||||
|
@ -45,7 +50,7 @@ namespace Oyster
|
||||||
|
|
||||||
void API::NewFrame()
|
void API::NewFrame()
|
||||||
{
|
{
|
||||||
Render::Rendering::Basic::NewFrame(View, Projection);
|
Render::Rendering::Basic::NewFrame(View, Projection, &Lights[0], Lights.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void API::RenderScene(Model::Model models[], int count)
|
void API::RenderScene(Model::Model models[], int count)
|
||||||
|
@ -90,10 +95,15 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
SAFE_DELETE(Core::viewPort);
|
SAFE_DELETE(Core::viewPort);
|
||||||
Oyster::Resource::OysterResource::Clean();
|
Oyster::Resource::OysterResource::Clean();
|
||||||
Oyster::Graphics::Core::ShaderManager::Clean();
|
Oyster::Graphics::Core::PipelineManager::Clean();
|
||||||
Oyster::Graphics::Render::Resources::Clean();
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
Oyster::Graphics::Render::Resources::Debug::Clean();
|
||||||
|
#endif
|
||||||
|
Oyster::Graphics::Render::Resources::Deffered::Clean();
|
||||||
|
|
||||||
SAFE_RELEASE(Core::depthStencil);
|
SAFE_RELEASE(Core::depthStencil);
|
||||||
|
SAFE_RELEASE(Core::depthStencilUAV);
|
||||||
SAFE_RELEASE(Core::backBufferRTV);
|
SAFE_RELEASE(Core::backBufferRTV);
|
||||||
SAFE_RELEASE(Core::backBufferUAV);
|
SAFE_RELEASE(Core::backBufferUAV);
|
||||||
|
|
||||||
|
@ -101,5 +111,15 @@ namespace Oyster
|
||||||
SAFE_RELEASE(Core::deviceContext);
|
SAFE_RELEASE(Core::deviceContext);
|
||||||
SAFE_RELEASE(Core::device);
|
SAFE_RELEASE(Core::device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void API::AddLight(Definitions::Pointlight light)
|
||||||
|
{
|
||||||
|
Lights.push_back(light);
|
||||||
|
}
|
||||||
|
|
||||||
|
void API::ClearLights()
|
||||||
|
{
|
||||||
|
Lights.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "../Definitions/GraphicalDefinition.h"
|
||||||
#include "..\Model\Model.h"
|
#include "..\Model\Model.h"
|
||||||
#include "OysterMath.h"
|
#include "OysterMath.h"
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
//#include <vld.h>
|
||||||
|
|
||||||
#ifdef GFX_DLL_EXPORT
|
#ifdef GFX_DLL_EXPORT
|
||||||
#define GFX_DLL_USAGE __declspec(dllexport)
|
#define GFX_DLL_USAGE __declspec(dllexport)
|
||||||
|
@ -41,6 +43,9 @@ namespace Oyster
|
||||||
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);
|
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);
|
||||||
static void DeleteModel(Oyster::Graphics::Model::Model* model);
|
static void DeleteModel(Oyster::Graphics::Model::Model* model);
|
||||||
|
|
||||||
|
static void AddLight(Definitions::Pointlight light);
|
||||||
|
static void ClearLights();
|
||||||
|
|
||||||
static State SetOptions(Option);
|
static State SetOptions(Option);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "..\Core\Dx11Includes.h"
|
#include "..\Core\Dx11Includes.h"
|
||||||
#include "..\Core\Core.h"
|
#include "..\Core\Core.h"
|
||||||
#include "ObjReader.h"
|
#include "ObjReader.h"
|
||||||
|
#include "..\..\Misc\Resource\OysterResource.h"
|
||||||
|
|
||||||
HRESULT CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
|
HRESULT CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
|
||||||
ID3D11DeviceContext* d3dContext,
|
ID3D11DeviceContext* d3dContext,
|
||||||
|
@ -38,10 +39,27 @@ void Oyster::Graphics::Loading::UnloadTexture(void* data)
|
||||||
|
|
||||||
void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
void Oyster::Graphics::Loading::LoadOBJ(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
||||||
{
|
{
|
||||||
OBJReader obj;
|
FileLoaders::ObjReader* obj = FileLoaders::ObjReader::LoadFile(filename);
|
||||||
obj.readOBJFile(filename);
|
Model::ModelInfo* info = new Model::ModelInfo();
|
||||||
Model::ModelInfo* info;
|
Oyster::FileLoaders::ObjReader::Vertex* vdata;
|
||||||
info = obj.toModel();
|
int count;
|
||||||
|
obj->GetVertexData(&vdata, count);
|
||||||
|
info->Vertices = new Core::Buffer();
|
||||||
|
Core::Buffer::BUFFER_INIT_DESC desc;
|
||||||
|
desc.ElementSize = sizeof(FileLoaders::ObjReader::Vertex);
|
||||||
|
desc.NumElements = count;
|
||||||
|
desc.InitData = vdata;
|
||||||
|
desc.Type = Core::Buffer::VERTEX_BUFFER;
|
||||||
|
desc.Usage = Core::Buffer::BUFFER_USAGE_IMMUTABLE;
|
||||||
|
|
||||||
|
info->VertexCount = count;
|
||||||
|
info->Vertices->Init(desc);
|
||||||
|
info->Indexed = false;
|
||||||
|
|
||||||
|
void* texture = Oyster::Resource::OysterResource::LoadResource((std::wstring(filename)+ L".png").c_str(),Graphics::Loading::LoadTexture);
|
||||||
|
|
||||||
|
info->Material.push_back((ID3D11ShaderResourceView*)texture);
|
||||||
|
|
||||||
out.loadedData = info;
|
out.loadedData = info;
|
||||||
out.resourceUnloadFnc = Oyster::Graphics::Loading::UnloadOBJ;
|
out.resourceUnloadFnc = Oyster::Graphics::Loading::UnloadOBJ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,152 +1,285 @@
|
||||||
#include "OBJReader.h"
|
#include "ObjReader.h"
|
||||||
#include "..\Definitions\GraphicalDefinition.h"
|
#include "Utilities.h"
|
||||||
#include <sstream>
|
#include "..\Core\Core.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "GeneralLoader.h"
|
#include <map>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
OBJReader::OBJReader()
|
using namespace Oyster::FileLoaders;
|
||||||
|
using namespace Oyster;
|
||||||
|
using namespace Oyster::Math;
|
||||||
|
|
||||||
|
ObjReader *ObjReader::LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform)
|
||||||
{
|
{
|
||||||
_mPos = 0;
|
static std::map<std::wstring, ObjReader *> cache;
|
||||||
_mNormal = 0;
|
|
||||||
_mTexel = 0;
|
ObjReader *reader = NULL;
|
||||||
|
|
||||||
|
if (cache.count(fileName))
|
||||||
|
{
|
||||||
|
reader = cache[fileName];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reader = new ObjReader();
|
||||||
|
reader->ParseFile(fileName + L".obj", transform);
|
||||||
|
|
||||||
|
cache[fileName] = reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
OBJReader::~OBJReader()
|
ObjReader::ObjReader(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBJReader::readOBJFile( std::wstring fileName )
|
|
||||||
|
ObjReader::~ObjReader(void)
|
||||||
{
|
{
|
||||||
std::fstream inStream;
|
|
||||||
std::string typeOfData = " ";
|
|
||||||
float vertexData;
|
|
||||||
std::string face1, face2, face3;
|
|
||||||
|
|
||||||
inStream.open( fileName + L".obj", std::fstream::in );
|
|
||||||
|
|
||||||
if( inStream.is_open() )
|
|
||||||
{
|
|
||||||
while( !inStream.eof() )
|
|
||||||
{
|
|
||||||
inStream >> typeOfData;
|
|
||||||
|
|
||||||
if( typeOfData == "v" )
|
|
||||||
{
|
|
||||||
Oyster::Math::Float3 position;
|
|
||||||
|
|
||||||
inStream >> vertexData;
|
|
||||||
position.x = vertexData;
|
|
||||||
|
|
||||||
inStream >> vertexData;
|
|
||||||
position.y = vertexData;
|
|
||||||
|
|
||||||
inStream >> vertexData;
|
|
||||||
position.z = vertexData;
|
|
||||||
|
|
||||||
_mVertexCoord.push_back( position );
|
|
||||||
|
|
||||||
}
|
|
||||||
else if( typeOfData == "vt" )
|
|
||||||
{
|
|
||||||
Oyster::Math::Float2 texel;
|
|
||||||
inStream >> vertexData;
|
|
||||||
texel.x = vertexData;
|
|
||||||
|
|
||||||
inStream >> vertexData;
|
|
||||||
texel.y = 1 - vertexData;
|
|
||||||
|
|
||||||
_mVertexTexture.push_back( texel );
|
|
||||||
}
|
|
||||||
else if( typeOfData == "vn" )
|
|
||||||
{
|
|
||||||
Oyster::Math::Float3 normal;
|
|
||||||
inStream >> vertexData;
|
|
||||||
normal.x = vertexData;
|
|
||||||
|
|
||||||
inStream >> vertexData;
|
|
||||||
normal.y = vertexData;
|
|
||||||
|
|
||||||
inStream >> vertexData;
|
|
||||||
normal.z = vertexData;
|
|
||||||
|
|
||||||
_mVertexNormal.push_back( normal );
|
|
||||||
}
|
|
||||||
else if( typeOfData == "f" )
|
|
||||||
{
|
|
||||||
inStream >> face1;
|
|
||||||
stringSplit( face1 );
|
|
||||||
|
|
||||||
addToOBJarray();
|
|
||||||
|
|
||||||
inStream >> face2;
|
|
||||||
stringSplit( face2 );
|
|
||||||
|
|
||||||
addToOBJarray();
|
|
||||||
|
|
||||||
inStream >> face3;
|
|
||||||
stringSplit( face3 );
|
|
||||||
|
|
||||||
addToOBJarray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inStream.close();
|
|
||||||
|
|
||||||
Mat = Oyster::Resource::OysterResource::LoadResource((fileName + L".png").c_str(),Oyster::Graphics::Loading::LoadTexture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Oyster::Graphics::Model::ModelInfo* OBJReader::toModel()
|
void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
|
||||||
{
|
{
|
||||||
Oyster::Graphics::Core::Buffer* b = new Oyster::Graphics::Core::Buffer();
|
wifstream input;
|
||||||
Oyster::Graphics::Core::Buffer::BUFFER_INIT_DESC desc;
|
input.open(fileName.c_str());
|
||||||
Oyster::Graphics::Model::ModelInfo* modelInfo = new Oyster::Graphics::Model::ModelInfo();
|
|
||||||
|
|
||||||
desc.ElementSize = 32;
|
if(!input.is_open())
|
||||||
desc.InitData = &this->_myOBJ[0];
|
|
||||||
desc.NumElements = this->_myOBJ.size();
|
|
||||||
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);
|
|
||||||
if(FAILED(hr))
|
|
||||||
{
|
{
|
||||||
//Something isn't okay here
|
return;
|
||||||
}
|
}
|
||||||
modelInfo->Indexed = false;
|
|
||||||
modelInfo->VertexCount = (int)desc.NumElements;
|
|
||||||
modelInfo->Vertices = b;
|
|
||||||
modelInfo->Material.push_back((ID3D11ShaderResourceView*)Mat);
|
|
||||||
|
|
||||||
return modelInfo;
|
wstring path;
|
||||||
|
//Utility::String::ExtractDirPath(path,fileName,'\\');
|
||||||
|
|
||||||
|
std::vector<Vertex> VertexList;
|
||||||
|
std::vector<Float3> vList;
|
||||||
|
std::vector<Float3> nList;
|
||||||
|
std::vector<Float2> uvList;
|
||||||
|
Vertex vertex1, vertex2, vertex3;
|
||||||
|
Float3 face[3];
|
||||||
|
Float3 position, normal;
|
||||||
|
Float2 uv;
|
||||||
|
wstring s;
|
||||||
|
|
||||||
|
while(!input.eof())
|
||||||
|
{
|
||||||
|
getline(input,s);
|
||||||
|
int offset = (int)s.find(' ');
|
||||||
|
|
||||||
|
if(offset!=-1)
|
||||||
|
{
|
||||||
|
wstring c = s.substr(0,offset);
|
||||||
|
|
||||||
|
if(c==L"v")
|
||||||
|
{
|
||||||
|
position = readVertex(offset,s);
|
||||||
|
vList.push_back(position);
|
||||||
|
}
|
||||||
|
else if(c==L"vt")
|
||||||
|
{
|
||||||
|
uv = readUV(offset,s);
|
||||||
|
uvList.push_back(uv);
|
||||||
|
}
|
||||||
|
else if(c==L"vn")
|
||||||
|
{
|
||||||
|
normal = readNormal(offset,s);
|
||||||
|
nList.push_back(normal);
|
||||||
|
}
|
||||||
|
else if(c==L"f")
|
||||||
|
{
|
||||||
|
readFace(offset, s, face);
|
||||||
|
|
||||||
|
vertex1.Position = vList[(int)face[0].x];
|
||||||
|
vertex1.UV = uvList[(int)face[0].y];
|
||||||
|
vertex1.Normal = nList[(int)face[0].z];
|
||||||
|
|
||||||
|
vertex2.Position = vList[(int)face[1].x];
|
||||||
|
vertex2.UV = uvList[(int)face[1].y];
|
||||||
|
vertex2.Normal = nList[(int)face[1].z];
|
||||||
|
|
||||||
|
vertex3.Position = vList[(int)face[2].x];
|
||||||
|
vertex3.UV = uvList[(int)face[2].y];
|
||||||
|
vertex3.Normal = nList[(int)face[2].z];
|
||||||
|
|
||||||
|
VertexList.push_back(vertex1);
|
||||||
|
VertexList.push_back(vertex2);
|
||||||
|
VertexList.push_back(vertex3);
|
||||||
|
}
|
||||||
|
else if(c==L"mtllib")
|
||||||
|
{
|
||||||
|
//this->materials = GetMaterials(path + s.substr(offset+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input.close();
|
||||||
|
|
||||||
|
this->numVertices = VertexList.size();
|
||||||
|
this->vertices = new Vertex[this->numVertices];
|
||||||
|
|
||||||
|
for(size_t i=0;i<this->numVertices;++i)
|
||||||
|
{
|
||||||
|
vertices[i].Position=Math::Float4(VertexList[i].Position,1);
|
||||||
|
vertices[i].Normal=Math::Float4(VertexList[i].Normal,0);
|
||||||
|
vertices[i].UV = VertexList[i].UV;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Private functions
|
void ObjReader::GetVertexData(Vertex **vertex,int &numVertex, std::map<std::string, ID3D11ShaderResourceView *> &Textures)
|
||||||
void OBJReader::stringSplit( std::string strToSplit )
|
|
||||||
{
|
{
|
||||||
char delim = '/';
|
numVertex=(int)this->numVertices;
|
||||||
std::string vPos, vNormal, vTexel;
|
(*vertex)=this->vertices;
|
||||||
std::stringstream aStream(strToSplit);
|
//Textures = this->materials;
|
||||||
getline( aStream, vPos, delim );
|
|
||||||
getline( aStream, vTexel, delim );
|
|
||||||
getline( aStream, vNormal );
|
|
||||||
|
|
||||||
_mPos = atoi( vPos.c_str() );
|
|
||||||
_mNormal = atoi( vNormal.c_str() );
|
|
||||||
_mTexel = atoi( vTexel.c_str() );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBJReader::addToOBJarray()
|
void ObjReader::GetVertexData(Vertex **vertex,int &numVertex)
|
||||||
{
|
{
|
||||||
OBJFormat temp;
|
numVertex=(int)this->numVertices;
|
||||||
|
(*vertex)=this->vertices;
|
||||||
temp._d3VertexCoord = _mVertexCoord.at( _mPos - 1 );
|
}
|
||||||
temp._d3VertexNormal = _mVertexNormal.at( _mNormal - 1 );
|
|
||||||
temp._d3VertexTexture = _mVertexTexture.at( _mTexel - 1 );
|
Float3 ObjReader::extract(std::string d1)
|
||||||
|
{
|
||||||
_myOBJ.push_back( temp );
|
Float3 data;
|
||||||
|
int offset=(int)d1.find('/');
|
||||||
|
//string d1 = Utility::String::WStringToString(d,d1);
|
||||||
|
data.x=(float)atoi(d1.substr(1,offset).c_str())-1;
|
||||||
|
|
||||||
|
int newOffset = (int)d1.find('/',offset+1);
|
||||||
|
string d2=d1.substr(offset+1,newOffset-offset-1);
|
||||||
|
data.y=(float)atoi(d2.c_str())-1;
|
||||||
|
offset=newOffset;
|
||||||
|
|
||||||
|
newOffset = (int)d1.find('/',offset+1);
|
||||||
|
string d3=d1.substr(offset+1,newOffset-offset-1);
|
||||||
|
data.z=(float)atoi(d3.c_str())-1;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 ObjReader::readVertex(int offset,wstring s)
|
||||||
|
{
|
||||||
|
int newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Float3 vertex;
|
||||||
|
string d;
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
vertex.x = (float)atof(d.c_str());
|
||||||
|
offset=newOffset;
|
||||||
|
|
||||||
|
newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
vertex.y = (float)atof(d.c_str());
|
||||||
|
offset=newOffset;
|
||||||
|
|
||||||
|
newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
vertex.z = (float)atof(d.c_str());
|
||||||
|
|
||||||
|
return vertex;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float2 ObjReader::readUV(int offset,wstring s)
|
||||||
|
{
|
||||||
|
int newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Float2 uv;
|
||||||
|
string d;
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
uv.x =(float)atof(d.c_str());
|
||||||
|
offset=newOffset;
|
||||||
|
|
||||||
|
newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
uv.y =1- (float)atof(d.c_str());
|
||||||
|
offset=newOffset;
|
||||||
|
|
||||||
|
return uv;
|
||||||
|
}
|
||||||
|
|
||||||
|
Float3 ObjReader::readNormal(int offset,wstring s)
|
||||||
|
{
|
||||||
|
int newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Float3 vertex;
|
||||||
|
string d;
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
vertex.x = (float)atof(d.c_str());
|
||||||
|
offset=newOffset;
|
||||||
|
|
||||||
|
newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
vertex.y = (float)atof(d.c_str());
|
||||||
|
offset=newOffset;
|
||||||
|
|
||||||
|
newOffset = (int)s.find(' ',offset+1);
|
||||||
|
Utility::String::WStringToString(s.substr(offset,newOffset-offset), d);
|
||||||
|
vertex.z = (float)atof(d.c_str());
|
||||||
|
|
||||||
|
return vertex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjReader::readFace(int offset,wstring s1, Oyster::Math::Float3 face[3])
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
Utility::String::WStringToString(s1,s);
|
||||||
|
|
||||||
|
int newOffset = (int)s.find(' ',offset+1);
|
||||||
|
string point1 = s.substr(offset,newOffset-offset);
|
||||||
|
|
||||||
|
offset = newOffset;
|
||||||
|
newOffset = (int)s.find(' ',offset+1);
|
||||||
|
string point2 = s.substr(offset,newOffset-offset);
|
||||||
|
|
||||||
|
offset = newOffset;
|
||||||
|
newOffset = (int)s.find(' ',offset+1);
|
||||||
|
string point3 = s.substr(offset,newOffset-offset);
|
||||||
|
|
||||||
|
face[0] = extract(point1);
|
||||||
|
face[1] = extract(point2);
|
||||||
|
face[2] = extract(point3);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, ID3D11ShaderResourceView *> ObjReader::GetMaterials(std::wstring fileName)
|
||||||
|
{
|
||||||
|
ifstream input;
|
||||||
|
input.open(fileName.c_str());
|
||||||
|
|
||||||
|
std::map<std::string, ID3D11ShaderResourceView *> materials;
|
||||||
|
ID3D11ShaderResourceView *srv;
|
||||||
|
string texture;
|
||||||
|
string s;
|
||||||
|
string path;
|
||||||
|
//Utility::String::extractDirPath(path,fileName,'\\');
|
||||||
|
if(!input.is_open())
|
||||||
|
return materials;
|
||||||
|
|
||||||
|
while(!input.eof())
|
||||||
|
{
|
||||||
|
getline(input,s);
|
||||||
|
int offset = (int)s.find(' ');
|
||||||
|
if(offset!=-1)
|
||||||
|
{
|
||||||
|
string c = s.substr(0,offset);
|
||||||
|
if(c=="map_Kd")
|
||||||
|
{
|
||||||
|
texture = path+s.substr(offset+1);
|
||||||
|
//D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
|
||||||
|
//materials["Diffuse"] = srv;
|
||||||
|
}
|
||||||
|
if(c=="map_G")
|
||||||
|
{
|
||||||
|
texture = path+s.substr(offset+1);
|
||||||
|
//D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
|
||||||
|
//materials["Glow"] = srv;
|
||||||
|
}
|
||||||
|
if(c=="map_Ks")
|
||||||
|
{
|
||||||
|
texture = path+s.substr(offset+1);
|
||||||
|
//D3DX11CreateShaderResourceViewFromFile(Oyster::Core::Device,texture.c_str(), NULL, NULL, &srv, NULL);
|
||||||
|
//materials["Specular"] = srv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
input.close();
|
||||||
|
|
||||||
|
return materials;
|
||||||
}
|
}
|
|
@ -1,56 +1,43 @@
|
||||||
#ifndef OBJREADER_H
|
#pragma once
|
||||||
#define OBJREADER_H
|
#include "../Model/ModelInfo.h"
|
||||||
#include "..\..\Misc\Utilities.h"
|
#include "../../OysterMath/OysterMath.h"
|
||||||
#include "..\..\OysterMath\OysterMath.h"
|
|
||||||
#include "..\Model\ModelInfo.h"
|
|
||||||
|
|
||||||
//#include <fstream>
|
namespace Oyster
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OBJReader
|
|
||||||
{
|
{
|
||||||
|
namespace FileLoaders
|
||||||
|
{
|
||||||
|
class ObjReader
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
struct OBJFormat
|
struct Vertex
|
||||||
{
|
{
|
||||||
Oyster::Math::Float3 _d3VertexCoord;
|
Oyster::Math::Float3 Position;
|
||||||
Oyster::Math::Float2 _d3VertexTexture;
|
Oyster::Math::Float2 UV;
|
||||||
Oyster::Math::Float3 _d3VertexNormal;
|
Oyster::Math::Float3 Normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OBJMaterialData
|
static ObjReader *LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
|
||||||
{
|
|
||||||
std::string _name;
|
ObjReader(void);
|
||||||
std::string _mapKd;
|
~ObjReader(void);
|
||||||
float _kd[3];
|
|
||||||
float _ka[3];
|
void GetVertexData(Vertex **vertex,int &numVertex, std::map<std::string, ID3D11ShaderResourceView *> &textures);
|
||||||
float _tf[3];
|
void GetVertexData(Vertex **vertex,int &numVertex);
|
||||||
float _ni;
|
|
||||||
|
|
||||||
OBJMaterialData()
|
|
||||||
{
|
|
||||||
_name = " ";
|
|
||||||
_mapKd = " ";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
std::vector<OBJFormat> _myOBJ;
|
|
||||||
private:
|
private:
|
||||||
|
Vertex *vertices;
|
||||||
|
size_t numVertices;
|
||||||
|
std::map<std::wstring, ID3D11ShaderResourceView *> materials;
|
||||||
|
|
||||||
std::vector<Oyster::Math::Float3> _mVertexCoord, _mVertexNormal;
|
void ParseFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
|
||||||
std::vector<Oyster::Math::Float2> _mVertexTexture;
|
|
||||||
|
|
||||||
int _mNrOfCoords, _mNrOfNormals, _mNrOfTexels, _mNrOfFaces;
|
Oyster::Math::Float3 extract(std::string d);
|
||||||
int _mPos, _mNormal, _mTexel;
|
Oyster::Math::Float3 readVertex(int offset,std::wstring s);
|
||||||
void stringSplit( std::string strToSplit );
|
Oyster::Math::Float2 readUV(int offset,std::wstring s);
|
||||||
void addToOBJarray();
|
Oyster::Math::Float3 readNormal(int offset,std::wstring s);
|
||||||
void* Mat;
|
void readFace(int offset,std::wstring s, Oyster::Math::Float3 face[3]);
|
||||||
|
|
||||||
public:
|
std::map<std::string, ID3D11ShaderResourceView *> GetMaterials(std::wstring fileName);
|
||||||
OBJReader();
|
};
|
||||||
~OBJReader();
|
}
|
||||||
|
}
|
||||||
void readOBJFile( std::wstring fileName);
|
|
||||||
Oyster::Graphics::Model::ModelInfo* toModel();
|
|
||||||
|
|
||||||
};
|
|
||||||
#endif
|
|
|
@ -50,7 +50,7 @@ namespace Oyster
|
||||||
|
|
||||||
void LoadShaderP(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
void LoadShaderP(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
||||||
{
|
{
|
||||||
LoadShader(filename,out,Core::ShaderManager::Pixel);
|
LoadShader(filename,out,Core::PipelineManager::Pixel);
|
||||||
if(out.loadedData==NULL)
|
if(out.loadedData==NULL)
|
||||||
{
|
{
|
||||||
memset(&out,0,sizeof(out));
|
memset(&out,0,sizeof(out));
|
||||||
|
@ -62,7 +62,7 @@ namespace Oyster
|
||||||
void LoadShaderG(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
void LoadShaderG(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
||||||
{
|
{
|
||||||
|
|
||||||
LoadShader(filename,out,Core::ShaderManager::Geometry);
|
LoadShader(filename,out,Core::PipelineManager::Geometry);
|
||||||
if(out.loadedData==NULL)
|
if(out.loadedData==NULL)
|
||||||
{
|
{
|
||||||
memset(&out,0,sizeof(out));
|
memset(&out,0,sizeof(out));
|
||||||
|
@ -74,7 +74,7 @@ namespace Oyster
|
||||||
void LoadShaderC(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
void LoadShaderC(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
||||||
{
|
{
|
||||||
|
|
||||||
LoadShader(filename,out,Core::ShaderManager::Compute);
|
LoadShader(filename,out,Core::PipelineManager::Compute);
|
||||||
if(out.loadedData==NULL)
|
if(out.loadedData==NULL)
|
||||||
{
|
{
|
||||||
memset(&out,0,sizeof(out));
|
memset(&out,0,sizeof(out));
|
||||||
|
@ -86,7 +86,7 @@ namespace Oyster
|
||||||
void LoadShaderH(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
void LoadShaderH(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
||||||
{
|
{
|
||||||
|
|
||||||
LoadShader(filename,out,Core::ShaderManager::Hull);
|
LoadShader(filename,out,Core::PipelineManager::Hull);
|
||||||
if(out.loadedData==NULL)
|
if(out.loadedData==NULL)
|
||||||
{
|
{
|
||||||
memset(&out,0,sizeof(out));
|
memset(&out,0,sizeof(out));
|
||||||
|
@ -98,7 +98,7 @@ namespace Oyster
|
||||||
void LoadShaderD(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
void LoadShaderD(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
||||||
{
|
{
|
||||||
|
|
||||||
LoadShader(filename,out,Core::ShaderManager::Domain);
|
LoadShader(filename,out,Core::PipelineManager::Domain);
|
||||||
if(out.loadedData==NULL)
|
if(out.loadedData==NULL)
|
||||||
{
|
{
|
||||||
memset(&out,0,sizeof(out));
|
memset(&out,0,sizeof(out));
|
||||||
|
@ -110,7 +110,7 @@ namespace Oyster
|
||||||
void LoadShaderV(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
void LoadShaderV(const wchar_t filename[], Oyster::Resource::CustomData& out)
|
||||||
{
|
{
|
||||||
|
|
||||||
LoadShader(filename,out,Core::ShaderManager::Vertex);
|
LoadShader(filename,out,Core::PipelineManager::Vertex);
|
||||||
if(out.loadedData==NULL)
|
if(out.loadedData==NULL)
|
||||||
{
|
{
|
||||||
memset(&out,0,sizeof(out));
|
memset(&out,0,sizeof(out));
|
||||||
|
@ -121,28 +121,28 @@ namespace Oyster
|
||||||
|
|
||||||
void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type)
|
void LoadShader(const wchar_t filename[], Oyster::Resource::CustomData& out, int type)
|
||||||
{
|
{
|
||||||
Core::ShaderManager::ShaderData data;
|
Core::PipelineManager::ShaderData data;
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
ID3DBlob *Shader=NULL, *Error=NULL;
|
ID3DBlob *Shader=NULL, *Error=NULL;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
switch (Core::ShaderManager::ShaderType(type))
|
switch (Core::PipelineManager::ShaderType(type))
|
||||||
{
|
{
|
||||||
case Oyster::Graphics::Core::ShaderManager::Vertex:
|
case Oyster::Graphics::Core::PipelineManager::Vertex:
|
||||||
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","vs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","vs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Hull:
|
case Oyster::Graphics::Core::PipelineManager::Hull:
|
||||||
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","hs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","hs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Domain:
|
case Oyster::Graphics::Core::PipelineManager::Domain:
|
||||||
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","ds_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","ds_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Geometry:
|
case Oyster::Graphics::Core::PipelineManager::Geometry:
|
||||||
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","gs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","gs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Pixel:
|
case Oyster::Graphics::Core::PipelineManager::Pixel:
|
||||||
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","ps_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","ps_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::ShaderManager::Compute:
|
case Oyster::Graphics::Core::PipelineManager::Compute:
|
||||||
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","cs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
hr = D3DCompileFromFile(filename,NULL,D3D_COMPILE_STANDARD_FILE_INCLUDE,"main","cs_5_0",D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,0,&Shader,&Error);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -185,7 +185,7 @@ namespace Oyster
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
out.loadedData = Core::ShaderManager::CreateShader(data, Core::ShaderManager::ShaderType(type));
|
out.loadedData = Core::PipelineManager::CreateShader(data, Core::PipelineManager::ShaderType(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "Render.h"
|
#include "Render.h"
|
||||||
#include "../Resources/Resources.h"
|
#include "../Resources/Deffered.h"
|
||||||
#include "../../Definitions/GraphicalDefinition.h"
|
#include "../../Definitions/GraphicalDefinition.h"
|
||||||
#include "../../Model/ModelInfo.h"
|
#include "../../Model/ModelInfo.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -13,22 +13,34 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
namespace Rendering
|
namespace Rendering
|
||||||
{
|
{
|
||||||
|
Definitions::Pointlight pl;
|
||||||
|
|
||||||
void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection)
|
void Basic::NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights)
|
||||||
{
|
{
|
||||||
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1));
|
Preparations::Basic::ClearBackBuffer(Oyster::Math::Float4(1,0,0,1));
|
||||||
Core::ShaderManager::SetShaderEffect(Graphics::Render::Resources::obj);
|
Preparations::Basic::ClearRTV(Resources::Deffered::GBufferRTV,Resources::Deffered::GBufferSize,Math::Float4(1,0,0,1));
|
||||||
Preparations::Basic::BindBackBufferRTV();
|
Core::PipelineManager::SetRenderPass(Graphics::Render::Resources::Deffered::GeometryPass);
|
||||||
|
|
||||||
Definitions::VP vp;
|
Definitions::VP vp;
|
||||||
vp.V = View;
|
vp.V = View;
|
||||||
vp.P = Projection;
|
vp.P = Projection;
|
||||||
|
|
||||||
void* data = Resources::VPData.Map();
|
void* data = Resources::Deffered::VPData.Map();
|
||||||
memcpy(data, &vp, sizeof(Definitions::VP));
|
memcpy(data, &vp, sizeof(Definitions::VP));
|
||||||
Resources::VPData.Unmap();
|
Resources::Deffered::VPData.Unmap();
|
||||||
|
|
||||||
Resources::VPData.Apply();
|
Definitions::LightConstants lc;
|
||||||
|
lc.InvProj = Projection.GetInverse();
|
||||||
|
lc.Pixels = Core::resolution;
|
||||||
|
lc.Lights = numLights;
|
||||||
|
|
||||||
|
data = Resources::Deffered::LightConstantsData.Map();
|
||||||
|
memcpy(data, &lc, sizeof(Definitions::LightConstants));
|
||||||
|
Resources::Deffered::LightConstantsData.Unmap();
|
||||||
|
|
||||||
|
data = Resources::Deffered::PointLightsData.Map();
|
||||||
|
memcpy(data, Lights, sizeof(Definitions::Pointlight) * numLights);
|
||||||
|
Resources::Deffered::PointLightsData.Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basic::RenderScene(Model::Model* models, int count)
|
void Basic::RenderScene(Model::Model* models, int count)
|
||||||
|
@ -37,14 +49,17 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
if(models[i].Visible)
|
if(models[i].Visible)
|
||||||
{
|
{
|
||||||
void* data = Resources::ModelData.Map();
|
void* data = Resources::Deffered::ModelData.Map();
|
||||||
memcpy(data,&(models[i].WorldMatrix),sizeof(Math::Float4x4));
|
memcpy(data,&(models[i].WorldMatrix),sizeof(Math::Float4x4));
|
||||||
Resources::ModelData.Unmap();
|
Resources::Deffered::ModelData.Unmap();
|
||||||
|
|
||||||
|
|
||||||
Model::ModelInfo* info = (Model::ModelInfo*)models[i].info;
|
Model::ModelInfo* info = (Model::ModelInfo*)models[i].info;
|
||||||
|
|
||||||
|
if(info->Material.size())
|
||||||
|
{
|
||||||
Core::deviceContext->PSSetShaderResources(0,info->Material.size(),&(info->Material[0]));
|
Core::deviceContext->PSSetShaderResources(0,info->Material.size(),&(info->Material[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
info->Vertices->Apply();
|
info->Vertices->Apply();
|
||||||
|
@ -62,8 +77,11 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
void Basic::EndFrame()
|
void Basic::EndFrame()
|
||||||
{
|
{
|
||||||
IDXGISwapChain* chain = Core::swapChain;
|
Core::PipelineManager::SetRenderPass(Resources::Deffered::LightPass);
|
||||||
chain->Present(0,0);
|
|
||||||
|
Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1);
|
||||||
|
|
||||||
|
Core::swapChain->Present(0,0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "..\..\Definitions\GraphicalDefinition.h"
|
||||||
#include "..\..\Core\Core.h"
|
#include "..\..\Core\Core.h"
|
||||||
#include "..\Preparations\Preparations.h"
|
#include "..\Preparations\Preparations.h"
|
||||||
#include "..\..\Model\Model.h"
|
#include "..\..\Model\Model.h"
|
||||||
|
@ -16,7 +16,7 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection);
|
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights);
|
||||||
static void RenderScene(Model::Model* models, int count);
|
static void RenderScene(Model::Model* models, int count);
|
||||||
static void EndFrame();
|
static void EndFrame();
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
#include "Debug.h"
|
||||||
|
#include "..\OysterGraphics\Definitions\GraphicalDefinition.h"
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
// /Bin/Executable/Tester ->
|
||||||
|
// /Code/OysterGraphics/Shader/HLSL
|
||||||
|
const std::wstring PathFromExeToCso = L"..\\Content\\Shaders\\";
|
||||||
|
const std::wstring PathFromExeToHlsl = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\";
|
||||||
|
const std::wstring VertexTransformDebug = L"TransformDebugVertex";
|
||||||
|
const std::wstring VertexDebug = L"DebugVertex";
|
||||||
|
const std::wstring PixelRed = L"DebugPixel";
|
||||||
|
const std::wstring PixelTexture = L"Texture";
|
||||||
|
const std::wstring ComputeDebug = L"Debug";
|
||||||
|
|
||||||
|
typedef Oyster::Graphics::Core::PipelineManager::ShaderType ShaderType;
|
||||||
|
typedef Oyster::Graphics::Core::PipelineManager::Get GetShader;
|
||||||
|
typedef Oyster::Graphics::Core::PipelineManager Shader;
|
||||||
|
typedef Oyster::Graphics::Core::Buffer Buffer;
|
||||||
|
|
||||||
|
namespace Oyster
|
||||||
|
{
|
||||||
|
namespace Graphics
|
||||||
|
{
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
//Shader::RenderPass Resources::Debug::obj;
|
||||||
|
Shader::RenderPass Resources::Debug::debugCompute;// = Shader::ShaderEffect();;
|
||||||
|
//Buffer Resources::Debug::ModelData = Buffer();
|
||||||
|
//Buffer Resources::Debug::VPData = Buffer();
|
||||||
|
|
||||||
|
//ID3D11ShaderResourceView* Resources::Debug::srv = NULL;
|
||||||
|
//ID3D11RenderTargetView* Resources::Debug::rtv = NULL;
|
||||||
|
|
||||||
|
Core::Init::State Resources::Debug::Init()
|
||||||
|
{
|
||||||
|
|
||||||
|
#pragma region LoadShaders
|
||||||
|
/** Load Compute Shaders for d3dcompile */
|
||||||
|
Core::PipelineManager::Init(PathFromExeToHlsl + L"ComputeDebug\\" + L"DebugCompute.hlsl", ShaderType::Compute, ComputeDebug);
|
||||||
|
|
||||||
|
#pragma endregion
|
||||||
|
return Core::Init::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Resources::Debug::Clean()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,39 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef Reources_h
|
||||||
|
#define Reources_h
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
|
||||||
|
#include "../OysterGraphics/Core/Core.h"
|
||||||
|
|
||||||
|
namespace Oyster
|
||||||
|
{
|
||||||
|
namespace Graphics
|
||||||
|
{
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
namespace Resources
|
||||||
|
{
|
||||||
|
class Debug
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//static Core::PipelineManager::RenderPass obj;
|
||||||
|
static Core::PipelineManager::RenderPass debugCompute;
|
||||||
|
//static Core::Buffer ModelData;
|
||||||
|
//static Core::Buffer VPData;
|
||||||
|
|
||||||
|
//static ID3D11ShaderResourceView* srv;
|
||||||
|
//static ID3D11RenderTargetView* rtv;
|
||||||
|
|
||||||
|
static Core::Init::State Init();
|
||||||
|
static void Clean();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,227 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Deffered.h"
|
||||||
|
#include "..\..\Definitions\GraphicalDefinition.h"
|
||||||
|
|
||||||
|
typedef Oyster::Graphics::Core::PipelineManager::ShaderType ShaderType;
|
||||||
|
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 PathToCSO = L"..\\Content\\Shaders\\";
|
||||||
|
|
||||||
|
namespace Oyster
|
||||||
|
{
|
||||||
|
namespace Graphics
|
||||||
|
{
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
namespace Resources
|
||||||
|
{
|
||||||
|
|
||||||
|
ID3D11RenderTargetView* Deffered::GBufferRTV[2] = {0};
|
||||||
|
ID3D11ShaderResourceView* Deffered::GBufferSRV[2] = {0};
|
||||||
|
|
||||||
|
|
||||||
|
Shader::RenderPass Deffered::GeometryPass;
|
||||||
|
Shader::RenderPass Deffered::LightPass;
|
||||||
|
|
||||||
|
Buffer Deffered::ModelData = Buffer();
|
||||||
|
Buffer Deffered::VPData = Buffer();
|
||||||
|
Buffer Deffered::LightConstantsData = Buffer();
|
||||||
|
|
||||||
|
Buffer Deffered::PointLightsData = Buffer();
|
||||||
|
ID3D11ShaderResourceView* Deffered::PointLightView = NULL;
|
||||||
|
|
||||||
|
Core::Init::State Deffered::Init()
|
||||||
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
std::wstring path = PathToHLSL;
|
||||||
|
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"LightPass" + end, ShaderType::Compute, L"LightPass");
|
||||||
|
|
||||||
|
//Create Buffers
|
||||||
|
Buffer::BUFFER_INIT_DESC desc;
|
||||||
|
desc.ElementSize = sizeof(Oyster::Math::Matrix);
|
||||||
|
desc.NumElements = 1;
|
||||||
|
desc.InitData = NULL;
|
||||||
|
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS;
|
||||||
|
desc.Usage = Buffer::BUFFER_USAGE::BUFFER_CPU_WRITE_DISCARD;
|
||||||
|
|
||||||
|
ModelData.Init(desc);
|
||||||
|
|
||||||
|
desc.NumElements = 2;
|
||||||
|
VPData.Init(desc);
|
||||||
|
|
||||||
|
desc.ElementSize = sizeof(Definitions::LightConstants);
|
||||||
|
desc.NumElements = 1;
|
||||||
|
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_CS;
|
||||||
|
|
||||||
|
LightConstantsData.Init(desc);
|
||||||
|
|
||||||
|
desc.ElementSize = sizeof(Definitions::Pointlight);
|
||||||
|
desc.NumElements = MaxLightSize;
|
||||||
|
desc.Type = Buffer::STRUCTURED_BUFFER;
|
||||||
|
PointLightsData.Init(desc);
|
||||||
|
|
||||||
|
//Create States
|
||||||
|
D3D11_RASTERIZER_DESC rdesc;
|
||||||
|
rdesc.CullMode = D3D11_CULL_BACK;
|
||||||
|
rdesc.FillMode = D3D11_FILL_SOLID;
|
||||||
|
rdesc.FrontCounterClockwise = true;
|
||||||
|
rdesc.DepthBias = 0;
|
||||||
|
rdesc.DepthBiasClamp = 0;
|
||||||
|
rdesc.DepthClipEnable = true;
|
||||||
|
rdesc.SlopeScaledDepthBias = 0;
|
||||||
|
rdesc.ScissorEnable = false;
|
||||||
|
rdesc.MultisampleEnable = false;
|
||||||
|
rdesc.AntialiasedLineEnable = false;
|
||||||
|
|
||||||
|
ID3D11RasterizerState* rs = NULL;
|
||||||
|
Oyster::Graphics::Core::device->CreateRasterizerState(&rdesc,&rs);
|
||||||
|
|
||||||
|
D3D11_SAMPLER_DESC sdesc;
|
||||||
|
sdesc.Filter = D3D11_FILTER_ANISOTROPIC;
|
||||||
|
sdesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
sdesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
sdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||||
|
sdesc.MipLODBias = 0;
|
||||||
|
sdesc.MaxAnisotropy =4;
|
||||||
|
sdesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
|
||||||
|
*sdesc.BorderColor = *Oyster::Math::Float4(1,1,1,1).element;
|
||||||
|
sdesc.MinLOD = 0;
|
||||||
|
sdesc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||||
|
|
||||||
|
ID3D11SamplerState** ss = new ID3D11SamplerState*[1];
|
||||||
|
Oyster::Graphics::Core::device->CreateSamplerState(&sdesc,ss);
|
||||||
|
|
||||||
|
D3D11_DEPTH_STENCIL_DESC ddesc;
|
||||||
|
ddesc.DepthEnable = true;
|
||||||
|
ddesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||||
|
ddesc.DepthFunc = D3D11_COMPARISON_LESS;
|
||||||
|
|
||||||
|
ddesc.StencilEnable = true;
|
||||||
|
ddesc.StencilReadMask = 0xFF;
|
||||||
|
ddesc.StencilWriteMask = 0xFF;
|
||||||
|
|
||||||
|
ddesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
||||||
|
ddesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
|
||||||
|
ddesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||||
|
ddesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||||
|
|
||||||
|
ddesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
||||||
|
ddesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
|
||||||
|
ddesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||||
|
ddesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||||
|
|
||||||
|
ID3D11DepthStencilState* dsState;
|
||||||
|
Core::device->CreateDepthStencilState(&ddesc,&dsState);
|
||||||
|
|
||||||
|
//Create Views
|
||||||
|
for(int i = 0; i< Resources::Deffered::GBufferSize; ++i)
|
||||||
|
{
|
||||||
|
Core::Init::CreateLinkedShaderResourceFromTexture(&GBufferRTV[i],&GBufferSRV[i],NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
Buffer* b = &PointLightsData;
|
||||||
|
|
||||||
|
Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL);
|
||||||
|
|
||||||
|
//Create ShaderEffects
|
||||||
|
GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Geometry");
|
||||||
|
GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Geometry");
|
||||||
|
|
||||||
|
D3D11_INPUT_ELEMENT_DESC indesc[] =
|
||||||
|
{
|
||||||
|
{ "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 },
|
||||||
|
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Shader::CreateInputLayout(indesc,3,GetShader::Vertex(L"Geometry"),GeometryPass.IAStage.Layout);
|
||||||
|
GeometryPass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
||||||
|
GeometryPass.CBuffers.Vertex.push_back(VPData);
|
||||||
|
GeometryPass.CBuffers.Vertex.push_back(ModelData);
|
||||||
|
GeometryPass.RenderStates.Rasterizer = rs;
|
||||||
|
GeometryPass.RenderStates.SampleCount = 1;
|
||||||
|
GeometryPass.RenderStates.SampleState = ss;
|
||||||
|
GeometryPass.RenderStates.DepthStencil = dsState;
|
||||||
|
for(int i = 0; i<Deffered::GBufferSize;++i)
|
||||||
|
{
|
||||||
|
GeometryPass.RTV.push_back(GBufferRTV[i]);
|
||||||
|
}
|
||||||
|
GeometryPass.depth = Core::depthStencil;
|
||||||
|
|
||||||
|
LightPass.Shaders.Compute = GetShader::Compute(L"LightPass");
|
||||||
|
LightPass.UAV.Compute.push_back(Core::backBufferUAV);
|
||||||
|
for(int i = 0; i<Deffered::GBufferSize;++i)
|
||||||
|
{
|
||||||
|
LightPass.SRV.Compute.push_back(GBufferSRV[i]);
|
||||||
|
}
|
||||||
|
LightPass.SRV.Compute.push_back(Core::depthStencilUAV);
|
||||||
|
LightPass.CBuffers.Compute.push_back(LightConstantsData);
|
||||||
|
LightPass.SRV.Compute.push_back(PointLightView);
|
||||||
|
|
||||||
|
|
||||||
|
return Core::Init::State::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Deffered::Clean()
|
||||||
|
{
|
||||||
|
Resources::Deffered::ModelData.~Buffer();
|
||||||
|
Resources::Deffered::VPData.~Buffer();
|
||||||
|
Resources::Deffered::LightConstantsData.~Buffer();
|
||||||
|
Resources::Deffered::PointLightsData.~Buffer();
|
||||||
|
|
||||||
|
for(int i = 0; i< GBufferSize; ++i)
|
||||||
|
{
|
||||||
|
SAFE_RELEASE(GBufferRTV[i]);
|
||||||
|
SAFE_RELEASE(GBufferSRV[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < (int)GeometryPass.CBuffers.Vertex.size(); ++i)
|
||||||
|
{
|
||||||
|
SAFE_RELEASE(GeometryPass.CBuffers.Vertex[i]);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < (int)GeometryPass.CBuffers.Pixel.size(); ++i)
|
||||||
|
{
|
||||||
|
SAFE_RELEASE(GeometryPass.CBuffers.Pixel[i]);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < (int)GeometryPass.CBuffers.Geometry.size(); ++i)
|
||||||
|
{
|
||||||
|
SAFE_RELEASE(GeometryPass.CBuffers.Geometry[i]);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < (int)GeometryPass.CBuffers.Compute.size(); ++i)
|
||||||
|
{
|
||||||
|
SAFE_RELEASE(GeometryPass.CBuffers.Compute[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
SAFE_RELEASE(GeometryPass.IAStage.Layout);
|
||||||
|
|
||||||
|
SAFE_RELEASE(GeometryPass.RenderStates.BlendState);
|
||||||
|
|
||||||
|
SAFE_RELEASE(GeometryPass.RenderStates.DepthStencil);
|
||||||
|
|
||||||
|
SAFE_RELEASE(GeometryPass.RenderStates.Rasterizer);
|
||||||
|
|
||||||
|
for(int i = 0; i < GeometryPass.RenderStates.SampleCount; ++i)
|
||||||
|
{
|
||||||
|
SAFE_RELEASE(GeometryPass.RenderStates.SampleState[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
SAFE_DELETE_ARRAY(GeometryPass.RenderStates.SampleState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../Core/Core.h"
|
||||||
|
|
||||||
|
namespace Oyster
|
||||||
|
{
|
||||||
|
namespace Graphics
|
||||||
|
{
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
namespace Resources
|
||||||
|
{
|
||||||
|
class Deffered
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const int GBufferSize = 2;
|
||||||
|
static const int MaxLightSize = 100;
|
||||||
|
//! GBuffers
|
||||||
|
//! 0 = Diffuse + SpecKoeff
|
||||||
|
//! 1 = Normal + Glow
|
||||||
|
static ID3D11RenderTargetView* GBufferRTV[GBufferSize];
|
||||||
|
static ID3D11ShaderResourceView* GBufferSRV[GBufferSize];
|
||||||
|
|
||||||
|
static Core::PipelineManager::RenderPass GeometryPass;
|
||||||
|
static Core::PipelineManager::RenderPass LightPass;
|
||||||
|
|
||||||
|
static Core::Buffer ModelData;
|
||||||
|
static Core::Buffer VPData;
|
||||||
|
|
||||||
|
static Core::Buffer LightConstantsData;
|
||||||
|
|
||||||
|
static Core::Buffer PointLightsData;
|
||||||
|
static ID3D11ShaderResourceView* PointLightView;
|
||||||
|
|
||||||
|
static Core::Init::State Init();
|
||||||
|
static void Clean();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,192 +0,0 @@
|
||||||
#include "Resources.h"
|
|
||||||
#include "..\OysterGraphics\Definitions\GraphicalDefinition.h"
|
|
||||||
|
|
||||||
// /Bin/Executable/Tester ->
|
|
||||||
// /Code/OysterGraphics/Shader/HLSL
|
|
||||||
const std::wstring PathFromExeToCso = L"..\\Content\\Shaders\\";
|
|
||||||
const std::wstring PathFromExeToHlsl = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\";
|
|
||||||
const std::wstring VertexTransformDebug = L"TransformDebugVertex";
|
|
||||||
const std::wstring VertexDebug = L"DebugVertex";
|
|
||||||
const std::wstring PixelRed = L"DebugPixel";
|
|
||||||
const std::wstring PixelTexture = L"Texture";
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
namespace Graphics
|
|
||||||
{
|
|
||||||
namespace Render
|
|
||||||
{
|
|
||||||
Shader::ShaderEffect Resources::obj;// = Shader::ShaderEffect();;
|
|
||||||
Buffer Resources::ModelData = Buffer();
|
|
||||||
Buffer Resources::VPData = Buffer();
|
|
||||||
|
|
||||||
Core::Init::State Resources::Init()
|
|
||||||
{
|
|
||||||
|
|
||||||
#pragma region LoadShaders
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
|
|
||||||
/** Load Vertex Shader for d3dcompile*/
|
|
||||||
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugCameraVertex.hlsl",ShaderType::Vertex, VertexTransformDebug);
|
|
||||||
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" +L"DebugVertex.hlsl",ShaderType::Vertex, VertexDebug);
|
|
||||||
|
|
||||||
/** Load Pixel Shader for d3dcompile */
|
|
||||||
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" + L"DebugPixel.hlsl", ShaderType::Pixel, PixelRed);
|
|
||||||
Core::ShaderManager::Init(PathFromExeToHlsl + L"SimpleDebug\\" + L"TextureDebug.hlsl", ShaderType::Pixel, PixelTexture);
|
|
||||||
|
|
||||||
|
|
||||||
#else
|
|
||||||
/** Load Vertex Shader with Precompiled */
|
|
||||||
Core::ShaderManager::Init(PathFromExeToCso + L"DebugCameraVertex.cso",ShaderType::Vertex, VertexTransformDebug);
|
|
||||||
Core::ShaderManager::Init(PathFromExeToCso + L"DebugVertex.cso",ShaderType::Vertex, VertexDebug);
|
|
||||||
|
|
||||||
/** Load Pixel Shader with Precompiled */
|
|
||||||
Core::ShaderManager::Init(PathFromExeToCso + L"DebugPixel.cso",ShaderType::Pixel, PixelRed);
|
|
||||||
Core::ShaderManager::Init(PathFromExeToCso + L"TextureDebug.cso",ShaderType::Pixel, PixelTexture);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region CreateBuffers
|
|
||||||
Buffer::BUFFER_INIT_DESC desc;
|
|
||||||
desc.ElementSize = sizeof(Oyster::Math::Matrix);
|
|
||||||
desc.NumElements = 1;
|
|
||||||
desc.InitData = NULL;
|
|
||||||
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS;
|
|
||||||
desc.Usage = Buffer::BUFFER_USAGE::BUFFER_CPU_WRITE_DISCARD;
|
|
||||||
|
|
||||||
ModelData.Init(desc);
|
|
||||||
|
|
||||||
desc.NumElements = 2;
|
|
||||||
VPData.Init(desc);
|
|
||||||
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region Setup Render States
|
|
||||||
/** @todo Create DX States */
|
|
||||||
|
|
||||||
D3D11_RASTERIZER_DESC rdesc;
|
|
||||||
rdesc.CullMode = D3D11_CULL_BACK;
|
|
||||||
rdesc.FillMode = D3D11_FILL_SOLID;
|
|
||||||
rdesc.FrontCounterClockwise = true;
|
|
||||||
rdesc.DepthBias = 0;
|
|
||||||
rdesc.DepthBiasClamp = 0;
|
|
||||||
rdesc.DepthClipEnable = true;
|
|
||||||
rdesc.SlopeScaledDepthBias = 0;
|
|
||||||
rdesc.ScissorEnable = false;
|
|
||||||
rdesc.MultisampleEnable = false;
|
|
||||||
rdesc.AntialiasedLineEnable = false;
|
|
||||||
|
|
||||||
ID3D11RasterizerState* rs = NULL;
|
|
||||||
Oyster::Graphics::Core::device->CreateRasterizerState(&rdesc,&rs);
|
|
||||||
|
|
||||||
D3D11_SAMPLER_DESC sdesc;
|
|
||||||
sdesc.Filter = D3D11_FILTER_ANISOTROPIC;
|
|
||||||
/// @todo parata med fredrik om wraping
|
|
||||||
sdesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
sdesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
sdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
|
||||||
sdesc.MipLODBias = 0;
|
|
||||||
sdesc.MaxAnisotropy =4;
|
|
||||||
sdesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
|
|
||||||
*sdesc.BorderColor = *Oyster::Math::Float4(1,1,1,1).element;
|
|
||||||
sdesc.MinLOD = 0;
|
|
||||||
sdesc.MaxLOD = D3D11_FLOAT32_MAX;
|
|
||||||
|
|
||||||
ID3D11SamplerState** ss = new ID3D11SamplerState*[1];
|
|
||||||
Oyster::Graphics::Core::device->CreateSamplerState(&sdesc,ss);
|
|
||||||
|
|
||||||
D3D11_DEPTH_STENCIL_DESC ddesc;
|
|
||||||
ddesc.DepthEnable = true;
|
|
||||||
ddesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
|
||||||
ddesc.DepthFunc = D3D11_COMPARISON_LESS;
|
|
||||||
|
|
||||||
ddesc.StencilEnable = true;
|
|
||||||
ddesc.StencilReadMask = 0xFF;
|
|
||||||
ddesc.StencilWriteMask = 0xFF;
|
|
||||||
|
|
||||||
ddesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
||||||
ddesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
|
|
||||||
ddesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
||||||
ddesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
||||||
|
|
||||||
ddesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
|
|
||||||
ddesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
|
|
||||||
ddesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
|
||||||
ddesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
|
||||||
|
|
||||||
ID3D11DepthStencilState* dsState;
|
|
||||||
Core::device->CreateDepthStencilState(&ddesc,&dsState);
|
|
||||||
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region Setup Views
|
|
||||||
/** @todo Create Views */
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region Create Shader Effects
|
|
||||||
/** @todo Create ShaderEffects */
|
|
||||||
obj.Shaders.Pixel = GetShader::Pixel(PixelTexture);
|
|
||||||
obj.Shaders.Vertex = GetShader::Vertex(VertexTransformDebug);
|
|
||||||
|
|
||||||
D3D11_INPUT_ELEMENT_DESC indesc[] =
|
|
||||||
{
|
|
||||||
{ "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 },
|
|
||||||
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Shader::CreateInputLayout(indesc,3,GetShader::Vertex(VertexTransformDebug),obj.IAStage.Layout);
|
|
||||||
obj.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
|
||||||
obj.CBuffers.Vertex.push_back(&VPData);
|
|
||||||
obj.RenderStates.Rasterizer = rs;
|
|
||||||
obj.RenderStates.SampleCount = 1;
|
|
||||||
obj.RenderStates.SampleState = ss;
|
|
||||||
obj.RenderStates.DepthStencil = dsState;
|
|
||||||
|
|
||||||
ModelData.Apply(1);
|
|
||||||
#pragma endregion
|
|
||||||
return Core::Init::Sucsess;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Resources::Clean()
|
|
||||||
{
|
|
||||||
Resources::ModelData.~Buffer();
|
|
||||||
for(int i = 0; i < obj.CBuffers.Vertex.size(); ++i)
|
|
||||||
{
|
|
||||||
obj.CBuffers.Vertex[i]->~Buffer();
|
|
||||||
}
|
|
||||||
for(int i = 0; i < obj.CBuffers.Pixel.size(); ++i)
|
|
||||||
{
|
|
||||||
SAFE_DELETE(obj.CBuffers.Pixel[i]);
|
|
||||||
}
|
|
||||||
for(int i = 0; i < obj.CBuffers.Geometry.size(); ++i)
|
|
||||||
{
|
|
||||||
SAFE_DELETE(obj.CBuffers.Geometry[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SAFE_RELEASE(obj.IAStage.Layout);
|
|
||||||
|
|
||||||
SAFE_RELEASE(obj.RenderStates.BlendState);
|
|
||||||
|
|
||||||
SAFE_RELEASE(obj.RenderStates.DepthStencil);
|
|
||||||
|
|
||||||
SAFE_RELEASE(obj.RenderStates.Rasterizer);
|
|
||||||
|
|
||||||
for(int i = 0; i < obj.RenderStates.SampleCount; ++i)
|
|
||||||
{
|
|
||||||
SAFE_RELEASE(obj.RenderStates.SampleState[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SAFE_DELETE_ARRAY(obj.RenderStates.SampleState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef Reources_h
|
|
||||||
#define Reources_h
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include "../OysterGraphics/Core/Core.h"
|
|
||||||
|
|
||||||
namespace Oyster
|
|
||||||
{
|
|
||||||
namespace Graphics
|
|
||||||
{
|
|
||||||
namespace Render
|
|
||||||
{
|
|
||||||
class Resources
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Core::ShaderManager::ShaderEffect obj;
|
|
||||||
static Core::Buffer ModelData;
|
|
||||||
static Core::Buffer VPData;
|
|
||||||
|
|
||||||
static Core::Init::State Init();
|
|
||||||
static void Clean();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
struct PointLight
|
struct PointLight
|
||||||
{
|
{
|
||||||
float4 PosRadius;
|
float3 Pos;
|
||||||
float4 ColorBright;
|
float Radius;
|
||||||
|
float3 Color;
|
||||||
|
float Bright;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DiffSpec
|
struct DiffSpec
|
||||||
|
@ -13,19 +15,21 @@ struct DiffSpec
|
||||||
float3 Specular;
|
float3 Specular;
|
||||||
};
|
};
|
||||||
|
|
||||||
cbuffer PointLights : register(b0)
|
cbuffer LightConstants : register(b0)
|
||||||
{
|
|
||||||
PointLight pl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cbuffer LightConstants : register(b1)
|
|
||||||
{
|
{
|
||||||
float4x4 InvProj;
|
float4x4 InvProj;
|
||||||
int2 Pixels;
|
float2 Pixels;
|
||||||
|
int Lights;
|
||||||
|
float Pad;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D DiffuseGlow : register(t0);
|
Texture2D DiffuseGlow : register(t0);
|
||||||
Texture2D NormalSpec : register(t1);
|
Texture2D NormalSpec : register(t1);
|
||||||
Texture2D DepthTexture : register(t2);
|
Texture2D DepthTexture : register(t2);
|
||||||
|
|
||||||
|
|
||||||
|
StructuredBuffer<PointLight> Points : register(t3);
|
||||||
|
|
||||||
|
RWTexture2D<float4> Output : register(u0);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -3,10 +3,10 @@ struct VertexIn
|
||||||
float3 pos : POSITION;
|
float3 pos : POSITION;
|
||||||
float2 UV : TEXCOORD;
|
float2 UV : TEXCOORD;
|
||||||
float3 normal : NORMAL;
|
float3 normal : NORMAL;
|
||||||
float3 tangent : TANGENT;
|
//float3 tangent : TANGENT;
|
||||||
float3 biTangent : BITANGENT;
|
//float3 biTangent : BITANGENT;
|
||||||
float4 boneIndex : BONEINDEX;
|
//float4 boneIndex : BONEINDEX;
|
||||||
float4 boneWeight : BONEWEIGHT;
|
//float4 boneWeight : BONEWEIGHT;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VertexOut
|
struct VertexOut
|
||||||
|
@ -15,8 +15,8 @@ struct VertexOut
|
||||||
float4 ViewPos : POSITION;
|
float4 ViewPos : POSITION;
|
||||||
float2 UV : TEXCOORD;
|
float2 UV : TEXCOORD;
|
||||||
float3 normal : NORMAL;
|
float3 normal : NORMAL;
|
||||||
float3 tangent : TANGENT;
|
//float3 tangent : TANGENT;
|
||||||
float3 biTangent : BITANGENT;
|
//float3 biTangent : BITANGENT;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PixelOut
|
struct PixelOut
|
||||||
|
@ -26,7 +26,9 @@ struct PixelOut
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture2D Diffuse : register(t0);
|
Texture2D Diffuse : register(t0);
|
||||||
Texture2D Specular : register(t1);
|
Texture2D Normal : register(t1);
|
||||||
|
|
||||||
|
SamplerState S1 : register(s0);
|
||||||
|
|
||||||
cbuffer PerFrame : register(b0)
|
cbuffer PerFrame : register(b0)
|
||||||
{
|
{
|
|
@ -1,9 +0,0 @@
|
||||||
#include "GBufferHeader.hlsli"
|
|
||||||
|
|
||||||
PixelOut main(VertexOut input)
|
|
||||||
{
|
|
||||||
PixelOut output;
|
|
||||||
output.DiffuseGlow = float4(1.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
output.NormalSpec = float4(input.normal, 1.0f);
|
|
||||||
return output;
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
#include "GBufferHeader.hlsli"
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -4,7 +4,7 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
|
||||||
{
|
{
|
||||||
DiffSpec output;
|
DiffSpec output;
|
||||||
float4 normalSpec = NormalSpec[texCoord];
|
float4 normalSpec = NormalSpec[texCoord];
|
||||||
float3 lightVec = pl.PosRadius.xyz - pos.xyz;
|
float3 lightVec = pl.Pos - pos.xyz;
|
||||||
float d = length(lightVec);
|
float d = length(lightVec);
|
||||||
lightVec = lightVec/d;
|
lightVec = lightVec/d;
|
||||||
|
|
||||||
|
@ -12,12 +12,17 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
|
||||||
float3 v = reflect(-lightVec, normalSpec.xyz);
|
float3 v = reflect(-lightVec, normalSpec.xyz);
|
||||||
float specFactor = pow(max(dot(v,normalize(-pos)), 0.0f),normalSpec.w);
|
float specFactor = pow(max(dot(v,normalize(-pos)), 0.0f),normalSpec.w);
|
||||||
//Check att later
|
//Check att later
|
||||||
float att = (max(d-pl.PosRadius.w,0)/pow(pl.PosRadius.w,2));
|
float att = max( 0, 1 - (d / pl.Radius));
|
||||||
|
//att = 1;
|
||||||
//fix Ilum calcs instead of PhongBlinn
|
//fix Ilum calcs instead of PhongBlinn
|
||||||
output.Diffuse = pl.ColorBright.w * att * diffFactor * pl.ColorBright.xyz;
|
output.Diffuse = pl.Bright * att * diffFactor * pl.Color;
|
||||||
output.Specular = pl.ColorBright.w * att * specFactor * pl.ColorBright.xyz;
|
output.Specular = pl.Bright * att * specFactor * pl.Color;
|
||||||
if(diffFactor == 0)
|
if(diffFactor == 0)
|
||||||
output.Specular * 0;
|
output.Specular * 0;
|
||||||
|
if(d > pl.Radius)
|
||||||
|
{
|
||||||
|
output.Diffuse = float4(0,0,0,1);
|
||||||
|
output.Specular = float4(0,0,0,1);
|
||||||
|
}
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
#include "Defines.hlsli"
|
||||||
|
#include "LightCalc.hlsli"
|
||||||
|
#include "PosManipulation.hlsli"
|
||||||
|
//todo
|
||||||
|
//LightCulling
|
||||||
|
//Calc Diff + Spec
|
||||||
|
//Calc Ambience
|
||||||
|
//Write Glow
|
||||||
|
|
||||||
|
|
||||||
|
[numthreads(16, 16, 1)]
|
||||||
|
void main( uint3 DTid : SV_DispatchThreadID )
|
||||||
|
{
|
||||||
|
float3 ViewPos = ToVpos(DTid.xy);
|
||||||
|
DiffSpec Shaded;
|
||||||
|
Shaded.Diffuse = float4(0,0,0,0);
|
||||||
|
Shaded.Specular = float4(0,0,0,0);
|
||||||
|
for(int i = 0; i < Lights; ++i)
|
||||||
|
{
|
||||||
|
DiffSpec light = LightCalc(Points[i], ViewPos, DTid.xy);
|
||||||
|
Shaded.Diffuse = light.Diffuse;
|
||||||
|
Shaded.Specular = light.Specular;
|
||||||
|
}
|
||||||
|
//Output[DTid.xy] = float4(ViewPos,1);
|
||||||
|
//Output[DTid.xy] = DepthTexture[DTid.xy].x;
|
||||||
|
//Output[DTid.xy] = float4(DTid.xy/ Pixels,1,1);
|
||||||
|
//Output[DTid.xy] = NormalSpec[DTid.xy];
|
||||||
|
//Output[DTid.xy] = float4(light.Diffuse, 1);
|
||||||
|
//Output[DTid.xy] = float4(light.Specular, 1);
|
||||||
|
Output[DTid.xy] = float4( Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz + /*Shaded.Specular +*/ DiffuseGlow[DTid.xy].xyz * 0.2f, 1);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "GBufferHeader.hlsli"
|
||||||
|
|
||||||
|
PixelOut main(VertexOut input)
|
||||||
|
{
|
||||||
|
PixelOut output;
|
||||||
|
output.DiffuseGlow = Diffuse.Sample(S1, input.UV);
|
||||||
|
output.NormalSpec = float4(normalize(input.normal), 1.0f);
|
||||||
|
return output;
|
||||||
|
}
|
|
@ -4,18 +4,19 @@
|
||||||
float3 ToVpos(float2 texCoord)
|
float3 ToVpos(float2 texCoord)
|
||||||
{
|
{
|
||||||
//Get proper UV
|
//Get proper UV
|
||||||
float2 UV = float2(texCoord) / float2(Pixels);
|
float2 UV = texCoord / Pixels;
|
||||||
|
|
||||||
float4 ViewPos;
|
float4 ViewPos = float4(0,0,0,0);
|
||||||
// Get the depth value for this pixel
|
// Get the depth value for this pixel
|
||||||
ViewPos.z= DepthTexture[texCoord].x;
|
ViewPos.z= DepthTexture[texCoord].x;
|
||||||
//Get X/w
|
//Get X/w
|
||||||
ViewPos.x = UV.x * 2 - 1;
|
ViewPos.x = UV.x * 2 - 1;
|
||||||
//Get Y/w
|
//Get Y/w
|
||||||
|
//ViewPos.y = -(UV.y * 2) + 1;
|
||||||
ViewPos.y = 1 - 2 * UV.y;
|
ViewPos.y = 1 - 2 * UV.y;
|
||||||
ViewPos.w = 1;
|
ViewPos.w = 1;
|
||||||
|
|
||||||
//Un project
|
//Un project
|
||||||
ViewPos = mul(ViewPos, InvProj);
|
ViewPos = mul(InvProj, ViewPos);
|
||||||
return ViewPos.xyz / ViewPos.w;
|
return ViewPos.xyz / ViewPos.w;
|
||||||
}
|
}
|
|
@ -1,16 +0,0 @@
|
||||||
#include "Defines.hlsli"
|
|
||||||
#include "LightCalc.hlsli"
|
|
||||||
#include "PosManipulation.hlsli"
|
|
||||||
//todo
|
|
||||||
//LightCulling
|
|
||||||
//Calc Diff + Spec
|
|
||||||
//Calc Ambience
|
|
||||||
//Write Glow
|
|
||||||
|
|
||||||
|
|
||||||
[numthreads(1, 1, 1)]
|
|
||||||
void main( uint3 DTid : SV_DispatchThreadID )
|
|
||||||
{
|
|
||||||
float3 ViewPos = ToVpos(DTid.xy);
|
|
||||||
//DiffSpec LightCalc(pl, float3 pos)
|
|
||||||
}
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "GBufferHeader.hlsli"
|
||||||
|
|
||||||
|
VertexOut main( VertexIn input )
|
||||||
|
{
|
||||||
|
VertexOut output;
|
||||||
|
float4 WorldPos = mul(World, float4(input.pos,1));
|
||||||
|
float4 ViewPos = mul(View, WorldPos);
|
||||||
|
output.pos = mul(Projection, ViewPos);
|
||||||
|
float4 WorldNor = mul(World, float4(input.normal,0));
|
||||||
|
float4 ViewNor = mul(View, WorldNor);
|
||||||
|
output.normal = ViewNor;
|
||||||
|
output.normal.z *= -1;
|
||||||
|
|
||||||
|
output.UV = input.UV;
|
||||||
|
//output.normal = ViewNor;
|
||||||
|
return output;
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ HINSTANCE g_hInst = NULL;
|
||||||
HWND g_hWnd = NULL;
|
HWND g_hWnd = NULL;
|
||||||
Oyster::Graphics::Model::Model* m = NULL;
|
Oyster::Graphics::Model::Model* m = NULL;
|
||||||
Oyster::Graphics::Model::Model* m2 = NULL;
|
Oyster::Graphics::Model::Model* m2 = NULL;
|
||||||
|
Oyster::Graphics::Model::Model* m3 = NULL;
|
||||||
Oyster::Math::Float4x4 V;
|
Oyster::Math::Float4x4 V;
|
||||||
Oyster::Math::Float4x4 P;
|
Oyster::Math::Float4x4 P;
|
||||||
|
|
||||||
|
@ -188,9 +189,11 @@ HRESULT InitDirect3D()
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
#pragma region Obj
|
#pragma region Obj
|
||||||
m = Oyster::Graphics::API::CreateModel(L"crate");
|
m = Oyster::Graphics::API::CreateModel(L"Orca");
|
||||||
m2 = Oyster::Graphics::API::CreateModel(L"crate");
|
m2 = Oyster::Graphics::API::CreateModel(L"identityCube");
|
||||||
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
|
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
|
||||||
|
m3 = Oyster::Graphics::API::CreateModel(L"identityCube");
|
||||||
|
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,7 +202,18 @@ HRESULT InitDirect3D()
|
||||||
P.Invert();
|
P.Invert();
|
||||||
|
|
||||||
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
|
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
|
||||||
V = Oyster::Math3D::InverseOrientationMatrix(V);
|
//V = Oyster::Math3D::OrientationMatrix_LookAtPos(Oyster::Math::Float3(0,0,0), Oyster::Math::Float3(0,1,0), Oyster::Math::Float3(0,0,-5.4f));
|
||||||
|
//V.v[3][2] *= -1;
|
||||||
|
V = V.GetInverse();
|
||||||
|
|
||||||
|
|
||||||
|
Oyster::Graphics::Definitions::Pointlight pl;
|
||||||
|
pl.Color = Oyster::Math::Float3(1,1,1);
|
||||||
|
pl.Bright = 30;
|
||||||
|
pl.Pos = (V * Oyster::Math::Float4(Oyster::Math::Float3(5,-5,5.4f), 1)).xyz;
|
||||||
|
pl.Radius = 15;
|
||||||
|
|
||||||
|
Oyster::Graphics::API::AddLight(pl);
|
||||||
|
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -207,9 +221,10 @@ HRESULT InitDirect3D()
|
||||||
float angle = 0;
|
float angle = 0;
|
||||||
HRESULT Update(float deltaTime)
|
HRESULT Update(float deltaTime)
|
||||||
{
|
{
|
||||||
angle += Oyster::Math::pi/30000;
|
angle += Oyster::Math::pi/10000;
|
||||||
m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle);
|
m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle);
|
||||||
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,0,1)*-angle,Oyster::Math::Float3(0,4,0),Oyster::Math::Float3::null);
|
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-angle,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null);
|
||||||
|
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,6 +235,7 @@ HRESULT Render(float deltaTime)
|
||||||
|
|
||||||
Oyster::Graphics::API::RenderModel(*m);
|
Oyster::Graphics::API::RenderModel(*m);
|
||||||
Oyster::Graphics::API::RenderModel(*m2);
|
Oyster::Graphics::API::RenderModel(*m2);
|
||||||
|
Oyster::Graphics::API::RenderModel(*m3);
|
||||||
|
|
||||||
Oyster::Graphics::API::EndFrame();
|
Oyster::Graphics::API::EndFrame();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue