# This example applies a post-processing texture filter to the offscreen canvas # in order to generate an angular fish-eye effect. # Based on the following discussion thread in the Processing forum: # http://forum.processing.org/topic/angular-fisheye # Some other resources about fish-eye projections: # 1) Excellent article from Paul Bourke on the math behind the angular fish-eye mapping # http://paulbourke.net/miscellaneous/domefisheye/fisheye/ # 2) Fish-eye effect implemented as a GLSL vertex shader: # http://pixelsorcery.wordpress.com/2010/07/13/fisheye-vertex-shader/ # 3) Another fish-eye GLSL shader (didn't test it though): # http://pages.cpsc.ucalgary.ca/~brosz/wiki/pmwiki.php/CSharp/08022008 load_libraries 'opengl', 'GLGraphics' include_package "codeanticode.glgraphics" attr_reader :canvas, :fisheye, :tex def setup() size(300, 300, GLConstants.GLGRAPHICS) # If your video card isn't up to it use following (no antialias) #@canvas = GLGraphicsOffScreen.new(self, width, height) @canvas = GLGraphicsOffScreen.new(self, width, height, true, 4) # Destination texture to store the fisheye image. @tex = GLTexture.new(self) @fisheye = GLTextureFilter.new(self, "FishEye.xml") # The aperture angle is specified in degrees. Values # greater than 180 can be specified, but the result won't # be consistent since the mapping is not one-to-one in # that case. fisheye.set_parameter_value("aperture", 180.0) end def draw() # Generating offscreen rendering: canvas.begin_draw canvas.background(0) canvas.lights canvas.stroke(255, 0, 0) (0...height).step(10) {|i| canvas.line(i, 0, i, height)} (0...width).step(10) {|j| canvas.line(0, j, width, j)} canvas.no_stroke canvas.translate(mouse_x, mouse_y, 100) canvas.rotate_x(frame_count * 0.01) canvas.rotate_y(frame_count * 0.01) canvas.box(50) canvas.end_draw fisheye.apply(canvas.get_texture(), tex) image(tex, 0, 0, width, height) end
This is is an example included with vanilla processing GLGraphics library be sure to copy the shader files from the GLGraphics/Examples/Output/FishEye/data into a data folder (where fish_eye.rb is saved). See also faux fish eye here.