Code: http://www.assembla.com/code/cis565-final-project/subversion/nodes/raymarchBox.c?rev=35 or http://glsl.heroku.com/e#2306.2
Slides: http://alice-yang.com/cis565/FinalPresentation.pptx
Video:
vec2 pos = vec2(ceil(p.x/c.x), ceil(p.z/c.z));The idea behind this is: Using the mod function for repetition is like dividing the space into individual cells. By dividing p by c, you get the 2D position of the cell in this "checkerboard". The ceil function serves to ensure each cell is represented by only one (int) value, since the rand function always returns the same output when given the same input.
Windows and Ledges |
Variation at the price of speed |
float rand(vec2 n)Since the loop variables (i,j in this instance) are unique for each building, I can use vec2(i,j) as the seed for the rand function, which guarantees a unique value for each call. Not sure if this is the best way, but for now it will do.
{
return 0.5 + 0.5 *
fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);
}