【问题标题】:GLSL odd even merge sortGLSL奇偶合并排序
【发布时间】: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


    【解决方案1】:

    此示例的代码可用heremain.cpp 文件的第 298 行是您需要的:

    glUniform3fARB(oddevenMergeSort.getUniformLocation("Param1"),
        float(pstage+pstage),
        float(ppass%pstage),
        float((pstage+pstage)-(ppass%pstage)-1)
    );
    glUniform3fARB(oddevenMergeSort.getUniformLocation("Param2"),
        float(width),
        float(height),
        float(ppass)
    ); 
    

    使用int ppass = 1&lt;&lt;pass;int pstage = 1&lt;&lt;stage;

    【讨论】:

      猜你喜欢
      • 2016-03-29
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多