@@ -13,6 +13,7 @@
|
|||||||
"Configuration": {
|
"Configuration": {
|
||||||
"UseCSharp": true,
|
"UseCSharp": true,
|
||||||
"UseLargeWorlds": false,
|
"UseLargeWorlds": false,
|
||||||
|
"UseReverseZ": true,
|
||||||
"UseDotNet": true,
|
"UseDotNet": true,
|
||||||
"Windows": {
|
"Windows": {
|
||||||
"UseSDL": false,
|
"UseSDL": false,
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ namespace FlaxEditor.Gizmo
|
|||||||
_material.SetParameterValue("OutlineColor0", _color0);
|
_material.SetParameterValue("OutlineColor0", _color0);
|
||||||
_material.SetParameterValue("OutlineColor1", _color1);
|
_material.SetParameterValue("OutlineColor1", _color1);
|
||||||
_material.SetParameterValue("CustomDepth", customDepth);
|
_material.SetParameterValue("CustomDepth", customDepth);
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
_material.SetParameterValue("ViewInfo", new Float4(1.0f / projection.M11, 1.0f / projection.M22, -near / (far - near), (far * near) / (far - near) / far));
|
_material.SetParameterValue("ViewInfo", new Float4(1.0f / projection.M11, 1.0f / projection.M22, -near / (far - near), (far * near) / (far - near) / far));
|
||||||
#else
|
#else
|
||||||
_material.SetParameterValue("ViewInfo", new Float4(1.0f / projection.M11, 1.0f / projection.M22, far / (far - near), -(far * near) / (far - near) / far));
|
_material.SetParameterValue("ViewInfo", new Float4(1.0f / projection.M11, 1.0f / projection.M22, far / (far - near), -(far * near) / (far - near) / far));
|
||||||
|
|||||||
@@ -1498,7 +1498,7 @@ namespace FlaxEditor.Viewport
|
|||||||
ivp.Invert();
|
ivp.Invert();
|
||||||
|
|
||||||
// Create near and far points, with device depth of 1 and 0 respectively
|
// Create near and far points, with device depth of 1 and 0 respectively
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
var nearPoint = new Vector3(mousePosition, 1.0f);
|
var nearPoint = new Vector3(mousePosition, 1.0f);
|
||||||
var farPoint = new Vector3(mousePosition, 0.0f);
|
var farPoint = new Vector3(mousePosition, 0.0f);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void BoundingFrustum::SetMatrix(const Matrix& matrix)
|
|||||||
_pFar.D = matrix.M44 - matrix.M43;
|
_pFar.D = matrix.M44 - matrix.M43;
|
||||||
_pFar.Normalize();
|
_pFar.Normalize();
|
||||||
|
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
// Swap far and near planes if reverse z
|
// Swap far and near planes if reverse z
|
||||||
Swap(_pFar, _pNear);
|
Swap(_pFar, _pNear);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ namespace FlaxEngine
|
|||||||
far.D = matrix.M44 - matrix.M43;
|
far.D = matrix.M44 - matrix.M43;
|
||||||
far.Normalize();
|
far.Normalize();
|
||||||
|
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
// Swap far and near planes if reverse z
|
// Swap far and near planes if reverse z
|
||||||
(near, far) = (far, near);
|
(near, far) = (far, near);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ void Matrix::OrthoOffCenter(float left, float right, float bottom, float top, fl
|
|||||||
result.M22 = 2.0f / (top - bottom);
|
result.M22 = 2.0f / (top - bottom);
|
||||||
result.M41 = (left + right) / (left - right);
|
result.M41 = (left + right) / (left - right);
|
||||||
result.M42 = (top + bottom) / (bottom - top);
|
result.M42 = (top + bottom) / (bottom - top);
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
result.M33 = -zRange;
|
result.M33 = -zRange;
|
||||||
result.M43 = zFar * zRange;
|
result.M43 = zFar * zRange;
|
||||||
#else
|
#else
|
||||||
@@ -554,7 +554,7 @@ void Matrix::PerspectiveOffCenter(float left, float right, float bottom, float t
|
|||||||
result.M31 = (left + right) / (left - right);
|
result.M31 = (left + right) / (left - right);
|
||||||
result.M32 = (top + bottom) / (bottom - top);
|
result.M32 = (top + bottom) / (bottom - top);
|
||||||
result.M34 = 1.0f;
|
result.M34 = 1.0f;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
result.M33 = -zNear * zRange;
|
result.M33 = -zNear * zRange;
|
||||||
result.M43 = zFar * zNear * zRange;
|
result.M43 = zFar * zNear * zRange;
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -2178,7 +2178,7 @@ namespace FlaxEngine
|
|||||||
result.M22 = 2.0f / (top - bottom);
|
result.M22 = 2.0f / (top - bottom);
|
||||||
result.M41 = (left + right) / (left - right);
|
result.M41 = (left + right) / (left - right);
|
||||||
result.M42 = (top + bottom) / (bottom - top);
|
result.M42 = (top + bottom) / (bottom - top);
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
result.M33 = -zRange;
|
result.M33 = -zRange;
|
||||||
result.M43 = zfar * zRange;
|
result.M43 = zfar * zRange;
|
||||||
#else
|
#else
|
||||||
@@ -2249,7 +2249,7 @@ namespace FlaxEngine
|
|||||||
M11 = yScale / aspect,
|
M11 = yScale / aspect,
|
||||||
M22 = yScale,
|
M22 = yScale,
|
||||||
M34 = 1.0f,
|
M34 = 1.0f,
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
M33 = -znear * zRange,
|
M33 = -znear * zRange,
|
||||||
M43 = znear * zfar * zRange,
|
M43 = znear * zfar * zRange,
|
||||||
#else
|
#else
|
||||||
@@ -2293,7 +2293,7 @@ namespace FlaxEngine
|
|||||||
M31 = (left + right) / (left - right),
|
M31 = (left + right) / (left - right),
|
||||||
M32 = (top + bottom) / (bottom - top),
|
M32 = (top + bottom) / (bottom - top),
|
||||||
M34 = 1.0f,
|
M34 = 1.0f,
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
M33 = -znear * zRange,
|
M33 = -znear * zRange,
|
||||||
M43 = znear * zfar * zRange,
|
M43 = znear * zfar * zRange,
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#undef MemoryBarrier
|
#undef MemoryBarrier
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
#define GPU_DEPTH_MIN_VALUE 1.0f
|
#define GPU_DEPTH_MIN_VALUE 1.0f
|
||||||
#define GPU_DEPTH_MAX_VALUE 0.0f
|
#define GPU_DEPTH_MAX_VALUE 0.0f
|
||||||
#define GPU_DEPTH_BOUNDS_SWAP(min, max) max, min
|
#define GPU_DEPTH_BOUNDS_SWAP(min, max) max, min
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ GPUPipelineState::Description GPUPipelineState::Description::Default =
|
|||||||
true, // DepthWriteEnable
|
true, // DepthWriteEnable
|
||||||
true, // DepthClipEnable
|
true, // DepthClipEnable
|
||||||
false, // DepthBoundsEnable
|
false, // DepthBoundsEnable
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
ComparisonFunc::Greater, // DepthFunc
|
ComparisonFunc::Greater, // DepthFunc
|
||||||
#else
|
#else
|
||||||
ComparisonFunc::Less, // DepthFunc
|
ComparisonFunc::Less, // DepthFunc
|
||||||
@@ -189,7 +189,7 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultNoDepth =
|
|||||||
false, // DepthWriteEnable
|
false, // DepthWriteEnable
|
||||||
false, // DepthClipEnable
|
false, // DepthClipEnable
|
||||||
false, // DepthBoundsEnable
|
false, // DepthBoundsEnable
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
ComparisonFunc::Greater, // DepthFunc
|
ComparisonFunc::Greater, // DepthFunc
|
||||||
#else
|
#else
|
||||||
ComparisonFunc::Less, // DepthFunc
|
ComparisonFunc::Less, // DepthFunc
|
||||||
@@ -218,7 +218,7 @@ GPUPipelineState::Description GPUPipelineState::Description::DefaultFullscreenTr
|
|||||||
false, // DepthWriteEnable
|
false, // DepthWriteEnable
|
||||||
false, // DepthClipEnable
|
false, // DepthClipEnable
|
||||||
false, // DepthBoundsEnable
|
false, // DepthBoundsEnable
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
ComparisonFunc::Greater, // DepthFunc
|
ComparisonFunc::Greater, // DepthFunc
|
||||||
#else
|
#else
|
||||||
ComparisonFunc::Less, // DepthFunc
|
ComparisonFunc::Less, // DepthFunc
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ bool DeferredMaterialShader::Load()
|
|||||||
// Motion Vectors pass
|
// Motion Vectors pass
|
||||||
psDesc.DepthWriteEnable = false;
|
psDesc.DepthWriteEnable = false;
|
||||||
psDesc.DepthEnable = true;
|
psDesc.DepthEnable = true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::GreaterEqual;
|
psDesc.DepthFunc = ComparisonFunc::GreaterEqual;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::LessEqual;
|
psDesc.DepthFunc = ComparisonFunc::LessEqual;
|
||||||
@@ -204,7 +204,7 @@ bool DeferredMaterialShader::Load()
|
|||||||
psDesc.DepthClipEnable = false;
|
psDesc.DepthClipEnable = false;
|
||||||
psDesc.DepthWriteEnable = true;
|
psDesc.DepthWriteEnable = true;
|
||||||
psDesc.DepthEnable = true;
|
psDesc.DepthEnable = true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ bool DeformableMaterialShader::Load()
|
|||||||
psDesc.DepthClipEnable = false;
|
psDesc.DepthClipEnable = false;
|
||||||
psDesc.DepthWriteEnable = true;
|
psDesc.DepthWriteEnable = true;
|
||||||
psDesc.DepthEnable = true;
|
psDesc.DepthEnable = true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ bool ForwardMaterialShader::Load()
|
|||||||
psDesc.DepthClipEnable = false;
|
psDesc.DepthClipEnable = false;
|
||||||
psDesc.DepthWriteEnable = true;
|
psDesc.DepthWriteEnable = true;
|
||||||
psDesc.DepthEnable = true;
|
psDesc.DepthEnable = true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ bool TerrainMaterialShader::Load()
|
|||||||
psDesc.DepthClipEnable = false;
|
psDesc.DepthClipEnable = false;
|
||||||
psDesc.DepthWriteEnable = true;
|
psDesc.DepthWriteEnable = true;
|
||||||
psDesc.DepthEnable = true;
|
psDesc.DepthEnable = true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
|
|||||||
@@ -684,7 +684,7 @@ float RenderTools::TemporalHalton(int32 index, int32 base)
|
|||||||
|
|
||||||
Float2 RenderTools::GetDepthBounds(const RenderView& view, const Float3& nearPoint, const Float3& farPoint)
|
Float2 RenderTools::GetDepthBounds(const RenderView& view, const Float3& nearPoint, const Float3& farPoint)
|
||||||
{
|
{
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
Float3 viewNearPoint = Float3::Transform(nearPoint, view.View);
|
Float3 viewNearPoint = Float3::Transform(nearPoint, view.View);
|
||||||
Float3 viewFarPoint = Float3::Transform(farPoint, view.View);
|
Float3 viewFarPoint = Float3::Transform(farPoint, view.View);
|
||||||
|
|
||||||
@@ -727,7 +727,7 @@ Float2 RenderTools::GetDepthBounds(const RenderView& view, const BoundingSphere&
|
|||||||
|
|
||||||
Float2 RenderTools::GetDepthBounds(const RenderView& view, const Span<Float3>& points)
|
Float2 RenderTools::GetDepthBounds(const RenderView& view, const Span<Float3>& points)
|
||||||
{
|
{
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
// Find min and max view depth range for list of points
|
// Find min and max view depth range for list of points
|
||||||
float nearDepth = view.Far, farDepth = view.Near;
|
float nearDepth = view.Far, farDepth = view.Near;
|
||||||
for (int32 i = 0; i < points.Length(); i++)
|
for (int32 i = 0; i < points.Length(); i++)
|
||||||
@@ -781,7 +781,7 @@ Float2 RenderTools::GetDepthBounds(const RenderView& view, const OrientedBoundin
|
|||||||
|
|
||||||
float RenderTools::GetDepthBounds(const RenderView& view, const Float3& point, bool near)
|
float RenderTools::GetDepthBounds(const RenderView& view, const Float3& point, bool near)
|
||||||
{
|
{
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
Float3 viewPoint = Float3::Transform(point, view.View);
|
Float3 viewPoint = Float3::Transform(point, view.View);
|
||||||
viewPoint.Z = Math::Clamp(viewPoint.Z, view.Near, view.Far);
|
viewPoint.Z = Math::Clamp(viewPoint.Z, view.Near, view.Far);
|
||||||
|
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public:
|
|||||||
static float GetDepthBounds(const RenderView& view, const Float3& point, bool near);
|
static float GetDepthBounds(const RenderView& view, const Float3& point, bool near);
|
||||||
static float GetDepthBounds(const RenderView& view, float viewDistance, bool near);
|
static float GetDepthBounds(const RenderView& view, float viewDistance, bool near);
|
||||||
// Skip background/sky pixels from shading
|
// Skip background/sky pixels from shading
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
static constexpr float DepthBoundMaxBackground = 0.0000001f;
|
static constexpr float DepthBoundMaxBackground = 0.0000001f;
|
||||||
#else
|
#else
|
||||||
static constexpr float DepthBoundMaxBackground = 1.0f - 0.0000001f;
|
static constexpr float DepthBoundMaxBackground = 1.0f - 0.0000001f;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void RenderView::Prepare(RenderContext& renderContext)
|
|||||||
void RenderView::PrepareCache(const RenderContext& renderContext, float width, float height, const Float2& temporalAAJitter, const RenderView* mainView)
|
void RenderView::PrepareCache(const RenderContext& renderContext, float width, float height, const Float2& temporalAAJitter, const RenderView* mainView)
|
||||||
{
|
{
|
||||||
// The same format used by the Flax common shaders and postFx materials
|
// The same format used by the Flax common shaders and postFx materials
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
ViewInfo = Float4(1.0f / Projection.M11, 1.0f / Projection.M22, -Near / (Far - Near), (Far * Near) / (Far - Near) / Far);
|
ViewInfo = Float4(1.0f / Projection.M11, 1.0f / Projection.M22, -Near / (Far - Near), (Far * Near) / (Far - Near) / Far);
|
||||||
#else
|
#else
|
||||||
ViewInfo = Float4(1.0f / Projection.M11, 1.0f / Projection.M22, Far / (Far - Near), -(Far * Near) / (Far - Near) / Far);
|
ViewInfo = Float4(1.0f / Projection.M11, 1.0f / Projection.M22, Far / (Far - Near), -(Far * Near) / (Far - Near) / Far);
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ void Sky::Draw(RenderContext& renderContext)
|
|||||||
psDesc.CullMode = CullMode::Inverted;
|
psDesc.CullMode = CullMode::Inverted;
|
||||||
psDesc.DepthWriteEnable = false;
|
psDesc.DepthWriteEnable = false;
|
||||||
psDesc.DepthClipEnable = false;
|
psDesc.DepthClipEnable = false;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::GreaterEqual;
|
psDesc.DepthFunc = ComparisonFunc::GreaterEqual;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::LessEqual;
|
psDesc.DepthFunc = ComparisonFunc::LessEqual;
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ void DepthOfFieldPass::Render(RenderContext& renderContext, GPUTexture*& frame,
|
|||||||
cbData.BokehTargetSize.Y = static_cast<float>(bokehTargetHeight);
|
cbData.BokehTargetSize.Y = static_cast<float>(bokehTargetHeight);
|
||||||
|
|
||||||
// TODO: use projection matrix instead of this far and near stuff?
|
// TODO: use projection matrix instead of this far and near stuff?
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
cbData.ProjectionAB.X = -nearPlane / (farPlane - nearPlane);
|
cbData.ProjectionAB.X = -nearPlane / (farPlane - nearPlane);
|
||||||
cbData.ProjectionAB.Y = (farPlane * nearPlane) / (farPlane - nearPlane);
|
cbData.ProjectionAB.Y = (farPlane * nearPlane) / (farPlane - nearPlane);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ bool LightPass::setupResources()
|
|||||||
psDesc.CullMode = CullMode::Normal;
|
psDesc.CullMode = CullMode::Normal;
|
||||||
if (_psLightLocal.Create(psDesc, shader, "PS_LocalLight"))
|
if (_psLightLocal.Create(psDesc, shader, "PS_LocalLight"))
|
||||||
return true;
|
return true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
@@ -111,7 +111,7 @@ bool LightPass::setupResources()
|
|||||||
psDesc.CullMode = CullMode::Normal;
|
psDesc.CullMode = CullMode::Normal;
|
||||||
if (_psLightSky->Init(psDesc))
|
if (_psLightSky->Init(psDesc))
|
||||||
return true;
|
return true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ bool ShadowsPass::setupResources()
|
|||||||
psDesc.CullMode = CullMode::Normal;
|
psDesc.CullMode = CullMode::Normal;
|
||||||
if (_psShadowPoint.Create(psDesc, shader, psLocalLight))
|
if (_psShadowPoint.Create(psDesc, shader, psLocalLight))
|
||||||
return true;
|
return true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
@@ -555,7 +555,7 @@ bool ShadowsPass::setupResources()
|
|||||||
psDesc.CullMode = CullMode::Normal;
|
psDesc.CullMode = CullMode::Normal;
|
||||||
if (_psShadowSpot.Create(psDesc, shader, psLocalLight, 8))
|
if (_psShadowSpot.Create(psDesc, shader, psLocalLight, 8))
|
||||||
return true;
|
return true;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
psDesc.DepthFunc = ComparisonFunc::Less;
|
psDesc.DepthFunc = ComparisonFunc::Less;
|
||||||
#else
|
#else
|
||||||
psDesc.DepthFunc = ComparisonFunc::Greater;
|
psDesc.DepthFunc = ComparisonFunc::Greater;
|
||||||
|
|||||||
@@ -249,8 +249,8 @@ bool ShaderCompiler::OnCompileBegin()
|
|||||||
const auto profile = GetProfile();
|
const auto profile = GetProfile();
|
||||||
const auto featureLevel = RenderTools::GetFeatureLevel(profile);
|
const auto featureLevel = RenderTools::GetFeatureLevel(profile);
|
||||||
_globalMacros.Add({ "FEATURE_LEVEL", Numbers[(int32)featureLevel] });
|
_globalMacros.Add({ "FEATURE_LEVEL", Numbers[(int32)featureLevel] });
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
_globalMacros.Add({ "FLAX_REVERSE_Z", "1"});
|
_globalMacros.Add({ "REVERSE_Z", "1"});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -20,8 +20,18 @@
|
|||||||
#include "./FlaxPlatforms/PS5/Shaders/PS5Common.hlsl"
|
#include "./FlaxPlatforms/PS5/Shaders/PS5Common.hlsl"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FLAX_REVERSE_Z
|
// Reversed Z support
|
||||||
#define FLAX_REVERSE_Z 0
|
#ifndef REVERSE_Z
|
||||||
|
#define REVERSE_Z 0
|
||||||
|
#endif
|
||||||
|
#if REVERSE_Z
|
||||||
|
#define DEPTH_MIN_VALUE 1
|
||||||
|
#define DEPTH_MAX_VALUE 0
|
||||||
|
//#define DEPTH_CMP(l, r) l > r
|
||||||
|
#else
|
||||||
|
#define DEPTH_MIN_VALUE 0
|
||||||
|
#define DEPTH_MAX_VALUE 1
|
||||||
|
//#define DEPTH_CMP(l, r) l < r
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Feature levels
|
// Feature levels
|
||||||
@@ -161,10 +171,11 @@ float4 LoadTextureWGSL(Texture2D tex, float2 uv)
|
|||||||
#else
|
#else
|
||||||
#define SAMPLE_RT_DEPTH(rt, texCoord) SAMPLE_RT(rt, texCoord).r
|
#define SAMPLE_RT_DEPTH(rt, texCoord) SAMPLE_RT(rt, texCoord).r
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// General purpose constants
|
||||||
#define HDR_CLAMP_MAX 65472.0
|
#define HDR_CLAMP_MAX 65472.0
|
||||||
#define PI 3.1415926535897932
|
#define PI 3.1415926535897932
|
||||||
#define UNITS_TO_METERS_SCALE 0.01f
|
#define UNITS_TO_METERS_SCALE 0.01f
|
||||||
#define REVERSE_Z 0
|
|
||||||
|
|
||||||
// Structure that contains information about GBuffer
|
// Structure that contains information about GBuffer
|
||||||
struct GBufferData
|
struct GBufferData
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ float4 PS(VS2PS input) : SV_Target
|
|||||||
{
|
{
|
||||||
float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(input.Position.xy, 0)).r;
|
float sceneDepthDeviceZ = SceneDepthTexture.Load(int3(input.Position.xy, 0)).r;
|
||||||
float interpolatedDeviceZ = input.Position.z;
|
float interpolatedDeviceZ = input.Position.z;
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
clip(interpolatedDeviceZ - sceneDepthDeviceZ);
|
clip(interpolatedDeviceZ - sceneDepthDeviceZ);
|
||||||
#else
|
#else
|
||||||
clip(sceneDepthDeviceZ - interpolatedDeviceZ);
|
clip(sceneDepthDeviceZ - interpolatedDeviceZ);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ float3 GetShadowPositionOffset(float offsetScale, float NoL, float3 normal)
|
|||||||
float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadowMapDepth)
|
float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadowMapDepth)
|
||||||
{
|
{
|
||||||
// `sceneDepth` and `shadowMapDepth`are raw depths, so we have to flip them when reverse-z is enabled
|
// `sceneDepth` and `shadowMapDepth`are raw depths, so we have to flip them when reverse-z is enabled
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
float thickness = max(shadowMapDepth - sceneDepth, 0);
|
float thickness = max(shadowMapDepth - sceneDepth, 0);
|
||||||
#else
|
#else
|
||||||
float thickness = max(sceneDepth - shadowMapDepth, 0);
|
float thickness = max(sceneDepth - shadowMapDepth, 0);
|
||||||
@@ -83,7 +83,7 @@ float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadow
|
|||||||
|
|
||||||
float occlusion = 1 - saturate(thickness * lerp(1.0f, 100.0f, opacity));
|
float occlusion = 1 - saturate(thickness * lerp(1.0f, 100.0f, opacity));
|
||||||
|
|
||||||
#if FLAX_REVERSE_Z
|
#if REVERSE_Z
|
||||||
return shadowMapDepth < 0.01f ? 1 : occlusion;
|
return shadowMapDepth < 0.01f ? 1 : occlusion;
|
||||||
#else
|
#else
|
||||||
return shadowMapDepth > 0.99f ? 1 : occlusion;
|
return shadowMapDepth > 0.99f ? 1 : occlusion;
|
||||||
|
|||||||
@@ -88,12 +88,10 @@ namespace Flax.Build
|
|||||||
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_SDL");
|
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_SDL");
|
||||||
options.ScriptingAPI.Defines.Add("PLATFORM_SDL");
|
options.ScriptingAPI.Defines.Add("PLATFORM_SDL");
|
||||||
}
|
}
|
||||||
|
if (EngineConfiguration.WithReverseZ(options))
|
||||||
if (!EngineConfiguration.WithTraditionalZ(options))
|
|
||||||
{
|
{
|
||||||
// Add reverse-z definitions
|
options.CompileEnv.PreprocessorDefinitions.Add("REVERSE_Z");
|
||||||
options.CompileEnv.PreprocessorDefinitions.Add("FLAX_REVERSE_Z");
|
options.ScriptingAPI.Defines.Add("REVERSE_Z");
|
||||||
options.ScriptingAPI.Defines.Add("FLAX_REVERSE_Z");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add include paths for this and all referenced projects sources
|
// Add include paths for this and all referenced projects sources
|
||||||
|
|||||||
@@ -307,10 +307,10 @@ namespace Flax.Build
|
|||||||
public static bool UseLargeWorlds = false;
|
public static bool UseLargeWorlds = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 1 to use traditional z buffer, or reversed z will be adopted by default.
|
/// 1 to use reversed Z Buffer, or traditional one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CommandLine("noReverseZ", "1 to use traditional z buffer, or reversed z will be adopted by default.")]
|
[CommandLine("useReverseZ", "1 to use reversed Z Buffer, or traditional one.")]
|
||||||
public static bool NoReverseZ = false;
|
public static bool UseReverseZ = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if managed C# scripting should be enabled, otherwise false. Engine without C# is partially supported and can be used when porting to a new platform before implementing C# runtime on it.
|
/// True if managed C# scripting should be enabled, otherwise false. Engine without C# is partially supported and can be used when porting to a new platform before implementing C# runtime on it.
|
||||||
@@ -349,10 +349,10 @@ namespace Flax.Build
|
|||||||
return UseLargeWorlds;
|
return UseLargeWorlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool WithTraditionalZ(NativeCpp.BuildOptions options)
|
public static bool WithReverseZ(NativeCpp.BuildOptions options)
|
||||||
{
|
{
|
||||||
// Whether to use traditional z-buffer instead of reversed z
|
// Whether to use traditional z-buffer or reversed depth
|
||||||
return NoReverseZ;
|
return UseReverseZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool WithDotNet(NativeCpp.BuildOptions options)
|
public static bool WithDotNet(NativeCpp.BuildOptions options)
|
||||||
|
|||||||
Reference in New Issue
Block a user