Permalink
Browse files

Hit R to toggle between stocastic and deterministic sampling

  • Loading branch information...
1 parent b734576 commit c812c4e833505c667124519bdee6db8aae66fabe @johshoff committed Mar 30, 2013
Showing with 13 additions and 2 deletions.
  1. +5 −0 app/assets/javascripts/home.js.coffee
  2. +8 −2 app/assets/javascripts/raytracer.js.coffee
@@ -31,6 +31,7 @@ $(document).ready(() ->
)
$(window).resize()
+
# keyboard input
key_w = false
key_s = false
@@ -57,6 +58,8 @@ $(document).ready(() ->
key_left = true
if e.which == 39
key_right = true
+ if e.which == "R".charCodeAt(0)
+ device.random_sampling = !device.random_sampling
)
$(window).keyup((e) ->
if e.which == "W".charCodeAt(0)
@@ -77,6 +80,8 @@ $(document).ready(() ->
key_right = false
)
+ device.random_sampling = false
+
# set up the scene
device.context = context
camera.pos.z = 1
@@ -198,8 +198,13 @@ render_block = (x, y, width, height, samples, index) ->
cell_height = height / rows
for i in [0...new_samples]
- the_x = x + (i % columns + 0.5) * cell_width
- the_y = y + (Math.floor(i / columns) + 0.5) * cell_height
+ if window.device.random_sampling == true
+ the_x = x + Math.random() * width
+ the_y = y + Math.random() * height
+ else
+ the_x = x + (i % columns + 0.5) * cell_width
+ the_y = y + (Math.floor(i / columns) + 0.5) * cell_height
+
the_sample = sample(the_x, the_y).times(1)
the_sample.x = the_x
the_sample.y = the_y
@@ -246,3 +251,4 @@ window.render = () ->
window.device.context.fillStyle = "#fff"
window.device.context.fillRect(device.x, device.y, device.width, device.height)
render_block(device.x, device.y, device.width, device.height, [], 0)
+

0 comments on commit c812c4e

Please sign in to comment.