【发布时间】:2014-09-29 06:22:12
【问题描述】:
我试图了解 gpugems 网站上的 the odd-ever merge sort example,但我无法弄清楚他们传递给制服的一些内容。这是整个着色器。
uniform vec3 Param1;
uniform vec3 Param2;
uniform sampler2D Data;
#define OwnPos gl_TexCoord[0]
// contents of the uniform data fields
#define TwoStage Param1.x
#define Pass_mod_Stage Param1.y
#define TwoStage_PmS_1 Param1.z
#define Width Param2.x
#define Height Param2.y
#define Pass Param2.z
void main(void){
// get self
vec4 self = texture2D(Data, OwnPos.xy);
float i = floor(OwnPos.x * Width) + floor(OwnPos.y * Height) * Width;
// my position within the range to merge
float j = floor(mod(i, TwoStage));
float compare;
if ( (j < Pass_mod_Stage) || (j > TwoStage_PmS_1) )
// must copy -> compare with self
compare = 0.0;
else
// must sort
if ( mod((j + Pass_mod_Stage) / Pass, 2.0) < 1.0)
// we are on the left side -> compare with partner on the right
compare = 1.0;
else
// we are on the right side -> compare with partner on the left
compare = -1.0;
// get the partner
float adr = i + compare * Pass;
vec4 partner = texture2D(Data, vec2(floor(mod(adr, Width)) / Width, floor(adr / Width) / Height));
// on the left it's a < operation; on the right it's a >= operation
gl_FragColor = (self.x * compare < partner.x * compare) ? self : partner;
}
让我感到困惑的部分是弄清楚他们分配给 Param1 和 Param2.z 的内容。
Param2.x 和 Param2.y 只是图像的宽度和高度。每次通过循环时,传递变量是否只是一个递增的数字?
Param1.x、Param1.y 和 Param1.z 让我完全被难住了。这个程序的 CPU 端是否应该发生一些他们不包括在内的事情?
任何帮助或澄清将不胜感激!谢谢
【问题讨论】:
标签: sorting glsl gpu mergesort fragment-shader