Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Progressive rendering

  • Loading branch information...
commit 757ca34a8ac50bfe2c1fcf182ffe6da00d5e7c15 1 parent 934699d
Christopher Chedeau authored January 02, 2012
4  raytracer.html
@@ -32,6 +32,8 @@
32 32
 				<img src="images/examples/light_3_small.png" title="light_3"/> 
33 33
 				<img src="images/examples/perlin_small.png" title="perlin"/> 
34 34
 				<img src="images/examples/perlin_sphere_small.png" title="perlin_sphere"/> 
  35
+				<img src="images/examples/example_5_small.png" title="example_5"/> 
  36
+				<img src="images/examples/example_7_small.png" title="example_7"/> 
35 37
 
36 38
 <!--
37 39
 				<img src="images/examples/sphere_checkerboard_small.png" title="sphere_checkerboard"/> 
@@ -41,8 +43,6 @@
41 43
 				<img src="images/examples/example_4_small.png" title="example_4"/> 
42 44
 				<img src="images/examples/example_6_small.png" title="example_6"/> 
43 45
 -->
44  
-				<img src="images/examples/example_5_small.png" title="example_5"/> 
45  
-				<img src="images/examples/example_7_small.png" title="example_7"/> 
46 46
 			</div>
47 47
 
48 48
 			<div class="buttons">
27  src/trace.coffee
@@ -36,20 +36,29 @@ $ ->
36 36
 		count = 0
37 37
 		t = +new Date()
38 38
 
  39
+		fillRect = (X, Y, size, r, g, b) ->
  40
+			for y in [0 ... size]
  41
+				idxData = ((Y + y) * W + X) * 4
  42
+				for x in [0 ... size]
  43
+					canvasData.data[idxData++] = r
  44
+					canvasData.data[idxData++] = g
  45
+					canvasData.data[idxData++] = b
  46
+					canvasData.data[idxData++] = 255
  47
+
39 48
 		worker.onmessage = (msg) ->
40 49
 			if msg.data[0] == 'result'
41  
-				y = msg.data[1]
42  
-				idxMsg = 2
  50
+				size = msg.data[1]
  51
+				y = msg.data[2]
  52
+				idxMsg = 3
43 53
 				idxData = y * W * 4
44  
-				for x in [0 ... W]
45  
-					canvasData.data[idxData++] = msg.data[idxMsg++]
46  
-					canvasData.data[idxData++] = msg.data[idxMsg++]
47  
-					canvasData.data[idxData++] = msg.data[idxMsg++]
48  
-					canvasData.data[idxData++] = 255
  54
+				for x in [0 ... W] by size
  55
+					if size == 32 or not (x % (size * 2) == 0 and y % (size * 2) == 0)
  56
+						fillRect x, y, size, msg.data[idxMsg++], msg.data[idxMsg++], msg.data[idxMsg++]
  57
+
49 58
 				context.putImageData canvasData, 0, 0
50 59
 
51  
-				if ++count == H
52  
-					$('#time').html(+new Date() - t + 'ms')
  60
+#				if size == 1 and ++count == H
  61
+				$('#time').html(Math.round((+new Date() - t) / 1000) + 's')
53 62
 
54 63
 			else if msg.data[0] == 'texture'
55 64
 				texture = msg.data[1]
25  src/worker.coffee
@@ -137,12 +137,19 @@ textures_remaining = 0
137 137
 			textures[name] = content
138 138
 
139 139
 		if textures_remaining == 0
140  
-			for y in [0 ... scene.global.H]
141  
-				result = ['result']
142  
-				result.push y
143  
-				for x in [0 ... scene.global.W]
144  
-					color = process x, y, scene.global.upscale, scene.global.randomRays
145  
-					result.push ~~(color[0] * 255)
146  
-					result.push ~~(color[1] * 255)
147  
-					result.push ~~(color[2] * 255)
148  
-				postMessage result
  140
+			size = 32
  141
+			while size >= 1
  142
+				for y in [0 ... scene.global.H] by size
  143
+					result = ['result']
  144
+					result.push size
  145
+					result.push y
  146
+					for x in [0 ... scene.global.W] by size
  147
+						if size == 32 or not (x % (size * 2) == 0 and y % (size * 2) == 0)
  148
+							color = process x, y, scene.global.upscale, scene.global.randomRays
  149
+							result.push ~~(color[0] * 255)
  150
+							result.push ~~(color[1] * 255)
  151
+							result.push ~~(color[2] * 255)
  152
+
  153
+					postMessage result
  154
+
  155
+				size /= 2

0 notes on commit 757ca34

Please sign in to comment.
Something went wrong with that request. Please try again.