Last active
May 11, 2016 06:23
-
-
Save monkstone/b53549b335b13f97dbc28736f704b61f to your computer and use it in GitHub Desktop.
Attempt to sequence loading of images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Earth model with bump mapping, specular texture and dynamic cloud layer. | |
# Adapted from the THREE.js tutorial to processing by Andres Colubri, | |
# translated to JRubyArt by Martin Prout: | |
# http://learningthreejs.com/blog/2013/09/16/how-to-make-the-earth-in-webgl/ | |
attr_reader :earth, :clouds, :earth_shader, :cloud_shader, :earth_rotation | |
attr_reader :clouds_rotation, :target_angle | |
IMAGES = %w(earthmap1k.jpg earthcloudmap.jpg earthcloudmaptrans.jpg earthbump1k.jpg earthspec1k.jpg).freeze | |
TEXTURES = %i(earth cloud alpha bump spec).freeze | |
def setup | |
sketch_title 'Blue Marble' | |
@earth_rotation = 0 | |
@clouds_rotation = 0 | |
zipped = TEXTURES.zip(IMAGES) | |
loaded_array = zipped.map { |value| [value[0], load_image(value[1])] } | |
images = loaded_array.to_h | |
@earth_shader = load_shader('EarthFrag.glsl', 'EarthVert.glsl') | |
earth_shader.set('texMap', images[:earth]) | |
earth_shader.set('bumpMap', images[:bump]) | |
earth_shader.set('specularMap', images[:spec]) | |
earth_shader.set('bumpScale', 0.05) | |
@cloud_shader = load_shader('CloudFrag.glsl', 'CloudVert.glsl') | |
cloud_shader.set('texMap', images[:cloud]) | |
cloud_shader.set('alphaMap', images[:alpha]) | |
@earth = create_shape(SPHERE, 200) | |
earth.setStroke(false) | |
earth.setSpecular(color(125)) | |
earth.setShininess(10) | |
@clouds = create_shape(SPHERE, 201) | |
clouds.setStroke(false) | |
end | |
def draw | |
background(0) | |
translate(width / 2, height / 2) | |
point_light(255, 255, 255, 300, 0, 500) | |
target_angle = map1d(mouse_x, (0..width), (0..TWO_PI)) | |
@earth_rotation += 0.05 * (target_angle - earth_rotation) | |
shader(earth_shader) | |
push_matrix | |
rotate_y(earth_rotation) | |
shape(earth) | |
pop_matrix | |
shader(cloud_shader) | |
push_matrix | |
rotate_y(earth_rotation + clouds_rotation) | |
shape(clouds) | |
pop_matrix | |
@clouds_rotation += 0.001 | |
end | |
def settings | |
size(600, 600, P3D) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment