Added stereogram postprocess

This commit is contained in:
turanszkij
2016-03-15 21:15:18 +01:00
parent 0944f7f8e3
commit 4a7a3eea78
16 changed files with 170 additions and 47 deletions
@@ -112,6 +112,13 @@ void DeferredRenderableComponent::RenderScene(DeviceContext context){
wiRenderer::UpdateDepthBuffer(dtDepthCopy.shaderResource, rtLinearDepth.shaderResource.front(), context);
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
rtGBuffer.Set(context); {
wiRenderer::DrawDecals(wiRenderer::getCamera(), context);
}
@@ -46,6 +46,7 @@ Luna<DeferredRenderableComponent_BindLua>::FunctionType DeferredRenderableCompon
lunamethod(Renderable3DComponent_BindLua, SetMotionBlurEnabled),
lunamethod(Renderable3DComponent_BindLua, SetSSSEnabled),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldEnabled),
lunamethod(Renderable3DComponent_BindLua, SetStereogramEnabled),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength),
@@ -46,6 +46,7 @@ Luna<ForwardRenderableComponent_BindLua>::FunctionType ForwardRenderableComponen
lunamethod(Renderable3DComponent_BindLua, SetMotionBlurEnabled),
lunamethod(Renderable3DComponent_BindLua, SetSSSEnabled),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldEnabled),
lunamethod(Renderable3DComponent_BindLua, SetStereogramEnabled),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength),
+66 -6
View File
@@ -53,6 +53,7 @@ void Renderable3DComponent::setProperties()
setMotionBlurEnabled(true);
setSSSEnabled(true);
setDepthOfFieldEnabled(false);
setStereogramEnabled(false);
setPreferredThreadingCount(0);
}
@@ -190,7 +191,8 @@ void Renderable3DComponent::Compose(){
Renderable2DComponent::Compose();
}
void Renderable3DComponent::RenderFrameSetUp(DeviceContext context) {
void Renderable3DComponent::RenderFrameSetUp(DeviceContext context)
{
if (!_needToUpdateRenderData.load())
{
return;
@@ -200,7 +202,14 @@ void Renderable3DComponent::RenderFrameSetUp(DeviceContext context) {
_needToUpdateRenderData.store(false);
}
void Renderable3DComponent::RenderReflections(DeviceContext context){
void Renderable3DComponent::RenderReflections(DeviceContext context)
{
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
if (!getReflectionsEnabled() || getReflectionQuality() < 0.01f)
{
return;
@@ -224,7 +233,14 @@ void Renderable3DComponent::RenderReflections(DeviceContext context){
wiRenderer::DrawSky(context,true);
}
}
void Renderable3DComponent::RenderShadows(DeviceContext context){
void Renderable3DComponent::RenderShadows(DeviceContext context)
{
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
if (!getShadowsEnabled())
{
return;
@@ -235,6 +251,12 @@ void Renderable3DComponent::RenderShadows(DeviceContext context){
}
void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRenderTarget& shadedSceneRT, DeviceContext context)
{
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
if (getLensFlareEnabled())
{
rtLensFlare.Activate(context);
@@ -270,7 +292,14 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende
}
}
void Renderable3DComponent::RenderBloom(DeviceContext context){
void Renderable3DComponent::RenderBloom(DeviceContext context)
{
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight());
@@ -303,7 +332,14 @@ void Renderable3DComponent::RenderBloom(DeviceContext context){
wiImage::Draw(rtBloom[1].shaderResource.back(), fx, context);
}
}
void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, DeviceContext context){
void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, DeviceContext context)
{
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
if (!getLightShaftsEnabled())
{
return;
@@ -331,7 +367,14 @@ void Renderable3DComponent::RenderLightShafts(wiRenderTarget& mainRT, DeviceCont
}
}
}
void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, DeviceContext context){
void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, DeviceContext context)
{
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight());
fx.presentFullScreen = true;
@@ -339,6 +382,8 @@ void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, De
fx.blendFlag = BLENDMODE_OPAQUE;
wiImage::Draw(shadedSceneRT.shaderResource.front(), fx, context);
fx.blendFlag = BLENDMODE_ALPHA;
wiImage::Draw(rtTransparent.shaderResource.back(), fx, context);
if (getEmittedParticlesEnabled()){
@@ -360,6 +405,12 @@ void Renderable3DComponent::RenderComposition1(wiRenderTarget& shadedSceneRT, De
}
}
void Renderable3DComponent::RenderComposition2(DeviceContext context){
if (getStereogramEnabled())
{
// We don't need the following for stereograms...
return;
}
wiImageEffects fx((float)wiRenderer::GetScreenWidth(), (float)wiRenderer::GetScreenHeight());
fx.blendFlag = BLENDMODE_OPAQUE;
@@ -410,6 +461,15 @@ void Renderable3DComponent::RenderColorGradedComposition(){
fx.blendFlag = BLENDMODE_OPAQUE;
fx.quality = QUALITY_NEAREST;
if (getStereogramEnabled())
{
fx.presentFullScreen = false;
fx.process.clear();
fx.process.setStereogram(true);
wiImage::Draw(wiTextureHelper::getInstance()->getRandom64x64(), fx);
return;
}
if (getColorGradingEnabled())
{
fx.quality = QUALITY_BILINEAR;
+3
View File
@@ -42,6 +42,7 @@ private:
bool motionBlurEnabled;
bool sssEnabled;
bool depthOfFieldEnabled;
bool stereogramEnabled;
protected:
wiRenderTarget
@@ -105,6 +106,7 @@ public:
inline bool getMotionBlurEnabled(){ return motionBlurEnabled; }
inline bool getSSSEnabled(){ return sssEnabled; }
inline bool getDepthOfFieldEnabled(){ return depthOfFieldEnabled; }
inline bool getStereogramEnabled() { return stereogramEnabled; }
inline unsigned int getThreadingCount(){ return (unsigned int)workerThreads.size(); }
@@ -139,6 +141,7 @@ public:
inline void setMotionBlurEnabled(bool value){ motionBlurEnabled = value; }
inline void setSSSEnabled(bool value){ sssEnabled = value; }
inline void setDepthOfFieldEnabled(bool value){ depthOfFieldEnabled = value; }
inline void setStereogramEnabled(bool value) { stereogramEnabled = value; }
virtual void setPreferredThreadingCount(unsigned short value);
@@ -47,6 +47,7 @@ Luna<Renderable3DComponent_BindLua>::FunctionType Renderable3DComponent_BindLua:
lunamethod(Renderable3DComponent_BindLua, SetMotionBlurEnabled),
lunamethod(Renderable3DComponent_BindLua, SetSSSEnabled),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldEnabled),
lunamethod(Renderable3DComponent_BindLua, SetStereogramEnabled),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldFocus),
lunamethod(Renderable3DComponent_BindLua, SetDepthOfFieldStrength),
@@ -283,6 +284,21 @@ int Renderable3DComponent_BindLua::SetDepthOfFieldEnabled(lua_State* L)
wiLua::SError(L, "SetDepthOfFieldEnabled(bool value) not enough arguments!");
return 0;
}
int Renderable3DComponent_BindLua::SetStereogramEnabled(lua_State* L)
{
if (component == nullptr)
{
wiLua::SError(L, "SetStereogramEnabled(bool value) component is null!");
return 0;
}
if (wiLua::SGetArgCount(L) > 0)
{
((Renderable3DComponent*)component)->setStereogramEnabled(wiLua::SGetBool(L, 1));
}
else
wiLua::SError(L, "SetStereogramEnabled(bool value) not enough arguments!");
return 0;
}
int Renderable3DComponent_BindLua::SetDepthOfFieldFocus(lua_State* L)
@@ -31,6 +31,7 @@ public:
int SetMotionBlurEnabled(lua_State* L);
int SetSSSEnabled(lua_State* L);
int SetDepthOfFieldEnabled(lua_State* L);
int SetStereogramEnabled(lua_State* L);
int SetDepthOfFieldFocus(lua_State* L);
int SetDepthOfFieldStrength(lua_State* L);
+14
View File
@@ -2249,6 +2249,20 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">
</ExcludedFromBuild>
</FxCompile>
<FxCompile Include="stereogramPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">Pixel</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">4.1</ShaderModel>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">4.1</ShaderModel>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release_RT|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">shaders/%(Filename).cso</ObjectFileOutput>
</FxCompile>
<FxCompile Include="sunPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='WinRT|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
@@ -2178,6 +2178,9 @@
<FxCompile Include="waterVS.hlsl">
<Filter>shaders\object</Filter>
</FxCompile>
<FxCompile Include="stereogramPS.hlsl">
<Filter>shaders\image</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<Image Include="fonts\basic.dds">
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef _SHADERDEF_CONSTANTBUFFERS_
#define _SHADERDEF_CONSTANTBUFFERS_
#ifndef _SHADER_GLOBALS_
#define _SHADER_GLOBALS_
#include "ConstantBufferMapping.h"
#include "SamplerMapping.h"
#include "TextureMapping.h"
@@ -120,4 +120,4 @@ CBUFFER(APICB, CBSLOT_API)
#define ALPHATEST(x) clip((x)-0.1);
#endif // _SHADERDEF_CONSTANTBUFFERS_
#endif // _SHADER_GLOBALS_
+32
View File
@@ -0,0 +1,32 @@
#include "postProcessHF.hlsli"
static const float pWid = 100;
static const float pHei = 100;
#define fragCoord PSIn.pos.xy
float4 main(VertexToPixelPostProcess PSIn) : SV_TARGET
{
float maxStep = 32.;
float d = 0.;
float2 uv = fragCoord.xy;
for (int count = 0; count < 100; count++) {
if (uv.x < pWid)
break;
float d = 1.0 - texture_lineardepth.SampleLevel(sampler_linear_clamp, uv / g_xWorld_ScreenWidthHeight.xy, 0).r / g_xCamera_ZFarP;
uv.x -= pWid - (d * maxStep);
}
float x = (uv.x % pWid) / pWid;
float y = (uv.y % pHei) / pHei;
float3 rgb = xTexture.SampleLevel(sampler_linear_wrap, float2(x, y), 0).yxz;
float4 fragColor = float4(rgb, 1.0);
return fragColor;
}
+11 -31
View File
@@ -14,7 +14,7 @@ BufferResource wiImage::constantBuffer,wiImage::processCb;
VertexShader wiImage::vertexShader,wiImage::screenVS;
PixelShader wiImage::pixelShader,wiImage::blurHPS,wiImage::blurVPS,wiImage::shaftPS,wiImage::outlinePS
,wiImage::dofPS,wiImage::motionBlurPS,wiImage::bloomSeparatePS,wiImage::fxaaPS,wiImage::ssaoPS,wiImage::deferredPS
,wiImage::ssssPS,wiImage::linDepthPS,wiImage::colorGradePS,wiImage::ssrPS, wiImage::screenPS;
,wiImage::ssssPS,wiImage::linDepthPS,wiImage::colorGradePS,wiImage::ssrPS, wiImage::screenPS, wiImage::stereogramPS;
RasterizerState wiImage::rasterizerState;
@@ -49,7 +49,6 @@ void wiImage::LoadBuffers()
void wiImage::LoadShaders()
{
vertexShader = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "imageVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
screenVS = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "screenVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
@@ -69,6 +68,8 @@ void wiImage::LoadShaders()
deferredPS = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "deferredPS.cso", wiResourceManager::PIXELSHADER));
ssrPS = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "ssr.cso", wiResourceManager::PIXELSHADER));
screenPS = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "screenPS.cso", wiResourceManager::PIXELSHADER));
stereogramPS = static_cast<PixelShader>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "stereogramPS.cso", wiResourceManager::PIXELSHADER));
}
void wiImage::SetUpStates()
{
@@ -276,7 +277,6 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont
XMMatrixScaling(effects.scale.x,effects.scale.y,1)
*XMMatrixRotationZ(effects.rotation)
*faceRot
//*XMMatrixInverse(0,XMMatrixLookAtLH(XMVectorSet(0,0,0,0),XMLoadFloat3(&effects.pos)-wiRenderer::getCamera()->Eye,XMVectorSet(0,1,0,0)))
*XMMatrixTranslation(effects.pos.x,effects.pos.y,effects.pos.z)
);
(*cb).mDimensions = XMFLOAT4(0,0,effects.siz.x,effects.siz.y);
@@ -312,28 +312,29 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont
fullScreenEffect = true;
if(effects.process.outline)
wiRenderer::BindPS(outlinePS,context);
wiRenderer::BindPS(outlinePS,context);
else if(effects.process.motionBlur)
wiRenderer::BindPS(motionBlurPS,context);
else if(effects.process.dofStrength)
wiRenderer::BindPS(dofPS,context);
else if(effects.process.fxaa)
wiRenderer::BindPS(fxaaPS,context);
else if(effects.process.ssao) {
else if(effects.process.ssao)
wiRenderer::BindPS(ssaoPS,context);
}
else if(effects.process.linDepth)
wiRenderer::BindPS(linDepthPS, context);
else if (effects.process.colorGrade)
wiRenderer::BindPS(colorGradePS, context);
else if (effects.process.ssr){
else if (effects.process.ssr)
wiRenderer::BindPS(ssrPS, context);
}
else if (effects.process.stereogram)
wiRenderer::BindPS(stereogramPS, context);
else if(effects.process.ssss.x + effects.process.ssss.y > 0)
wiRenderer::BindPS(ssssPS,context);
else if(effects.bloom.separate)
wiRenderer::BindPS(bloomSeparatePS,context);
else wiHelper::messageBox("Postprocess branch not implemented!");
else
wiHelper::messageBox("Postprocess branch not implemented!");
(*prcb).params0[0] = effects.process.motionBlur;
(*prcb).params0[1] = effects.process.outline;
@@ -361,28 +362,6 @@ void wiImage::Draw(TextureView texture, const wiImageEffects& effects,DeviceCont
wiRenderer::UpdateBuffer(processCb,prcb,context);
}
//int normalmapmode=0;
//if(effects.normalMap && effects.refractionMap)
// normalmapmode=1;
//if(effects.extractNormalMap==true)
// normalmapmode=2;
//(*prcb).params[0] = (effects.maskMap ? 1.f : 0.f);
//(*prcb).params[1] = effects.fade;
//(*prcb).params[2] = effects.opacity;
//(*prcb).params[3] = (float)normalmapmode;
//(*prcb).params[4] = (float)wiRenderer::GetScreenWidth();
//(*prcb).params[5] = (float)wiRenderer::GetScreenHeight();
//(*prcb).params[6] = effects.siz.x;
//(*prcb).params[7] = effects.siz.y;
//wiRenderer::UpdateBuffer(processCb,prcb,context);
//wiRenderer::BindTexturePS(effects.depthMap,0,context);
//wiRenderer::BindTexturePS(effects.normalMap,1,context);
//wiRenderer::BindTexturePS(effects.velocityMap,3,context);
//wiRenderer::BindTexturePS(effects.refractionMap,4,context);
wiRenderer::BindTexturePS(effects.maskMap, TEXSLOT_ONDEMAND1, context);
wiRenderer::BindTexturePS(effects.distortionMap, TEXSLOT_ONDEMAND2, context);
wiRenderer::BindTexturePS(effects.refractionSource, TEXSLOT_ONDEMAND3, context);
@@ -497,6 +476,7 @@ void wiImage::CleanUp()
wiRenderer::SafeRelease(colorGradePS);
wiRenderer::SafeRelease(ssrPS);
wiRenderer::SafeRelease(screenPS);
wiRenderer::SafeRelease(stereogramPS);
if(constantBuffer) constantBuffer->Release();
if(processCb) processCb->Release();
+1 -1
View File
@@ -48,7 +48,7 @@ protected:
static VertexShader vertexShader,screenVS;
static PixelShader pixelShader,blurHPS,blurVPS,shaftPS,outlinePS,dofPS,motionBlurPS,bloomSeparatePS
,fxaaPS,ssaoPS,ssssPS,deferredPS,linDepthPS,colorGradePS,ssrPS, screenPS;
,fxaaPS,ssaoPS,ssssPS,deferredPS,linDepthPS,colorGradePS,ssrPS, screenPS, stereogramPS;
+3 -1
View File
@@ -76,8 +76,9 @@ public:
bool ssr;
bool linDepth;
bool colorGrade;
bool stereogram;
void clear() { active = motionBlur = outline = fxaa = ssao = linDepth = colorGrade = ssr = false; dofStrength = 0; ssss = XMFLOAT2(0, 0); }
void clear() { active = motionBlur = outline = fxaa = ssao = linDepth = colorGrade = ssr = stereogram = false; dofStrength = 0; ssss = XMFLOAT2(0, 0); }
void setDOF(float value) { dofStrength = value; active = value > FLT_EPSILON; }
void setMotionBlur(bool value) { motionBlur = value; active = value; }
void setOutline(bool value) { outline = value; active = value; }
@@ -88,6 +89,7 @@ public:
//direction*Properties
void setSSSS(const XMFLOAT2& value) { ssss = value; active = value.x || value.y; }
void setSSR(bool value) { ssr = value; active = value; }
void setStereogram(bool value) { stereogram = value; active = value; }
Processing() { clear(); }
};
Processing process;
+6 -3
View File
@@ -1939,7 +1939,8 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int
(*lcb).mBiasResSoftshadow=XMFLOAT4(l->shadowBias,(float)SHADOWMAPRES,(float)SOFTSHADOW,0);
for (unsigned int shmap = 0; shmap < l->shadowMaps_dirLight.size(); ++shmap){
(*lcb).mShM[shmap]=l->shadowCam[shmap].getVP();
BindTexturePS(l->shadowMaps_dirLight[shmap].depth->shaderResource,TEXSLOT_SHADOW0+shmap,context);
if(l->shadowMaps_dirLight[shmap].depth)
BindTexturePS(l->shadowMaps_dirLight[shmap].depth->shaderResource,TEXSLOT_SHADOW0+shmap,context);
}
UpdateBuffer(constantBuffers[CBTYPE_DIRLIGHT],lcb,context);
@@ -1956,7 +1957,8 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int
if (l->shadow && l->shadowMap_index>=0)
{
(*lcb).enerdis.w = 1.f;
BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW_CUBE, context);
if(Light::shadowMaps_pointLight[l->shadowMap_index].depth)
BindTexturePS(Light::shadowMaps_pointLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW_CUBE, context);
}
UpdateBuffer(constantBuffers[CBTYPE_POINTLIGHT], lcb, context);
@@ -1986,7 +1988,8 @@ void wiRenderer::DrawLights(Camera* camera, DeviceContext context, unsigned int
if (l->shadow && l->shadowMap_index>=0)
{
(*lcb).mShM = l->shadowCam[0].getVP();
BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW0, context);
if(Light::shadowMaps_spotLight[l->shadowMap_index].depth)
BindTexturePS(Light::shadowMaps_spotLight[l->shadowMap_index].depth->shaderResource, TEXSLOT_SHADOW0, context);
}
UpdateBuffer(constantBuffers[CBTYPE_SPOTLIGHT], lcb, context);
+2 -2
View File
@@ -5,9 +5,9 @@ namespace wiVersion
// major features
const int major = 0;
// minor features, major bug fixes
const int minor = 6;
const int minor = 7;
// minor bug fixes, alterations, refactors
const int revision = 8;
const int revision = 0;
long GetVersion()