Implement reverse floating point depth buffer. (Breaks OpenGL)

This commit is contained in:
UnknownShadow200 2016-03-26 21:47:37 +11:00
parent c38718b3ba
commit 87721a8e6e
4 changed files with 16 additions and 12 deletions

View File

@ -131,7 +131,7 @@ namespace ClassicalSharp {
FpsLimitMethod method = Options.GetEnum( OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync );
SetFpsLimitMethod( method );
Graphics.DepthTest = true;
Graphics.DepthTestFunc( CompareFunc.LessEqual );
Graphics.DepthTestFunc( CompareFunc.GreaterEqual );
//Graphics.DepthWrite = true;
Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );

View File

@ -46,7 +46,7 @@ namespace ClassicalSharp.GraphicsAPI {
createFlags = CreateFlags.MixedVertexProcessing;
try {
device = d3d.CreateDevice( adapter, DeviceType.Hardware, windowHandle, createFlags, args );
} catch ( SharpDXException ) {
} catch( SharpDXException ) {
createFlags = CreateFlags.SoftwareVertexProcessing;
device = d3d.CreateDevice( adapter, DeviceType.Hardware, windowHandle, createFlags, args );
}
@ -188,7 +188,7 @@ namespace ClassicalSharp.GraphicsAPI {
int lastClearCol;
public override void Clear() {
device.Clear( ClearFlags.Target | ClearFlags.ZBuffer, lastClearCol, 1f, 0 );
device.Clear( ClearFlags.Target | ClearFlags.ZBuffer, lastClearCol, 0f, 0 );
}
public override void ClearColour( FastColour col ) {
@ -597,7 +597,7 @@ namespace ClassicalSharp.GraphicsAPI {
modeMappings = new PrimitiveType[2];
modeMappings[0] = PrimitiveType.TriangleList; modeMappings[1] = PrimitiveType.LineList;
depthFormats = new Format[6];
depthFormats[0] = Format.D32; depthFormats[1] = Format.D24X8; depthFormats[2] = Format.D24S8;
depthFormats[0] = Format.D32F_Lockable; depthFormats[1] = Format.D24X8; depthFormats[2] = Format.D24S8;
depthFormats[3] = Format.D24X4S4; depthFormats[4] = Format.D16; depthFormats[5] = Format.D15S1;
viewFormats = new Format[4];
viewFormats[0] = Format.X8R8G8B8; viewFormats[1] = Format.R8G8B8;

View File

@ -220,8 +220,6 @@ namespace OpenTK {
throw new ArgumentOutOfRangeException("zNear");
if (zFar <= 0)
throw new ArgumentOutOfRangeException("zFar");
if (zNear >= zFar)
throw new ArgumentOutOfRangeException("zNear");
float yMax = zNear * (float)System.Math.Tan(0.5f * fovy);
float yMin = -yMax;
@ -232,18 +230,23 @@ namespace OpenTK {
}
public static Matrix4 CreatePerspectiveFieldOfView(float fovy, float aspect, float zNear, float zFar) {
float f = 1.0f / (float)Math.Tan(fovy / 2.0f); // 1.0 / tan(X) == cotangent(X)
//infinite Perspective matrix reversed
return new Matrix4(
f/aspect, 0.0f, 0.0f, 0.0f,
0.0f, f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, -1.0f,
0.0f, 0.0f, zNear, 0.0f);
Matrix4 result;
CreatePerspectiveFieldOfView(fovy, aspect, zNear, zFar, out result);
return result;
}
public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, out Matrix4 result) {
if (zNear <= 0)
throw new ArgumentOutOfRangeException("zNear");
if (zFar <= 0)
throw new ArgumentOutOfRangeException("zFar");
if (zNear >= zFar)
throw new ArgumentOutOfRangeException("zNear");
if (zNear <= 0) throw new ArgumentOutOfRangeException("zNear");
if (zFar <= 0) throw new ArgumentOutOfRangeException("zFar");
float x = (2.0f * zNear) / (right - left);
float y = (2.0f * zNear) / (top - bottom);

View File

@ -216,6 +216,7 @@ namespace SharpDX.Direct3D9 {
D24X8 = 77,
D24X4S4 = 79,
D16 = 80,
D32F_Lockable = 82,
VertexData = 100,
Index16 = 101,
Index32 = 102,