Simplify SetMatrix code
This commit is contained in:
@@ -46,21 +46,6 @@ void BoundingFrustum::SetMatrix(const Matrix& matrix)
|
|||||||
_pBottom.D = matrix.M44 + matrix.M42;
|
_pBottom.D = matrix.M44 + matrix.M42;
|
||||||
_pBottom.Normalize();
|
_pBottom.Normalize();
|
||||||
|
|
||||||
#if FLAX_REVERSE_Z
|
|
||||||
// Far plane
|
|
||||||
_pFar.Normal.X = matrix.M13;
|
|
||||||
_pFar.Normal.Y = matrix.M23;
|
|
||||||
_pFar.Normal.Z = matrix.M33;
|
|
||||||
_pFar.D = matrix.M43;
|
|
||||||
_pFar.Normalize();
|
|
||||||
|
|
||||||
// Near plane
|
|
||||||
_pNear.Normal.X = matrix.M14 - matrix.M13;
|
|
||||||
_pNear.Normal.Y = matrix.M24 - matrix.M23;
|
|
||||||
_pNear.Normal.Z = matrix.M34 - matrix.M33;
|
|
||||||
_pNear.D = matrix.M44 - matrix.M43;
|
|
||||||
_pNear.Normalize();
|
|
||||||
#else
|
|
||||||
// Near plane
|
// Near plane
|
||||||
_pNear.Normal.X = matrix.M13;
|
_pNear.Normal.X = matrix.M13;
|
||||||
_pNear.Normal.Y = matrix.M23;
|
_pNear.Normal.Y = matrix.M23;
|
||||||
@@ -74,6 +59,10 @@ void BoundingFrustum::SetMatrix(const Matrix& matrix)
|
|||||||
_pFar.Normal.Z = matrix.M34 - matrix.M33;
|
_pFar.Normal.Z = matrix.M34 - matrix.M33;
|
||||||
_pFar.D = matrix.M44 - matrix.M43;
|
_pFar.D = matrix.M44 - matrix.M43;
|
||||||
_pFar.Normalize();
|
_pFar.Normalize();
|
||||||
|
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
|
// Swap far and near planes if reverse z
|
||||||
|
Swap(_pFar, _pNear);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,13 +188,13 @@ namespace FlaxEngine
|
|||||||
{
|
{
|
||||||
switch (index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case 0: return pLeft;
|
case 0: return pLeft;
|
||||||
case 1: return pRight;
|
case 1: return pRight;
|
||||||
case 2: return pTop;
|
case 2: return pTop;
|
||||||
case 3: return pBottom;
|
case 3: return pBottom;
|
||||||
case 4: return pNear;
|
case 4: return pNear;
|
||||||
case 5: return pFar;
|
case 5: return pFar;
|
||||||
default: return new Plane();
|
default: return new Plane();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,21 +230,6 @@ namespace FlaxEngine
|
|||||||
bottom.D = matrix.M44 + matrix.M42;
|
bottom.D = matrix.M44 + matrix.M42;
|
||||||
bottom.Normalize();
|
bottom.Normalize();
|
||||||
|
|
||||||
#if FLAX_REVERSE_Z
|
|
||||||
// Far plane
|
|
||||||
far.Normal.X = matrix.M13;
|
|
||||||
far.Normal.Y = matrix.M23;
|
|
||||||
far.Normal.Z = matrix.M33;
|
|
||||||
far.D = matrix.M43;
|
|
||||||
far.Normalize();
|
|
||||||
|
|
||||||
// Near plane
|
|
||||||
near.Normal.X = matrix.M14 - matrix.M13;
|
|
||||||
near.Normal.Y = matrix.M24 - matrix.M23;
|
|
||||||
near.Normal.Z = matrix.M34 - matrix.M33;
|
|
||||||
near.D = matrix.M44 - matrix.M43;
|
|
||||||
near.Normalize();
|
|
||||||
#else
|
|
||||||
// Near plane
|
// Near plane
|
||||||
near.Normal.X = matrix.M13;
|
near.Normal.X = matrix.M13;
|
||||||
near.Normal.Y = matrix.M23;
|
near.Normal.Y = matrix.M23;
|
||||||
@@ -258,6 +243,10 @@ namespace FlaxEngine
|
|||||||
far.Normal.Z = matrix.M34 - matrix.M33;
|
far.Normal.Z = matrix.M34 - matrix.M33;
|
||||||
far.D = matrix.M44 - matrix.M43;
|
far.D = matrix.M44 - matrix.M43;
|
||||||
far.Normalize();
|
far.Normalize();
|
||||||
|
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
|
// Swap far and near planes if reverse z
|
||||||
|
(near, far) = (far, near);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,37 +374,37 @@ namespace FlaxEngine
|
|||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
planeResult = pNear.Intersects(ref point);
|
planeResult = pNear.Intersects(ref point);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
planeResult = pFar.Intersects(ref point);
|
planeResult = pFar.Intersects(ref point);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
planeResult = pLeft.Intersects(ref point);
|
planeResult = pLeft.Intersects(ref point);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
planeResult = pRight.Intersects(ref point);
|
planeResult = pRight.Intersects(ref point);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
planeResult = pTop.Intersects(ref point);
|
planeResult = pTop.Intersects(ref point);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
planeResult = pBottom.Intersects(ref point);
|
planeResult = pBottom.Intersects(ref point);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (planeResult)
|
switch (planeResult)
|
||||||
{
|
{
|
||||||
case PlaneIntersectionType.Back: return ContainmentType.Disjoint;
|
case PlaneIntersectionType.Back: return ContainmentType.Disjoint;
|
||||||
case PlaneIntersectionType.Intersecting:
|
case PlaneIntersectionType.Intersecting:
|
||||||
result = PlaneIntersectionType.Intersecting;
|
result = PlaneIntersectionType.Intersecting;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case PlaneIntersectionType.Intersecting: return ContainmentType.Intersects;
|
case PlaneIntersectionType.Intersecting: return ContainmentType.Intersects;
|
||||||
default: return ContainmentType.Contains;
|
default: return ContainmentType.Contains;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,37 +491,37 @@ namespace FlaxEngine
|
|||||||
{
|
{
|
||||||
switch (i)
|
switch (i)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
planeResult = pNear.Intersects(ref sphere);
|
planeResult = pNear.Intersects(ref sphere);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
planeResult = pFar.Intersects(ref sphere);
|
planeResult = pFar.Intersects(ref sphere);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
planeResult = pLeft.Intersects(ref sphere);
|
planeResult = pLeft.Intersects(ref sphere);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
planeResult = pRight.Intersects(ref sphere);
|
planeResult = pRight.Intersects(ref sphere);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
planeResult = pTop.Intersects(ref sphere);
|
planeResult = pTop.Intersects(ref sphere);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
planeResult = pBottom.Intersects(ref sphere);
|
planeResult = pBottom.Intersects(ref sphere);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (planeResult)
|
switch (planeResult)
|
||||||
{
|
{
|
||||||
case PlaneIntersectionType.Back: return ContainmentType.Disjoint;
|
case PlaneIntersectionType.Back: return ContainmentType.Disjoint;
|
||||||
case PlaneIntersectionType.Intersecting:
|
case PlaneIntersectionType.Intersecting:
|
||||||
result = PlaneIntersectionType.Intersecting;
|
result = PlaneIntersectionType.Intersecting;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case PlaneIntersectionType.Intersecting: return ContainmentType.Intersects;
|
case PlaneIntersectionType.Intersecting: return ContainmentType.Intersects;
|
||||||
default: return ContainmentType.Contains;
|
default: return ContainmentType.Contains;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,19 @@ float3 GetShadowPositionOffset(float offsetScale, float NoL, float3 normal)
|
|||||||
|
|
||||||
float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadowMapDepth)
|
float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadowMapDepth)
|
||||||
{
|
{
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
float thickness = max(shadowMapDepth - sceneDepth, 0);
|
float thickness = max(shadowMapDepth - sceneDepth, 0);
|
||||||
|
#else
|
||||||
|
float thickness = max(sceneDepth - shadowMapDepth, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
float occlusion = 1 - thickness * lerp(1.0f, 100.0f, opacity);
|
float occlusion = 1 - thickness * lerp(1.0f, 100.0f, opacity);
|
||||||
|
|
||||||
|
#if FLAX_REVERSE_Z
|
||||||
return shadowMapDepth < 0.01f ? 1 : occlusion;
|
return shadowMapDepth < 0.01f ? 1 : occlusion;
|
||||||
|
#else
|
||||||
|
return shadowMapDepth > 0.99f ? 1 : occlusion;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user