Skip to content

Commit f1def72

Browse files
committed
Find a distance between rendering passes where no objects overlap
1 parent 560cc19 commit f1def72

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/Core/Universe.m

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,24 +4407,39 @@ - (void) drawUniverse
44074407

44084408
BOOL fogging, bpHide = [self breakPatternHide];
44094409

4410-
float pass1FarPlane = INTERMEDIATE_CLEAR_DEPTH;
44114410
drawCounter++;
4411+
float breakPlane = INTERMEDIATE_CLEAR_DEPTH;
4412+
for( int i = 0; i < draw_count; i++ )
4413+
{
4414+
if ([my_entities[i] cameraRangeFront] > breakPlane)
4415+
{
4416+
continue;
4417+
}
4418+
if ([my_entities[i] cameraRangeBack] > breakPlane)
4419+
{
4420+
breakPlane = [my_entities[i] cameraRangeBack];
4421+
}
4422+
}
4423+
4424+
OOLog( @"kja", @"breakPlane: %f", breakPlane );
44124425

4426+
// 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
4427+
float distanceFactor = sqrt(1 + ([gameView fov:YES]*[gameView fov:YES] * (1.0 + 1.0/(aspect*aspect))));
4428+
44134429
for (vdist=0;vdist<=1;vdist++)
44144430
{
44154431
float nearPlane = vdist ? 1.0 : INTERMEDIATE_CLEAR_DEPTH;
4416-
float farPlane = vdist ? pass1FarPlane : MAX_CLEAR_DEPTH;
4417-
float ratio = (displayGUI ? 0.5 : [gameView fov:YES]) * nearPlane; // 0.5 is field of view ratio for GUIs
4418-
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
4432+
float farPlane = vdist ? breakPlane : MAX_CLEAR_DEPTH;
4433+
float ratio = (displayGUI ? 0.5 : [gameView fov:YES]) * nearPlane / distanceFactor; // 0.5 is field of view ratio for GUIs
44194434

44204435
OOGLResetProjection();
44214436
if ((displayGUI && 4*aspect >= 3) || (!displayGUI && 4*aspect <= 3))
44224437
{
4423-
OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, nearPlane, farPlane);
4438+
OOGLFrustum(-ratio, ratio, -aspect*ratio, aspect*ratio, nearPlane / distanceFactor, farPlane);
44244439
}
44254440
else
44264441
{
4427-
OOGLFrustum(-3*ratio/aspect/4, 3*ratio/aspect/4, -3*ratio/4, 3*ratio/4, nearPlane, farPlane);
4442+
OOGLFrustum(-3*ratio/aspect/4, 3*ratio/aspect/4, -3*ratio/4, 3*ratio/4, nearPlane / distanceFactor, farPlane);
44284443
}
44294444

44304445
[self getActiveViewMatrix:&view_matrix forwardVector:&view_dir upVector:&view_up];
@@ -4484,7 +4499,7 @@ - (void) drawUniverse
44844499
{
44854500
[self setMainLightPosition:[cachedSun cameraRelativePosition]];
44864501
}
4487-
OOGL(glLightfv(GL_LIGHT1, GL_POSITION, main_light_position));
4502+
OOGL(glLightfv(GL_LIGHT1, GL_POSITION, main_light_position));
44884503
}
44894504
else
44904505
{
@@ -4508,11 +4523,11 @@ - (void) drawUniverse
45084523
double fog_scale, half_scale;
45094524
GLfloat flat_ambdiff[4] = {1.0, 1.0, 1.0, 1.0}; // for alpha
45104525
GLfloat mat_no[4] = {0.0, 0.0, 0.0, 1.0}; // nothing
4511-
4526+
45124527
OOGL(glHint(GL_FOG_HINT, [self reducedDetail] ? GL_FASTEST : GL_NICEST));
4513-
4528+
45144529
[self defineFrustum]; // camera is set up for this frame
4515-
4530+
45164531
OOVerifyOpenGLState();
45174532
OOCheckOpenGLErrors(@"Universe after setting up for opaque pass");
45184533
OOLog(@"universe.profile.draw",@"Begin opaque pass");
@@ -4526,9 +4541,8 @@ - (void) drawUniverse
45264541

45274542
if (bpHide && !drawthing->isImmuneToBreakPatternHide) continue;
45284543
if ([drawthing lastDrawCounter] == drawCounter) continue;
4529-
if (vdist == 0 && [drawthing cameraRangeFront] < nearDistance)
4544+
if (vdist == 0 && [drawthing cameraRangeFront] < nearPlane)
45304545
{
4531-
if ([drawthing cameraRangeBack] > pass1FarPlane) pass1FarPlane = [drawthing cameraRangeBack]*1.1;
45324546
continue;
45334547
}
45344548

0 commit comments

Comments
 (0)