Permalink
Browse files

Progressive rendering

  • Loading branch information...
1 parent 934699d commit 757ca34a8ac50bfe2c1fcf182ffe6da00d5e7c15 @vjeux committed Jan 2, 2012
Showing with 36 additions and 20 deletions.
  1. +2 −2 raytracer.html
  2. +18 −9 src/trace.coffee
  3. +16 −9 src/worker.coffee
View
@@ -32,6 +32,8 @@
<img src="images/examples/light_3_small.png" title="light_3"/>
<img src="images/examples/perlin_small.png" title="perlin"/>
<img src="images/examples/perlin_sphere_small.png" title="perlin_sphere"/>
+ <img src="images/examples/example_5_small.png" title="example_5"/>
+ <img src="images/examples/example_7_small.png" title="example_7"/>
<!--
<img src="images/examples/sphere_checkerboard_small.png" title="sphere_checkerboard"/>
@@ -41,8 +43,6 @@
<img src="images/examples/example_4_small.png" title="example_4"/>
<img src="images/examples/example_6_small.png" title="example_6"/>
-->
- <img src="images/examples/example_5_small.png" title="example_5"/>
- <img src="images/examples/example_7_small.png" title="example_7"/>
</div>
<div class="buttons">
View
@@ -36,20 +36,29 @@ $ ->
count = 0
t = +new Date()
+ fillRect = (X, Y, size, r, g, b) ->
+ for y in [0 ... size]
+ idxData = ((Y + y) * W + X) * 4
+ for x in [0 ... size]
+ canvasData.data[idxData++] = r
+ canvasData.data[idxData++] = g
+ canvasData.data[idxData++] = b
+ canvasData.data[idxData++] = 255
+
worker.onmessage = (msg) ->
if msg.data[0] == 'result'
- y = msg.data[1]
- idxMsg = 2
+ size = msg.data[1]
+ y = msg.data[2]
+ idxMsg = 3
idxData = y * W * 4
- for x in [0 ... W]
- canvasData.data[idxData++] = msg.data[idxMsg++]
- canvasData.data[idxData++] = msg.data[idxMsg++]
- canvasData.data[idxData++] = msg.data[idxMsg++]
- canvasData.data[idxData++] = 255
+ for x in [0 ... W] by size
+ if size == 32 or not (x % (size * 2) == 0 and y % (size * 2) == 0)
+ fillRect x, y, size, msg.data[idxMsg++], msg.data[idxMsg++], msg.data[idxMsg++]
+
context.putImageData canvasData, 0, 0
- if ++count == H
- $('#time').html(+new Date() - t + 'ms')
+# if size == 1 and ++count == H
+ $('#time').html(Math.round((+new Date() - t) / 1000) + 's')
else if msg.data[0] == 'texture'
texture = msg.data[1]
View
@@ -137,12 +137,19 @@ textures_remaining = 0
textures[name] = content
if textures_remaining == 0
- for y in [0 ... scene.global.H]
- result = ['result']
- result.push y
- for x in [0 ... scene.global.W]
- color = process x, y, scene.global.upscale, scene.global.randomRays
- result.push ~~(color[0] * 255)
- result.push ~~(color[1] * 255)
- result.push ~~(color[2] * 255)
- postMessage result
+ size = 32
+ while size >= 1
+ for y in [0 ... scene.global.H] by size
+ result = ['result']
+ result.push size
+ result.push y
+ for x in [0 ... scene.global.W] by size
+ if size == 32 or not (x % (size * 2) == 0 and y % (size * 2) == 0)
+ color = process x, y, scene.global.upscale, scene.global.randomRays
+ result.push ~~(color[0] * 255)
+ result.push ~~(color[1] * 255)
+ result.push ~~(color[2] * 255)
+
+ postMessage result
+
+ size /= 2

0 comments on commit 757ca34

Please sign in to comment.