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

Commit

Permalink
Release 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
elfrank committed Jan 29, 2020
1 parent 5d38c8e commit d42ea7d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
33 changes: 21 additions & 12 deletions build/RayTracingRenderer.es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,6 @@
var tileHeight;
var columns;
var rows;
var firstTileTime = 0;
var width = 0;
var height = 0; // initial number of pixels per rendered tile
// based on correlation between system performance and max supported render buffer size
Expand All @@ -2667,14 +2666,21 @@
var pixelsPerTileQuantized = pixelsPerTile;
var desiredTimePerTile = 20;
var timePerPixel = desiredTimePerTile / pixelsPerTile;
var lastTime = 0;
var timeElapsed = 0;

function restartTimer() {
firstTileTime = 0;
function updateTime(time) {
if (lastTime) {
timeElapsed = time - lastTime;
}

lastTime = time;
}

function reset() {
currentTile = -1;
firstTileTime = 0;
timeElapsed = 0;
lastTime = 0;
}

function setSize(w, h) {
Expand All @@ -2695,8 +2701,7 @@
}

function initTiles() {
if (firstTileTime) {
var timeElapsed = Date.now() - firstTileTime;
if (timeElapsed) {
var timePerTile = timeElapsed / numTiles;
var expAvg = 0.5;
var newPixelsPerTile = pixelsPerTile * desiredTimePerTile / timePerTile;
Expand All @@ -2705,7 +2710,6 @@
timePerPixel = expAvg * timePerPixel + (1 - expAvg) * newTimePerPixel;
}

firstTileTime = Date.now();
pixelsPerTile = clamp(pixelsPerTile, 8192, width * height);
setTileDimensions(pixelsPerTile);
}
Expand All @@ -2716,6 +2720,13 @@
if (currentTile % numTiles === 0) {
initTiles();
currentTile = 0;
timeElapsed = 0;
}

var isLastTile = currentTile === numTiles - 1;

if (isLastTile) {
requestAnimationFrame(updateTime);
}

var x = currentTile % columns;
Expand All @@ -2726,7 +2737,7 @@
tileWidth: tileWidth,
tileHeight: tileHeight,
isFirstTile: currentTile === 0,
isLastTile: currentTile === numTiles - 1
isLastTile: isLastTile
};
}

Expand All @@ -2736,7 +2747,6 @@
},
nextTile: nextTile,
reset: reset,
restartTimer: restartTimer,
setSize: setSize
};
}
Expand Down Expand Up @@ -3034,8 +3044,7 @@
tileWidth = _tileRender$nextTile.tileWidth,
tileHeight = _tileRender$nextTile.tileHeight,
isFirstTile = _tileRender$nextTile.isFirstTile,
isLastTile = _tileRender$nextTile.isLastTile; // move to isLastTile?

isLastTile = _tileRender$nextTile.isLastTile;

if (isFirstTile) {
if (sampleCount === 0) {
Expand Down Expand Up @@ -3131,7 +3140,7 @@
return {
draw: draw,
drawFull: drawFull,
restartTimer: tileRender.restartTimer,
restartTimer: tileRender.reset,
setSize: setSize,
getTotalSamplesRendered: function getTotalSamplesRendered() {
return sampleCount;
Expand Down
35 changes: 21 additions & 14 deletions build/RayTracingRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3415,8 +3415,6 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
let columns;
let rows;

let firstTileTime = 0;

let width = 0;
let height = 0;

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

let timePerPixel = desiredTimePerTile / pixelsPerTile;

function restartTimer() {
firstTileTime = 0;
let lastTime = 0;
let timeElapsed = 0;

function updateTime(time) {
if (lastTime) {
timeElapsed = time - lastTime;
}

lastTime = time;
}

function reset() {
currentTile = -1;
firstTileTime = 0;
timeElapsed = 0;
lastTime = 0;
}

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

function initTiles() {
if (firstTileTime) {
const timeElapsed = Date.now() - firstTileTime;
if (timeElapsed) {
const timePerTile = timeElapsed / numTiles;

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

firstTileTime = Date.now();

pixelsPerTile = clamp(pixelsPerTile, 8192, width * height);

setTileDimensions(pixelsPerTile);
Expand All @@ -3486,6 +3489,12 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
if (currentTile % numTiles === 0) {
initTiles();
currentTile = 0;
timeElapsed = 0;
}

const isLastTile = currentTile === numTiles - 1;
if (isLastTile) {
requestAnimationFrame(updateTime);
}

const x = currentTile % columns;
Expand All @@ -3497,7 +3506,7 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
tileWidth,
tileHeight,
isFirstTile: currentTile === 0,
isLastTile: currentTile === numTiles - 1
isLastTile,
};
}

Expand All @@ -3507,8 +3516,7 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
},
nextTile,
reset,
restartTimer,
setSize
setSize,
};
}

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

// move to isLastTile?
if (isFirstTile) {

if (sampleCount === 0) { // previous rendered image was a preview image
Expand Down Expand Up @@ -4026,7 +4033,7 @@ void sampleGlassSpecular(SurfaceInteraction si, int bounce, inout Path path) {
return {
draw,
drawFull,
restartTimer: tileRender.restartTimer,
restartTimer: tileRender.reset,
setSize,
getTotalSamplesRendered() {
return sampleCount;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ray-tracing-renderer",
"version": "0.4.0",
"version": "0.5.0",
"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.",
"main": "build/RayTracingRenderer.js",
"scripts": {
Expand Down

0 comments on commit d42ea7d

Please sign in to comment.