From bfcca0c2ed7c4b53748c03e39728da2700e366d7 Mon Sep 17 00:00:00 2001 From: Kevin Anthoney Date: Sun, 24 May 2015 15:09:10 +0100 Subject: [PATCH 1/6] partial fix for two-pass planet slicing effect --- src/Cocoa/MyOpenGLView.h | 2 +- src/Core/Universe.m | 12 +++++++++--- src/SDL/MyOpenGLView.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Cocoa/MyOpenGLView.h b/src/Cocoa/MyOpenGLView.h index f2befb25a..7a527d2c7 100644 --- a/src/Cocoa/MyOpenGLView.h +++ b/src/Cocoa/MyOpenGLView.h @@ -30,7 +30,7 @@ MA 02110-1301, USA. #define MAX_CLEAR_DEPTH 10000000000.0 // 10 000 000 km. -#define INTERMEDIATE_CLEAR_DEPTH 100.0 +#define INTERMEDIATE_CLEAR_DEPTH 50000.0 // 100 m. #define MIN_FOV_DEG 30.0f diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 802c8d1d3..bf0770334 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -4405,11 +4405,13 @@ - (void) drawUniverse } BOOL fogging, bpHide = [self breakPatternHide]; + + float pass1FarPlane = INTERMEDIATE_CLEAR_DEPTH; for (vdist=0;vdist<=1;vdist++) { float nearPlane = vdist ? 1.0 : INTERMEDIATE_CLEAR_DEPTH; - float farPlane = vdist ? INTERMEDIATE_CLEAR_DEPTH : MAX_CLEAR_DEPTH; + float farPlane = vdist ? pass1FarPlane : MAX_CLEAR_DEPTH; float ratio = (displayGUI ? 0.5 : [gameView fov:YES]) * nearPlane; // 0.5 is field of view ratio for GUIs OOGLResetProjection(); @@ -4520,8 +4522,12 @@ - (void) drawUniverse OOEntityStatus d_status = [drawthing status]; if (bpHide && !drawthing->isImmuneToBreakPatternHide) continue; - if (vdist == 1 && [drawthing cameraRangeFront] > farPlane*1.5) continue; - if (vdist == 0 && [drawthing cameraRangeBack] < nearPlane) continue; + if (vdist == 1 && [drawthing cameraRangeFront] > farPlane) continue; + if (vdist == 0 && [drawthing cameraRangeFront] < nearPlane) + { + if ([drawthing cameraRangeBack] > pass1FarPlane) pass1FarPlane = [drawthing cameraRangeBack]; + continue; + } // if (vdist == 1 && [drawthing isPlanet]) continue; if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode)) // either demo ship mode or in flight diff --git a/src/SDL/MyOpenGLView.h b/src/SDL/MyOpenGLView.h index 21b026cae..1f6006f5f 100644 --- a/src/SDL/MyOpenGLView.h +++ b/src/SDL/MyOpenGLView.h @@ -41,7 +41,7 @@ MA 02110-1301, USA. #define MAX_CLEAR_DEPTH 10000000000.0 // 10 000 000 km. -#define INTERMEDIATE_CLEAR_DEPTH 100.0 +#define INTERMEDIATE_CLEAR_DEPTH 50000.0 // 100 m. From ff3b66e2709b4996b80b66a7377b341d7d738785 Mon Sep 17 00:00:00 2001 From: Kevin Anthoney Date: Sun, 24 May 2015 15:59:50 +0100 Subject: [PATCH 2/6] Try and fix disappearing asteroid problem --- src/Core/Entities/Entity.h | 4 ++++ src/Core/Entities/Entity.m | 14 ++++++++++++++ src/Core/Universe.m | 10 ++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Core/Entities/Entity.h b/src/Core/Entities/Entity.h index de2b7ee34..e02a9a938 100644 --- a/src/Core/Entities/Entity.h +++ b/src/Core/Entities/Entity.h @@ -148,6 +148,7 @@ enum OOScanClass OOTimeAbsolute spawnTime; struct JSObject *_jsSelf; + OOTimeAbsolute lastDrawTime; @private NSUInteger _sessionID; @@ -272,6 +273,9 @@ enum OOScanClass - (void) dumpState; // General "describe situtation verbosely in log" command. - (void) dumpSelfState; // Subclasses should override this, not -dumpState, and call throught to super first. +- (OOTimeAbsolute) lastDrawTime; +- (void) setLastDrawTime: (OOTimeAbsolute) drawTime; + // Subclass repsonsibilities - (double) findCollisionRadius; - (void) drawImmediate:(bool)immediate translucent:(bool)translucent; diff --git a/src/Core/Entities/Entity.m b/src/Core/Entities/Entity.m index 76b3f20ec..5741dad55 100644 --- a/src/Core/Entities/Entity.m +++ b/src/Core/Entities/Entity.m @@ -92,6 +92,7 @@ - (id) init gTotalEntityMemory += [self oo_objectSize]; #endif + lastDrawTime = 0; return self; } @@ -1044,6 +1045,19 @@ - (void)subEntityReallyDied:(ShipEntity *)sub } +- (OOTimeAbsolute) lastDrawTime +{ + return lastDrawTime; +} + + +- (void) setLastDrawTime: (OOTimeAbsolute) drawTime +{ + lastDrawTime = drawTime; + return; +} + + // For shader bindings. - (GLfloat)universalTime { diff --git a/src/Core/Universe.m b/src/Core/Universe.m index bf0770334..784d7ba54 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -4407,6 +4407,7 @@ - (void) drawUniverse BOOL fogging, bpHide = [self breakPatternHide]; float pass1FarPlane = INTERMEDIATE_CLEAR_DEPTH; + OOTimeAbsolute drawTime = universal_time; for (vdist=0;vdist<=1;vdist++) { @@ -4522,13 +4523,12 @@ - (void) drawUniverse OOEntityStatus d_status = [drawthing status]; if (bpHide && !drawthing->isImmuneToBreakPatternHide) continue; - if (vdist == 1 && [drawthing cameraRangeFront] > farPlane) continue; - if (vdist == 0 && [drawthing cameraRangeFront] < nearPlane) + if ([drawthing lastDrawTime] >= drawTime) continue; + if (vdist == 0 && [drawthing cameraRangeFront] < nearPlane * 1.1) { - if ([drawthing cameraRangeBack] > pass1FarPlane) pass1FarPlane = [drawthing cameraRangeBack]; + if ([drawthing cameraRangeBack] > pass1FarPlane) pass1FarPlane = [drawthing cameraRangeBack]*1.1; continue; } -// if (vdist == 1 && [drawthing isPlanet]) continue; if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode)) // either demo ship mode or in flight { @@ -4572,6 +4572,7 @@ - (void) drawUniverse [self lightForEntity:demoShipMode || drawthing->isSunlit]; // draw the thing + [drawthing setLastDrawTime: drawTime]; [drawthing drawImmediate:false translucent:false]; OOGLPopModelView(); @@ -4619,6 +4620,7 @@ - (void) drawUniverse } // draw the thing + [drawthing setLastDrawTime: drawTime]; [drawthing drawImmediate:false translucent:true]; // atmospheric fog From 8438c621d8d0390dba8224c33b6edccbd353b6c5 Mon Sep 17 00:00:00 2001 From: kanthoney Date: Sun, 31 May 2015 11:39:09 +0100 Subject: [PATCH 3/6] prevent objects from disappearing when on the two pass boundary and at the corner of the screen with a high FOV setting --- src/Core/Universe.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 784d7ba54..1b71e143a 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -4414,6 +4414,7 @@ - (void) drawUniverse float nearPlane = vdist ? 1.0 : INTERMEDIATE_CLEAR_DEPTH; float farPlane = vdist ? pass1FarPlane : MAX_CLEAR_DEPTH; float ratio = (displayGUI ? 0.5 : [gameView fov:YES]) * nearPlane; // 0.5 is field of view ratio for GUIs + float nearDistance = sqrt(nearPlane*nearPlane + ratio*ratio*(1+1/(aspect*aspect))); // distance to object that's on the near plane and in the corner of the screen OOGLResetProjection(); if ((displayGUI && 4*aspect >= 3) || (!displayGUI && 4*aspect <= 3)) @@ -4524,7 +4525,7 @@ - (void) drawUniverse if (bpHide && !drawthing->isImmuneToBreakPatternHide) continue; if ([drawthing lastDrawTime] >= drawTime) continue; - if (vdist == 0 && [drawthing cameraRangeFront] < nearPlane * 1.1) + if (vdist == 0 && [drawthing cameraRangeFront] < nearDistance) { if ([drawthing cameraRangeBack] > pass1FarPlane) pass1FarPlane = [drawthing cameraRangeBack]*1.1; continue; From 560cc195a18f372735b8266c54d46f1c946a8472 Mon Sep 17 00:00:00 2001 From: kanthoney Date: Sun, 31 May 2015 13:28:50 +0100 Subject: [PATCH 4/6] Fix issue with Universe disappearing when game paused --- src/Core/Entities/Entity.h | 6 +++--- src/Core/Entities/Entity.m | 10 +++++----- src/Core/Universe.h | 1 + src/Core/Universe.m | 9 +++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Core/Entities/Entity.h b/src/Core/Entities/Entity.h index e02a9a938..d400ea293 100644 --- a/src/Core/Entities/Entity.h +++ b/src/Core/Entities/Entity.h @@ -148,7 +148,7 @@ enum OOScanClass OOTimeAbsolute spawnTime; struct JSObject *_jsSelf; - OOTimeAbsolute lastDrawTime; + NSUInteger lastDrawCounter; @private NSUInteger _sessionID; @@ -273,8 +273,8 @@ enum OOScanClass - (void) dumpState; // General "describe situtation verbosely in log" command. - (void) dumpSelfState; // Subclasses should override this, not -dumpState, and call throught to super first. -- (OOTimeAbsolute) lastDrawTime; -- (void) setLastDrawTime: (OOTimeAbsolute) drawTime; +- (NSUInteger) lastDrawCounter; +- (void) setLastDrawCounter: (NSUInteger) drawCounter; // Subclass repsonsibilities - (double) findCollisionRadius; diff --git a/src/Core/Entities/Entity.m b/src/Core/Entities/Entity.m index 5741dad55..6905987da 100644 --- a/src/Core/Entities/Entity.m +++ b/src/Core/Entities/Entity.m @@ -92,7 +92,7 @@ - (id) init gTotalEntityMemory += [self oo_objectSize]; #endif - lastDrawTime = 0; + lastDrawCounter = 0; return self; } @@ -1045,15 +1045,15 @@ - (void)subEntityReallyDied:(ShipEntity *)sub } -- (OOTimeAbsolute) lastDrawTime +- (NSUInteger) lastDrawCounter { - return lastDrawTime; + return lastDrawCounter; } -- (void) setLastDrawTime: (OOTimeAbsolute) drawTime +- (void) setLastDrawCounter: (NSUInteger) drawCounter { - lastDrawTime = drawTime; + lastDrawCounter = drawCounter; return; } diff --git a/src/Core/Universe.h b/src/Core/Universe.h index 7e0356c54..2f3bd97a9 100644 --- a/src/Core/Universe.h +++ b/src/Core/Universe.h @@ -309,6 +309,7 @@ enum NSMutableSet *entitiesDeadThisUpdate; int framesDoneThisUpdate; + NSUInteger drawCounter; #if OOLITE_SPEECH_SYNTH #if OOLITE_MAC_OS_X diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 1b71e143a..627c4d096 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -382,6 +382,7 @@ - (id) initWithGameView:(MyOpenGLView *)inGameView universeRegion = [[CollisionRegion alloc] initAsUniverse]; entitiesDeadThisUpdate = [[NSMutableSet alloc] init]; framesDoneThisUpdate = 0; + drawCounter = 0; [[GameController sharedController] logProgress:DESC(@"initializing-debug-support")]; OOInitDebugSupport(); @@ -4407,7 +4408,7 @@ - (void) drawUniverse BOOL fogging, bpHide = [self breakPatternHide]; float pass1FarPlane = INTERMEDIATE_CLEAR_DEPTH; - OOTimeAbsolute drawTime = universal_time; + drawCounter++; for (vdist=0;vdist<=1;vdist++) { @@ -4524,7 +4525,7 @@ - (void) drawUniverse OOEntityStatus d_status = [drawthing status]; if (bpHide && !drawthing->isImmuneToBreakPatternHide) continue; - if ([drawthing lastDrawTime] >= drawTime) continue; + if ([drawthing lastDrawCounter] == drawCounter) continue; if (vdist == 0 && [drawthing cameraRangeFront] < nearDistance) { if ([drawthing cameraRangeBack] > pass1FarPlane) pass1FarPlane = [drawthing cameraRangeBack]*1.1; @@ -4573,7 +4574,7 @@ - (void) drawUniverse [self lightForEntity:demoShipMode || drawthing->isSunlit]; // draw the thing - [drawthing setLastDrawTime: drawTime]; + [drawthing setLastDrawCounter: drawCounter]; [drawthing drawImmediate:false translucent:false]; OOGLPopModelView(); @@ -4621,7 +4622,7 @@ - (void) drawUniverse } // draw the thing - [drawthing setLastDrawTime: drawTime]; + [drawthing setLastDrawCounter: drawCounter]; [drawthing drawImmediate:false translucent:true]; // atmospheric fog From f1def72687aade5beda8c6e60b0ae94b88281d09 Mon Sep 17 00:00:00 2001 From: kanthoney Date: Sun, 31 May 2015 16:22:02 +0100 Subject: [PATCH 5/6] Find a distance between rendering passes where no objects overlap --- src/Core/Universe.m | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 627c4d096..509d41f76 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -4407,24 +4407,39 @@ - (void) drawUniverse BOOL fogging, bpHide = [self breakPatternHide]; - float pass1FarPlane = INTERMEDIATE_CLEAR_DEPTH; drawCounter++; + float breakPlane = INTERMEDIATE_CLEAR_DEPTH; + for( int i = 0; i < draw_count; i++ ) + { + if ([my_entities[i] cameraRangeFront] > breakPlane) + { + continue; + } + if ([my_entities[i] cameraRangeBack] > breakPlane) + { + breakPlane = [my_entities[i] cameraRangeBack]; + } + } + + OOLog( @"kja", @"breakPlane: %f", breakPlane ); + // We need to bring forward the near plane of the frustum on the long distance pass by this factor to avoid clipping objects at the corner of the window + float distanceFactor = sqrt(1 + ([gameView fov:YES]*[gameView fov:YES] * (1.0 + 1.0/(aspect*aspect)))); + for (vdist=0;vdist<=1;vdist++) { float nearPlane = vdist ? 1.0 : INTERMEDIATE_CLEAR_DEPTH; - float farPlane = vdist ? pass1FarPlane : MAX_CLEAR_DEPTH; - float ratio = (displayGUI ? 0.5 : [gameView fov:YES]) * nearPlane; // 0.5 is field of view ratio for GUIs - float nearDistance = sqrt(nearPlane*nearPlane + ratio*ratio*(1+1/(aspect*aspect))); // distance to object that's on the near plane and in the corner of the screen + float farPlane = vdist ? breakPlane : MAX_CLEAR_DEPTH; + float ratio = (displayGUI ? 0.5 : [gameView fov:YES]) * nearPlane / distanceFactor; // 0.5 is field of view ratio for GUIs OOGLResetProjection(); if ((displayGUI && 4*aspect >= 3) || (!displayGUI && 4*aspect <= 3)) { - OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, nearPlane, farPlane); + OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, nearPlane / distanceFactor, farPlane); } else { - OOGLFrustum(-3*ratio/aspect/4, 3*ratio/aspect/4, -3*ratio/4, 3*ratio/4, nearPlane, farPlane); + OOGLFrustum(-3*ratio/aspect/4, 3*ratio/aspect/4, -3*ratio/4, 3*ratio/4, nearPlane / distanceFactor, farPlane); } [self getActiveViewMatrix:&view_matrix forwardVector:&view_dir upVector:&view_up]; @@ -4484,7 +4499,7 @@ - (void) drawUniverse { [self setMainLightPosition:[cachedSun cameraRelativePosition]]; } - OOGL(glLightfv(GL_LIGHT1, GL_POSITION, main_light_position)); + OOGL(glLightfv(GL_LIGHT1, GL_POSITION, main_light_position)); } else { @@ -4508,11 +4523,11 @@ - (void) drawUniverse double fog_scale, half_scale; GLfloat flat_ambdiff[4] = {1.0, 1.0, 1.0, 1.0}; // for alpha GLfloat mat_no[4] = {0.0, 0.0, 0.0, 1.0}; // nothing - + OOGL(glHint(GL_FOG_HINT, [self reducedDetail] ? GL_FASTEST : GL_NICEST)); - + [self defineFrustum]; // camera is set up for this frame - + OOVerifyOpenGLState(); OOCheckOpenGLErrors(@"Universe after setting up for opaque pass"); OOLog(@"universe.profile.draw",@"Begin opaque pass"); @@ -4526,9 +4541,8 @@ - (void) drawUniverse if (bpHide && !drawthing->isImmuneToBreakPatternHide) continue; if ([drawthing lastDrawCounter] == drawCounter) continue; - if (vdist == 0 && [drawthing cameraRangeFront] < nearDistance) + if (vdist == 0 && [drawthing cameraRangeFront] < nearPlane) { - if ([drawthing cameraRangeBack] > pass1FarPlane) pass1FarPlane = [drawthing cameraRangeBack]*1.1; continue; } From 7afac3e10b6650ab53849cae13729b8fa20fb56c Mon Sep 17 00:00:00 2001 From: kanthoney Date: Sun, 31 May 2015 18:49:06 +0100 Subject: [PATCH 6/6] remove logging --- src/Core/Universe.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Core/Universe.m b/src/Core/Universe.m index 509d41f76..974ff5366 100644 --- a/src/Core/Universe.m +++ b/src/Core/Universe.m @@ -4421,8 +4421,6 @@ - (void) drawUniverse } } - OOLog( @"kja", @"breakPlane: %f", breakPlane ); - // We need to bring forward the near plane of the frustum on the long distance pass by this factor to avoid clipping objects at the corner of the window float distanceFactor = sqrt(1 + ([gameView fov:YES]*[gameView fov:YES] * (1.0 + 1.0/(aspect*aspect))));