Skip to content

Commit

Permalink
Merge branch '#97' into #92
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin02 committed Jul 22, 2018
2 parents 9cc03e6 + 7cb51f5 commit 38ec6cb
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 35 deletions.
8 changes: 8 additions & 0 deletions SOCEngine/SOCEngine/Common/Half.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Half.h"
#include <assert.h>
#include <math.h>

Half::Half(ushort us)
: _value(us)
Expand All @@ -16,6 +17,13 @@ Half::Half(float f)
// 1 5 10
// s eeeee mmmmmmmmmm

const float epsilon = 1.192092896e-07F;
if (fabsf(f) <= epsilon)
{
_value = 0.0f;
return;
}

unsigned int floatBit = *((unsigned int*)&f);

int exponent = (int)((floatBit &0x7F800000) >> 23) - 127 + 15;
Expand Down
14 changes: 11 additions & 3 deletions SOCEngine/SOCEngine/Rendering/Postprocessing/Bloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ void Bloom::Initialize(Device::DirectX& dx, Manager::ShaderManager& shaderMgr, c
_adaptedLuminanceMaps[1].Initialize(dx, Size<uint>(1, 1), DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, 0, 1, 1);

_bloomThresholdMap.Initialize(dx, renderSize, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, 0, 1, 1);

_paramCB.Initialize(dx);
_paramCB.UpdateSubResource(dx, ParamCBData());
}
else
{
_bloom.Initialize(dx, Param("Bloom", "Bloom_InFullScreen_PS", nullptr), shaderMgr);
}

_paramCB.Initialize(dx);
_paramCB.UpdateSubResource(dx, ParamCBData());
}

void Bloom::Destroy()
Expand Down Expand Up @@ -129,4 +129,12 @@ void Bloom::RenderBloom(DirectX& dx, RenderTexture& outRT, const RenderTexture&
_bloom.Render(dx, outRT, true);

_currentAdaptedLuminanceIndx = !_currentAdaptedLuminanceIndx;
}

void Bloom::SetElapsedTime(float time)
{
Half hTime(time);
Half hInvTime(1.0f / time);

_paramData.packedDeltaTime = (hInvTime.GetValue() << 16) | hTime.GetValue();
}
12 changes: 7 additions & 5 deletions SOCEngine/SOCEngine/Rendering/Postprocessing/Bloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ namespace Rendering
public:
struct ParamCBData
{
float dt = 0.0f;
float exposureStrength = 0.2f;
float exposureSpeed = 0.8f;
float bloomThreshold = 0.4f;
uint packedDeltaTime = 0;

float exposureStrength = 0.2f;
float exposureSpeed = 0.8f;
float bloomThreshold = 0.4f;
};

public:
Expand All @@ -35,10 +36,11 @@ namespace Rendering

void RenderThresholdMap(Device::DirectX& dx, const Texture::RenderTexture& inColorMap, const Copy& copy, TempTextures& tempTextures, const Renderer::TBRParamCB& tbrParamCB);
void RenderBloom(Device::DirectX& dx, Texture::RenderTexture& outRT, const Texture::RenderTexture& inputColorMap, const Renderer::TBRParamCB& tbrParamCB);
void SetElapsedTime(float time);

SET_ACCESSOR(ElapsedTime, float, _paramData.dt);
SET_ACCESSOR(Param, const ParamCBData&, _paramData);
GET_CONST_ACCESSOR(Param, const ParamCBData&, _paramData);
GET_CONST_ACCESSOR_REF(ParamCB, _paramCB);

GET_CONST_ACCESSOR(Use, bool, _use);

Expand Down
5 changes: 3 additions & 2 deletions SOCEngine/SOCEngine/Rendering/Postprocessing/MotionBlur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ void MotionBlur::UpdateParamCB(DirectX& dx)
_dirty = false;
}

void MotionBlur::Render(DirectX& dx, RenderTexture& outRT, const RenderTexture& inColorMap, const MainRenderer& mainRenderer)
void MotionBlur::Render(DirectX& dx, RenderTexture& outRT, const RenderTexture& inColorMap, const MainRenderer& mainRenderer, const ConstBuffer& hdrGlobalParamCB)
{
AutoBinderSRV<PixelShader> color(dx, TextureBindIndex(0), inColorMap.GetTexture2D()->GetShaderResourceView());
AutoBinderSRV<PixelShader> velocity(dx, TextureBindIndex::GBuffer_Velocity_Metallic_Specularity, mainRenderer.GetGBuffers().velocity_metallic_specularity.GetTexture2D()->GetShaderResourceView());
AutoBinderCB<PixelShader> tbrParam(dx, ConstBufferBindIndex::TBRParam, mainRenderer.GetTBRParamCB());
AutoBinderCB<PixelShader> param(dx, ConstBufferBindIndex(1), _paramCB);
AutoBinderCB<PixelShader> hdrParam(dx, ConstBufferBindIndex::HDRGlobalParamCB, hdrGlobalParamCB);
AutoBinderCB<PixelShader> param(dx, ConstBufferBindIndex(2), _paramCB);

AutoBinderSampler<PixelShader> pointSampler(dx, SamplerStateBindIndex(0), SamplerState::Point);
AutoBinderSampler<PixelShader> linearSampler(dx, SamplerStateBindIndex(1), SamplerState::Linear);
Expand Down
7 changes: 5 additions & 2 deletions SOCEngine/SOCEngine/Rendering/Postprocessing/MotionBlur.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Rendering
public:
struct ParamCBData
{
float length = 0.025f;
float length = 0.0025f;
float kernelSize = 7.5f;
float kernelStep = 1.0f;
uint dummy;
Expand All @@ -28,7 +28,10 @@ namespace Rendering
void Destroy();

void UpdateParamCB(Device::DirectX& dx);
void Render(Device::DirectX& dx, Texture::RenderTexture& outRT, const Texture::RenderTexture& inColorMap, const Renderer::MainRenderer& mainRenderer);
void Render(Device::DirectX& dx, Texture::RenderTexture& outRT,
const Texture::RenderTexture& inColorMap,
const Renderer::MainRenderer& mainRenderer,
const Buffer::ConstBuffer& hdrGlobalParamCB);

SET_ACCESSOR_DIRTY(Param, const ParamCBData&, _paramData);
GET_CONST_ACCESSOR(Param, const ParamCBData&, _paramData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void PostProcessPipeline::Render(DirectX& dx, MainRenderer& mainRenderer, const

if(_useMotionBlur)
{
GetPostproessing<MotionBlur>().Render(dx, *output, _useSSAO ? *input : *mainScene, mainRenderer);
const auto& bloomCB = GetPostproessing<Bloom>().GetParamCB();
GetPostproessing<MotionBlur>().Render(dx, *output, _useSSAO ? *input : *mainScene, mainRenderer, bloomCB);
std::swap(input, output);
}

Expand Down Expand Up @@ -121,8 +122,8 @@ void PostProcessPipeline::Render(DirectX& dx, MainRenderer& mainRenderer, const
void PostProcessPipeline::UpdateCB(DirectX& dx, const ObjectManager& objMgr,
const LightManager& lightMgr, const TransformPool& tfPool, const MainCamera& mainCam)
{
if(GetPostproessing<Bloom>().GetUse())
GetPostproessing<Bloom>().UpdateParamCB(dx);
GetPostproessing<Bloom>().UpdateParamCB(dx);

if(_useDoF) GetPostproessing<DepthOfField>().UpdateParamCB(dx);
if(_useSSAO) GetPostproessing<SSAO>().UpdateParamCB(dx);
if(_useSunShaft) GetPostproessing<SunShaft>().UpdateParamCB(dx, objMgr, lightMgr, tfPool, mainCam);
Expand Down
5 changes: 0 additions & 5 deletions SOCEngine/SOCEngine/Rendering/RenderingSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ void RenderingSystem::Initialize(Engine& engine, bool useBloom)
_postProcessing.Initialize(engine.GetDirectX(), _shaderManager, engine.GetComponentSystem().GetMainCamera(), useBloom);
}

void RenderingSystem::Update(Engine& engine, float dt)
{
_postProcessing.SetElapsedTime(dt);
}

void RenderingSystem::Render(Engine& engine, float dt)
{
auto& dx = engine.GetDirectX();
Expand Down
1 change: 0 additions & 1 deletion SOCEngine/SOCEngine/Rendering/RenderingSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace Rendering

void InitializeRenderer(Core::Engine& engine, const RenderSetting&& param);
void Initialize(Core::Engine& engine, bool useBloom);
void Update(Core::Engine& engine, float dt);
void Render(Core::Engine& engine, float dt);
void Destroy(Core::Engine& engine);

Expand Down
2 changes: 1 addition & 1 deletion SOCEngine/SOCEngine/ShaderCodes/EyeAdaptation.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ float EyeAdaptation_InFullScreen_PS(PS_INPUT input) : SV_Target
float curLum = Luminance(CurColorMap.SampleLevel(LinearSampler, float2(0.5f, 0.5f), 11).rgb);
float prevLum = PrevAdaptedLuminanceMap.Load(uint3(0, 0, 0)).x;

float result = prevLum + (curLum - prevLum) * (1.0f - exp(-GetTimeDelta() * GetExposureSpeed()));
float result = prevLum + (curLum - prevLum) * (1.0f - exp(-GetDeltaTime() * GetExposureSpeed()));

return result;
}
17 changes: 11 additions & 6 deletions SOCEngine/SOCEngine/ShaderCodes/HDRCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

cbuffer HDRGlobalParam : register(b1)
{
float hdr_timeDelta;
float hdr_exposureStrength;
float hdr_exposureSpeed;
uint hdr_packedDeltaTime;
float hdr_exposureStrength;
float hdr_exposureSpeed;

float bloom_threshold;
float bloom_threshold;
};

float GetExposureStrength()
Expand All @@ -27,9 +27,14 @@ float GetBloomThreshold()
return bloom_threshold;
}

float GetTimeDelta()
float GetDeltaTime()
{
return hdr_timeDelta;
return f16tof32(hdr_packedDeltaTime & 0xffff);
}

float GetInvDeltaTime()
{
return f16tof32(hdr_packedDeltaTime >> 16);
}

#endif
17 changes: 10 additions & 7 deletions SOCEngine/SOCEngine/ShaderCodes/MotionBlur.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include "FullScreenShader.h"
#include "TBDRInput.h"
#include "CommonConstBuffer.h"
#include "HDRCommon.h"

cbuffer MotionBlurParamCB : register(b1)
cbuffer MotionBlurParamCB : register(b2)
{
float Length;
float KernelSize;
float KernelStep;
uint dummy;
float mbParam_length;
float mbParam_kernelSize;
float mbParam_kernelStep;
uint mbParam_dummy;
};

Texture2D<float4> InputSceneMap : register( t0 );
Expand All @@ -35,10 +36,12 @@ float4 MotionBlurPS(PS_INPUT input) : SV_Target
float2 bl = GetVelocity(input.uv, int2(-Offset, Offset));
float2 br = GetVelocity(input.uv, int2( Offset, Offset));
float2 ce = GetVelocity(input.uv, int2( 0, 0));
float2 velocity = (tl + tr + bl + br + ce) * 0.2f * Length;
float2 velocity = (tl + tr + bl + br + ce) * 0.2f * mbParam_length;

velocity *= GetInvDeltaTime(); // auto scalling

float4 color = 0;
for(float i=-KernelSize; i<=KernelSize; i+=KernelStep)
for(float i=-mbParam_kernelSize; i<= mbParam_kernelSize; i+= mbParam_kernelStep)
{
float2 uv = saturate(input.uv + velocity * i);
color += InputSceneMap.Sample(LinearSampler, uv);
Expand Down

0 comments on commit 38ec6cb

Please sign in to comment.