This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* scale preview res dynamically * don't render preview on first frame * add missing code * comments * rename class * actually average benchmark * improve benchmarking; get time from requestAnimationFrame * use renderer.time(), improvements * rename renderer.time to renderer.sync; tweak scaling values; update examples
- Loading branch information
Lucas Crane
authored
Mar 10, 2020
1 parent
66e9cbc
commit cfb6851
Showing
7 changed files
with
192 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { clamp } from './util'; | ||
import { Vector2 } from 'three'; | ||
|
||
export function makeRenderSize(gl) { | ||
const desiredMsPerFrame = 20; | ||
|
||
let fullWidth; | ||
let fullHeight; | ||
|
||
let renderWidth; | ||
let renderHeight; | ||
let scale = new Vector2(1, 1); | ||
|
||
let pixelsPerFrame = pixelsPerFrameEstimate(gl); | ||
|
||
function setSize(w, h) { | ||
fullWidth = w; | ||
fullHeight = h; | ||
calcDimensions(); | ||
} | ||
|
||
function calcDimensions() { | ||
const aspectRatio = fullWidth / fullHeight; | ||
renderWidth = Math.round(clamp(Math.sqrt(pixelsPerFrame * aspectRatio), 1, fullWidth)); | ||
renderHeight = Math.round(clamp(renderWidth / aspectRatio, 1, fullHeight)); | ||
scale.set(renderWidth / fullWidth, renderHeight / fullHeight); | ||
} | ||
|
||
function adjustSize(elapsedFrameMs) { | ||
if (!elapsedFrameMs) { | ||
return; | ||
} | ||
|
||
// tweak to find balance. higher = faster convergence, lower = less fluctuations to microstutters | ||
const strength = 600; | ||
|
||
const error = desiredMsPerFrame - elapsedFrameMs; | ||
|
||
pixelsPerFrame += strength * error; | ||
pixelsPerFrame = clamp(pixelsPerFrame, 8192, fullWidth * fullHeight); | ||
calcDimensions(); | ||
} | ||
|
||
return { | ||
adjustSize, | ||
setSize, | ||
scale, | ||
get width() { | ||
return renderWidth; | ||
}, | ||
get height() { | ||
return renderHeight; | ||
} | ||
}; | ||
} | ||
|
||
function pixelsPerFrameEstimate(gl) { | ||
const maxRenderbufferSize = gl.getParameter(gl.MAX_RENDERBUFFER_SIZE); | ||
|
||
if (maxRenderbufferSize <= 8192) { | ||
return 80000; | ||
} else if (maxRenderbufferSize === 16384) { | ||
return 150000; | ||
} else if (maxRenderbufferSize >= 32768) { | ||
return 400000; | ||
} | ||
} |
Oops, something went wrong.