我有两个向量,其点数很大,但任意(v1.length 不需要等于 v2.length),我想将它们成对相乘。因为这是 AS3 代码大循环中的主要瓶颈,所以我想我应该尝试提取代码并通过 Pixel Bender 异步运行它。现在,为了表示数据,我将有两个 image2 变量作为输入。
如何从一张图像中获取像素并用另一张图像的每个像素进行计算?我刚刚学习 Pixel Bender,所以我可能忽略了一些循环的解决方法。
编辑:也许我需要澄清一下。假设我有这样的东西
var v1:Vector.<Point> = ...;
var v2:Vector.<Point> = ...;
var result:Vector.<Point> = ...;
for (var i:int = 0; i < v1.length; ++i)
for (var j:int = 0; j < v2.length; ++j)
result[i] += v1[i] * v2[j];
这是一个嵌套循环 - 我如何在 Pixel Bender 中模拟它?
I have two vectors of a large, but arbitrary (v1.length need not equal v2.length), number of points, and I want to pairwise multiply them. Because this is the main bottleneck in a large loop of AS3 code, I thought I would try to pull out the code and run it async via Pixel Bender. Now, to represent the data I would have two image2 variables as input.
How can I get a pixel from one image and do the calculations with each pixel of the other image? I am just learning Pixel Bender, so I may have overlooked some work around for looping.
EDIT: Perhaps I need to clarify. Let's say I have something like this
var v1:Vector.<Point> = ...;
var v2:Vector.<Point> = ...;
var result:Vector.<Point> = ...;
for (var i:int = 0; i < v1.length; ++i)
for (var j:int = 0; j < v2.length; ++j)
result[i] += v1[i] * v2[j];
This is a nested loop--how can I emulate it in Pixel Bender?
发布评论
评论(2)
闪光灯像素弯曲器中禁止循环和嵌套循环(内置循环除外)。
http://forums.adobe.com/thread/840318
http://blog.leeburrows.com/2011/02/pixelbender-filters-3/
我想例外的是 Pixelbender 3D,它处于测试阶段,设计用于与鼹鼠山一起使用蜜蜂。
编辑
以下是 Adobe 官方文档的链接,明确确认了上述内容:
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pixelbender/pdfs/pixelbender_guide.pdf
从第 17 页:
Pixel Bender Flash 播放器不支持:
->除了 if 和 else 之外的循环或控制结构。
当我发现自己的情况时,这对我来说真是一个无赖,我认为这是 Adobe 的一个重大失败。
Loops and nested loops (other than those built-in) are prohibited in pixel bender for flash.
http://forums.adobe.com/thread/840318
http://blog.leeburrows.com/2011/02/pixelbender-filters-3/
I guess the exception is pixelbender 3D, which is in beta and designed to be used with the molehill API's.
EDIT
Here are links that are official Adobe docs that explicitly confirm the above:
http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pixelbender/pdfs/pixelbender_guide.pdf
From page 17:
Pixel Bender in Flash Player does not support:
-> loops or control structures other than if and else.
This was a real bummer for me when I found out myself and I think this is a major failure on Adobe's part.
像素弯曲器内核中的主要函数是一个循环,并且会针对内核评估的每个像素进行回调。以下是有关如何准确实现您想要的操作(使用多个输入)的教程的链接。
http://www.adobe.com/devnet/pixelbender/articles/creating_effects_pt09 .html#articlecontentAdobe_numberedheader
本质上,它只是定义两个输入:
请注意,sampleNearest 的两个参数是源图像,以及要采样的像素的坐标。我相信 outCoord() 只是循环内的当前像素。如前所述,evaludatePixel(据我理解)对于输入中存在的每个像素被调用一次。这是上述代码的修改版本(来自链接),它同时读取两个输入的值:
这里有两个视频教程,将详细解释像素如何工作:
http://gotoandlearn.com/play.php?id=83
http://gotoandlearn.com/play.php?id=84
http://www.gotoandlearn.com/play.php?id=95
The main function inside a pixel bender kernel is a loop, and is called back for every single pixel being evaluated by the kernel. Here is a link to a tutorial on how do to exactly what you want (working with multiple inputs).
http://www.adobe.com/devnet/pixelbender/articles/creating_effects_pt09.html#articlecontentAdobe_numberedheader
Essentially it just comes down to defining two inputs:
Note that the two parameters of sampleNearest are the source image, and the coordinates of the pixel to sample. outCoord() I believe is simply the current pixel within the loop. As mentioned, evaludatePixel (to my understanding) is called once per pixel that exists in the input. Here is a modified version of the above code (from the link) that is reading the value of both inputs at the same time:
Here are two video tutorials that will explain much more about how pixel works at length:
http://gotoandlearn.com/play.php?id=83
http://gotoandlearn.com/play.php?id=84
http://www.gotoandlearn.com/play.php?id=95