Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit d42ea7d

Browse files
committed
Release 0.5.0
1 parent 5d38c8e commit d42ea7d

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

build/RayTracingRenderer.es5.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,7 +2657,6 @@
26572657
var tileHeight;
26582658
var columns;
26592659
var rows;
2660-
var firstTileTime = 0;
26612660
var width = 0;
26622661
var height = 0; // initial number of pixels per rendered tile
26632662
// based on correlation between system performance and max supported render buffer size
@@ -2667,14 +2666,21 @@
26672666
var pixelsPerTileQuantized = pixelsPerTile;
26682667
var desiredTimePerTile = 20;
26692668
var timePerPixel = desiredTimePerTile / pixelsPerTile;
2669+
var lastTime = 0;
2670+
var timeElapsed = 0;
26702671

2671-
function restartTimer() {
2672-
firstTileTime = 0;
2672+
function updateTime(time) {
2673+
if (lastTime) {
2674+
timeElapsed = time - lastTime;
2675+
}
2676+
2677+
lastTime = time;
26732678
}
26742679

26752680
function reset() {
26762681
currentTile = -1;
2677-
firstTileTime = 0;
2682+
timeElapsed = 0;
2683+
lastTime = 0;
26782684
}
26792685

26802686
function setSize(w, h) {
@@ -2695,8 +2701,7 @@
26952701
}
26962702

26972703
function initTiles() {
2698-
if (firstTileTime) {
2699-
var timeElapsed = Date.now() - firstTileTime;
2704+
if (timeElapsed) {
27002705
var timePerTile = timeElapsed / numTiles;
27012706
var expAvg = 0.5;
27022707
var newPixelsPerTile = pixelsPerTile * desiredTimePerTile / timePerTile;
@@ -2705,7 +2710,6 @@
27052710
timePerPixel = expAvg * timePerPixel + (1 - expAvg) * newTimePerPixel;
27062711
}
27072712

2708-
firstTileTime = Date.now();
27092713
pixelsPerTile = clamp(pixelsPerTile, 8192, width * height);
27102714
setTileDimensions(pixelsPerTile);
27112715
}
@@ -2716,6 +2720,13 @@
27162720
if (currentTile % numTiles === 0) {
27172721
initTiles();
27182722
currentTile = 0;
2723+
timeElapsed = 0;
2724+
}
2725+
2726+
var isLastTile = currentTile === numTiles - 1;
2727+
2728+
if (isLastTile) {
2729+
requestAnimationFrame(updateTime);
27192730
}
27202731

27212732
var x = currentTile % columns;
@@ -2726,7 +2737,7 @@
27262737
tileWidth: tileWidth,
27272738
tileHeight: tileHeight,
27282739
isFirstTile: currentTile === 0,
2729-
isLastTile: currentTile === numTiles - 1
2740+
isLastTile: isLastTile
27302741
};
27312742
}
27322743

@@ -2736,7 +2747,6 @@
27362747
},
27372748
nextTile: nextTile,
27382749
reset: reset,
2739-
restartTimer: restartTimer,
27402750
setSize: setSize
27412751
};
27422752
}
@@ -3034,8 +3044,7 @@
30343044
tileWidth = _tileRender$nextTile.tileWidth,
30353045
tileHeight = _tileRender$nextTile.tileHeight,
30363046
isFirstTile = _tileRender$nextTile.isFirstTile,
3037-
isLastTile = _tileRender$nextTile.isLastTile; // move to isLastTile?
3038-
3047+
isLastTile = _tileRender$nextTile.isLastTile;
30393048

30403049
if (isFirstTile) {
30413050
if (sampleCount === 0) {
@@ -3131,7 +3140,7 @@
31313140
return {
31323141
draw: draw,
31333142
drawFull: drawFull,
3134-
restartTimer: tileRender.restartTimer,
3143+
restartTimer: tileRender.reset,
31353144
setSize: setSize,
31363145
getTotalSamplesRendered: function getTotalSamplesRendered() {
31373146
return sampleCount;

build/RayTracingRenderer.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,8 +3415,6 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
34153415
let columns;
34163416
let rows;
34173417

3418-
let firstTileTime = 0;
3419-
34203418
let width = 0;
34213419
let height = 0;
34223420

@@ -3431,13 +3429,21 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
34313429

34323430
let timePerPixel = desiredTimePerTile / pixelsPerTile;
34333431

3434-
function restartTimer() {
3435-
firstTileTime = 0;
3432+
let lastTime = 0;
3433+
let timeElapsed = 0;
3434+
3435+
function updateTime(time) {
3436+
if (lastTime) {
3437+
timeElapsed = time - lastTime;
3438+
}
3439+
3440+
lastTime = time;
34363441
}
34373442

34383443
function reset() {
34393444
currentTile = -1;
3440-
firstTileTime = 0;
3445+
timeElapsed = 0;
3446+
lastTime = 0;
34413447
}
34423448

34433449
function setSize(w, h) {
@@ -3460,8 +3466,7 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
34603466
}
34613467

34623468
function initTiles() {
3463-
if (firstTileTime) {
3464-
const timeElapsed = Date.now() - firstTileTime;
3469+
if (timeElapsed) {
34653470
const timePerTile = timeElapsed / numTiles;
34663471

34673472
const expAvg = 0.5;
@@ -3473,8 +3478,6 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
34733478
timePerPixel = expAvg * timePerPixel + (1 - expAvg) * newTimePerPixel;
34743479
}
34753480

3476-
firstTileTime = Date.now();
3477-
34783481
pixelsPerTile = clamp(pixelsPerTile, 8192, width * height);
34793482

34803483
setTileDimensions(pixelsPerTile);
@@ -3486,6 +3489,12 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
34863489
if (currentTile % numTiles === 0) {
34873490
initTiles();
34883491
currentTile = 0;
3492+
timeElapsed = 0;
3493+
}
3494+
3495+
const isLastTile = currentTile === numTiles - 1;
3496+
if (isLastTile) {
3497+
requestAnimationFrame(updateTime);
34893498
}
34903499

34913500
const x = currentTile % columns;
@@ -3497,7 +3506,7 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
34973506
tileWidth,
34983507
tileHeight,
34993508
isFirstTile: currentTile === 0,
3500-
isLastTile: currentTile === numTiles - 1
3509+
isLastTile,
35013510
};
35023511
}
35033512

@@ -3507,8 +3516,7 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
35073516
},
35083517
nextTile,
35093518
reset,
3510-
restartTimer,
3511-
setSize
3519+
setSize,
35123520
};
35133521
}
35143522

@@ -3924,7 +3932,6 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
39243932
function drawTile() {
39253933
const { x, y, tileWidth, tileHeight, isFirstTile, isLastTile } = tileRender.nextTile();
39263934

3927-
// move to isLastTile?
39283935
if (isFirstTile) {
39293936

39303937
if (sampleCount === 0) { // previous rendered image was a preview image
@@ -4026,7 +4033,7 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
40264033
return {
40274034
draw,
40284035
drawFull,
4029-
restartTimer: tileRender.restartTimer,
4036+
restartTimer: tileRender.reset,
40304037
setSize,
40314038
getTotalSamplesRendered() {
40324039
return sampleCount;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ray-tracing-renderer",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"description": "A [Three.js](https://github.com/mrdoob/three.js/) renderer which utilizes path tracing to render a scene with true photorealism. The renderer supports global illumination, reflections, soft shadows, and realistic environment lighting.",
55
"main": "build/RayTracingRenderer.js",
66
"scripts": {

0 commit comments

Comments
 (0)