Fixed Glow Mapping

This commit is contained in:
lanariel 2014-02-13 15:24:19 +01:00
parent 5fbb901c69
commit 491dc88bd1
11 changed files with 145 additions and 42 deletions

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

@ -162,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()
{
@ -169,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

@ -23,8 +23,8 @@ namespace Oyster
{
namespace Render
{
ID3D11RenderTargetView* Resources::GBufferRTV[Resources::GBufferSize] = {0};
#pragma region Declare Static
ID3D11RenderTargetView* Resources::GBufferRTV[Resources::GBufferSize] = {0};
ID3D11ShaderResourceView* Resources::GBufferSRV[Resources::GBufferSize] = {0};
ID3D11UnorderedAccessView* Resources::LBufferUAV[Resources::LBufferSize] = {0};
@ -48,6 +48,7 @@ namespace Oyster
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()
@ -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);
@ -377,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");
@ -412,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");
@ -459,6 +472,7 @@ namespace Oyster
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

@ -81,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)
{
0.05f, 0.05f, 0.1f, 0.15f, 0.3f, 0.15f, 0.1f, 0.05f, 0.05f
//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

@ -45,6 +45,7 @@ PixelOut main(VertexOut input)
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*255);
output.NormalSpec = float4(normal, Normal.Sample(S1, input.UV).w*0);
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,23 +4,49 @@ Texture2D Ambient : register(t2);
RWTexture2D<float4> Output;
SamplerState S1 : register(s0);
cbuffer Size : register(b0)
{
int2 Pixels;
}
#define AmbFactor 0.3f;
#define AmbFactor 0.1f;
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 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((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,11 +171,11 @@ 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.8f,0.8f,1);
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", true);
@ -193,21 +193,21 @@ HRESULT InitDirect3D()
pl.Color = Oyster::Math::Float3(1,1,1);
pl.Bright = 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(1,1,1);
pl.Bright = 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(1,1,1);
pl.Bright = 1;
pl.Bright = 0.5f;
pl.Pos = Oyster::Math::Float3(0,0,20);
pl.Radius = 90;
@ -220,6 +220,7 @@ 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;
@ -233,10 +234,10 @@ HRESULT Render(float deltaTime)
Oyster::Graphics::API::SetView(V);
Oyster::Graphics::API::NewFrame();
//Oyster::Graphics::API::RenderModel(m);
Oyster::Graphics::API::RenderModel(m);
Oyster::Graphics::API::RenderModel(m2);
Oyster::Graphics::API::RenderModel(m3);
//Oyster::Graphics::API::StartGuiRender();
Oyster::Graphics::API::StartGuiRender();
//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();