Skip to content

Two pass planet slice #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Cocoa/MyOpenGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Core/Entities/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ enum OOScanClass
OOTimeAbsolute spawnTime;

struct JSObject *_jsSelf;
NSUInteger lastDrawCounter;

@private
NSUInteger _sessionID;
Expand Down Expand Up @@ -274,6 +275,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.

- (NSUInteger) lastDrawCounter;
- (void) setLastDrawCounter: (NSUInteger) drawCounter;

// Subclass repsonsibilities
- (double) findCollisionRadius;
- (void) drawImmediate:(bool)immediate translucent:(bool)translucent;
Expand Down
14 changes: 14 additions & 0 deletions src/Core/Entities/Entity.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ - (id) init
gTotalEntityMemory += [self oo_objectSize];
#endif

lastDrawCounter = 0;
return self;
}

Expand Down Expand Up @@ -1047,6 +1048,19 @@ - (void)subEntityReallyDied:(ShipEntity *)sub
}


- (NSUInteger) lastDrawCounter
{
return lastDrawCounter;
}


- (void) setLastDrawCounter: (NSUInteger) drawCounter
{
lastDrawCounter = drawCounter;
return;
}


// For shader bindings.
- (GLfloat)universalTime
{
Expand Down
1 change: 1 addition & 0 deletions src/Core/Universe.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ enum

NSMutableSet *entitiesDeadThisUpdate;
int framesDoneThisUpdate;
NSUInteger drawCounter;

#if OOLITE_SPEECH_SYNTH
#if OOLITE_MAC_OS_X
Expand Down
46 changes: 34 additions & 12 deletions src/Core/Universe.m
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -4397,21 +4398,38 @@ - (void) drawUniverse
}

BOOL fogging, bpHide = [self breakPatternHide];


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];
}
}

// 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 ? INTERMEDIATE_CLEAR_DEPTH : MAX_CLEAR_DEPTH;
float ratio = (displayGUI ? 0.5 : [gameView fov:YES]) * nearPlane; // 0.5 is field of view ratio for GUIs
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];
Expand Down Expand Up @@ -4471,7 +4489,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
{
Expand All @@ -4494,13 +4512,13 @@ - (void) drawUniverse
GLfloat fogFactor = 0.5 / airResistanceFactor;
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
GLfloat mat_no[4] = {0.0, 0.0, 0.0, 1.0}; // nothing
GLfloat fog_blend;

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");
Expand All @@ -4513,9 +4531,11 @@ - (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 isPlanet]) continue;
if ([drawthing lastDrawCounter] == drawCounter) continue;
if (vdist == 0 && [drawthing cameraRangeFront] < nearPlane)
{
continue;
}

if (!((d_status == STATUS_COCKPIT_DISPLAY) ^ demoShipMode)) // either demo ship mode or in flight
{
Expand Down Expand Up @@ -4561,6 +4581,7 @@ - (void) drawUniverse
[self lightForEntity:demoShipMode || drawthing->isSunlit];

// draw the thing
[drawthing setLastDrawCounter: drawCounter];
[drawthing drawImmediate:false translucent:false];

OOGLPopModelView();
Expand Down Expand Up @@ -4611,6 +4632,7 @@ - (void) drawUniverse
}

// draw the thing
[drawthing setLastDrawCounter: drawCounter];
[drawthing drawImmediate:false translucent:true];

// atmospheric fog
Expand Down
2 changes: 1 addition & 1 deletion src/SDL/MyOpenGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down