- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 Scene Kit 中使用 SCNCamera 获得像鱼眼镜头那样的失真?
类似于这种图像的“鞠躬”:
//正如 Rickster 指出的那样,这种失真被称为“桶形失真”。
从文档中,这是让我对使用相机进行这种失真的可能性感兴趣的部分:
If you compute your own projection transform matrix, you can use this method to set it directly, overriding the transformation synthesized from the camera’s geometric properties.
最佳答案
您正在寻找的是所谓的桶形失真。
有几种方法可以做到这一点,所有方法都使用 GLSL 着色器。
您可以使用经典的 OpenGL 代码,例如 this example对于 Occulus Rift(你需要稍微改变着色器),或者我个人最喜欢的:SCNTechnique
.
创建一个包含 Barrel Fragment Shader (.fsh) 的技术,并设置它的 draw
DRAW_QUAD
的参数.然后,只需将该技术应用于您的相机。
您可以在此处找到桶形失真着色器的示例:http://www.geeks3d.com/20140213/glsl-shader-library-fish-eye-and-dome-and-barrel-distortion-post-processing-filters/2/
编辑:这是一个示例代码:
桶.json (这应该放在你的 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"
}
}
}
attribute vec4 a_position;
varying vec2 uv;
void main() {
gl_Position = a_position;
uv = a_position.xy;
}
// 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(p.y, p.x);
float radius = length(p);
radius = pow(radius, barrelPower);
p.x = radius * cos(theta);
p.y = 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);
}
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;
关于camera - 带场景套件相机的鱼眼广角 : Possible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31550971/
是否有任何 eclipse 插件允许在单独的编辑器中仅显示类中的一个方法?就像只将类中的一个方法复制到单独的编辑器中一样,但是可以编辑(保存、使用引用搜索、ctrl+单击以导航到引用的对象)此类。简而
我正在使用这个 d3 示例并实现了鱼眼。基本上,组元素包含矩形和文本元素。如何在鼠标悬停时使组 (bar+txt) 更宽? 这是我的 fiddle :http://jsfiddle.net/30114
我一直在尝试创建一个具有 d3 鱼眼笛卡尔失真且仅 x 轴失真的垂直条形图。 我已经成功地使用以下代码扭曲了鼠标悬停时垂直条的 x 位置: var maxMag = d3.max(dataset, f
我想在我的网站上放置一个水平鱼眼/停靠导航,但我需要它固定定位...我发现的所有导航都不支持固定定位。 以下是我找到的一些链接: jQuery OS X Dock #1 - 不支持固定定位 CSS D
由于 lenscorrection,使用 ffmpeg 似乎可以补偿鱼眼失真过滤器: ffmpeg -i in.mp4 -vf "lenscorrection=cx=0.5:cy=0.5:k1=-.2
我是一名优秀的程序员,十分优秀!