Wide-angle fisheye with a set of scenes Camera: maybe?

How to get distortion like what fisheye lens does with SCNCamera view in scene set?

Something like this "worship" of images:

enter image description here

// as Ricker noted, this distortion is known as "barrel distortion."

Of the documents, this is the part that intrigued me with the ability to do such distortions with the camera:

If you compute your own projection transformation matrix, you can use this method to set it directly by overriding the synthesized transformation from the geometric properties of the cameras.

Unfortunately, I do not know anything about the possibilities and possibilities of calculating my own projection transformation matrix. I hope this can be done with this distortion ... but I don’t know, therefore, the question.

Any other means with the camera is ideal. Too. Wanting to avoid workaround and get a more β€œorganic” look of such distortion when the camera rotates and moves around the scene.

Watch a video for skateboarding how it looks in real life.

+7
camera scenekit
source share
1 answer

What you are looking for is called Barrel Distrortion.

There are several ways to do this, they all use GLSL shaders.

You can use the classic OpenGL code, for example this example for Occulus Rift (you need to change the shader a bit), or my personal favorite: SCNTechnique .

Create a technique containing the trunk fragment shader (.fsh) and set the draw parameter to DRAW_QUAD . Then just apply the technique to your camera.

Here you can find an example of the Barrel Distortion shader: http://www.geeks3d.com/20140213/glsl-shader-library-fish-eye-and-dome-and-barrel-distortion-post-processing-filters/2/


EDIT: here is a sample code:

barrel.json (this should come with scnassets)

 { "passes" : { "barrel" : { "outputs" : { "color" : "COLOR" }, "inputs" : { "colorSampler" : "COLOR", "noiseSampler" : "noiseSymbol", "a_position" : "a_position-symbol" }, "program" : "art.scnassets/barrel", "draw" : "DRAW_QUAD" } }, "sequence" : [ "barrel" ], "symbols" : { "a_position-symbol" : { "semantic" : "vertex" }, "noiseSymbol" : { "image" : "noise.png", "type" : "sampler2D" }, "barrelPower" : { "type" : "float" } } } 

barrel.vsh

 attribute vec4 a_position; varying vec2 uv; void main() { gl_Position = a_position; uv = a_position.xy; } 

barrel.fsh

 // Adapted from : // http://www.geeks3d.com/20140213/glsl-shader-library-fish-eye-and-dome-and-barrel-distortion-post-processing-filters/2/ uniform sampler2D colorSampler; const float PI = 3.1415926535; uniform float barrelPower; varying vec2 uv; vec2 Distort(vec2 p) { float theta = atan(py, px); float radius = length(p); radius = pow(radius, barrelPower); px = radius * cos(theta); py = radius * sin(theta); return 0.5 * (p + 1.0); } void main() { vec2 rg = 2.0 * uv.xy - 1.0; vec2 uv2; float d = length(xy); if (d < 1.0){ uv2 = Distort(xy); }else{ uv2 = uv.xy; } gl_FragColor = texture2D(colorSampler, uv2); } 

something.m

 NSURL *url = [[NSBundle mainBundle] URLForResource:@"art.scnassets/barrel" withExtension:@"json"]; NSDictionary *tecDic = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL: url] options:nil error:nil]; SCNTechnique* technique = [SCNTechnique techniqueWithDictionary:tecDic]; [technique setValue: [NSNumber numberWithFloat:0.5] forKey:@"barrelPower"]; cameraNode.technique = technique; 
+8
source share

All Articles