-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
FrameTime
and FrameCount
; prevent multiple unit updates per f…
…rame (#373)
- Loading branch information
Showing
6 changed files
with
68 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"@shader-composer/core": minor | ||
--- | ||
|
||
Added two new units: `FrameTime` and `FrameCount`. | ||
|
||
`FrameTime` is a unit that represents the time in seconds since the application started. Most importantly, this value is guaranteed to be stable across the duration of a frame, so it's perfect for synchronizing multiple shaders. | ||
|
||
`FrameCount` provides an integer counter of the number of frames rendered since the start of the application. This, too, is great for synchronizing shaders, and might be better for when you need an auto-increasing integer value instead of a floating point time value. | ||
|
||
If you need these values in your JavaScript `update` callbacks, you can import the new `frame` object and access its `time` and `count` properties. |
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,24 @@ | ||
/** | ||
* An object containing information about the current frame. | ||
*/ | ||
export const frame = { | ||
/** | ||
* The current frame time, in seconds. This value does not change | ||
* over the course of a single frame. | ||
*/ | ||
time: performance.now() / 1000, | ||
|
||
/** | ||
* The current frame count. | ||
*/ | ||
count: 0 | ||
} | ||
|
||
function tick() { | ||
requestAnimationFrame(tick) | ||
|
||
frame.time = performance.now() / 1000 | ||
frame.count++ | ||
} | ||
|
||
requestAnimationFrame(tick) |