Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you tried looking at <a href="http://paulbourke.net/miscellaneous/lenscorrection/" rel="nofollow noreferrer">Paul Bourke's example code for OpenGL</a>? I don't know if it's compatible with OpenGL-ES. Note the feedback about using "glCopyTexSubImage2D instead of doing a slow glReadPixels".</p> <p>AFAICT, Paul Bourke is doing essentially what you said, creating a distorted grid (your "dome object") to lay the image on. According to <a href="https://stackoverflow.com/questions/4279922/algorithm-for-creating-fisheye-effect-from-a-normal-image">this question</a>, that's a good approach.</p> <p><strong>Updated:</strong></p> <p>Or, since iPhone's OpenGL-ES supports shaders (at least in some versions), you could get better performance using a plane distortion technique like <a href="http://adrianboeing.blogspot.com/2011/01/webgl-tunnel-effect-explained.html" rel="nofollow noreferrer">this</a>. You'd just have to change the formulas for <code>uv.x</code> and <code>uv.y</code>. Then you wouldn't need to be concerned about breaking up the image into a grid of small polygons... you'd have single-pixel resolution for free. :-)</p> <p>Hm... maybe you need to define what kind of "fisheye" effect you are looking for. Seems there is <a href="http://paulbourke.net/miscellaneous/domefisheye/fisheye/" rel="nofollow noreferrer">more than one</a>.</p> <p>See also <a href="https://stackoverflow.com/questions/4246143/using-both-programmable-and-fixed-pipeline-functionality-in-opengl">this question</a>.</p> <p><strong>Updated again:</strong></p> <p>Here is some GLSL code I wrote to do a lens effect in a shader. I believe it's a hemispherical fisheye lens. It runs under WebGL, which uses OpenGL ES, so it should be adaptable for iPhone.</p> <pre><code>#ifdef GL_ES precision highp float; #endif uniform vec2 resolution; uniform vec4 mouse; uniform sampler2D tex0; // lens void main(void) { vec2 p = gl_FragCoord.xy / resolution.xy; vec2 m = mouse.xy / resolution.xy; float lensSize = 0.4; vec2 d = p - m; float r = sqrt(dot(d, d)); // distance of pixel from mouse vec2 uv; if (r &gt;= lensSize) { uv = p; } else { // Thanks to Paul Bourke for these formulas; see // http://paulbourke.net/miscellaneous/lenscorrection/ // and .../lenscorrection/lens.c // Choose one formula to uncomment: // SQUAREXY: // uv = m + vec2(d.x * abs(d.x), d.y * abs(d.y)); // SQUARER: uv = m + d * r; // a.k.a. m + normalize(d) * r * r // SINER: // uv = m + normalize(d) * sin(r * 3.14159 * 0.5); // ASINR: // uv = m + normalize(d) * asin(r) / (3.14159 * 0.5); } vec3 col = texture2D(tex0, vec2(uv.x, -uv.y)).xyz; gl_FragColor = vec4(col, 1.0); } </code></pre> <p>To test this, paste it into <a href="http://www.iquilezles.org/apps/shadertoy/" rel="nofollow noreferrer">ShaderToy</a> in a WebGL-enabled browser. Set input 0 to a texture like <a href="http://www.iquilezles.org/apps/shadertoy/presets/tex0.jpg" rel="nofollow noreferrer">http://www.iquilezles.org/apps/shadertoy/presets/tex0.jpg</a> or <a href="http://www.iquilezles.org/apps/shadertoy/presets/tex4.jpg" rel="nofollow noreferrer">http://www.iquilezles.org/apps/shadertoy/presets/tex4.jpg</a></p> <p>Click the play button, and drag the mouse around on the rendering area. The lens is centered on the mouse pointer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload