SSAO and frame counter
This commit is contained in:
parent
341e33ee78
commit
7c567ec360
|
@ -7,6 +7,7 @@
|
||||||
#include "Dx11Includes.h"
|
#include "Dx11Includes.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "OysterMath.h"
|
#include "OysterMath.h"
|
||||||
|
#include <vld.h>
|
||||||
|
|
||||||
namespace Oyster
|
namespace Oyster
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,21 +51,36 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderV, -1, ForceReload);
|
data = Resource::OysterResource::LoadResource(filename.c_str(),Loading::LoadShaderV, -1, ForceReload);
|
||||||
if(data)
|
if(data)
|
||||||
|
{
|
||||||
|
if(ForceReload && VSMap.count(name))
|
||||||
|
{
|
||||||
|
VS[VSMap[name]] = (ID3D11VertexShader*)data;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
VSMap[name] = VS.size();
|
VSMap[name] = VS.size();
|
||||||
VS.push_back((ID3D11VertexShader*)data);
|
VS.push_back((ID3D11VertexShader*)data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::PipelineManager::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)
|
||||||
{
|
{
|
||||||
if(data!=0)
|
if(data!=0)
|
||||||
|
{
|
||||||
|
if(ForceReload && HSMap.count(name))
|
||||||
|
{
|
||||||
|
HS[HSMap[name]] = (ID3D11HullShader*)data;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
HSMap[name] = HS.size();
|
HSMap[name] = HS.size();
|
||||||
HS.push_back((ID3D11HullShader*)data);
|
HS.push_back((ID3D11HullShader*)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::PipelineManager::Domain:
|
case Oyster::Graphics::Core::PipelineManager::Domain:
|
||||||
|
@ -73,43 +88,72 @@ namespace Oyster
|
||||||
if(!DSMap.count(name) || ForceReload)
|
if(!DSMap.count(name) || ForceReload)
|
||||||
{
|
{
|
||||||
if(data!=0)
|
if(data!=0)
|
||||||
|
{
|
||||||
|
if(ForceReload && DSMap.count(name))
|
||||||
|
{
|
||||||
|
DS[DSMap[name]] = (ID3D11DomainShader*)data;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
DSMap[name] = DS.size();
|
DSMap[name] = DS.size();
|
||||||
DS.push_back((ID3D11DomainShader*)data);
|
DS.push_back((ID3D11DomainShader*)data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::PipelineManager::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)
|
||||||
{
|
{
|
||||||
if(data!=0)
|
if(data!=0)
|
||||||
|
{
|
||||||
|
if(ForceReload && GSMap.count(name))
|
||||||
|
{
|
||||||
|
GS[GSMap[name]] = (ID3D11GeometryShader*)data;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
GSMap[name] = GS.size();
|
GSMap[name] = GS.size();
|
||||||
GS.push_back((ID3D11GeometryShader*)data);
|
GS.push_back((ID3D11GeometryShader*)data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::PipelineManager::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)
|
||||||
{
|
{
|
||||||
if(data!=0)
|
if(data!=0)
|
||||||
|
{
|
||||||
|
if(ForceReload && PSMap.count(name))
|
||||||
|
{
|
||||||
|
PS[PSMap[name]] = (ID3D11PixelShader*)data;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
PSMap[name] = PS.size();
|
PSMap[name] = PS.size();
|
||||||
PS.push_back((ID3D11PixelShader*)data);
|
PS.push_back((ID3D11PixelShader*)data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Oyster::Graphics::Core::PipelineManager::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)
|
||||||
{
|
{
|
||||||
if(data!=0)
|
if(data!=0)
|
||||||
|
{
|
||||||
|
if(ForceReload && CSMap.count(name))
|
||||||
|
{
|
||||||
|
CS[CSMap[name]] = (ID3D11ComputeShader*)data;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
CSMap[name] = CS.size();
|
CSMap[name] = CS.size();
|
||||||
CS.push_back((ID3D11ComputeShader*)data);
|
CS.push_back((ID3D11ComputeShader*)data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -375,9 +419,9 @@ namespace Oyster
|
||||||
|
|
||||||
void Core::PipelineManager::CleanPipeline()
|
void Core::PipelineManager::CleanPipeline()
|
||||||
{
|
{
|
||||||
deviceContext->VSSetShaderResources(0,16,Core::srvNULL);
|
//deviceContext->VSSetShaderResources(0,16,Core::srvNULL);
|
||||||
deviceContext->GSSetShaderResources(0,16,Core::srvNULL);
|
//deviceContext->GSSetShaderResources(0,16,Core::srvNULL);
|
||||||
deviceContext->PSSetShaderResources(0,16,Core::srvNULL);
|
//deviceContext->PSSetShaderResources(0,16,Core::srvNULL);
|
||||||
deviceContext->CSSetShaderResources(0,16,Core::srvNULL);
|
deviceContext->CSSetShaderResources(0,16,Core::srvNULL);
|
||||||
deviceContext->CSSetUnorderedAccessViews(0,8,Core::uavNULL,NULL);
|
deviceContext->CSSetUnorderedAccessViews(0,8,Core::uavNULL,NULL);
|
||||||
deviceContext->OMSetRenderTargets(8,Core::rtvNULL, NULL);
|
deviceContext->OMSetRenderTargets(8,Core::rtvNULL, NULL);
|
||||||
|
|
|
@ -20,6 +20,12 @@ namespace Oyster
|
||||||
Oyster::Math::Matrix P;
|
Oyster::Math::Matrix P;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PerModel
|
||||||
|
{
|
||||||
|
Math::Matrix WV;
|
||||||
|
Math::Matrix WVP;
|
||||||
|
};
|
||||||
|
|
||||||
struct FinalVertex
|
struct FinalVertex
|
||||||
{
|
{
|
||||||
Oyster::Math::Float3 pos;
|
Oyster::Math::Float3 pos;
|
||||||
|
@ -34,9 +40,10 @@ namespace Oyster
|
||||||
struct LightConstants
|
struct LightConstants
|
||||||
{
|
{
|
||||||
Math::Float4x4 InvProj;
|
Math::Float4x4 InvProj;
|
||||||
|
Math::Float4x4 Proj;
|
||||||
Math::Float2 Pixels;
|
Math::Float2 Pixels;
|
||||||
int Lights;
|
int Lights;
|
||||||
float Pad;
|
float SSAORadius;
|
||||||
Oyster::Math::Float4x4 View;
|
Oyster::Math::Float4x4 View;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "../FileLoader/ObjReader.h"
|
#include "../FileLoader/ObjReader.h"
|
||||||
#include "../../Misc/Resource/OysterResource.h"
|
#include "../../Misc/Resource/OysterResource.h"
|
||||||
#include "../FileLoader/GeneralLoader.h"
|
#include "../FileLoader/GeneralLoader.h"
|
||||||
|
#include <vld.h>
|
||||||
|
|
||||||
namespace Oyster
|
namespace Oyster
|
||||||
{
|
{
|
||||||
|
@ -26,12 +27,6 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
return API::Fail;
|
return API::Fail;
|
||||||
}
|
}
|
||||||
#ifdef _DEBUG
|
|
||||||
if(Render::Resources::Debug::Init() == Core::Init::Fail)
|
|
||||||
{
|
|
||||||
return API::Fail;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
Render::Resources::Deffered::Init();
|
Render::Resources::Deffered::Init();
|
||||||
|
|
||||||
Render::Preparations::Basic::SetViewPort();
|
Render::Preparations::Basic::SetViewPort();
|
||||||
|
@ -62,12 +57,12 @@ namespace Oyster
|
||||||
|
|
||||||
void API::RenderScene(Model::Model models[], int count)
|
void API::RenderScene(Model::Model models[], int count)
|
||||||
{
|
{
|
||||||
Render::Rendering::Basic::RenderScene(models,count);
|
Render::Rendering::Basic::RenderScene(models,count, View, Projection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void API::RenderModel(Model::Model& m)
|
void API::RenderModel(Model::Model& m)
|
||||||
{
|
{
|
||||||
Render::Rendering::Basic::RenderScene(&m,1);
|
Render::Rendering::Basic::RenderScene(&m,1, View, Projection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void API::EndFrame()
|
void API::EndFrame()
|
||||||
|
@ -103,10 +98,6 @@ namespace Oyster
|
||||||
SAFE_DELETE(Core::viewPort);
|
SAFE_DELETE(Core::viewPort);
|
||||||
Oyster::Resource::OysterResource::Clean();
|
Oyster::Resource::OysterResource::Clean();
|
||||||
Oyster::Graphics::Core::PipelineManager::Clean();
|
Oyster::Graphics::Core::PipelineManager::Clean();
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
Oyster::Graphics::Render::Resources::Debug::Clean();
|
|
||||||
#endif
|
|
||||||
Oyster::Graphics::Render::Resources::Deffered::Clean();
|
Oyster::Graphics::Render::Resources::Deffered::Clean();
|
||||||
|
|
||||||
SAFE_RELEASE(Core::depthStencil);
|
SAFE_RELEASE(Core::depthStencil);
|
||||||
|
@ -128,5 +119,13 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
Lights.clear();
|
Lights.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
API::State API::ReloadShaders()
|
||||||
|
{
|
||||||
|
Render::Resources::Deffered::InitShaders();
|
||||||
|
return State::Sucsess;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
#include "..\Model\Model.h"
|
#include "..\Model\Model.h"
|
||||||
#include "OysterMath.h"
|
#include "OysterMath.h"
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
//#include <vld.h>
|
#include <vld.h>
|
||||||
|
|
||||||
#ifdef GFX_DLL_EXPORT
|
#ifdef GFX_DLL_EXPORT
|
||||||
#define GFX_DLL_USAGE __declspec(dllexport)
|
#define GFX_DLL_USAGE __declspec(dllexport)
|
||||||
|
@ -29,23 +29,40 @@ namespace Oyster
|
||||||
};
|
};
|
||||||
|
|
||||||
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion);
|
static State Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Oyster::Math::Float2 StartResulotion);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
static State ReloadShaders();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//! @todo Memory Leaks
|
||||||
|
|
||||||
|
//! @brief Clean Resources and release all memory
|
||||||
static void Clean();
|
static void Clean();
|
||||||
|
|
||||||
|
//! @brief Sets the view matrix to use next frame
|
||||||
static void SetView(Oyster::Math::Float4x4& View);
|
static void SetView(Oyster::Math::Float4x4& View);
|
||||||
|
//! @brief Sets the projection matrix to use next frame
|
||||||
static void SetProjection(Oyster::Math::Float4x4& Projection);
|
static void SetProjection(Oyster::Math::Float4x4& Projection);
|
||||||
|
|
||||||
//! @brief will internally use last values from SetView and SetProjection
|
//! @brief will internally use last values from SetView and SetProjection
|
||||||
static void NewFrame();
|
static void NewFrame();
|
||||||
|
//! @brief Renders a list of models
|
||||||
static void RenderScene(Oyster::Graphics::Model::Model models[], int count);
|
static void RenderScene(Oyster::Graphics::Model::Model models[], int count);
|
||||||
|
//! @brief Renders a single model
|
||||||
static void RenderModel(Oyster::Graphics::Model::Model& model);
|
static void RenderModel(Oyster::Graphics::Model::Model& model);
|
||||||
|
//! @brief Performs light calculations, post effects and presents the scene
|
||||||
static void EndFrame();
|
static void EndFrame();
|
||||||
|
|
||||||
|
//! @brief Creates a model from the supplied file, note: do not include .obj
|
||||||
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);
|
static Oyster::Graphics::Model::Model* CreateModel(std::wstring filename);
|
||||||
|
//! @brief deletes a model and relases the models resources
|
||||||
static void DeleteModel(Oyster::Graphics::Model::Model* model);
|
static void DeleteModel(Oyster::Graphics::Model::Model* model);
|
||||||
|
|
||||||
|
//! @brief adds a light to the scene
|
||||||
static void AddLight(Definitions::Pointlight light);
|
static void AddLight(Definitions::Pointlight light);
|
||||||
|
//! @brief removes all lights from the scene
|
||||||
static void ClearLights();
|
static void ClearLights();
|
||||||
|
|
||||||
|
//! @brief Sets Options to the graphics, note: currently unused
|
||||||
static State SetOptions(Option);
|
static State SetOptions(Option);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,12 @@ 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)
|
||||||
{
|
{
|
||||||
FileLoaders::ObjReader* obj = FileLoaders::ObjReader::LoadFile(filename);
|
FileLoaders::ObjReader obj;
|
||||||
|
obj.LoadFile(filename);
|
||||||
Model::ModelInfo* info = new Model::ModelInfo();
|
Model::ModelInfo* info = new Model::ModelInfo();
|
||||||
Oyster::FileLoaders::ObjReader::Vertex* vdata;
|
Oyster::FileLoaders::ObjReader::Vertex* vdata;
|
||||||
int count;
|
int count;
|
||||||
obj->GetVertexData(&vdata, count);
|
obj.GetVertexData(&vdata, count);
|
||||||
info->Vertices = new Core::Buffer();
|
info->Vertices = new Core::Buffer();
|
||||||
Core::Buffer::BUFFER_INIT_DESC desc;
|
Core::Buffer::BUFFER_INIT_DESC desc;
|
||||||
desc.ElementSize = sizeof(FileLoaders::ObjReader::Vertex);
|
desc.ElementSize = sizeof(FileLoaders::ObjReader::Vertex);
|
||||||
|
|
|
@ -3,31 +3,16 @@
|
||||||
#include "..\Core\Core.h"
|
#include "..\Core\Core.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vld.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Oyster::FileLoaders;
|
using namespace Oyster::FileLoaders;
|
||||||
using namespace Oyster;
|
using namespace Oyster;
|
||||||
using namespace Oyster::Math;
|
using namespace Oyster::Math;
|
||||||
|
|
||||||
ObjReader *ObjReader::LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform)
|
void ObjReader::LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform)
|
||||||
{
|
{
|
||||||
static std::map<std::wstring, ObjReader *> cache;
|
this->ParseFile(fileName + L".obj", transform);
|
||||||
|
|
||||||
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(void)
|
ObjReader::ObjReader(void)
|
||||||
|
@ -37,6 +22,7 @@ ObjReader::ObjReader(void)
|
||||||
|
|
||||||
ObjReader::~ObjReader(void)
|
ObjReader::~ObjReader(void)
|
||||||
{
|
{
|
||||||
|
SAFE_DELETE_ARRAY(this->vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
|
void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
|
||||||
|
@ -50,7 +36,6 @@ void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
wstring path;
|
wstring path;
|
||||||
//Utility::String::ExtractDirPath(path,fileName,'\\');
|
|
||||||
|
|
||||||
std::vector<Vertex> VertexList;
|
std::vector<Vertex> VertexList;
|
||||||
std::vector<Float3> vList;
|
std::vector<Float3> vList;
|
||||||
|
@ -74,6 +59,7 @@ void ObjReader::ParseFile(std::wstring fileName, Float4x4 transform)
|
||||||
if(c==L"v")
|
if(c==L"v")
|
||||||
{
|
{
|
||||||
position = readVertex(offset,s);
|
position = readVertex(offset,s);
|
||||||
|
//position *= 0.001f;
|
||||||
vList.push_back(position);
|
vList.push_back(position);
|
||||||
}
|
}
|
||||||
else if(c==L"vt")
|
else if(c==L"vt")
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Oyster
|
||||||
Oyster::Math::Float3 Normal;
|
Oyster::Math::Float3 Normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
static ObjReader *LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
|
void LoadFile(std::wstring fileName, Oyster::Math::Float4x4 transform = Oyster::Math::Float4x4::identity);
|
||||||
|
|
||||||
ObjReader(void);
|
ObjReader(void);
|
||||||
~ObjReader(void);
|
~ObjReader(void);
|
||||||
|
|
|
@ -34,6 +34,8 @@ namespace Oyster
|
||||||
lc.Pixels = Core::resolution;
|
lc.Pixels = Core::resolution;
|
||||||
lc.Lights = numLights;
|
lc.Lights = numLights;
|
||||||
lc.View = View;
|
lc.View = View;
|
||||||
|
lc.Proj = Projection;
|
||||||
|
lc.SSAORadius = 3;
|
||||||
|
|
||||||
data = Resources::Deffered::LightConstantsData.Map();
|
data = Resources::Deffered::LightConstantsData.Map();
|
||||||
memcpy(data, &lc, sizeof(Definitions::LightConstants));
|
memcpy(data, &lc, sizeof(Definitions::LightConstants));
|
||||||
|
@ -44,14 +46,18 @@ namespace Oyster
|
||||||
Resources::Deffered::PointLightsData.Unmap();
|
Resources::Deffered::PointLightsData.Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basic::RenderScene(Model::Model* models, int count)
|
void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < count; ++i)
|
for(int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
if(models[i].Visible)
|
if(models[i].Visible)
|
||||||
{
|
{
|
||||||
|
Definitions::PerModel pm;
|
||||||
|
pm.WV = View * models[i].WorldMatrix;
|
||||||
|
pm.WVP = Projection * pm.WV;
|
||||||
|
|
||||||
void* data = Resources::Deffered::ModelData.Map();
|
void* data = Resources::Deffered::ModelData.Map();
|
||||||
memcpy(data,&(models[i].WorldMatrix),sizeof(Math::Float4x4));
|
memcpy(data,&(pm),sizeof(pm));
|
||||||
Resources::Deffered::ModelData.Unmap();
|
Resources::Deffered::ModelData.Unmap();
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,6 +88,10 @@ namespace Oyster
|
||||||
|
|
||||||
Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1);
|
Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1);
|
||||||
|
|
||||||
|
Core::PipelineManager::SetRenderPass(Resources::Deffered::PostPass);
|
||||||
|
|
||||||
|
Core::deviceContext->Dispatch((Core::resolution.x + 15U) / 16U,(Core::resolution.y + 15U) / 16U,1);
|
||||||
|
|
||||||
Core::swapChain->Present(0,0);
|
Core::swapChain->Present(0,0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Oyster
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static void NewFrame(Oyster::Math::Float4x4 View, Oyster::Math::Float4x4 Projection, Definitions::Pointlight* Lights, int numLights);
|
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, Math::Matrix View, Math::Matrix Projection);
|
||||||
static void EndFrame();
|
static void EndFrame();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ typedef Oyster::Graphics::Core::Buffer Buffer;
|
||||||
const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\Deffered Shaders\\";
|
const std::wstring PathToHLSL = L"..\\..\\Code\\OysterGraphics\\Shader\\HLSL\\Deffered Shaders\\";
|
||||||
const std::wstring PathToCSO = L"..\\Content\\Shaders\\";
|
const std::wstring PathToCSO = L"..\\Content\\Shaders\\";
|
||||||
|
|
||||||
|
const int KernelSize = 10;
|
||||||
|
const int SampleSpread = 8;
|
||||||
|
|
||||||
namespace Oyster
|
namespace Oyster
|
||||||
{
|
{
|
||||||
namespace Graphics
|
namespace Graphics
|
||||||
|
@ -20,12 +23,15 @@ namespace Oyster
|
||||||
namespace Resources
|
namespace Resources
|
||||||
{
|
{
|
||||||
|
|
||||||
ID3D11RenderTargetView* Deffered::GBufferRTV[2] = {0};
|
ID3D11RenderTargetView* Deffered::GBufferRTV[Deffered::GBufferSize] = {0};
|
||||||
ID3D11ShaderResourceView* Deffered::GBufferSRV[2] = {0};
|
ID3D11ShaderResourceView* Deffered::GBufferSRV[Deffered::GBufferSize] = {0};
|
||||||
|
|
||||||
|
ID3D11UnorderedAccessView* Deffered::LBufferUAV[Deffered::LBufferSize] = {0};
|
||||||
|
ID3D11ShaderResourceView* Deffered::LBufferSRV[Deffered::LBufferSize] = {0};
|
||||||
|
|
||||||
Shader::RenderPass Deffered::GeometryPass;
|
Shader::RenderPass Deffered::GeometryPass;
|
||||||
Shader::RenderPass Deffered::LightPass;
|
Shader::RenderPass Deffered::LightPass;
|
||||||
|
Shader::RenderPass Deffered::PostPass;
|
||||||
|
|
||||||
Buffer Deffered::ModelData = Buffer();
|
Buffer Deffered::ModelData = Buffer();
|
||||||
Buffer Deffered::VPData = Buffer();
|
Buffer Deffered::VPData = Buffer();
|
||||||
|
@ -34,7 +40,10 @@ namespace Oyster
|
||||||
Buffer Deffered::PointLightsData = Buffer();
|
Buffer Deffered::PointLightsData = Buffer();
|
||||||
ID3D11ShaderResourceView* Deffered::PointLightView = NULL;
|
ID3D11ShaderResourceView* Deffered::PointLightView = NULL;
|
||||||
|
|
||||||
Core::Init::State Deffered::Init()
|
ID3D11ShaderResourceView* Deffered::SSAOKernel = NULL;
|
||||||
|
ID3D11ShaderResourceView* Deffered::SSAORandom = NULL;
|
||||||
|
|
||||||
|
Core::Init::State Deffered::InitShaders()
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
std::wstring path = PathToHLSL;
|
std::wstring path = PathToHLSL;
|
||||||
|
@ -47,10 +56,17 @@ namespace Oyster
|
||||||
Core::PipelineManager::Init(path + L"PixelGatherData" + end, ShaderType::Pixel, L"Geometry");
|
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"VertexGatherData" + end, ShaderType::Vertex, L"Geometry");
|
||||||
Core::PipelineManager::Init(path + L"LightPass" + end, ShaderType::Compute, L"LightPass");
|
Core::PipelineManager::Init(path + L"LightPass" + end, ShaderType::Compute, L"LightPass");
|
||||||
|
Core::PipelineManager::Init(path + L"PostPass" + end, ShaderType::Compute, L"PostPass");
|
||||||
|
return Core::Init::State::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Init::State Deffered::Init()
|
||||||
|
{
|
||||||
|
InitShaders();
|
||||||
|
|
||||||
//Create Buffers
|
//Create Buffers
|
||||||
Buffer::BUFFER_INIT_DESC desc;
|
Buffer::BUFFER_INIT_DESC desc;
|
||||||
desc.ElementSize = sizeof(Oyster::Math::Matrix);
|
desc.ElementSize = sizeof(Definitions::PerModel);
|
||||||
desc.NumElements = 1;
|
desc.NumElements = 1;
|
||||||
desc.InitData = NULL;
|
desc.InitData = NULL;
|
||||||
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS;
|
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_VS;
|
||||||
|
@ -72,7 +88,7 @@ namespace Oyster
|
||||||
desc.Type = Buffer::STRUCTURED_BUFFER;
|
desc.Type = Buffer::STRUCTURED_BUFFER;
|
||||||
PointLightsData.Init(desc);
|
PointLightsData.Init(desc);
|
||||||
|
|
||||||
//Create States
|
////Create States
|
||||||
D3D11_RASTERIZER_DESC rdesc;
|
D3D11_RASTERIZER_DESC rdesc;
|
||||||
rdesc.CullMode = D3D11_CULL_BACK;
|
rdesc.CullMode = D3D11_CULL_BACK;
|
||||||
rdesc.FillMode = D3D11_FILL_SOLID;
|
rdesc.FillMode = D3D11_FILL_SOLID;
|
||||||
|
@ -131,11 +147,82 @@ namespace Oyster
|
||||||
Core::Init::CreateLinkedShaderResourceFromTexture(&GBufferRTV[i],&GBufferSRV[i],NULL);
|
Core::Init::CreateLinkedShaderResourceFromTexture(&GBufferRTV[i],&GBufferSRV[i],NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < Resources::Deffered::LBufferSize; ++i)
|
||||||
|
{
|
||||||
|
Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&LBufferSRV[i],&LBufferUAV[i]);
|
||||||
|
}
|
||||||
|
|
||||||
Buffer* b = &PointLightsData;
|
Buffer* b = &PointLightsData;
|
||||||
|
|
||||||
Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL);
|
Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&PointLightView,NULL);
|
||||||
|
srand(time(0));
|
||||||
|
//SSAO
|
||||||
|
Math::Vector3 kernel[KernelSize];
|
||||||
|
Math::Vector3 random[SampleSpread];
|
||||||
|
for(int i = 0;i < KernelSize; ++i)
|
||||||
|
{
|
||||||
|
kernel[i] = Oyster::Math::Vector3::null;
|
||||||
|
while( kernel[i] == Oyster::Math::Vector3::null )
|
||||||
|
{
|
||||||
|
kernel[i] = Oyster::Math::Vector3(
|
||||||
|
(float)rand() / (RAND_MAX + 1) * (1 - -1) + -1,
|
||||||
|
(float)rand() / (RAND_MAX + 1) * (1 - -1) + -1,
|
||||||
|
(float)rand() / (RAND_MAX + 1) * (1 - 0) + 0);
|
||||||
|
}
|
||||||
|
kernel[i].Normalize();
|
||||||
|
|
||||||
//Create ShaderEffects
|
float scale = float(i) / float(KernelSize);
|
||||||
|
|
||||||
|
scale = (0.1f*(1 - scale * scale) + 1.0f *( scale * scale));
|
||||||
|
kernel[i] *= scale;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < SampleSpread; ++i)
|
||||||
|
{
|
||||||
|
random[i] = Oyster::Math::Vector3::null;
|
||||||
|
while( random[i] == Oyster::Math::Vector3::null )
|
||||||
|
{
|
||||||
|
random[i] = Oyster::Math::Vector3(
|
||||||
|
(float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1,
|
||||||
|
(float)rand() / (RAND_MAX + 1) * (1 - -1)+ -1,
|
||||||
|
0.0f);
|
||||||
|
}
|
||||||
|
random[i].Normalize();
|
||||||
|
}
|
||||||
|
//kernel[0] = Math::Vector3(0,1,1);
|
||||||
|
//kernel[0].Normalize();
|
||||||
|
|
||||||
|
D3D11_TEXTURE1D_DESC T1desc;
|
||||||
|
T1desc.Width = KernelSize;
|
||||||
|
T1desc.MipLevels = T1desc.ArraySize = 1;
|
||||||
|
T1desc.Format = DXGI_FORMAT_R32G32B32_FLOAT;
|
||||||
|
T1desc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
|
T1desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||||
|
T1desc.CPUAccessFlags = 0;
|
||||||
|
T1desc.MiscFlags = 0;
|
||||||
|
|
||||||
|
D3D11_SUBRESOURCE_DATA sphere;
|
||||||
|
sphere.pSysMem = kernel;
|
||||||
|
|
||||||
|
D3D11_SUBRESOURCE_DATA rnd;
|
||||||
|
rnd.pSysMem = random;
|
||||||
|
|
||||||
|
ID3D11Texture1D *pTexture1[2];
|
||||||
|
|
||||||
|
Core::device->CreateTexture1D( &T1desc, &sphere, &pTexture1[0] );
|
||||||
|
Core::device->CreateShaderResourceView( pTexture1[0], 0, &SSAOKernel );
|
||||||
|
pTexture1[0]->Release();
|
||||||
|
|
||||||
|
T1desc.Width = SampleSpread;
|
||||||
|
Core::device->CreateTexture1D( &T1desc, &rnd, &pTexture1[1] );
|
||||||
|
Core::device->CreateShaderResourceView( (pTexture1[1]), 0, &SSAORandom );
|
||||||
|
pTexture1[1]->Release();
|
||||||
|
|
||||||
|
////Create ShaderEffects
|
||||||
|
|
||||||
|
////---------------- Geometry Pass Setup ----------------------------
|
||||||
GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Geometry");
|
GeometryPass.Shaders.Pixel = GetShader::Pixel(L"Geometry");
|
||||||
GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Geometry");
|
GeometryPass.Shaders.Vertex = GetShader::Vertex(L"Geometry");
|
||||||
|
|
||||||
|
@ -161,8 +248,12 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
GeometryPass.depth = Core::depthStencil;
|
GeometryPass.depth = Core::depthStencil;
|
||||||
|
|
||||||
|
////---------------- Light Pass Setup ----------------------------
|
||||||
LightPass.Shaders.Compute = GetShader::Compute(L"LightPass");
|
LightPass.Shaders.Compute = GetShader::Compute(L"LightPass");
|
||||||
LightPass.UAV.Compute.push_back(Core::backBufferUAV);
|
for(int i = 0; i<Deffered::LBufferSize;++i)
|
||||||
|
{
|
||||||
|
LightPass.UAV.Compute.push_back(LBufferUAV[i]);
|
||||||
|
}
|
||||||
for(int i = 0; i<Deffered::GBufferSize;++i)
|
for(int i = 0; i<Deffered::GBufferSize;++i)
|
||||||
{
|
{
|
||||||
LightPass.SRV.Compute.push_back(GBufferSRV[i]);
|
LightPass.SRV.Compute.push_back(GBufferSRV[i]);
|
||||||
|
@ -170,7 +261,16 @@ namespace Oyster
|
||||||
LightPass.SRV.Compute.push_back(Core::depthStencilUAV);
|
LightPass.SRV.Compute.push_back(Core::depthStencilUAV);
|
||||||
LightPass.CBuffers.Compute.push_back(LightConstantsData);
|
LightPass.CBuffers.Compute.push_back(LightConstantsData);
|
||||||
LightPass.SRV.Compute.push_back(PointLightView);
|
LightPass.SRV.Compute.push_back(PointLightView);
|
||||||
|
LightPass.SRV.Compute.push_back(SSAOKernel);
|
||||||
|
LightPass.SRV.Compute.push_back(SSAORandom);
|
||||||
|
|
||||||
|
////---------------- Post Pass Setup ----------------------------
|
||||||
|
PostPass.Shaders.Compute = GetShader::Compute(L"PostPass");
|
||||||
|
for(int i = 0; i<Deffered::LBufferSize;++i)
|
||||||
|
{
|
||||||
|
PostPass.SRV.Compute.push_back(LBufferSRV[i]);
|
||||||
|
}
|
||||||
|
PostPass.UAV.Compute.push_back(Core::backBufferUAV);
|
||||||
|
|
||||||
return Core::Init::State::Success;
|
return Core::Init::State::Success;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +281,9 @@ namespace Oyster
|
||||||
Resources::Deffered::VPData.~Buffer();
|
Resources::Deffered::VPData.~Buffer();
|
||||||
Resources::Deffered::LightConstantsData.~Buffer();
|
Resources::Deffered::LightConstantsData.~Buffer();
|
||||||
Resources::Deffered::PointLightsData.~Buffer();
|
Resources::Deffered::PointLightsData.~Buffer();
|
||||||
|
SAFE_RELEASE(Resources::Deffered::PointLightView);
|
||||||
|
SAFE_RELEASE(Deffered::SSAOKernel);
|
||||||
|
SAFE_RELEASE(Deffered::SSAORandom);
|
||||||
|
|
||||||
for(int i = 0; i< GBufferSize; ++i)
|
for(int i = 0; i< GBufferSize; ++i)
|
||||||
{
|
{
|
||||||
|
@ -188,22 +291,10 @@ namespace Oyster
|
||||||
SAFE_RELEASE(GBufferSRV[i]);
|
SAFE_RELEASE(GBufferSRV[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i< LBufferSize; ++i)
|
||||||
for(int i = 0; i < (int)GeometryPass.CBuffers.Vertex.size(); ++i)
|
|
||||||
{
|
{
|
||||||
SAFE_RELEASE(GeometryPass.CBuffers.Vertex[i]);
|
SAFE_RELEASE(LBufferUAV[i]);
|
||||||
}
|
SAFE_RELEASE(LBufferSRV[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.IAStage.Layout);
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Oyster
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const int GBufferSize = 2;
|
static const int GBufferSize = 2;
|
||||||
|
static const int LBufferSize = 3;
|
||||||
static const int MaxLightSize = 100;
|
static const int MaxLightSize = 100;
|
||||||
//! GBuffers
|
//! GBuffers
|
||||||
//! 0 = Diffuse + SpecKoeff
|
//! 0 = Diffuse + SpecKoeff
|
||||||
|
@ -22,8 +23,14 @@ namespace Oyster
|
||||||
static ID3D11RenderTargetView* GBufferRTV[GBufferSize];
|
static ID3D11RenderTargetView* GBufferRTV[GBufferSize];
|
||||||
static ID3D11ShaderResourceView* GBufferSRV[GBufferSize];
|
static ID3D11ShaderResourceView* GBufferSRV[GBufferSize];
|
||||||
|
|
||||||
|
|
||||||
|
static ID3D11UnorderedAccessView* LBufferUAV[LBufferSize];
|
||||||
|
static ID3D11ShaderResourceView* LBufferSRV[LBufferSize];
|
||||||
|
|
||||||
static Core::PipelineManager::RenderPass GeometryPass;
|
static Core::PipelineManager::RenderPass GeometryPass;
|
||||||
static Core::PipelineManager::RenderPass LightPass;
|
static Core::PipelineManager::RenderPass LightPass;
|
||||||
|
static Core::PipelineManager::RenderPass PostPass;
|
||||||
|
|
||||||
|
|
||||||
static Core::Buffer ModelData;
|
static Core::Buffer ModelData;
|
||||||
static Core::Buffer VPData;
|
static Core::Buffer VPData;
|
||||||
|
@ -33,7 +40,12 @@ namespace Oyster
|
||||||
static Core::Buffer PointLightsData;
|
static Core::Buffer PointLightsData;
|
||||||
static ID3D11ShaderResourceView* PointLightView;
|
static ID3D11ShaderResourceView* PointLightView;
|
||||||
|
|
||||||
|
static ID3D11ShaderResourceView* SSAOKernel;
|
||||||
|
|
||||||
|
static ID3D11ShaderResourceView* SSAORandom;
|
||||||
|
|
||||||
static Core::Init::State Init();
|
static Core::Init::State Init();
|
||||||
|
static Core::Init::State InitShaders();
|
||||||
static void Clean();
|
static void Clean();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,10 @@ struct DiffSpec
|
||||||
cbuffer LightConstants : register(b0)
|
cbuffer LightConstants : register(b0)
|
||||||
{
|
{
|
||||||
float4x4 InvProj;
|
float4x4 InvProj;
|
||||||
|
float4x4 Proj;
|
||||||
float2 Pixels;
|
float2 Pixels;
|
||||||
int Lights;
|
int Lights;
|
||||||
float Pad;
|
float SSAORadius;
|
||||||
float4x4 View;
|
float4x4 View;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,9 +29,13 @@ 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);
|
StructuredBuffer<PointLight> Points : register(t3);
|
||||||
|
|
||||||
RWTexture2D<float4> Output : register(u0);
|
Texture1D SSAOKernel : register(t4);
|
||||||
|
Texture1D SSAORand : register(t5);
|
||||||
|
|
||||||
|
RWTexture2D<float4> Diffuse : register(u0);
|
||||||
|
RWTexture2D<float4> Specular : register(u1);
|
||||||
|
RWTexture2D<float> Ambient : register(u2);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -39,5 +39,6 @@ cbuffer PerFrame : register(b0)
|
||||||
|
|
||||||
cbuffer PerModel : register(b1)
|
cbuffer PerModel : register(b1)
|
||||||
{
|
{
|
||||||
matrix World;
|
matrix WV;
|
||||||
|
matrix WVP;
|
||||||
}
|
}
|
|
@ -14,7 +14,6 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
|
||||||
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( 0, 1 - (d / pl.Radius));
|
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.Bright * att * diffFactor * pl.Color;
|
output.Diffuse = pl.Bright * att * diffFactor * pl.Color;
|
||||||
output.Specular = pl.Bright * att * specFactor * pl.Color;
|
output.Specular = pl.Bright * att * specFactor * pl.Color;
|
||||||
|
|
|
@ -1,31 +1,40 @@
|
||||||
#include "Defines.hlsli"
|
#include "Defines.hlsli"
|
||||||
#include "LightCalc.hlsli"
|
#include "LightCalc.hlsli"
|
||||||
#include "PosManipulation.hlsli"
|
#include "PosManipulation.hlsli"
|
||||||
|
#include "SSAO.hlsli"
|
||||||
//todo
|
//todo
|
||||||
//LightCulling
|
//LightCulling
|
||||||
//Calc Diff + Spec
|
//Calc Diff + Spec Done
|
||||||
//Calc Ambience
|
//Calc Ambience Done
|
||||||
//Write Glow
|
//Write Glow
|
||||||
|
|
||||||
|
|
||||||
[numthreads(16, 16, 1)]
|
[numthreads(16, 16, 1)]
|
||||||
void main( uint3 DTid : SV_DispatchThreadID )
|
void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID )
|
||||||
{
|
{
|
||||||
float3 ViewPos = ToVpos(DTid.xy);
|
float2 UV = DTid / Pixels;
|
||||||
|
UV.x = UV.x * 2 - 1;
|
||||||
|
UV.y = 1 - 2 * UV.y;
|
||||||
|
float3 ViewPos = ToVpos(DTid.xy, UV);
|
||||||
DiffSpec Shaded;
|
DiffSpec Shaded;
|
||||||
Shaded.Diffuse = float4(0,0,0,0);
|
Shaded.Diffuse = float4(0,0,0,0);
|
||||||
Shaded.Specular = float4(0,0,0,0);
|
Shaded.Specular = float4(0,0,0,0);
|
||||||
|
|
||||||
for(int i = 0; i < Lights; ++i)
|
for(int i = 0; i < Lights; ++i)
|
||||||
{
|
{
|
||||||
DiffSpec light = LightCalc(Points[i], ViewPos, DTid.xy);
|
DiffSpec light = LightCalc(Points[i], ViewPos, DTid.xy);
|
||||||
Shaded.Diffuse = light.Diffuse;
|
Shaded.Diffuse += light.Diffuse;
|
||||||
Shaded.Specular = light.Specular;
|
Shaded.Specular += light.Specular;
|
||||||
}
|
}
|
||||||
//Output[DTid.xy] = float4(ViewPos,1);
|
|
||||||
//Output[DTid.xy] = DepthTexture[DTid.xy].x;
|
Diffuse[DTid.xy] = float4(Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz,1);
|
||||||
//Output[DTid.xy] = float4(DTid.xy/ Pixels,1,1);
|
Specular[DTid.xy] = float4(Shaded.Specular, 1);
|
||||||
//Output[DTid.xy] = NormalSpec[DTid.xy];
|
|
||||||
//Output[DTid.xy] = float4(light.Diffuse, 1);
|
|
||||||
//Output[DTid.xy] = float4(light.Specular, 1);
|
if((DTid.x + DTid.y) %4 == 0 )
|
||||||
Output[DTid.xy] = float4( Shaded.Diffuse * DiffuseGlow[DTid.xy].xyz + Shaded.Specular + DiffuseGlow[DTid.xy].xyz * 0.2f, 1);
|
{
|
||||||
|
float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy);
|
||||||
|
Ambient[DTid.xy/4] = AmbValue;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,22 +1,23 @@
|
||||||
|
#ifndef PosHelper
|
||||||
|
#define PosHelper
|
||||||
#include "Defines.hlsli"
|
#include "Defines.hlsli"
|
||||||
|
|
||||||
//assumes ProperfloatTexCoords
|
//assumes ProperfloatTexCoords
|
||||||
float3 ToVpos(float2 texCoord)
|
float3 ToVpos(int2 texCoord, float2 UV)
|
||||||
{
|
{
|
||||||
//Get proper UV
|
|
||||||
float2 UV = texCoord / Pixels;
|
|
||||||
|
|
||||||
float4 ViewPos = float4(0,0,0,0);
|
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;
|
||||||
//Get Y/w
|
//Get Y/w
|
||||||
//ViewPos.y = -(UV.y * 2) + 1;
|
//ViewPos.y = -(UV.y * 2) + 1;
|
||||||
ViewPos.y = 1 - 2 * UV.y;
|
ViewPos.y = UV.y;
|
||||||
ViewPos.w = 1;
|
ViewPos.w = 1;
|
||||||
|
|
||||||
//Un project
|
//Un project
|
||||||
ViewPos = mul(InvProj, ViewPos);
|
ViewPos = mul(InvProj, ViewPos);
|
||||||
return ViewPos.xyz / ViewPos.w;
|
return ViewPos.xyz / ViewPos.w;
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,12 @@
|
||||||
|
Texture2D Diffuse : register(t0);
|
||||||
|
Texture2D Specular : register(t1);
|
||||||
|
Texture2D Ambient : register(t2);
|
||||||
|
|
||||||
|
RWTexture2D<float4> Output;
|
||||||
|
|
||||||
|
[numthreads(16, 16, 1)]
|
||||||
|
void main( uint3 DTid : SV_DispatchThreadID )
|
||||||
|
{
|
||||||
|
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/4].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
|
||||||
|
Output[DTid.xy] = Diffuse[DTid.xy];
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
#include "Defines.hlsli"
|
||||||
|
#include "PosManipulation.hlsli"
|
||||||
|
|
||||||
|
static float Radius =5;
|
||||||
|
|
||||||
|
float GetSSAO(float3 pos, float2 uv, int2 texCoord2, uint2 rndID)
|
||||||
|
{
|
||||||
|
|
||||||
|
float occlusion = 0.0f;
|
||||||
|
//create sample coordinate system
|
||||||
|
float4 rnd = float4( SSAORand[(rndID.x + rndID.y) % SSAORand.Length.x].xyz, 0.0f );
|
||||||
|
rnd = normalize(rnd);
|
||||||
|
float3 normal = NormalSpec[uv].xyz;
|
||||||
|
float4 tangent = float4( normalize(rnd.xyz - (normal * dot(rnd.xyz, normal))), 0.0f );
|
||||||
|
float4 biTangent = float4( cross(tangent.xyz, normal), 0.0f );
|
||||||
|
|
||||||
|
float4x4 tbn = float4x4(tangent, biTangent, float4(normal,0), float4(pos*Radius,1));
|
||||||
|
|
||||||
|
for( uint i = 0; i < SSAOKernel.Length.x; ++i )
|
||||||
|
{
|
||||||
|
//take sample from localspace to viewspace
|
||||||
|
float4 sampled = mul(tbn, float4(SSAOKernel[i].xyz,1));
|
||||||
|
//project sample to get uv.xy
|
||||||
|
float4 ProjOffset = sampled;
|
||||||
|
ProjOffset = mul(Proj, ProjOffset);
|
||||||
|
float4 offset = ProjOffset;
|
||||||
|
float2 UV = offset;
|
||||||
|
offset /= offset.w;
|
||||||
|
offset.xyz = offset.xyz * 0.5f + 0.5f;
|
||||||
|
//extra invert y axis, DX11
|
||||||
|
offset.y = 1.0f - offset.y;
|
||||||
|
|
||||||
|
// get depth from that point in screenspace
|
||||||
|
uint2 texCoord;
|
||||||
|
texCoord = (uint2)(offset.xy * Pixels);
|
||||||
|
float3 ViewPos = ToVpos(texCoord, UV);
|
||||||
|
|
||||||
|
float sampleDepth = ViewPos.z;
|
||||||
|
|
||||||
|
//compare to depth from sample
|
||||||
|
float rangeCheck = (abs(pos.z - sampleDepth) < Radius) ? 1.0f : 0.0f;
|
||||||
|
occlusion += (sampleDepth >= sampled.z ? 1.0f : 0.0f) * rangeCheck;
|
||||||
|
}
|
||||||
|
occlusion /= (float)(SSAOKernel.Length.x);
|
||||||
|
occlusion = 1.0f - occlusion;
|
||||||
|
|
||||||
|
return occlusion;
|
||||||
|
}
|
||||||
|
|
|
@ -3,15 +3,8 @@
|
||||||
VertexOut main( VertexIn input )
|
VertexOut main( VertexIn input )
|
||||||
{
|
{
|
||||||
VertexOut output;
|
VertexOut output;
|
||||||
float4 WorldPos = mul(World, float4(input.pos,1));
|
output.pos = mul(WVP, float4(input.pos,1));
|
||||||
float4 ViewPos = mul(View, WorldPos);
|
output.normal = mul(WV, float4(input.normal,0));
|
||||||
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.UV = input.UV;
|
||||||
//output.normal = ViewNor;
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
|
@ -70,8 +70,11 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
|
||||||
__int64 prevTimeStamp = 0;
|
__int64 prevTimeStamp = 0;
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
|
||||||
|
|
||||||
|
std::string fps = "FPS:";
|
||||||
|
char count[100];
|
||||||
// Main message loop
|
// Main message loop
|
||||||
MSG msg = {0};
|
MSG msg = {0};
|
||||||
|
float fpsCounter = 0;
|
||||||
while(WM_QUIT != msg.message)
|
while(WM_QUIT != msg.message)
|
||||||
{
|
{
|
||||||
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
|
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) )
|
||||||
|
@ -88,13 +91,20 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdL
|
||||||
//render
|
//render
|
||||||
Update(dt);
|
Update(dt);
|
||||||
Render(dt);
|
Render(dt);
|
||||||
|
fpsCounter += dt;
|
||||||
|
if(fpsCounter>0.1f)
|
||||||
|
{
|
||||||
|
sprintf_s(count, "%f",1/dt);
|
||||||
|
SetWindowTextA(g_hWnd, (fps + count).c_str());
|
||||||
|
fpsCounter = 0;
|
||||||
|
}
|
||||||
prevTimeStamp = currTimeStamp;
|
prevTimeStamp = currTimeStamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Oyster::Graphics::API::DeleteModel(m);
|
Oyster::Graphics::API::DeleteModel(m);
|
||||||
Oyster::Graphics::API::DeleteModel(m2);
|
Oyster::Graphics::API::DeleteModel(m2);
|
||||||
|
Oyster::Graphics::API::DeleteModel(m3);
|
||||||
Oyster::Graphics::API::Clean();
|
Oyster::Graphics::API::Clean();
|
||||||
return (int) msg.wParam;
|
return (int) msg.wParam;
|
||||||
}
|
}
|
||||||
|
@ -161,56 +171,24 @@ HRESULT InitDirect3D()
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region Triangle
|
m = Oyster::Graphics::API::CreateModel(L"christmastree");
|
||||||
//Oyster::Graphics::Definitions::ObjVertex mesh[] =
|
|
||||||
//{
|
|
||||||
// {Oyster::Math::Vector3(-1,1,0),Oyster::Math::Vector2(0,0),Oyster::Math::Vector3(1,1,0)},
|
|
||||||
// {Oyster::Math::Vector3(1,-1,0),Oyster::Math::Vector2(0,0),Oyster::Math::Vector3(1,1,0)},
|
|
||||||
// {Oyster::Math::Vector3(1,1,0),Oyster::Math::Vector2(0,0),Oyster::Math::Vector3(1,1,0)},
|
|
||||||
//};
|
|
||||||
|
|
||||||
//Oyster::Graphics::Buffer::BUFFER_INIT_DESC desc;
|
|
||||||
//desc.ElementSize= sizeof(Oyster::Graphics::Definitions::ObjVertex);
|
|
||||||
//desc.NumElements = 3;
|
|
||||||
//desc.InitData=mesh;
|
|
||||||
//desc.Type = Oyster::Graphics::Buffer::BUFFER_TYPE::VERTEX_BUFFER;
|
|
||||||
//desc.Usage = Oyster::Graphics::Buffer::BUFFER_USAGE::BUFFER_USAGE_IMMUTABLE;
|
|
||||||
|
|
||||||
//Oyster::Graphics::Buffer *b = new Oyster::Graphics::Buffer();;
|
|
||||||
//b->Init(desc);
|
|
||||||
|
|
||||||
////b.Apply(0);
|
|
||||||
//Oyster::Graphics::Render::ModelInfo* mi = new Oyster::Graphics::Render::ModelInfo();
|
|
||||||
//mi->Indexed = false;
|
|
||||||
//mi->VertexCount = 3;
|
|
||||||
//mi->Vertices = b;
|
|
||||||
|
|
||||||
//m->info = mi;
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
#pragma region Obj
|
|
||||||
m = Oyster::Graphics::API::CreateModel(L"orca_dummy");
|
|
||||||
m2 = Oyster::Graphics::API::CreateModel(L"worldDummy");
|
m2 = Oyster::Graphics::API::CreateModel(L"worldDummy");
|
||||||
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"worldDummy");
|
m3 = Oyster::Graphics::API::CreateModel(L"worldDummy");
|
||||||
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
|
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
|
||||||
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
|
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,100);
|
||||||
Oyster::Graphics::API::SetProjection(P);
|
Oyster::Graphics::API::SetProjection(P);
|
||||||
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,15.4f));
|
||||||
//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();
|
V = V.GetInverse();
|
||||||
|
|
||||||
|
|
||||||
Oyster::Graphics::Definitions::Pointlight pl;
|
Oyster::Graphics::Definitions::Pointlight pl;
|
||||||
pl.Color = Oyster::Math::Float3(1,1,1);
|
pl.Color = Oyster::Math::Float3(1,1,1);
|
||||||
pl.Bright = 1;
|
pl.Bright = 1;
|
||||||
pl.Pos = Oyster::Math::Float3(0,0,5.4f);
|
pl.Pos = Oyster::Math::Float3(0,5,5.4f);
|
||||||
pl.Radius = 15;
|
pl.Radius = 15;
|
||||||
|
|
||||||
Oyster::Graphics::API::AddLight(pl);
|
Oyster::Graphics::API::AddLight(pl);
|
||||||
|
@ -222,7 +200,7 @@ float angle = 0;
|
||||||
HRESULT Update(float deltaTime)
|
HRESULT Update(float deltaTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
angle += Oyster::Math::pi/10000;
|
angle += Oyster::Math::pi/8 * deltaTime;
|
||||||
m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle);
|
m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle);
|
||||||
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-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);
|
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null);
|
||||||
|
@ -269,6 +247,12 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
case VK_ESCAPE:
|
case VK_ESCAPE:
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
break;
|
break;
|
||||||
|
//R
|
||||||
|
case 0x52:
|
||||||
|
#ifdef _DEBUG
|
||||||
|
Oyster::Graphics::API::ReloadShaders();
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue