Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic

This commit is contained in:
Erik Persson 2014-02-14 11:34:59 +01:00
commit 3c928f497f
22 changed files with 257 additions and 86 deletions

View File

@ -83,15 +83,15 @@ namespace DanBias
if(EventButton<Owner>::GetState() == ButtonState_None)
{
Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
//Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
}
else if(EventButton<Owner>::GetState() == ButtonState_Hover)
{
Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
//Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
}
else
{
Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
//Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
}
}
@ -101,7 +101,7 @@ namespace DanBias
{
if(buttonText.size() > 0)
{
Oyster::Graphics::API::RenderText(buttonText, pos.xy, size, textColor);
//Oyster::Graphics::API::RenderText(buttonText, pos.xy, size, textColor);
}
}

View File

@ -391,7 +391,7 @@ bool GameState::Render(float dt)
std::wstring fps;
float f = 1/dt;
fps = std::to_wstring(f);
Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.2f,0.05f));
//Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.2f,0.05f));
Oyster::Graphics::API::EndFrame();
return true;

View File

@ -255,7 +255,7 @@ bool LoginState::Render(float dt)
Oyster::Graphics::API::StartTextRender();
EventHandler::Instance().RenderText();
Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7f, 0.2f), Oyster::Math::Float2(0.1f, 0.1f*(1008.0f/730.0f)), Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
//Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7f, 0.2f), Oyster::Math::Float2(0.1f, 0.1f*(1008.0f/730.0f)), Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
Oyster::Graphics::API::EndFrame();
return true;

View File

@ -73,6 +73,15 @@ namespace Oyster
int offset;
float coff;
};
struct BlurrData
{
unsigned int StartX;
unsigned int StartY;
unsigned int StopX;
unsigned int StopY;
Math::Float4 BlurMask;
};
}
}
}

View File

@ -87,6 +87,7 @@ namespace Oyster
m->WorldMatrix = Oyster::Math::Float4x4::identity;
m->Visible = true;
m->Animation.AnimationPlaying = NULL;
m->Tint = Math::Float3(1);
m->info = (Model::ModelInfo*)Core::loader.LoadResource((Core::modelPath + filename).c_str(),Oyster::Graphics::Loading::LoadDAN, Oyster::Graphics::Loading::UnloadDAN);
Model::ModelInfo* mi = (Model::ModelInfo*)m->info;
@ -158,7 +159,7 @@ namespace Oyster
Render::Gui::Begin2DRender();
}
void API::RenderGuiElement(API::Texture tex, Math::Float2 pos, Math::Float2 size, Math::Float3 color)
void API::RenderGuiElement(API::Texture tex, Math::Float3 pos, Math::Float2 size, Math::Float3 color)
{
Render::Gui::Render((ID3D11ShaderResourceView*)tex,pos,size,color);
}
@ -191,9 +192,9 @@ namespace Oyster
Render::Gui::Begin2DTextRender();
}
void API::RenderText(std::wstring text, Math::Float2 Pos, Math::Float2 Size, Math::Float3 color)
void API::RenderText(std::wstring text, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 color)
{
Render::Gui::RenderText(text,Pos,Size,color);
Render::Gui::RenderText(text, Pos, Size, FontSize, color);
}
}
}

View File

@ -57,13 +57,13 @@ namespace Oyster
static void StartGuiRender();
//! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system
static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1));
static void RenderGuiElement(Texture, Math::Float3 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1));
//! @brief Configures Renderer to process 2D Text, data will be passed in to EndFrame()
static void StartTextRender();
//! @brief Renders a single GUI string using the texture provided and the Pos in the center, %based system
static void RenderText(std::wstring, Math::Float2 Pos, Math::Float2 Size, Math::Float3 Color = Math::Float3(1,1,1));
static void RenderText(std::wstring, Math::Float3 Pos, Math::Float2 Size, float FontSize, Math::Float3 Color = Math::Float3(1,1,1));
//! @brief Performs light calculations, post effects and presents the scene
static void EndFrame();

View File

@ -23,6 +23,7 @@ namespace Oyster
{
ModelInfo* info;
Oyster::Math::Float4x4 WorldMatrix;
Oyster::Math::Float3 Tint;
bool Visible;
AnimationData Animation;
};

View File

@ -138,6 +138,10 @@ namespace Oyster
memcpy(data,&(pm),sizeof(pm));
Resources::Gather::ModelData.Unmap();
data = Render::Resources::Color.Map();
memcpy(data,&models[i].Tint,sizeof(Math::Float3));
Render::Resources::Color.Unmap();
if(info->Material.size())
{
Core::deviceContext->PSSetShaderResources(0,(UINT)info->Material.size(),&(info->Material[0]));
@ -158,6 +162,46 @@ namespace Oyster
}
}
void BlurGlow()
{
Definitions::BlurrData bd;
bd.BlurMask = Math::Float4(1,1,1,1);
bd.StopX = Core::resolution.x/2;
bd.StopY = Core::resolution.y;
bd.StartX = 0;
bd.StartY = Core::resolution.y/2;
void* data = Resources::Blur::Data.Map();
memcpy(data,&bd,sizeof(Definitions::BlurrData));
Resources::Blur::Data.Unmap();
Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass);
Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1);
Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass);
Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1);
}
void BlurSSAO()
{
Definitions::BlurrData bd;
bd.BlurMask = Math::Float4(0,0,0,1);
bd.StopX = Core::resolution.x/2;
bd.StopY = Core::resolution.y/2;
bd.StartX = 0;
bd.StartY = 0;
void* data = Resources::Blur::Data.Map();
memcpy(data,&bd,sizeof(Definitions::BlurrData));
Resources::Blur::Data.Unmap();
Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass);
Core::deviceContext->Dispatch((UINT)((Core::resolution.x/2 + 127U) / 128U), (UINT)(Core::resolution.y/2), 1);
Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass);
Core::deviceContext->Dispatch((UINT)(Core::resolution.x/2), (UINT)((Core::resolution.y/2 + 127U) / 128U), 1);
}
void DefaultRenderer::EndFrame()
{
@ -165,11 +209,9 @@ namespace Oyster
Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
//Core::PipelineManager::SetRenderPass(Resources::Blur::HorPass);
//Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
BlurGlow();
//Core::PipelineManager::SetRenderPass(Resources::Blur::VertPass);
//Core::deviceContext->Dispatch((UINT)((Core::resolution.x + 15U) / 16U), (UINT)((Core::resolution.y + 15U) / 16U), 1);
BlurSSAO();
Core::PipelineManager::SetRenderPass(Resources::Post::Pass);

View File

@ -16,7 +16,7 @@ namespace Oyster
Core::PipelineManager::SetRenderPass(Render::Resources::Gui::Pass);
}
void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float2 pos, Math::Float2 size, Math::Float3 color)
void Gui::Render(ID3D11ShaderResourceView* tex,Math::Float3 pos, Math::Float2 size, Math::Float3 color)
{
Core::deviceContext->PSSetShaderResources(0,1,&tex);
@ -28,6 +28,7 @@ namespace Oyster
gd.Translation = Math::Matrix::identity;
gd.Translation.m41 = pos.x;
gd.Translation.m42 = pos.y;
gd.Translation.m43 = pos.z;
gd.Translation.m11 = size.x;
gd.Translation.m22 = size.y;
@ -35,9 +36,9 @@ namespace Oyster
memcpy(data,&gd,sizeof(Definitions::GuiData));
Render::Resources::Gui::Data.Unmap();
data = Render::Resources::Gui::Color.Map();
data = Render::Resources::Color.Map();
memcpy(data,&color,sizeof(Math::Float3));
Render::Resources::Gui::Color.Unmap();
Render::Resources::Color.Unmap();
Core::deviceContext->Draw(1,0);
@ -49,10 +50,10 @@ namespace Oyster
Core::PipelineManager::SetRenderPass(Resources::Gui::Text::Pass);
}
void Gui::RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 color)
void Gui::RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 color)
{
size.x = size.x / (text.length() * TEXT_SPACING /2);
//size.x = size.x / (text.length() * TEXT_SPACING /2);
pos *= 2;
@ -60,15 +61,18 @@ namespace Oyster
pos.y *= -1;
pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2);
//pos.x = pos.x - (size.x * (text.length()-1) * TEXT_SPACING /2);
pos.x = pos.x + size.x/ (text.length() * TEXT_SPACING/2);
pos.y = pos.y - size.y/2;
Definitions::GuiData gd;
gd.Translation = Math::Matrix::identity;
gd.Translation.m41 = pos.x;
gd.Translation.m42 = pos.y;
gd.Translation.m11 = size.x;
gd.Translation.m22 = size.y;
gd.Translation.m43 = pos.z;
gd.Translation.m11 = FontSize * 0.8f;
gd.Translation.m22 = FontSize;
void* data = Render::Resources::Gui::Data.Map();
@ -76,25 +80,26 @@ namespace Oyster
Render::Resources::Gui::Data.Unmap();
Definitions::Text2D tmpInst;
data = Render::Resources::Gui::Color.Map();
data = Render::Resources::Color.Map();
memcpy(data,&color,sizeof(Math::Float3));
Render::Resources::Gui::Color.Unmap();
Render::Resources::Color.Unmap();
void* dest = Resources::Gui::Text::Vertex.Map();
Definitions::Text2D* dataView = reinterpret_cast<Definitions::Text2D*>(dest);
//tmpInst.charOffset=_pos;
for (unsigned int i=0; i<text.length(); i++)
{
tmpInst.coff=(1.0f/TEXT_NR_LETTERS);
tmpInst.offset=text[i]-32;
tmpInst.pos=i*(size.x * TEXT_SPACING);
//float tst=getCharID(_str[i]);
//tmpInst.offset=tst;
//tmpInst.charOffset.x=_pos.x-i*TEXT_SIZE;
//tmpInst.data=tst;
tmpInst.pos=i*(FontSize * 0.8f * TEXT_SPACING);
if(tmpInst.pos > size.x)
{
text = text.substr(0,i-1);
break;
}
dataView[i]=tmpInst;
}
//TextInstances[_id].NumLetters=instances;
Resources::Gui::Text::Vertex.Unmap();

View File

@ -12,9 +12,9 @@ namespace Oyster
{
public:
static void Begin2DRender();
static void Render(ID3D11ShaderResourceView* tex, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1));
static void Render(ID3D11ShaderResourceView* tex, Math::Float3 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1));
static void Begin2DTextRender();
static void RenderText(std::wstring text, Math::Float2 pos, Math::Float2 size, Math::Float3 tint = Math::Float3(1,1,1));
static void RenderText(std::wstring text, Math::Float3 pos, Math::Float2 size, float FontSize, Math::Float3 tint = Math::Float3(1,1,1));
};
}
}

View File

@ -23,7 +23,7 @@ namespace Oyster
{
namespace Render
{
#pragma region Declare Static
ID3D11RenderTargetView* Resources::GBufferRTV[Resources::GBufferSize] = {0};
ID3D11ShaderResourceView* Resources::GBufferSRV[Resources::GBufferSize] = {0};
@ -45,9 +45,10 @@ namespace Oyster
Buffer Resources::Gather::AnimationData = Buffer();
Buffer Resources::Light::LightConstantsData = Buffer();
Buffer Resources::Gui::Data = Buffer();
Buffer Resources::Gui::Color = Buffer();
Buffer Resources::Color = Buffer();
Buffer Resources::Gui::Text::Vertex = Buffer();
Buffer Resources::Post::Data = Buffer();
Buffer Resources::Blur::Data = Buffer();
Buffer Resources::Light::PointLightsData = Buffer();
ID3D11ShaderResourceView* Resources::Light::PointLightView = NULL;
@ -61,6 +62,7 @@ namespace Oyster
ID3D11BlendState* Resources::RenderStates::bs = NULL;
ID3D11ShaderResourceView* Resources::Gui::Text::Font = NULL;
#pragma endregion
Core::Init::State Resources::InitShaders()
@ -121,7 +123,7 @@ namespace Oyster
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_PS;
desc.ElementSize = sizeof(Math::Float3);
Gui::Color.Init(desc);
Color.Init(desc);
desc.Type = Buffer::BUFFER_TYPE::CONSTANT_BUFFER_GS;
desc.NumElements = 1;
@ -135,6 +137,9 @@ namespace Oyster
desc.ElementSize = sizeof(Definitions::LightConstants);
Light::LightConstantsData.Init(desc);
desc.ElementSize = sizeof(Definitions::BlurrData);
Blur::Data.Init(desc);
desc.ElementSize = sizeof(Definitions::Pointlight);
desc.NumElements = MaxLightSize;
desc.Type = Buffer::STRUCTURED_BUFFER;
@ -235,6 +240,9 @@ namespace Oyster
Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&LBufferSRV[i],&LBufferUAV[i]);
}
//Blur
Core::Init::CreateLinkedShaderResourceFromTexture(NULL,&Blur::BufferSRV,&Blur::BufferUAV);
Buffer* b = &Light::PointLightsData;
Core::Init::CreateLinkedShaderResourceFromStructuredBuffer(&b,&Light::PointLightView,NULL);
@ -342,6 +350,7 @@ namespace Oyster
Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData);
Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData);
Gather::Pass.CBuffers.Pixel.push_back(Color);
Gather::Pass.RenderStates.Rasterizer = RenderStates::rs;
Gather::Pass.RenderStates.SampleCount = 1;
Gather::Pass.RenderStates.SampleState = RenderStates::ss;
@ -376,6 +385,8 @@ namespace Oyster
}
Post::Pass.UAV.Compute.push_back(Core::backBufferUAV);
Post::Pass.CBuffers.Compute.push_back(Post::Data);
Post::Pass.RenderStates.SampleCount = 1;
Post::Pass.RenderStates.SampleState = RenderStates::ss;
////---------------- GUI Pass Setup ----------------------------
Gui::Pass.Shaders.Vertex = GetShader::Vertex(L"2D");
@ -383,7 +394,7 @@ namespace Oyster
Gui::Pass.Shaders.Geometry = GetShader::Geometry(L"2D");
Gui::Pass.RTV.push_back(GBufferRTV[2]);
Gui::Pass.CBuffers.Geometry.push_back(Gui::Data);
Gui::Pass.CBuffers.Pixel.push_back(Gui::Color);
Gui::Pass.CBuffers.Pixel.push_back(Color);
D3D11_INPUT_ELEMENT_DESC indesc2D[] =
{
@ -411,6 +422,9 @@ namespace Oyster
//And the Ambient UAV is now the output texture
Blur::VertPass.UAV.Compute.push_back(LBufferUAV[2]);
Blur::HorPass.CBuffers.Compute.push_back(Blur::Data);
Blur::VertPass.CBuffers.Compute.push_back(Blur::Data);
////---------------- 2DText Pass Setup ----------------------------
Gui::Text::Pass.Shaders.Vertex = GetShader::Vertex(L"2DText");
Gui::Text::Pass.Shaders.Geometry = GetShader::Geometry(L"2DText");
@ -427,7 +441,7 @@ namespace Oyster
Shader::CreateInputLayout(Text2Ddesc,3, GetShader::Vertex(L"2DText") ,Gui::Text::Pass.IAStage.Layout);
Gui::Text::Pass.CBuffers.Geometry.push_back(Gui::Data);
Gui::Text::Pass.CBuffers.Pixel.push_back(Gui::Color);
Gui::Text::Pass.CBuffers.Pixel.push_back(Color);
Gui::Text::Pass.SRV.Pixel.push_back(Gui::Text::Font);
Gui::Text::Pass.RTV.push_back(GBufferRTV[2]);
Gui::Text::Pass.RenderStates.SampleCount = 1;
@ -455,9 +469,10 @@ namespace Oyster
Light::LightConstantsData.~Buffer();
Light::PointLightsData.~Buffer();
Gui::Data.~Buffer();
Gui::Color.~Buffer();
Color.~Buffer();
Gui::Text::Vertex.~Buffer();
Post::Data.~Buffer();
Blur::Data.~Buffer();
SAFE_RELEASE(Light::PointLightView);
SAFE_RELEASE(Light::SSAOKernel);
SAFE_RELEASE(Light::SSAORandom);

View File

@ -31,6 +31,9 @@ namespace Oyster
static ID3D11ShaderResourceView* LBufferSRV[LBufferSize];
static Core::Buffer Color;
struct RenderStates
{
static ID3D11RasterizerState* rs;
@ -61,7 +64,6 @@ namespace Oyster
{
static Core::PipelineManager::RenderPass Pass;
static Core::Buffer Data;
static Core::Buffer Color;
struct Text
{
static Core::PipelineManager::RenderPass Pass;
@ -79,6 +81,8 @@ namespace Oyster
//Blur UAV and SRV
static ID3D11UnorderedAccessView* BufferUAV;
static ID3D11ShaderResourceView* BufferSRV;
static Core::Buffer Data;
};
struct Post

View File

@ -7,14 +7,14 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
if(gThreadID.x < blurRadius)
{
int x = max(ThreadID.x-blurRadius,0);
gCache[gThreadID.x] = inTex[int2(x,ThreadID.y)];
gCache[gThreadID.x] = inTex[min(int2(x,ThreadID.y) + Start, Stop-1)];
}
if(gThreadID.x >= N-blurRadius)
{
int x = min(ThreadID.x+blurRadius,inTex.Length.x-1);
gCache[gThreadID.x+2*blurRadius] = inTex[int2(x,ThreadID.y)];
int x = min(ThreadID.x+blurRadius,Stop.x-1);
gCache[gThreadID.x+2*blurRadius] = inTex[int2(x,ThreadID.y) + Start];
}
gCache[gThreadID.x+blurRadius] = inTex[min(ThreadID.xy,inTex.Length.xy-1)];
gCache[gThreadID.x+blurRadius] = inTex[min(ThreadID.xy + Start, Stop-1)];
GroupMemoryBarrierWithGroupSync();
@ -27,7 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
blurCol +=Weights[i + blurRadius] * gCache[k];
}
outTex[ThreadID.xy] = blurCol;
//Output[ThreadID.xy] = Diffuse[((ThreadID.xy))];
outTex[ThreadID.xy + Start] = blurCol * BlurMask + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);
}

View File

@ -3,12 +3,26 @@
static const float Weights[9] =
cbuffer BlurrData : register(b1)
{
//static const int blurRadius = 0;
//static const float Weights[1] =
//{
// 1.0f
//};
/*static const int blurRadius = 4;
static const float Weights[9] =
{
0.05f, 0.05f, 0.1f, 0.15f, 0.3f, 0.15f, 0.1f, 0.05f, 0.05f
};*/
static const int blurRadius = 5;
static const float Weights[11] =
{
0.05f,0.05f,0.1f,0.1f,0.1f,0.2f,0.1f,0.1f,0.1f,0.05f,0.05f
};
};
static const int blurRadius = 4;
#define N 128
#define gSize (N+2*blurRadius)
@ -17,14 +31,13 @@ groupshared float4 gCache[gSize];
Texture2D inTex : register(t0);
RWTexture2D<float4> outTex : register(u0);
//cbuffer BlurrData : register(c0)
//{
// static const int blurRadius = 5;
// static const float Weights[11] =
// {
// 0.05f,0.05f,0.1f,0.1f,0.1f,0.2f,0.1f,0.1f,0.1f,0.05f,0.05f
// };
//};
cbuffer BlurrData : register(b0)
{
uint2 Start;
uint2 Stop;
float4 BlurMask;
};
//[numthreads(16,16,1)]
//void TryCompute(uint3 ThreadID : SV_DispatchThreadID)

View File

@ -7,14 +7,14 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
if(gThreadID.y < blurRadius)
{
int y = max(ThreadID.y-blurRadius,0);
gCache[gThreadID.y] = inTex[int2(ThreadID.x,y)];
gCache[gThreadID.y] = inTex[min(int2(ThreadID.x,y) + Start, Stop-1)];
}
if(gThreadID.y >= N-blurRadius)
{
int y = min(ThreadID.y+blurRadius,inTex.Length.y-1);
gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y)];
int y = min(ThreadID.y+blurRadius, Stop.y-1);
gCache[gThreadID.y+2*blurRadius] = inTex[int2(ThreadID.x,y) + Start];
}
gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy,inTex.Length.xy-1)];
gCache[gThreadID.y+blurRadius] = inTex[min(ThreadID.xy + Start, Stop.xy-1)];
GroupMemoryBarrierWithGroupSync();
@ -27,6 +27,6 @@ void main(int3 ThreadID : SV_DispatchThreadID, int3 gThreadID : SV_GroupThreadID
blurCol +=Weights[i + blurRadius] * gCache[k];
}
outTex[ThreadID.xy] = blurCol;
//Output[ThreadID.xy] = inTex[((ThreadID.xy))];
outTex[ThreadID.xy + Start] = blurCol + inTex[ThreadID.xy + Start] * ( float4(1,1,1,1) - BlurMask);;
//outTex[ThreadID.xy] = inTex[ThreadID.xy];
}

View File

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

View File

@ -14,6 +14,7 @@ VertexOut main( VertexIn input )
input.normal = mul(boneTrans,float4(input.normal,1)).xyz * Animated + input.normal * int(1-Animated);
output.pos = mul(WVP, float4(input.pos,1));
output.ViewPos = mul(WV, float4(input.pos,1));
output.normal = mul(WV, float4(input.normal,0)).xyz;
output.UV = input.UV;
return output;

View File

@ -12,7 +12,7 @@ struct VertexIn
struct VertexOut
{
float4 pos : SV_POSITION;
//float4 ViewPos : POSITION;
float4 ViewPos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
//float3 tangent : TANGENT;
@ -42,3 +42,8 @@ cbuffer PerModel : register(b1)
int Animated;
float3 Pad;
}
cbuffer Tint : register(b0)
{
float3 Color;
}

View File

@ -24,5 +24,7 @@ DiffSpec LightCalc(PointLight pl, float3 pos, int2 texCoord)
output.Diffuse = float3(0,0,0);
output.Specular = float3(0,0,0);
}
float SpecCo = normalSpec.w < 1 ? 0.0f : 1.0f;
output.Specular = output.Specular * SpecCo;
return output;
}

View File

@ -36,7 +36,7 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID )
float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy/2);
Ambient[DTid.xy/2] = float4(DiffuseGlow[DTid.xy].xyz, AmbValue);
Ambient[DTid.xy/2 + float2(Pixels.x/2, 0)] = GUI[DTid.xy];
//Ambient[DTid.xy] = GUI[DTid.xy];
Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffuseGlow[DTid.xy].xyz * DiffuseGlow[DTid.xy].w*10,1);
}
}

View File

@ -4,6 +4,8 @@ Texture2D Ambient : register(t2);
RWTexture2D<float4> Output;
SamplerState S1 : register(s0);
cbuffer Size : register(b0)
{
int2 Pixels;
@ -11,16 +13,40 @@ cbuffer Size : register(b0)
#define AmbFactor 0.8f;
float4 SuperSample(float4 Glow, uint3 DTid)
{
// Line X
float2 index = (float2)(DTid.xy/2);
index += float2(0,Output.Length.y/2);
index = index / Output.Length;
Glow = Ambient.SampleLevel(S1, index,1);
//Line Y+1
//Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)+1)];
//Line Y-1
//Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)-1)];
//Glow = Glow/9;
return Glow;
}
[numthreads(16, 16, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
float4 Light = Diffuse[DTid.xy] + saturate(Specular[DTid.xy]);
float4 Amb = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 0);
float4 Amb = float4(Ambient[DTid.xy/2].xyz/* * Ambient[DTid.xy/2].w */, 0);
//float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)];
float4 Glow = Ambient[DTid.xy/2 + uint2(0,Output.Length.y/2)];
Glow = SuperSample(Glow,DTid);
float4 GUI;
uint2 index = DTid.xy/2 + uint2(Pixels.x/2,0);
uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0);
float3 PostLight = Amb.xyz * AmbFactor;
PostLight = PostLight + Light.xyz;
PostLight = PostLight + Light.xyz; // + Glow;
GUI = float4(Ambient[index]);
PostLight = PostLight * (1 - GUI.w);
Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1);
//Output[DTid.xy] = Glow;
}

View File

@ -171,12 +171,15 @@ HRESULT InitDirect3D()
}
m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan");
m->WorldMatrix.m[0][0] = 50;
m->WorldMatrix.m[1][1] = 50;
m->WorldMatrix.m[2][2] = 0.00000005f;
//m->WorldMatrix.m[0][0] = 50;
//m->WorldMatrix.m[1][1] = 50;
//m->WorldMatrix.m[2][2] = 0.00000005f;
m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
m2->Tint = Oyster::Math::Float3(0.1f,0.1f,1);
m3 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
Oyster::Graphics::API::PlayAnimation(m2, L"movement",false);
Oyster::Graphics::API::PlayAnimation(m2, L"movement", true);
Oyster::Graphics::API::PlayAnimation(m3, L"movement", true);
t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png");
t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png");
@ -189,22 +192,22 @@ HRESULT InitDirect3D()
pl.Color = Oyster::Math::Float3(1,0,0);
pl.Bright = 1;
pl.Color = Oyster::Math::Float3(1,1,1);
pl.Bright = 0.5f;
pl.Pos = Oyster::Math::Float3(-20,0,0);
pl.Radius = 90;
Oyster::Graphics::API::AddLight(pl);
pl.Color = Oyster::Math::Float3(0,1,0);
pl.Bright = 1;
pl.Color = Oyster::Math::Float3(1,1,1);
pl.Bright = 0.5f;
pl.Pos = Oyster::Math::Float3(0,20,0);
pl.Radius = 90;
Oyster::Graphics::API::AddLight(pl);
pl.Color = Oyster::Math::Float3(0,0,1);
pl.Bright = 1;
pl.Color = Oyster::Math::Float3(1,1,1);
pl.Bright = 0.5f;
pl.Pos = Oyster::Math::Float3(0,0,20);
pl.Radius = 90;
@ -217,7 +220,9 @@ float angle = 0;
HRESULT Update(float deltaTime)
{
//angle += Oyster::Math::pi/16 * deltaTime;
m->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0) * angle,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null);
//Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity;
Oyster::Graphics::API::Update(deltaTime);
//m2->Animation.data.AnimationTime += deltaTime;// * 0.5f;
@ -231,16 +236,17 @@ HRESULT Render(float deltaTime)
Oyster::Graphics::API::RenderModel(m);
Oyster::Graphics::API::RenderModel(m2);
Oyster::Graphics::API::RenderModel(m3);
Oyster::Graphics::API::StartGuiRender();
Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1));
//Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(1,0,0));
//Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1), Oyster::Math::Float3(0,0,1));
//Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0));
Oyster::Graphics::API::StartTextRender();
std::wstring fps;
float f = 1/deltaTime;
fps = std::to_wstring(f);
//Oyster::Graphics::API::RenderText(L"Lanariel",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
//Oyster::Graphics::API::RenderText(L"Lanariel WAS HERE",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float3(0,1,0));
Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float3(0.5f,0.1f,1.0f),Oyster::Math::Float2(0.5f,0.1f), 0.08f, Oyster::Math::Float3(0,1,0));
Oyster::Graphics::API::EndFrame();
return S_OK;