Commit a32b4517 authored by D-AIRY's avatar D-AIRY

Reversed depth buffer

parent 754b0bd5
......@@ -16,7 +16,7 @@ VSO_SceneCommon main(VSI_Geometry IN)
// OUT.vPosition = mul(half4(IN.vPosition, 1.f), g_mWVP);
OUT.vPosition = mul(float4(IN.vPosition, 1.f), g_mW);
OUT.vPosition = mul(OUT.vPosition, g_mVP);
OUT.vNormal = mul(IN.vNormal,g_mW);
OUT.vNormal = mul(IN.vNormal, g_mW);
OUT.vTexUV = IN.vTexUV;
OUT.vPos = OUT.vPosition;
......
......@@ -95,6 +95,7 @@ PSO_Lbuffer main(VSO_ResPos IN)
#ifdef IS_SHADOWED
half fShadow = /* saturate( */g_txShadow.Sample(g_sPointClamp, IN.vTexUV).r/* ) */;
// half fShadow = 0.5f;
// clip(fShadow - 0.001);
......@@ -110,6 +111,13 @@ PSO_Lbuffer main(VSO_ResPos IN)
#endif
half4 vPosition = half4(g_vViewPos.xyz + IN.vWorldRay * fDepth, 1.0);
// // OUT.vAmdient.xyz = frac(vPosition.xyz);
// OUT.vAmdient.xyz = vPosition.xyz;
// OUT.vAmdient.w = 0;
// OUT.vSpecular = 0;
// return OUT;
half fDistance = distance(vPosition.xyz, g_vLightPosShadow.xyz);
half fInvDistance = 1.f - (fDistance/g_vLightColorPower.w);
......
......@@ -16,6 +16,10 @@ PSO_Gbuffer main(PSI_XMaterial IN)
// ClipFar(IN.vPos.z, g_vNearFarLayers.y);
IN.vNormal = normalize(IN.vNormal);
#ifndef WANT_WRITE_DEPTH
float fDepth = 1.0f - (IN.vPos.z / g_vNearFarInvWinSize.x);
#endif
XMaterial mtrl = XMATERIAL_MAIN(IN);
PSO_Gbuffer OUT;
......@@ -33,15 +37,18 @@ PSO_Gbuffer main(PSI_XMaterial IN)
mtrl.fAO
);
float fDepth = (
//float fDepth =
#ifdef WANT_WRITE_DEPTH
mtrl.fDepth
float fDepth = (mtrl.fDepth + g_vNearFarInvWinSize.x) / g_vNearFarInvWinSize.y;
#else
IN.vPos.z
// 1.0f - IN.vPos.z / g_vNearFarInvWinSize.x;
//(IN.vPos.z / IN.vPos.w);
// 1.0f / (1.0 - IN.vPos.z)
// (g_vNearFarInvWinSize.y - g_vNearFarInvWinSize.x - IN.vPos.z)
#endif
+ g_vNearFarInvWinSize.x) / g_vNearFarInvWinSize.y;
// + g_vNearFarInvWinSize.x) / g_vNearFarInvWinSize.y;
OUT.vDepth = float4(fDepth, fDepth, fDepth, 1.0f);
// OUT.vDepth = float4(((g_vNearFarInvWinSize.y - g_vNearFarInvWinSize.x) - IN.vPos.z) * 0.01, fDepth, fDepth, 1.0f);
return(OUT);
}
......@@ -33,7 +33,8 @@ void ClipFar(float fZ, float fFar)
//! просчет цвета линейной глубины [0,1] на основании текущей позиции и плоскостей отсечения!
float ComDepthByPos(float4 vPositionWVP, float2 vNearFar)
{
return ((vPositionWVP.z + vNearFar.x)/vNearFar.y);
// return ((vPositionWVP.z + vNearFar.x)/vNearFar.y);
return (1.0f - vPositionWVP.z/vNearFar.x);
}
//! аналогично #ComDepthByPos, только возвращает вектор
......
/*
mtrltp_base.ps
Рендер прозрачной геометрии
*/
#include "../struct.h"
#include "../mtrl.h"
//##########################################################################
SamplerState g_sScene: register(s0);
Texture2D g_txColor: register(t0); // basetexture
Texture2D g_txParameters: register(t10); // basetexture
//##########################################################################
// half4 g_vNearFarLayers;
#include "../const.h"
cbuffer CDataClipPlanes: register(b6)
{
float4 g_vClipPlanes[4];
};
//##########################################################################
float4 main(VSO_SceneCommon IN):COLOR0
{
// ClipFar(IN.vPos.z, g_vNearFarLayers.y);
// IN.vNormal = normalize(IN.vNormal);
float3 vPos = IN.vPos.xyz / IN.vPos.w;
[unroll]for(uint i = 0; i < 4; ++i)
{
float4 vPlane = g_vClipPlanes[i];
clip(dot(vPlane.xyz, vPos) + vPlane.w);
}
return(g_txColor.Sample(g_sScene, IN.vTexUV));
/* return(CreateGbuffer(
float4(g_txColor.Sample(g_sScene, IN.vTexUV).xyz, 0.0f),
IN.vNormal,
g_txParameters.Sample(g_sScene, IN.vTexUV),
IN.vPos,
g_vNearFarLayers
)); */
}
/*
mtrltp_refract.ps
Рендер прозрачной геометрии с рефракцией
*/
#include "../struct.h"
#include "../mtrl.h"
//##########################################################################
SamplerState g_sScene: register(s0);
SamplerState g_sSceneRefract: register(s1);
Texture2D g_txColor: register(t0); // basetexture
Texture2D g_txDuDv: register(t2); // detail_r
Texture2D g_txParameters: register(t10); //
Texture2D g_txSceneColor: register(t11); //
Texture2D g_txSceneDepth: register(t12); //
//##########################################################################
// half4 g_vNearFarLayers;
#include "../const.h"
cbuffer CDataClipPlanes: register(b6)
{
float4 g_vClipPlanes[4];
};
//##########################################################################
float4 main(VSO_SceneCommon IN):COLOR0
{
// ClipFar(IN.vPos.z, g_vNearFarLayers.y);
// IN.vNormal = normalize(IN.vNormal);
float3 vPos = IN.vPos.xyz / IN.vPos.w;
[unroll]for(uint i = 0; i < 4; ++i)
{
float4 vPlane = g_vClipPlanes[i];
clip(dot(vPlane.xyz, vPos) + vPlane.w);
}
float2 vDuDv = g_txDuDv.Sample(g_sScene, IN.vTexUV).xy;
float2 vSceneUV = (vPos.xy * float2(1.0, -1.0) + g_vNearFarInvWinSize.zw * 0.5) * 0.5 + 0.5;
float2 vSceneUVrefract = vSceneUV + (vDuDv - 0.5) * 0.3; // 0.035
float3 vSceneColor;
if(g_txSceneDepth.Sample(g_sSceneRefract, vSceneUVrefract).x < ComDepthByPos(IN.vPos, g_vNearFarLayers.xy))
{
vSceneColor = g_txSceneColor.Sample(g_sSceneRefract, vSceneUV).xyz;
// clip(-1);
}
else
{
// clip(-1);
vSceneColor = g_txSceneColor.Sample(g_sSceneRefract, vSceneUVrefract).xyz;
// return(float4(ComDepthByPos(IN.vPos, g_vNearFarLayers.xy), 0, 0, 1));
// return(float4(g_txSceneDepth.Sample(g_sSceneRefract, vSceneUVrefract).x, 0, 0, 1));
}
// float3 vSceneColor = g_txSceneColor.Sample(g_sSceneRefract, vSceneUVrefract).xyz;
float4 vColor = g_txColor.Sample(g_sScene, IN.vTexUV);
// return(float4(float3(), 1.0));
return(float4(float3(vSceneColor * (1.0 - vColor.w) + vColor.xyz * vColor.w), 1.0));
/* return(CreateGbuffer(
float4(g_txColor.Sample(g_sScene, IN.vTexUV).xyz, 0.0f),
IN.vNormal,
g_txParameters.Sample(g_sScene, IN.vTexUV),
IN.vPos,
g_vNearFarLayers
)); */
}
......@@ -11,6 +11,8 @@ namespace gdata
extern ICamera *pCamera;
};
//! При изменении базовых шейдеров отредактировать https://wiki.skyxengine.com/index.php?title=Стандартные_шейдеры_материалов
CRenderPipeline::CRenderPipeline(IGXDevice *pDevice):
m_pDevice(pDevice)
{
......@@ -381,6 +383,8 @@ CRenderPipeline::CRenderPipeline(IGXDevice *pDevice):
GXDepthStencilDesc dsDesc;
dsDesc.cmpFuncDepth = GXCMP_GREATER_EQUAL;
m_pDepthStencilStateDefault = m_pDevice->createDepthStencilState(&dsDesc);
dsDesc.useDepthWrite = FALSE;
m_pDepthStencilStateNoZWrite = m_pDevice->createDepthStencilState(&dsDesc);
......@@ -710,7 +714,7 @@ void CRenderPipeline::renderGBuffer()
m_pMaterialSystem->bindRenderPass(m_pRenderPassGBuffer);
pCtx->setRasterizerState(NULL);
pCtx->setDepthStencilState(NULL);
pCtx->setDepthStencilState(m_pDepthStencilStateDefault);
pCtx->setBlendState(NULL);
rfunc::SetRenderSceneFilter();
......@@ -736,7 +740,7 @@ void CRenderPipeline::renderGBuffer()
pCtx->setColorTarget(NULL, 1);
pCtx->setColorTarget(pColorSurf);
pCtx->clear(GX_CLEAR_COLOR | GX_CLEAR_DEPTH | GX_CLEAR_STENCIL, RENDER_DEFAUL_BACKGROUND_COLOR);
pCtx->clear(GX_CLEAR_COLOR | GX_CLEAR_DEPTH | GX_CLEAR_STENCIL, RENDER_DEFAUL_BACKGROUND_COLOR, 0.0f);
pCtx->setColorTarget(pNormalSurf, 1);
pCtx->setColorTarget(pParamSurf, 2);
......@@ -1164,8 +1168,14 @@ void CRenderPipeline::renderTransparent()
IGXContext *pCtx = m_pDevice->getThreadContext();
//pCtx->setPSConstant(m_pSceneShaderDataPS, SCR_SCENE);
pCtx->setVSConstant(m_pCameraShaderDataVS, SCR_CAMERA);
rfunc::SetRenderSceneFilter();
m_pMaterialSystem->bindRenderPass(m_pRenderPassTransparency);
// pCtx->setRasterizerState(NULL);
pCtx->setDepthStencilState(m_pDepthStencilStateNoZWrite);
pCtx->setBlendState(m_pBlendStateAlpha);
pCtx->setSamplerState(m_pRefractionScene, 1);
......
......@@ -95,6 +95,7 @@ protected:
//! Буфер тени
IGXTexture2D *m_pShadow = NULL;
IGXDepthStencilState *m_pDepthStencilStateDefault = NULL;
IGXDepthStencilState *m_pDepthStencilStateNoZWrite = NULL;
IGXDepthStencilState *m_pDepthStencilStateNoZ = NULL;
IGXBlendState *m_pBlendStateAlpha = NULL;
......
......@@ -105,6 +105,8 @@ UINT CShadowCache::processNextBunch()
Core_RMatrixGet(G_RI_MATRIX_VIEW, &mOldView);
Core_RMatrixGet(G_RI_MATRIX_PROJECTION, &mOldProj);
m_pRenderPipeline->getDevice()->getThreadContext()->setDepthStencilState(NULL);
bool isSomeFound = false;
if(m_isFirstBunch)
{
......
......@@ -139,13 +139,14 @@ void gdata::InitAllMatrix()
gdata::vNearFar.y = *r_far;
gdata::fProjFov = *r_default_fov;
gdata::mCamProj = SMMatrixPerspectiveFovLH(gdata::fProjFov, vWinSize.x / vWinSize.y, gdata::vNearFar.x, gdata::vNearFar.y);
// gdata::mCamProj = SMMatrixPerspectiveFovLH(gdata::fProjFov, vWinSize.x / vWinSize.y, gdata::vNearFar.x, gdata::vNearFar.y);
gdata::mCamProj = SMMatrixPerspectiveFovLH(gdata::fProjFov, vWinSize.x / vWinSize.y, gdata::vNearFar.y, gdata::vNearFar.x);
//gdata::MCamProj = SMMatrixOrthographicLH(vWinSize.x / 4, vWinSize.y / 4, gdata::NearFar.x, gdata::NearFar.y);
gdata::mLightProj = SMMatrixPerspectiveFovLH(gdata::fProjFov, vWinSize.x / vWinSize.y, gdata::vNearFar.x, G_DATA_LIGHT_FAR);
// gdata::mLightProj = SMMatrixPerspectiveFovLH(gdata::fProjFov, vWinSize.x / vWinSize.y, gdata::vNearFar.x, G_DATA_LIGHT_FAR);
//gdata::MLightProj = SMMatrixOrthographicLH(vWinSize.x / 4, vWinSize.y / 4, gdata::NearFar.x, G_DATA_LIGHT_FAR);
gdata::mRefPlaneSkyProj = SMMatrixPerspectiveFovLH(gdata::fProjFov, vWinSize.x / vWinSize.y, gdata::vNearFar.x, G_DATA_LIGHT_FAR);
gdata::mRefCubeSkyProj = SMMatrixPerspectiveFovLH(SM_PI * 0.5f, 1, gdata::vNearFar.x, G_DATA_LIGHT_FAR);
// gdata::mRefPlaneSkyProj = SMMatrixPerspectiveFovLH(gdata::fProjFov, vWinSize.x / vWinSize.y, gdata::vNearFar.x, G_DATA_LIGHT_FAR);
// gdata::mRefCubeSkyProj = SMMatrixPerspectiveFovLH(SM_PI * 0.5f, 1, gdata::vNearFar.x, G_DATA_LIGHT_FAR);
Core_RMatrixSet(G_RI_MATRIX_OBSERVER_PROJ, &gdata::mCamProj);
Core_RMatrixSet(G_RI_MATRIX_LIGHT_PROJ, &gdata::mLightProj);
......@@ -204,7 +205,7 @@ void gdata::shaders_id::InitAllShaders()
gdata::rstates::pDepthStencilStateMrtStage0 = gdata::pDXDevice->createDepthStencilState(&dsDesc);
dsDesc.useDepthTest = TRUE;
dsDesc.cmpFuncDepth = GXCMP_LESS_EQUAL;
dsDesc.cmpFuncDepth = GXCMP_GREATER_EQUAL;
dsDesc.stencilTestFront.cmpFunc = GXCMP_NOT_EQUAL;
dsDesc.stencilTestFront.opPass = GXSTENCIL_OP_DECR;
gdata::rstates::pDepthStencilStateMrtStage1 = gdata::pDXDevice->createDepthStencilState(&dsDesc);
......
......@@ -54,13 +54,13 @@ void rfunc::SetRenderSceneFilter()
switch(r_texfilter_type2)
{
case 1:
samplerDesc.filter = GXFILTER_MIN_MAG_MIP_POINT;
samplerDesc.filter = GXFILTER_MIN_MAG_MIP_LINEAR;
break;
case 2:
samplerDesc.filter = GXFILTER_ANISOTROPIC;
break;
default:
samplerDesc.filter = GXFILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.filter = GXFILTER_MIN_MAG_MIP_POINT;
break;
}
samplerDesc.fMinLOD = (float)r_texfilter_max_miplevel2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment